View Javadoc

1   /*
2    * Copyright 2001-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */ 
16  package org.apache.commons.betwixt;
17  
18  import java.io.Serializable;
19  
20  import org.apache.commons.betwixt.strategy.DefaultObjectStringConverter;
21  import org.apache.commons.betwixt.strategy.ObjectStringConverter;
22  
23  /*** <p>Stores mapping phase binding configuration.</p>
24    *
25    * <p>There are two phase in Betwixt's processing.
26    * The first phase is the introspection of the bean.
27    * Strutural configuration settings effect this phase.
28    * The second phase comes when Betwixt dynamically uses
29    * reflection to execute the mapping.
30    * This object stores configuration settings pertaining 
31    * to the second phase.</p>
32    *
33    * <p>These common settings have been collected into one class
34    * to make round tripping easier since the same <code>BindingConfiguration</code>
35    * can be shared.</p> 
36    *
37    * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
38    * @since 0.5
39    */
40  public class BindingConfiguration implements Serializable {
41  
42      /*** Should <code>ID</code>'s and <code>IDREF</code> be used cross-reference matching objects? */
43      private boolean mapIDs = true;
44      /*** Converts objects &lt-&gt; strings */
45      private ObjectStringConverter objectStringConverter;
46      /*** The name of the classname attribute used when creating derived beans */
47      private String classNameAttribute = "className";
48      
49      /***
50       * Constructs a BindingConfiguration with default properties.
51       */
52      public BindingConfiguration() {
53          this(new DefaultObjectStringConverter(), true);
54      }
55      
56      /*** 
57       * Constructs a BindingConfiguration
58       * @param objectStringConverter the <code>ObjectStringConverter</code>
59       * to be used to convert Objects &lt;-&gt; Strings
60       * @param mapIDs should <code>ID</code>'s and <code>IDREF</code> be used to cross-reference
61       */ 
62      public BindingConfiguration(ObjectStringConverter objectStringConverter, boolean mapIDs) {
63          setObjectStringConverter(objectStringConverter);
64          setMapIDs(mapIDs);
65      }
66      
67      /***
68        * Gets the Object &lt;-&gt; String converter.
69        * @return the ObjectStringConverter to use, not null
70        */
71      public ObjectStringConverter getObjectStringConverter() {
72          return objectStringConverter;
73      }
74      
75      /***
76        * Sets the Object &lt;-&gt; String converter.
77        * @param objectStringConverter the ObjectStringConverter to be used, not null
78        */
79      public void setObjectStringConverter(ObjectStringConverter objectStringConverter) {
80          this.objectStringConverter = objectStringConverter;
81      }
82      
83      /*** 
84       * Should <code>ID</code>'s and <code>IDREF</code> attributes 
85       * be used to cross-reference matching objects? 
86       *
87       * @return true if <code>ID</code> and <code>IDREF</code> 
88       * attributes should be used to cross-reference instances
89       */
90      public boolean getMapIDs() {
91          return mapIDs;
92      }
93      
94      /***
95       *Should <code>ID</code>'s and <code>IDREF</code> attributes 
96       * be used to cross-reference matching objects? 
97       *
98       * @param mapIDs pass true if <code>ID</code>'s should be used to cross-reference
99       */
100     public void setMapIDs(boolean mapIDs) {
101         this.mapIDs = mapIDs;
102     }        
103     
104     /***
105      * The name of the attribute which can be specified in the XML to override the
106      * type of a bean used at a certain point in the schema.
107      *
108      * <p>The default value is 'className'.</p>
109      * 
110      * @return The name of the attribute used to overload the class name of a bean
111      */
112     public String getClassNameAttribute() {
113         return classNameAttribute;
114     }
115 
116     /***
117      * Sets the name of the attribute which can be specified in 
118      * the XML to override the type of a bean used at a certain 
119      * point in the schema.
120      *
121      * <p>The default value is 'className'.</p>
122      * 
123      * @param classNameAttribute The name of the attribute used to overload the class name of a bean
124      */
125     public void setClassNameAttribute(String classNameAttribute) {
126         this.classNameAttribute = classNameAttribute;
127     }
128 }