001: package org.apache.ojb.broker.metadata;
002:
003: /* Copyright 2003-2005 The Apache Software Foundation
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: import java.io.Serializable;
019: import java.util.Properties;
020:
021: import org.apache.commons.lang.SystemUtils;
022: import org.apache.commons.lang.builder.ToStringBuilder;
023: import org.apache.commons.lang.builder.ToStringStyle;
024: import org.apache.ojb.broker.util.XmlHelper;
025:
026: /**
027: * Encapsulates sequence manager configuration properties managed by
028: * {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor}.
029: * <br/>
030: * All sequence manager implementation specific configuration
031: * attributes are represented by key/value pairs in a
032: * <code>Properties</code> object and could be reached via
033: * {@link #getConfigurationProperties} or {@link #getAttribute(String key)}.
034: *
035: * @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
036: * @version $Id: SequenceDescriptor.java,v 1.11.2.2 2005/04/26 03:41:36 mkalen Exp $
037: */
038: public class SequenceDescriptor implements Serializable, XmlCapable,
039: AttributeContainer {
040:
041: private static final long serialVersionUID = -5161713731380949398L;
042: private JdbcConnectionDescriptor jcd;
043: private Class sequenceManagerClass;
044: private Properties configurationProperties;
045:
046: public SequenceDescriptor(JdbcConnectionDescriptor jcd) {
047: this .jcd = jcd;
048: this .configurationProperties = new Properties();
049: }
050:
051: public SequenceDescriptor(JdbcConnectionDescriptor jcd,
052: Class sequenceManagerClass) {
053: this (jcd);
054: this .sequenceManagerClass = sequenceManagerClass;
055: }
056:
057: public JdbcConnectionDescriptor getJdbcConnectionDescriptor() {
058: return jcd;
059: }
060:
061: public void setJdbcConnectionDescriptor(JdbcConnectionDescriptor jcd) {
062: this .jcd = jcd;
063: }
064:
065: public Class getSequenceManagerClass() {
066: return sequenceManagerClass;
067: }
068:
069: public void setSequenceManagerClass(Class sequenceManagerClass) {
070: this .sequenceManagerClass = sequenceManagerClass;
071: }
072:
073: public void addAttribute(String attributeName, String attributeValue) {
074: configurationProperties.setProperty(attributeName,
075: attributeValue);
076: }
077:
078: public String getAttribute(String key) {
079: return getAttribute(key, null);
080: }
081:
082: public String getAttribute(String attributeName, String defaultValue) {
083: String result = configurationProperties
084: .getProperty(attributeName);
085: if (result == null)
086: result = defaultValue;
087: return result;
088: }
089:
090: public Properties getConfigurationProperties() {
091: return configurationProperties;
092: }
093:
094: public void setConfigurationProperties(
095: Properties configurationProperties) {
096: this .configurationProperties = configurationProperties;
097: }
098:
099: public String toString() {
100: ToStringBuilder buf = new ToStringBuilder(this ,
101: ToStringStyle.MULTI_LINE_STYLE);
102: buf
103: .append(" sequenceManagerClass",
104: getSequenceManagerClass()).append(
105: " Properties", getConfigurationProperties());
106: return buf.toString();
107: }
108:
109: public String toXML() {
110: RepositoryTags tags = RepositoryTags.getInstance();
111: String eol = SystemUtils.LINE_SEPARATOR;
112: StringBuffer buf = new StringBuffer(1024);
113: //opening tag + attributes
114: buf.append(" ");
115: buf.append(tags.getOpeningTagNonClosingById(SEQUENCE_MANAGER));
116: buf.append(eol);
117: buf.append(" ");
118: buf.append(tags.getAttribute(SEQUENCE_MANAGER_CLASS, ""
119: + getSequenceManagerClass().getName()));
120: buf.append(" >");
121: buf.append(eol);
122: buf.append(" <!-- ");
123: buf.append(eol);
124: buf
125: .append(" Add sequence manger properties here, using custom attributes");
126: buf.append(eol);
127: buf
128: .append(" e.g. <attribute attribute-name=\"grabSize\" attribute-value=\"20\"/>");
129: buf.append(eol);
130: buf.append(" -->");
131: buf.append(eol);
132: XmlHelper.appendSerializedAttributes(buf, " ",
133: getConfigurationProperties());
134: buf.append(" ");
135: buf.append(tags.getClosingTagById(SEQUENCE_MANAGER));
136: buf.append(eol);
137:
138: return buf.toString();
139: }
140:
141: }
|