| 1 | |
package org.apache.ojb.broker.metadata; |
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
import java.io.Serializable; |
| 19 | |
import java.util.Properties; |
| 20 | |
|
| 21 | |
import org.apache.commons.lang.SystemUtils; |
| 22 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
| 23 | |
import org.apache.commons.lang.builder.ToStringStyle; |
| 24 | |
import org.apache.ojb.broker.util.XmlHelper; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
public class SequenceDescriptor implements Serializable, XmlCapable, AttributeContainer |
| 39 | |
{ |
| 40 | |
|
| 41 | |
private static final long serialVersionUID = -5161713731380949398L; |
| 42 | |
private JdbcConnectionDescriptor jcd; |
| 43 | |
private Class sequenceManagerClass; |
| 44 | |
private Properties configurationProperties; |
| 45 | |
|
| 46 | |
public SequenceDescriptor(JdbcConnectionDescriptor jcd) |
| 47 | |
{ |
| 48 | |
this.jcd = jcd; |
| 49 | |
this.configurationProperties = new Properties(); |
| 50 | |
} |
| 51 | |
|
| 52 | |
public SequenceDescriptor(JdbcConnectionDescriptor jcd, Class sequenceManagerClass) |
| 53 | |
{ |
| 54 | |
this(jcd); |
| 55 | |
this.sequenceManagerClass = sequenceManagerClass; |
| 56 | |
} |
| 57 | |
|
| 58 | |
public JdbcConnectionDescriptor getJdbcConnectionDescriptor() |
| 59 | |
{ |
| 60 | |
return jcd; |
| 61 | |
} |
| 62 | |
|
| 63 | |
public void setJdbcConnectionDescriptor(JdbcConnectionDescriptor jcd) |
| 64 | |
{ |
| 65 | |
this.jcd = jcd; |
| 66 | |
} |
| 67 | |
|
| 68 | |
public Class getSequenceManagerClass() |
| 69 | |
{ |
| 70 | |
return sequenceManagerClass; |
| 71 | |
} |
| 72 | |
|
| 73 | |
public void setSequenceManagerClass(Class sequenceManagerClass) |
| 74 | |
{ |
| 75 | |
this.sequenceManagerClass = sequenceManagerClass; |
| 76 | |
} |
| 77 | |
|
| 78 | |
public void addAttribute(String attributeName, String attributeValue) |
| 79 | |
{ |
| 80 | |
configurationProperties.setProperty(attributeName, attributeValue); |
| 81 | |
} |
| 82 | |
|
| 83 | |
public String getAttribute(String key) |
| 84 | |
{ |
| 85 | |
return getAttribute(key, null); |
| 86 | |
} |
| 87 | |
|
| 88 | |
public String getAttribute(String attributeName, String defaultValue) |
| 89 | |
{ |
| 90 | |
String result = configurationProperties.getProperty(attributeName); |
| 91 | |
if(result == null) result = defaultValue; |
| 92 | |
return result; |
| 93 | |
} |
| 94 | |
|
| 95 | |
public Properties getConfigurationProperties() |
| 96 | |
{ |
| 97 | |
return configurationProperties; |
| 98 | |
} |
| 99 | |
|
| 100 | |
public void setConfigurationProperties(Properties configurationProperties) |
| 101 | |
{ |
| 102 | |
this.configurationProperties = configurationProperties; |
| 103 | |
} |
| 104 | |
|
| 105 | |
public String toString() |
| 106 | |
{ |
| 107 | |
ToStringBuilder buf = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE); |
| 108 | |
buf.append(" sequenceManagerClass", getSequenceManagerClass()). |
| 109 | |
append(" Properties", getConfigurationProperties()); |
| 110 | |
return buf.toString(); |
| 111 | |
} |
| 112 | |
|
| 113 | |
public String toXML() |
| 114 | |
{ |
| 115 | |
RepositoryTags tags = RepositoryTags.getInstance(); |
| 116 | |
String eol = SystemUtils.LINE_SEPARATOR; |
| 117 | |
StringBuffer buf = new StringBuffer( 1024 ); |
| 118 | |
|
| 119 | |
buf.append( " " ); |
| 120 | |
buf.append( tags.getOpeningTagNonClosingById( SEQUENCE_MANAGER ) ); |
| 121 | |
buf.append( eol ); |
| 122 | |
buf.append( " " ); |
| 123 | |
buf.append( tags.getAttribute( SEQUENCE_MANAGER_CLASS, "" + getSequenceManagerClass().getName() ) ); |
| 124 | |
buf.append( " >" ); |
| 125 | |
buf.append( eol ); |
| 126 | |
buf.append( " <!-- " ); |
| 127 | |
buf.append( eol ); |
| 128 | |
buf.append( " Add sequence manger properties here, using custom attributes" ); |
| 129 | |
buf.append( eol ); |
| 130 | |
buf.append( " e.g. <attribute attribute-name=\"grabSize\" attribute-value=\"20\"/>" ); |
| 131 | |
buf.append( eol ); |
| 132 | |
buf.append( " -->" ); |
| 133 | |
buf.append( eol ); |
| 134 | |
XmlHelper.appendSerializedAttributes(buf, " ", getConfigurationProperties()); |
| 135 | |
buf.append( " " ); |
| 136 | |
buf.append( tags.getClosingTagById( SEQUENCE_MANAGER ) ); |
| 137 | |
buf.append( eol ); |
| 138 | |
|
| 139 | |
return buf.toString(); |
| 140 | |
} |
| 141 | |
|
| 142 | |
} |