Coverage Report - org.apache.ojb.broker.metadata.SequenceDescriptor
 
Classes in this File Line Coverage Branch Coverage Complexity
SequenceDescriptor
N/A
N/A
1.077
 
 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;
 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  
  * 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.1 2007-08-24 22:17:29 ewestfal Exp $
 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  
         //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  
 }