String qualifiedClassName = objectClassDoc.qualifiedName ();
instances.put (qualifiedClassName, this);
objectClassInfo = new ClassInfo (objectClassDoc);
ClassDoc identityBaseClassDoc;
Tag [] tags = objectClassDoc.tags ("mariner-object-base-identity-class");
// If a base identity class has been specified, try to use it
// otherwise search for one.
if(tags.length == 1) {
String baseIdentityClassName = tags[0].text();
identityBaseClassDoc = rootDoc.classNamed (baseIdentityClassName);
if(identityBaseClassDoc == null) {
throw new IllegalStateException("Cannot find base identity class" +
baseIdentityClassName);
}
} else {
identityBaseClassDoc = getIdentityBaseClassDoc (rootDoc,
objectClassDoc);
}
System.out.println("Using base class " + identityBaseClassDoc.qualifiedName());
identityBaseClassInfo = new ClassInfo (identityBaseClassDoc);
// Create a ClassInfo for the identity class.
String identityClassName = objectClassInfo.getName () + "Identity";
String identityClassQualifiedName
= objectClassInfo.getQualifiedName () + "Identity";
identityClassInfo = new ClassInfo (objectClassInfo.getPackageInfo (),
identityBaseClassInfo,
identityClassName,
identityClassQualifiedName);
allIdentityFields = new ArrayList ();
// Find out whether this object has any dependencies.
tags = objectClassDoc.tags ("mariner-object-guardian");
if (tags.length == 1) {
String guardianClass = tags [0].text ();
ClassDoc guardianClassDoc = rootDoc.classNamed (guardianClass);
if (guardianClassDoc == null) {
throw new IllegalStateException ("Cannot find guardian class "
+ guardianClass);
}
guardianInfo = RepositoryObjectInfo.getInstance (rootDoc,
guardianClassDoc);
} else if (tags.length > 1) {
throw new IllegalStateException ("Class can only have one"
+ " mariner-object-guardian");
}
// Create an array of the new fields in the class.
tags = objectClassDoc.tags ("mariner-object-identity-field");
int identityFieldCount = tags.length;
for (int i = 0; i < identityFieldCount; i += 1) {
// Get the field name.
String fieldName = tags [i].text ();
FieldInfo identityField;
// If it is inherited from the base class then ignore it.
identityField = identityBaseClassInfo.getField (fieldName, true);
if (identityField != null) {
if (GenerateUtilities.isProjectField(identityField)) {
projectIdentityField = identityField;
}
// Add it to the list of all the identity fields.
allIdentityFields.add (identityField);
continue;
}
// Get the details of the object's field.
FieldInfo objectField = objectClassInfo.getField (fieldName, true);
String comment = objectField.getComment ();
comment = getConstructorParameterComment (objectClassDoc,
fieldName,
comment);
// Create a field for the identity class.
identityField = new FieldInfo (objectField, comment);
// Add it to the class.
identityClassInfo.addField (identityField);
// Add it to the list of all the identity fields.
allIdentityFields.add (identityField);
// Get the details of the object's getter method.
MethodInfo objectGetter = objectClassInfo.getGetterMethod (fieldName,
true);
MethodInfo identityGetter
= new MethodInfo (objectGetter.getName (),
objectGetter.getReturnType (),
objectGetter.getComment ());
// Add it to the class.
identityClassInfo.addMethod (identityGetter);
}
// Create the list of parameters for the constructor.
List constructorParameters = new ArrayList ();
for (Iterator i = allIdentityFields.iterator (); i.hasNext ();) {
FieldInfo field = (FieldInfo) i.next ();
ParameterInfo parameter = new ParameterInfo (field.getClassInfo (),
field.getName (),
field.getType ());
constructorParameters.add (parameter);
}
ConstructorInfo constructor = new ConstructorInfo (constructorParameters);
identityClassInfo.addConstructor (constructor);
// Get the list of extra identity fields.
if (guardianInfo == null) {
extraIdentityFields = new ArrayList (allIdentityFields);
} else {
ClassInfo guardianIdentityClassInfo
= guardianInfo.getIdentityClassInfo ();
extraIdentityFields = getExtraFields (allIdentityFields,
guardianIdentityClassInfo);
}
// Create the set of the names of fields to ignore.
Set ignore = new HashSet ();
ignore.add ("identity");
tags = objectClassDoc.tags ("mariner-object-ignore-field");
for (int i = 0; i < tags.length; i += 1) {
//System.out.println ("Field " + tags [i].text ()
//+ " should be ignored");
ignore.add (tags [i].text ());
}
// Initialise the list of object fields.
allObjectFields = objectClassInfo.getAllInstanceFields ();
for (Iterator i = allObjectFields.iterator (); i.hasNext ();) {
FieldInfo field = (FieldInfo) i.next ();
String fieldName = field.getName ();
if (ignore.contains (fieldName)) {
//System.out.println ("Ignoring " + fieldName);
i.remove ();
}
}
extraObjectFields = getExtraFields (allObjectFields, identityClassInfo);
dependentsInfo = new ArrayList ();
tags = objectClassDoc.tags ("mariner-object-dependent");
for (int i = 0; i < tags.length; i += 1) {
String dependentClassName = tags [i].text ();
ClassDoc dependentClassDoc = rootDoc.classNamed (dependentClassName);
if (dependentClassDoc == null) {
throw new IllegalStateException ("Cannot find class named "
+ dependentClassName);
}