KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > broker > metadata > SequenceDescriptor


1 package org.apache.ojb.broker.metadata;
2
3 /* Copyright 2003-2005 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 import java.io.Serializable JavaDoc;
19 import java.util.Properties JavaDoc;
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  * Encapsulates sequence manager configuration properties managed by
28  * {@link org.apache.ojb.broker.metadata.JdbcConnectionDescriptor}.
29  * <br/>
30  * All sequence manager implementation specific configuration
31  * attributes are represented by key/value pairs in a
32  * <code>Properties</code> object and could be reached via
33  * {@link #getConfigurationProperties} or {@link #getAttribute(String key)}.
34  *
35  * @author <a HREF="mailto:armin@codeAuLait.de">Armin Waibel</a>
36  * @version $Id: SequenceDescriptor.java,v 1.11.2.2 2005/04/26 03:41:36 mkalen Exp $
37  */

38 public class SequenceDescriptor implements Serializable JavaDoc, XmlCapable, AttributeContainer
39 {
40
41     private static final long serialVersionUID = -5161713731380949398L;
42     private JdbcConnectionDescriptor jcd;
43     private Class JavaDoc sequenceManagerClass;
44     private Properties JavaDoc configurationProperties;
45
46     public SequenceDescriptor(JdbcConnectionDescriptor jcd)
47     {
48         this.jcd = jcd;
49         this.configurationProperties = new Properties JavaDoc();
50     }
51
52     public SequenceDescriptor(JdbcConnectionDescriptor jcd, Class JavaDoc 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 JavaDoc getSequenceManagerClass()
69     {
70         return sequenceManagerClass;
71     }
72
73     public void setSequenceManagerClass(Class JavaDoc sequenceManagerClass)
74     {
75         this.sequenceManagerClass = sequenceManagerClass;
76     }
77
78     public void addAttribute(String JavaDoc attributeName, String JavaDoc attributeValue)
79     {
80         configurationProperties.setProperty(attributeName, attributeValue);
81     }
82
83     public String JavaDoc getAttribute(String JavaDoc key)
84     {
85         return getAttribute(key, null);
86     }
87
88     public String JavaDoc getAttribute(String JavaDoc attributeName, String JavaDoc defaultValue)
89     {
90         String JavaDoc result = configurationProperties.getProperty(attributeName);
91         if(result == null) result = defaultValue;
92         return result;
93     }
94
95     public Properties JavaDoc getConfigurationProperties()
96     {
97         return configurationProperties;
98     }
99
100     public void setConfigurationProperties(Properties JavaDoc configurationProperties)
101     {
102         this.configurationProperties = configurationProperties;
103     }
104
105     public String JavaDoc 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 JavaDoc toXML()
114     {
115         RepositoryTags tags = RepositoryTags.getInstance();
116         String JavaDoc eol = SystemUtils.LINE_SEPARATOR;
117         StringBuffer JavaDoc buf = new StringBuffer JavaDoc( 1024 );
118         //opening tag + attributes
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 }
143
Popular Tags