* @throws DmcValueExceptionSet
*/
void addClass(ClassDefinition cd) throws ResultException, DmcValueException {
if (checkAndAdd(cd.getObjectName(),cd,classDefs) == false){
ResultException ex = new ResultException();
ex.addError(clashMsg(cd.getObjectName(),cd,classDefs,"class names"));
throw(ex);
}
if (checkAndAdd(cd.getObjectName(),cd,allDefs) == false){
ResultException ex = new ResultException();
ex.addError(clashMsg(cd.getObjectName(),cd,allDefs,"definition names"));
throw(ex);
}
if (cd.getAbbrev() != null){
// We have an abbreviation - so it must also be unique and
// added to the appropriate maps
StringName abbrevName = new StringName(cd.getAbbrev());
if (checkAndAdd(abbrevName,cd,classDefs) == false){
ResultException ex = new ResultException();
ex.addError(clashMsg(abbrevName,cd,classDefs,"class abbreviations"));
throw(ex);
}
if (checkAndAdd(abbrevName,cd,allDefs) == false){
ResultException ex = new ResultException();
ex.addError(clashMsg(abbrevName,cd,allDefs,"definition names"));
throw(ex);
}
classAbbrevs.put(abbrevName,cd);
}
///////////////////////////////////////////////////////////////////////
if (cd.getDmdID() == null){
ResultException ex = new ResultException("Missing dmdID for class: " + cd.getName());
ex.setLocationInfo(cd.getFile(), cd.getLineNumber());
throw(ex);
}
if (cd.getDefinedIn() == null){
ResultException ex = new ResultException("definedIn missing for class: " + cd.getName());
ex.setLocationInfo(cd.getFile(), cd.getLineNumber());
throw(ex);
}
else{
if (performIDChecks){
if ( (cd.getDefinedIn().getSchemaBaseID() == null) ||
(cd.getDefinedIn().getSchemaIDRange() == null) ){
ResultException ex = new ResultException("schemaBaseID or schemaIDRange missing for schema: " + cd.getDefinedIn().getName());
throw(ex);
}
}
}
if (performIDChecks){
// Bump up the DMD ID by the amount of schemaBaseID
int base = cd.getDefinedIn().getSchemaBaseID();
int range = cd.getDefinedIn().getSchemaIDRange();
int current = cd.getDmdID();
if (current >= range){
ResultException ex = new ResultException("Number of classes exceeds schema ID range: " + cd.getName());
throw(ex);
}
cd.setDmdID(base + current);
}
if (classesByID.get(cd.getDmdID()) != null){
ResultException ex = new ResultException();
ex.addError(clashMsg(cd.getDmdID(),cd,classesByID,"dmdID"));
throw(ex);
}
classesByID.put(cd.getDmdID(), cd);
///////////////////////////////////////////////////////////////////////
if (cd.getObjectName().getNameString().length() > longestClassName)
longestClassName = cd.getObjectName().getNameString().length();
// Another bit of trickiness here. We don't resolve references for the entire schema
// until we've loaded the whole thing, but, in this case, we need to pre-resolve
// the ClassDefinition - which should be okay, because classes are the last things
// that're loaded.
try {
cd.resolveReferences(this);
} catch (DmcValueExceptionSet e) {
ResultException ex = new ResultException();
ex.addError("Unresolved references in ClassDefinition: " + cd.getName());
// ex.setLocationInfo(cd.getFile(), cd.getLineNumber());
for(DmcValueException dve : e.getExceptions()){
ex.moreMessages(dve.getMessage());
}
throw(ex);
}
if (cd.getDerivedFrom() != null){
cd.getDerivedFrom().updateDerived(cd);
}
cd.setDmoImport(cd.getDefinedIn().getSchemaPackage() + ".generated.dmo." + cd.getName() + "DMO");
cd.setDmoClass(cd.getName() + "DMO");
cd.setDmwImport(cd.getDefinedIn().getDmwPackage() + ".generated.dmw." + cd.getName() + "DMW");
cd.setDmwClass(cd.getName() + "DMW");
cd.setDmwIteratorImport(cd.getDefinedIn().getDmwPackage() + ".generated.dmw." + cd.getName() + "IterableDMW");
cd.setDmwIteratorClass(cd.getName() + "IterableDMW");
cd.setDmtImport(cd.getDefinedIn().getSchemaPackage() + ".generated.types.DmcType" + cd.getName() + "REF");
cd.setDmtREFImport(cd.getDefinedIn().getSchemaPackage() + ".generated.types." + cd.getName() + "REF");
cd.setDmtClass(cd.getName() + "REF");
if (cd.getUseWrapperType() == WrapperTypeEnum.EXTENDED){
if (cd.getSubpackage() == null)
cd.setDmeImport(cd.getDefinedIn().getDmwPackage() + ".extended." + cd.getName());
else
cd.setDmeImport(cd.getDefinedIn().getDmwPackage() + ".extended." + cd.getSubpackage() + "." + cd.getName());
cd.setDmeClass(cd.getName());
}
else{
cd.setDmeImport("THE WRAPPER FOR " + cd.getName() + " ISN'T EXTENDED - YOU'VE GOT A CODE GENERATION ERROR! DWEEB!");
cd.setDmeClass("THE WRAPPER FOR " + cd.getName() + " ISN'T EXTENDED - YOU'VE GOT A CODE GENERATION ERROR! DWEEB!");
}
if (cd.getClassType() == ClassTypeEnum.AUXILIARY){
cd.setDmoAuxClass(cd.getName() + "DMO");
cd.setDmoAuxClassImport(cd.getDefinedIn().getSchemaPackage() + ".generated.auxw." + cd.getName() + "DMO");
if (cd.getDefinedIn().getDmwPackage() != null){
cd.setDmwAuxClass(cd.getName());
cd.setDmwAuxClassImport(cd.getDefinedIn().getDmwPackage() + ".generated.auxw." + cd.getName());
}
}
// cd.updateImplemented();
// And now, set the java class that will be used with the DmwObjectFactory
if (cd.getJavaClass() == null){
if (cd.getUseWrapperType() == WrapperTypeEnum.BASE)
cd.setJavaClass(cd.getDmwImport());
else if (cd.getUseWrapperType() == WrapperTypeEnum.EXTENDED){
// DebugInfo.debug(" --- JAVA CLASS " + cd.getDmeImport());
cd.setJavaClass(cd.getDmeImport());
}
}
// Add the class to our java class to class definition map
classesByJavaClass.put(cd.getJavaClass(), cd);
Iterator<AttributeDefinition> adit = null;
if ( (adit = cd.getMay()) != null){
while(adit.hasNext()){
AttributeDefinition ad = adit.next();
ad.addUsingClass(cd);
}
}
if ( (adit = cd.getMust()) != null){
while(adit.hasNext()){
AttributeDefinition ad = adit.next();
ad.addUsingClass(cd);
}
}
// Iterator<ClassDefinition> cdit = null;
// if ( (cdit = cd.getAllowedParents()) != null){
// while(cdit.hasNext()){
// ClassDefinition p = cdit.next();
// p.updateAllowedSubcomps(cd);
// }
// }
//
// if ( (cdit = cd.getAllowedChildren()) != null){
// while(cdit.hasNext()){
// ClassDefinition c = cdit.next();
// cd.updateAllowedSubcomps(c);
// }
// }
Iterator<ActionDefinition> acdit = null;
if ( (acdit = cd.getActions()) != null){
while(acdit.hasNext()){
ActionDefinition ad = acdit.next();
ad.addUsingClass(cd);
}
}
////////////////////////////////////////////////////////////////////////////////
// CREATE INTERNAL TYPE FOR REFERENCES
if (cd.getClassType() != ClassTypeEnum.AUXILIARY){
// Things get a little tricky here - we want to be able to refer to objects without
// having to manually define wrapper types for them, so we create internal TypeDefinitions
// for them. The internal type is DmcType<classname>REF.
TypeDefinition td = new TypeDefinition();
// td.addObjectClass(MetaSchemaAG._TypeDefinition);
td.setInternallyGenerated(true);
td.setName(cd.getName());
td.setDescription("This is an internally generated type to allow references to " + cd.getName() + " values.");
td.setIsEnumType(false);
td.setIsRefType(true);
if (cd.getIsNamedBy() != null){
// We only need a help class when we have named objects - regular old object references
// can get by without this
td.setHelperClassName(cd.getDefinedIn().getSchemaPackage() + ".generated.types." + cd.getName() + "REF");
if (cd.getIsNamedBy().getValueType() != ValueTypeEnum.SINGLE){
ResultException ex = new ResultException();
ex.addError("The naming attribute: " + cd.getIsNamedBy().getName() + " for class: " + cd.getName() + " must be valueType SINGLE");
ex.result.lastResult().fileName(cd.getIsNamedBy().getFile());
ex.result.lastResult().lineNumber(cd.getIsNamedBy().getLineNumber());
throw(ex);
}
}