Index: org/exolab/castor/builder/MemberFactory.java
===================================================================
--- org/exolab/castor/builder/MemberFactory.java (Revision 6199)
+++ org/exolab/castor/builder/MemberFactory.java (Arbeitskopie)
@@ -66,21 +66,10 @@
* @author Keith Visco
* @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
*/
-public class MemberFactory {
+public class MemberFactory extends BaseFactory {
/**
- * The FieldInfo factory.
- */
- private FieldInfoFactory _infoFactory = null;
-
- /**
- * The BuilderConfiguration instance, for callbacks
- * to obtain certain configured properties
- */
- private BuilderConfiguration _config = null;
-
- /**
* Creates a new MemberFactory with default type factory.
*
* @param config the BuilderConfiguration
@@ -98,26 +87,16 @@
*/
public MemberFactory(BuilderConfiguration config, FieldInfoFactory infoFactory)
{
- super();
- if (config == null) {
- String err = "The 'BuilderConfiguration' argument must not be null.";
- throw new IllegalArgumentException(err);
- }
- _config = config;
-
- if (infoFactory == null)
- _infoFactory = new FieldInfoFactory();
- else
- _infoFactory = infoFactory;
+ super(config, infoFactory);
if (_config.generateExtraCollectionMethods()) {
- _infoFactory.setCreateExtraMethods(true);
+ this.infoFactory.setCreateExtraMethods(true);
}
String suffix = _config.getProperty(CollectionInfo.REFERENCE_SUFFIX_PROPERTY, null);
- _infoFactory.setReferenceMethodSuffix(suffix);
+ this.infoFactory.setReferenceMethodSuffix(suffix);
if (_config.boundPropertiesEnabled()) {
- _infoFactory.setBoundProperties(true);
+ this.infoFactory.setBoundProperties(true);
}
} //-- MemberFactory
@@ -140,13 +119,13 @@
String xmlName = null;
FieldInfo result = null;
if (any.getMaxOccurs() >1 || any.getMaxOccurs() <0 ) {
- result = _infoFactory.createCollection(xsType, vName, "anyObject");
+ result = this.infoFactory.createCollection(xsType, vName, "anyObject");
XSList xsList = ((CollectionInfo)result).getXSList();
xsList.setMinimumSize(any.getMinOccurs());
xsList.setMaximumSize(any.getMaxOccurs());
}
else
- result = _infoFactory.createFieldInfo(xsType, vName);
+ result = this.infoFactory.createFieldInfo(xsType, vName);
if (any.getMinOccurs() > 0 )
result.setRequired(true);
else
@@ -182,7 +161,7 @@
String fieldName = "_choiceValue";
XSType xsType = new XSClass(SGTypes.Object, "any");
FieldInfo fInfo = null;
- fInfo = _infoFactory.createFieldInfo(xsType,fieldName);
+ fInfo = this.infoFactory.createFieldInfo(xsType,fieldName);
fInfo.setNodeType(XMLInfo.ELEMENT_TYPE);
fInfo.setComment("Internal choice value storage");
fInfo.setRequired(false);
@@ -203,14 +182,14 @@
String fieldName = "_content"; //new xsType()???
FieldInfo fInfo = null;
if (xsType.getType() == XSType.COLLECTION) {
- fInfo = _infoFactory.createCollection( ((XSList) xsType).getContentType(),
+ fInfo = this.infoFactory.createCollection( ((XSList) xsType).getContentType(),
fieldName,
null);
}
else {
- fInfo = _infoFactory.createFieldInfo(xsType,fieldName);
+ fInfo = this.infoFactory.createFieldInfo(xsType,fieldName);
}
fInfo.setNodeType(XMLInfo.TEXT_TYPE);
fInfo.setComment("internal content storage");
@@ -358,7 +337,7 @@
//--we are processing a container object (group)
//--so we need to adjust the name of the members of the collection
CollectionInfo cInfo;
- cInfo = _infoFactory.createCollection(xsType, vName, memberName, component.getCollectionType());
+ cInfo = this.infoFactory.createCollection(xsType, vName, memberName, component.getCollectionType());
XSList xsList = cInfo.getXSList();
if (!simpleTypeCollection) {
@@ -369,16 +348,16 @@
} else {
switch (xsType.getType()) {
case XSType.ID_TYPE:
- fieldInfo = _infoFactory.createIdentity(memberName);
+ fieldInfo = this.infoFactory.createIdentity(memberName);
break;
case XSType.COLLECTION:
String collectionName = component.getCollectionType();
- fieldInfo = _infoFactory.createCollection( ((XSList) xsType).getContentType(),
+ fieldInfo = this.infoFactory.createCollection( ((XSList) xsType).getContentType(),
memberName,
memberName, collectionName);
break;
default:
- fieldInfo = _infoFactory.createFieldInfo(xsType, memberName);
+ fieldInfo = this.infoFactory.createFieldInfo(xsType, memberName);
break;
}
}
@@ -550,42 +529,4 @@
return null;
} //-- createComment
- /**
- * Normalizes the given string for use in comments
- *
- * @param value the String to normalize
- **/
- private static String normalize (String value) {
-
- if (value == null) return null;
-
- char[] chars = value.toCharArray();
- char[] newChars = new char[chars.length];
- int count = 0;
- int i = 0;
- boolean skip = false;
-
- while (i < chars.length) {
- char ch = chars[i++];
-
- if ((ch == ' ') || (ch == '\t')) {
- if ((!skip) && (count != 0)) {
- newChars[count++] = ' ';
- }
- skip = true;
- }
- else {
- if (count == 0) {
- //-- ignore new lines only if count == 0
- if ((ch == '\r') || (ch == '\n')) {
- continue;
- }
- }
- newChars[count++] = ch;
- skip = false;
- }
- }
- return new String(newChars,0,count);
- }
-
} //-- MemberFactory
Index: org/exolab/castor/builder/BaseFactory.java
===================================================================
--- org/exolab/castor/builder/BaseFactory.java (Revision 0)
+++ org/exolab/castor/builder/BaseFactory.java (Revision 0)
@@ -0,0 +1,79 @@
+package org.exolab.castor.builder;
+
+public class BaseFactory {
+
+ /**
+ * The BuilderConfiguration instance, for callbacks
+ * to obtain certain configured properties
+ */
+ protected BuilderConfiguration _config = null;
+ /**
+ * The type factory.
+ **/
+ protected FieldInfoFactory infoFactory = null;
+
+ /**
+ * Creates an instance of this class.
+ * @param config XML code generator configuration
+ * @param infoFactory
+ */
+ public BaseFactory(BuilderConfiguration config, FieldInfoFactory infoFactory) {
+ if (config == null) {
+ String err = "The 'BuilderConfiguration' argument must not be null.";
+ throw new IllegalArgumentException(err);
+ }
+ _config = config;
+
+ if (infoFactory == null) {
+ this.infoFactory = new FieldInfoFactory();
+ } else {
+ this.infoFactory = infoFactory;
+ }
+
+ }
+
+ /**
+ * Normalizes the given string for use in comments
+ *
+ * @param value the String to normalize
+ **/
+ protected String normalize(String value) {
+
+ if (value == null) return null;
+
+ char[] chars = value.toCharArray();
+ char[] newChars = new char[chars.length + 10];
+ int count = 0;
+ int i = 0;
+ boolean skip = false;
+
+ while (i < chars.length) {
+ char ch = chars[i++];
+
+ if ((ch == ' ') || (ch == '\t')) {
+ if ((!skip) && (count != 0)) {
+ newChars[count++] = ' ';
+ }
+ skip = true;
+ } else if (ch =='*') {
+ if (chars[i] == '/') {
+ newChars[count++] = ch;
+ newChars[count++] = '\\';
+ }
+ }
+ else {
+ if (count == 0) {
+ //-- ignore new lines only if count == 0
+ if ((ch == '\r') || (ch == '\n')) {
+ continue;
+ }
+ }
+ newChars[count++] = ch;
+ skip = false;
+ }
+ }
+ return new String(newChars,0,count);
+ }
+
+
+}
Index: org/exolab/castor/builder/SourceFactory.java
===================================================================
--- org/exolab/castor/builder/SourceFactory.java (Revision 6199)
+++ org/exolab/castor/builder/SourceFactory.java (Arbeitskopie)
@@ -99,7 +99,7 @@
* @author Arnaud Blandin
* @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
*/
-public class SourceFactory {
+public class SourceFactory extends BaseFactory {
private static final String ENUM_ACCESS_INTERFACE =
@@ -114,11 +114,6 @@
private static final String ITEM_NAME = "Item";
/**
- * The type factory.
- **/
- private FieldInfoFactory infoFactory = null;
-
- /**
* The current Binding for which we are creating classes
*/
private ExtendedBinding _binding = null;
@@ -156,11 +151,6 @@
private boolean _caseInsensitive = false;
/**
- * The BuilderConfiguration instance
- */
- private BuilderConfiguration _config = null;
-
- /**
* The TypeConversion instance to use for mapping
* SimpleTypes into XSTypes
*/
@@ -183,17 +173,8 @@
* @param infoFactory the FieldInfoFactory to use
*/
public SourceFactory(BuilderConfiguration config, FieldInfoFactory infoFactory) {
- super();
- if (config == null) {
- String error = "The argument 'config' must not be null.";
- throw new IllegalArgumentException(error);
- }
- _config = config;
- if (infoFactory == null)
- this.infoFactory = new FieldInfoFactory();
- else
- this.infoFactory = infoFactory;
-
+ super(config, infoFactory);
+
// set the config into the info factory (CASTOR-1346)
infoFactory.setBoundProperties(config.boundPropertiesEnabled());
@@ -2256,45 +2237,6 @@
} //-- escapeValue
-
- /**
- * Normalizes the given string for use in comments
- *
- * @param value the String to normalize
- **/
- private static String normalize (String value) {
-
- if (value == null) return null;
-
- char[] chars = value.toCharArray();
- char[] newChars = new char[chars.length];
- int count = 0;
- int i = 0;
- boolean skip = false;
-
- while (i < chars.length) {
- char ch = chars[i++];
-
- if ((ch == ' ') || (ch == '\t')) {
- if ((!skip) && (count != 0)) {
- newChars[count++] = ' ';
- }
- skip = true;
- }
- else {
- if (count == 0) {
- //-- ignore new lines only if count == 0
- if ((ch == '\r') || (ch == '\n')) {
- continue;
- }
- }
- newChars[count++] = ch;
- skip = false;
- }
- }
- return new String(newChars,0,count);
- }
-
} //-- SourceFactory