org.exolab.castor.builder

Class CollectionInfo

Known Direct Subclasses:
CollectionInfoJ2, CollectionInfoODMG30

public class CollectionInfo
extends FieldInfo

A helper used for generating source that deals with Collections
Version:
$Revision: 6387 $ $Date: 2006-02-23 01:08:24 -0700 (Thu, 23 Feb 2006) $
Author:
Keith Visco

Field Summary

static String
DEFAULT_REFERENCE_SUFFIX
static String
REFERENCE_SUFFIX_PROPERTY
The property used to overwrite the reference suffix for extra collection methods

Fields inherited from class org.exolab.castor.builder.FieldInfo

READ_METHOD, READ_WRITE_METHODS, WRITE_METHOD

Fields inherited from class org.exolab.castor.builder.XMLInfo

ATTRIBUTE_TYPE, CHOICE_NODE_NAME_ERROR_INDICATION, ELEMENT_TYPE, TEXT_TYPE

Constructor Summary

CollectionInfo(XSType contentType, String name, String elementName, boolean useJava50)
Creates a new CollectionInfo

Method Summary

protected void
addMaxSizeCheck(String methodName, JSourceCode sourceCode)
void
createAccessMethods(JClass jClass, boolean useJava50)
Generate the various accessor methods.
protected void
createAddAndRemoveMethods(JClass jClass)
protected void
createAddMethod(JClass jClass)
protected void
createBoundPropertyCode(JSourceCode sourceCode)
Creates the necessary source code for notifying PropertyChangeListeners when the collection has been updated.
protected void
createCollectionIterationMethods(JClass jClass, boolean useJava50)
Generate methods for iterating over the objects in the collection.
protected void
createEnumerateMethod(JClass jClass, boolean useJava50)
protected boolean
createExtraMethods()
Returns true if extra collection methods should be generated.
protected void
createGetAndSetMethods(JClass jClass, boolean useJava50)
protected void
createGetAsArrayMethod(JClass jClass, boolean useJava50)
protected void
createGetAsReferenceMethod(JClass jClass)
protected void
createGetByIndexMethod(JClass jClass)
protected void
createGetCountMethod(JClass jClass)
protected void
createInsertMethod(JClass jClass)
protected void
createIteratorMethod(JClass jClass, boolean useJava50)
protected void
createRemoveAllMethod(JClass jClass)
Creates implementation of removeAll() method.
protected void
createRemoveByIndexMethod(JClass jClass)
Creates implementation of remove(int i) method.
protected void
createRemoveObjectMethod(JClass jClass)
Creates implementation of remove(Object) method.
protected void
createSetAsArrayMethod(JClass jClass, boolean useJava50)
protected void
createSetAsCopyMethod(JClass jClass)
Creates implementation of collection set method.
protected void
createSetAsReferenceMethod(JClass jClass, boolean useJava50)
Creates implementation of collection reference set method.
protected void
createSetByIndexMethod(JClass jClass)
void
generateInitializerCode(JSourceCode sourceCode)
FieldInfo
getContent()
String
getContentName()
XSType
getContentType()
String
getElementName()
protected String
getMethodSuffix()
protected String
getReferenceMethodSuffix()
Returns the suffix (ending) that should be used when creating the extra collection methods.
XSList
getXSList()
boolean
isMultivalued()
void
setCreateExtraMethods(boolean extraMethods)
Sets whether or not to create extra collection methods for accessing the actual collection.
void
setReferenceMethodSuffix(String suffix)
Sets the method suffix (ending) to use when creating the extra collection methods.

Methods inherited from class org.exolab.castor.builder.FieldInfo

createAccessMethods, createGetterComment, createGetterMethod, createHasAndDeleteMethods, createJavaField, createSetterComment, createSetterMethod, generateInitializerCode, getComment, getDeclaringClassInfo, getDefaultValue, getDeleteMethodName, getFixedValue, getHasMethodName, getMethodSuffix, getMethods, getName, getReadMethodName, getValidator, getWriteMethodName, getXMLFieldHandler, isBound, isContainer, isHasAndDeleteMethods, isNillable, isTransient, setBound, setComment, setContainer, setDeclaringClassInfo, setDefaultValue, setFieldInfoReference, setFinal, setFixedValue, setMethods, setNillable, setStatic, setTransient, setValidator, setXMLFieldHandler

Methods inherited from class org.exolab.castor.builder.XMLInfo

getNamespacePrefix, getNamespaceURI, getNodeName, getNodeType, getNodeTypeName, getSchemaType, isElementDefinition, isMultivalued, isRequired, setElementDefinition, setMultivalued, setNamespacePrefix, setNamespaceURI, setNodeName, setNodeType, setRequired, setSchemaType

Field Details

DEFAULT_REFERENCE_SUFFIX

public static final String DEFAULT_REFERENCE_SUFFIX

REFERENCE_SUFFIX_PROPERTY

public static final String REFERENCE_SUFFIX_PROPERTY
The property used to overwrite the reference suffix for extra collection methods

Constructor Details

CollectionInfo

public CollectionInfo(XSType contentType,
                      String name,
                      String elementName,
                      boolean useJava50)
Creates a new CollectionInfo
Parameters:
contentType - the _content type of the collection, ie. the type of objects that the collection will contain
name - the name of the Collection
elementName - the element name for each element in collection
useJava50 - true if source code is supposed to be generated for Java 5

Method Details

addMaxSizeCheck

protected void addMaxSizeCheck(String methodName,
                               JSourceCode sourceCode)

createAccessMethods

public void createAccessMethods(JClass jClass,
                                boolean useJava50)
Generate the various accessor methods.
Overrides:
createAccessMethods in interface FieldInfo

createAddAndRemoveMethods

protected void createAddAndRemoveMethods(JClass jClass)
Parameters:
jClass -

createAddMethod

protected void createAddMethod(JClass jClass)

createBoundPropertyCode

protected void createBoundPropertyCode(JSourceCode sourceCode)
Creates the necessary source code for notifying PropertyChangeListeners when the collection has been updated.
Parameters:
sourceCode - the JSourceCode to add the new source code to.

createCollectionIterationMethods

protected void createCollectionIterationMethods(JClass jClass,
                                                boolean useJava50)
Generate methods for iterating over the objects in the collection. For Java-1 collections, we only generate an Enumerator. Implementations for other versions of Java should call this method for backward compatbility and then add any additional new methods.
Parameters:
jClass - the JClass to which we add this method
useJava50 - true if source code is supposed to be generated for Java 5

createEnumerateMethod

protected void createEnumerateMethod(JClass jClass,
                                     boolean useJava50)

createExtraMethods

protected final boolean createExtraMethods()
Returns true if extra collection methods should be generated. The extra collection methods are methods which return an actual reference to the underlying collection as opposed to an enumeration, iterator, or copy.
Returns:
true if extra collection methods should be generated

createGetAndSetMethods

protected void createGetAndSetMethods(JClass jClass,
                                      boolean useJava50)
Parameters:
jClass - the JClass to which we add this method
useJava50 - true if source code is supposed to be generated for Java 5

createGetAsArrayMethod

protected void createGetAsArrayMethod(JClass jClass,
                                      boolean useJava50)

createGetAsReferenceMethod

protected void createGetAsReferenceMethod(JClass jClass)

createGetByIndexMethod

protected void createGetByIndexMethod(JClass jClass)

createGetCountMethod

protected void createGetCountMethod(JClass jClass)

createInsertMethod

protected void createInsertMethod(JClass jClass)

createIteratorMethod

protected void createIteratorMethod(JClass jClass,
                                    boolean useJava50)

createRemoveAllMethod

protected void createRemoveAllMethod(JClass jClass)
Creates implementation of removeAll() method.
Parameters:
jClass - the JClass to which we add this method

createRemoveByIndexMethod

protected void createRemoveByIndexMethod(JClass jClass)
Creates implementation of remove(int i) method.
Parameters:
jClass - the JClass to which we add this method

createRemoveObjectMethod

protected void createRemoveObjectMethod(JClass jClass)
Creates implementation of remove(Object) method.
Parameters:
jClass - the JClass to which we add this method

createSetAsArrayMethod

protected void createSetAsArrayMethod(JClass jClass,
                                      boolean useJava50)

createSetAsCopyMethod

protected void createSetAsCopyMethod(JClass jClass)
Creates implementation of collection set method. The method will assign the field a copy of the given collection.
The fields will be checked for type safety.
Parameters:
jClass -

createSetAsReferenceMethod

protected void createSetAsReferenceMethod(JClass jClass,
                                          boolean useJava50)
Creates implementation of collection reference set method. This method is a non-type safe method which simply assigns the given collection to the field.
Parameters:
jClass -
useJava50 - true if source code is supposed to be generated for Java 5

createSetByIndexMethod

protected void createSetByIndexMethod(JClass jClass)

generateInitializerCode

public void generateInitializerCode(JSourceCode sourceCode)
Overrides:
generateInitializerCode in interface FieldInfo

getContent

public FieldInfo getContent()

getContentName

public String getContentName()

getContentType

public XSType getContentType()

getElementName

public String getElementName()

getMethodSuffix

protected String getMethodSuffix()
Overrides:
getMethodSuffix in interface FieldInfo

getReferenceMethodSuffix

protected final String getReferenceMethodSuffix()
Returns the suffix (ending) that should be used when creating the extra collection methods.
Returns:
the suffix for the reference methods

getXSList

public XSList getXSList()

isMultivalued

public boolean isMultivalued()
Overrides:
isMultivalued in interface XMLInfo

setCreateExtraMethods

public void setCreateExtraMethods(boolean extraMethods)
Sets whether or not to create extra collection methods for accessing the actual collection.
Parameters:
extraMethods - a boolean that when true indicates that extra collection accessor methods should be created. False by default.

setReferenceMethodSuffix

public void setReferenceMethodSuffix(String suffix)
Sets the method suffix (ending) to use when creating the extra collection methods.
Parameters:
suffix - the method suffix to use when creating the extra collection methods. If null or emtpty the default value, as specified by DEFAULT_REFERENCE_SUFFIX will used.

Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com