001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. 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: package org.apache.commons.betwixt;
018:
019: import java.io.Serializable;
020:
021: import org.apache.commons.betwixt.strategy.DefaultObjectStringConverter;
022: import org.apache.commons.betwixt.strategy.IdStoringStrategy;
023: import org.apache.commons.betwixt.strategy.ObjectStringConverter;
024: import org.apache.commons.betwixt.strategy.ValueSuppressionStrategy;
025:
026: /** <p>Stores mapping phase binding configuration.</p>
027: *
028: * <p>There are two phase in Betwixt's processing.
029: * The first phase is the introspection of the bean.
030: * Strutural configuration settings effect this phase.
031: * The second phase comes when Betwixt dynamically uses
032: * reflection to execute the mapping.
033: * This object stores configuration settings pertaining
034: * to the second phase.</p>
035: *
036: * <p>These common settings have been collected into one class
037: * to make round tripping easier since the same <code>BindingConfiguration</code>
038: * can be shared.</p>
039: *
040: * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
041: * @since 0.5
042: */
043: public class BindingConfiguration implements Serializable {
044:
045: /** Should <code>ID</code>'s and <code>IDREF</code> be used cross-reference matching objects? */
046: private boolean mapIDs = true;
047: /** Converts objects <-> strings */
048: private ObjectStringConverter objectStringConverter;
049: /** The name of the classname attribute used when creating derived beans */
050: private String classNameAttribute = "className";
051: /** Strategy for suppressing attributes with certain values when writing */
052: private ValueSuppressionStrategy valueSuppressionStrategy = ValueSuppressionStrategy.DEFAULT;
053: /** Strategy for storing and accessing ID values */
054: private IdStoringStrategy idStoringStrategy = IdStoringStrategy
055: .createDefault();
056:
057: /**
058: * Constructs a BindingConfiguration with default properties.
059: */
060: public BindingConfiguration() {
061: this (new DefaultObjectStringConverter(), true);
062: }
063:
064: /**
065: * Constructs a BindingConfiguration
066: * @param objectStringConverter the <code>ObjectStringConverter</code>
067: * to be used to convert Objects <-> Strings
068: * @param mapIDs should <code>ID</code>'s and <code>IDREF</code> be used to cross-reference
069: */
070: public BindingConfiguration(
071: ObjectStringConverter objectStringConverter, boolean mapIDs) {
072: setObjectStringConverter(objectStringConverter);
073: setMapIDs(mapIDs);
074: }
075:
076: /**
077: * Gets the Object <-> String converter.
078: * @return the ObjectStringConverter to use, not null
079: */
080: public ObjectStringConverter getObjectStringConverter() {
081: return objectStringConverter;
082: }
083:
084: /**
085: * Sets the Object <-> String converter.
086: * @param objectStringConverter the ObjectStringConverter to be used, not null
087: */
088: public void setObjectStringConverter(
089: ObjectStringConverter objectStringConverter) {
090: this .objectStringConverter = objectStringConverter;
091: }
092:
093: /**
094: * Should <code>ID</code>'s and <code>IDREF</code> attributes
095: * be used to cross-reference matching objects?
096: *
097: * @return true if <code>ID</code> and <code>IDREF</code>
098: * attributes should be used to cross-reference instances
099: */
100: public boolean getMapIDs() {
101: return mapIDs;
102: }
103:
104: /**
105: *Should <code>ID</code>'s and <code>IDREF</code> attributes
106: * be used to cross-reference matching objects?
107: *
108: * @param mapIDs pass true if <code>ID</code>'s should be used to cross-reference
109: */
110: public void setMapIDs(boolean mapIDs) {
111: this .mapIDs = mapIDs;
112: }
113:
114: /**
115: * The name of the attribute which can be specified in the XML to override the
116: * type of a bean used at a certain point in the schema.
117: *
118: * <p>The default value is 'className'.</p>
119: *
120: * @return The name of the attribute used to overload the class name of a bean
121: */
122: public String getClassNameAttribute() {
123: return classNameAttribute;
124: }
125:
126: /**
127: * Sets the name of the attribute which can be specified in
128: * the XML to override the type of a bean used at a certain
129: * point in the schema.
130: *
131: * <p>The default value is 'className'.</p>
132: *
133: * @param classNameAttribute The name of the attribute used to overload the class name of a bean
134: */
135: public void setClassNameAttribute(String classNameAttribute) {
136: this .classNameAttribute = classNameAttribute;
137: }
138:
139: /**
140: * Gets the <code>ValueSuppressionStrategy</code>.
141: * This is used to control the expression of attributes with certain values.
142: * @since 0.7
143: * @return <code>ValueSuppressionStrategy</code>, not null
144: */
145: public ValueSuppressionStrategy getValueSuppressionStrategy() {
146: return valueSuppressionStrategy;
147: }
148:
149: /**
150: * Sets the <code>ValueSuppressionStrategy</code>.
151: * This is used to control the expression of attributes with certain values.
152: * @since 0.7
153: * @param valueSuppressionStrategy <code>ValueSuppressionStrategy</code>, not null
154: */
155: public void setValueSuppressionStrategy(
156: ValueSuppressionStrategy valueSuppressionStrategy) {
157: this .valueSuppressionStrategy = valueSuppressionStrategy;
158: }
159:
160: /**
161: * Gets the strategy used to manage storage and retrieval of id's.
162: *
163: * @since 0.7
164: * @return Returns the <code>IdStoringStrategy</code>, not null
165: */
166: public IdStoringStrategy getIdMappingStrategy() {
167: return idStoringStrategy;
168: }
169:
170: /**
171: * Sets the strategy used to manage storage and retrieval of id's.
172: *
173: * @since 0.7
174: * @param idMappingStrategy
175: * <code>IdStoringStrategy</code> to be set, not null
176: */
177: public void setIdMappingStrategy(IdStoringStrategy idMappingStrategy) {
178: this.idStoringStrategy = idMappingStrategy;
179: }
180: }
|