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. import java.io.Serializable;
  18. import org.apache.commons.betwixt.strategy.DefaultObjectStringConverter;
  19. import org.apache.commons.betwixt.strategy.ObjectStringConverter;
  20. /** <p>Stores mapping phase binding configuration.</p>
  21. *
  22. * <p>There are two phase in Betwixt's processing.
  23. * The first phase is the introspection of the bean.
  24. * Strutural configuration settings effect this phase.
  25. * The second phase comes when Betwixt dynamically uses
  26. * reflection to execute the mapping.
  27. * This object stores configuration settings pertaining
  28. * to the second phase.</p>
  29. *
  30. * <p>These common settings have been collected into one class
  31. * to make round tripping easier since the same <code>BindingConfiguration</code>
  32. * can be shared.</p>
  33. *
  34. * @author <a href="mailto:rdonkin@apache.org">Robert Burrell Donkin</a>
  35. * @since 0.5
  36. */
  37. public class BindingConfiguration implements Serializable {
  38. /** Should <code>ID</code>'s and <code>IDREF</code> be used cross-reference matching objects? */
  39. private boolean mapIDs = true;
  40. /** Converts objects <-> strings */
  41. private ObjectStringConverter objectStringConverter;
  42. /** The name of the classname attribute used when creating derived beans */
  43. private String classNameAttribute = "className";
  44. /**
  45. * Constructs a BindingConfiguration with default properties.
  46. */
  47. public BindingConfiguration() {
  48. this(new DefaultObjectStringConverter(), true);
  49. }
  50. /**
  51. * Constructs a BindingConfiguration
  52. * @param objectStringConverter the <code>ObjectStringConverter</code>
  53. * to be used to convert Objects <-> Strings
  54. * @param mapIDs should <code>ID</code>'s and <code>IDREF</code> be used to cross-reference
  55. */
  56. public BindingConfiguration(ObjectStringConverter objectStringConverter, boolean mapIDs) {
  57. setObjectStringConverter(objectStringConverter);
  58. setMapIDs(mapIDs);
  59. }
  60. /**
  61. * Gets the Object <-> String converter.
  62. * @return the ObjectStringConverter to use, not null
  63. */
  64. public ObjectStringConverter getObjectStringConverter() {
  65. return objectStringConverter;
  66. }
  67. /**
  68. * Sets the Object <-> String converter.
  69. * @param objectStringConverter the ObjectStringConverter to be used, not null
  70. */
  71. public void setObjectStringConverter(ObjectStringConverter objectStringConverter) {
  72. this.objectStringConverter = objectStringConverter;
  73. }
  74. /**
  75. * Should <code>ID</code>'s and <code>IDREF</code> attributes
  76. * be used to cross-reference matching objects?
  77. *
  78. * @return true if <code>ID</code> and <code>IDREF</code>
  79. * attributes should be used to cross-reference instances
  80. */
  81. public boolean getMapIDs() {
  82. return mapIDs;
  83. }
  84. /**
  85. *Should <code>ID</code>'s and <code>IDREF</code> attributes
  86. * be used to cross-reference matching objects?
  87. *
  88. * @param mapIDs pass true if <code>ID</code>'s should be used to cross-reference
  89. */
  90. public void setMapIDs(boolean mapIDs) {
  91. this.mapIDs = mapIDs;
  92. }
  93. /**
  94. * The name of the attribute which can be specified in the XML to override the
  95. * type of a bean used at a certain point in the schema.
  96. *
  97. * <p>The default value is 'className'.</p>
  98. *
  99. * @return The name of the attribute used to overload the class name of a bean
  100. */
  101. public String getClassNameAttribute() {
  102. return classNameAttribute;
  103. }
  104. /**
  105. * Sets the name of the attribute which can be specified in
  106. * the XML to override the type of a bean used at a certain
  107. * point in the schema.
  108. *
  109. * <p>The default value is 'className'.</p>
  110. *
  111. * @param classNameAttribute The name of the attribute used to overload the class name of a bean
  112. */
  113. public void setClassNameAttribute(String classNameAttribute) {
  114. this.classNameAttribute = classNameAttribute;
  115. }
  116. }