while(preadl.hasNext()){
AttributeDefinition d = preadl.next();
DmcAttribute<?> attr = d.getDmcObject().get("type");
if (attr == null){
ResultException ex = new ResultException();
ex.addError("The AttributeDefinition " + d.getName() + " has no type attribute.");
ex.result.lastResult().fileName(d.getFile());
ex.result.lastResult().lineNumber(d.getLineNumber());
throw(ex);
}
DmcNamedObjectREF ref = (DmcNamedObjectREF) attr.getSV();
// It might be a "real" type, so try that first
TypeDefinition td = tdef(ref.getObjectName().getNameString());
if( td == null){
ClassDefinition cd = cdef(ref.getObjectName().getNameString());
if (cd == null){
ResultException ex = new ResultException();
ex.addError("The type: " + ref.getObjectName() + " referred to in AttributeDefinition " + d.getName() + " is invalid.");
ex.result.lastResult().fileName(d.getFile());
ex.result.lastResult().lineNumber(d.getLineNumber());
throw(ex);
}
else{
ref.setObject((DmcNamedObjectIF) cd.getInternalTypeRef().getDmcObject());
}
}
else{
ref.setObject((DmcNamedObjectIF) td.getDmcObject());
}
}
}
// And more of the same kind of magic with complex types - we have to
// preresolve the type references in the same way as with attributes
Iterator<ComplexTypeDefinition> ctdl = sd.getComplexTypeDefList();
if (ctdl != null){
while(ctdl.hasNext()){
ComplexTypeDefinition ctd = ctdl.next();
// The usual resolution mechanisms don't work for the fields, we have to
// handle that manually.
Iterator<Field> fields = ctd.getField();
while(fields.hasNext()){
Field field = fields.next();
DmcNamedObjectREF ref = (DmcNamedObjectREF)field.getType();
// It might be a "real" type, so try that first
TypeDefinition td = tdef(ref.getObjectName().getNameString());
if( td == null){
ClassDefinition cd = cdef(ref.getObjectName().getNameString());
if (cd == null){
ResultException ex = new ResultException();
ex.addError("The type: " + ref.getObjectName() + " referred to in ComplexTypeDefinition " + ctd.getName() + " is invalid.");
ex.result.lastResult().fileName(ctd.getFile());
ex.result.lastResult().lineNumber(ctd.getLineNumber());
throw(ex);
}
else{
ref.setObject((DmcNamedObjectIF) cd.getInternalTypeRef().getDmcObject());
}
}
else{
ref.setObject((DmcNamedObjectIF) td.getDmcObject());
}
}
// And finally, the complex type def has to have it object class resolved so that
// we don't run into problems later when generating the DMW schema
try {
ctd.resolveReferences(this);
} catch (DmcValueExceptionSet e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// And more of the same kind of magic with extended references types - we have to
// preresolve the type references in the same way as with attributes
Iterator<ExtendedReferenceTypeDefinition> ertdl = sd.getExtendedReferenceTypeDefList();
if (ertdl != null){
while(ertdl.hasNext()){
ExtendedReferenceTypeDefinition ertd = ertdl.next();
DmcTypeClassDefinitionREFSV attr = (DmcTypeClassDefinitionREFSV) ertd.getDMO().get(MetaDMSAG.__extendedReferenceClass);
if (attr == null){
ResultException ex = new ResultException();
ex.addError("Missing extendedReferenceClass for ExtendedReferenceTypeDefinition: " + ertd.getName());
ex.result.lastResult().fileName(ertd.getFile());
ex.result.lastResult().lineNumber(ertd.getLineNumber());
throw(ex);
}
try {
attr.resolveReferences(this);
} catch (DmcValueException e) {
ResultException ex = new ResultException();
ex.addError("Unknown class referred to by extendedReferenceClass: " + attr.getSV().getObjectName().getNameString());
ex.result.lastResult().fileName(ertd.getFile());
ex.result.lastResult().lineNumber(ertd.getLineNumber());
throw(ex);
}
try {
ertd.getInternalType().setOriginalClass(ertd.getExtendedReferenceClass());
} catch (DmcValueException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// ClassDefinition cd = cdef(attr.getName());
// if (cd == null){
// ResultException ex = new ResultException();
// ex.addError("Missing extendedReferenceClass for ExtendedReferenceTypeDefinition: " + ertd.getName());
// ex.result.lastResult().fileName(ertd.getFile());
// ex.result.lastResult().lineNumber(ertd.getLineNumber());
// throw(ex);
// }
if (ertd.getExtendedReferenceClass().getIsNamedBy() == null){
ResultException ex = new ResultException();
ex.addError("The class: " + ertd.getExtendedReferenceClass().getObjectName().getNameString() + " referred to in ExtendedReferenceTypeDefinition " + ertd.getName() + " is not a named object.");
ex.result.lastResult().fileName(ertd.getFile());
ex.result.lastResult().lineNumber(ertd.getLineNumber());
throw(ex);
}
Iterator<Field> fields = ertd.getField();
while(fields.hasNext()){
Field field = fields.next();
DmcNamedObjectREF ref = (DmcNamedObjectREF)field.getType();
// It might be a "real" type, so try that first
TypeDefinition td = tdef(ref.getObjectName().getNameString());
if( td == null){
ClassDefinition cd = cdef(ref.getObjectName().getNameString());
if (cd == null){
ResultException ex = new ResultException();
ex.addError("The type: " + ref.getObjectName() + " referred to in ExtendedReferenceTypeDefinition " + ertd.getName() + " is invalid.");
ex.result.lastResult().fileName(ertd.getFile());
ex.result.lastResult().lineNumber(ertd.getLineNumber());
throw(ex);
}
else{
ref.setObject((DmcNamedObjectIF) cd.getInternalTypeRef().getDmcObject());
}
}
else{
ref.setObject((DmcNamedObjectIF) td.getDmcObject());
}
}
}
}
Iterator<ActionDefinition> actdl = sd.getActionDefList();
if (actdl != null){
while(actdl.hasNext()){
ActionDefinition d = actdl.next();
try {
d.resolveReferences(this);
} catch (DmcValueExceptionSet e) {
ResultException ex = new ResultException();
ex.addError("Unresolved references in ActionDefinition: " + d.getName());
ex.setLocationInfo(d.getFile(), d.getLineNumber());
for(DmcValueException dve : e.getExceptions()){
ex.moreMessages(dve.getMessage());
}
throw(ex);
}
}
}
Iterator<AttributeDefinition> adl = sd.getAttributeDefList();
if (adl != null){
while(adl.hasNext()){
AttributeDefinition d = adl.next();
if (d.getName().getNameString().equals("field")){
DebugInfo.debug("HERE");
}
try {
d.resolveReferences(this);
} catch (DmcValueExceptionSet e) {
ResultException ex = new ResultException();
ex.addError("Unresolved references in AttributeDefinition: " + d.getName());
ex.setLocationInfo(d.getFile(), d.getLineNumber());
for(DmcValueException dve : e.getExceptions()){
ex.moreMessages(dve.getMessage());
}
throw(ex);
}
// TODO move towards generic object validation mechanisms - this check should be a rule
if ( (d.getValueType() == ValueTypeEnum.HASHMAPPED) || (d.getValueType() == ValueTypeEnum.TREEMAPPED)){
if (d.getType().getKeyClass() == null){
if (d.getType().getIsRefType()){
if (d.getType().getIsExtendedRefType()){
ResultException ex = new ResultException();
ex.addError("AttributeDefinition: " + d.getName() + " cannot have valueType HASHMAPPED/TREEMAPPED since extended reference types are not keyed.");
ex.setLocationInfo(d.getFile(), d.getLineNumber());
throw(ex);
}
if (d.getType().getOriginalClass().getIsNamedBy() == null){
ResultException ex = new ResultException();
ex.addError("AttributeDefinition: " + d.getName() + " cannot have valueType HASHMAPPED/TREEMAPPED since the " + d.getType().getName() + " type does not refer to a named object.");
ex.setLocationInfo(d.getFile(), d.getLineNumber());
throw(ex);
}
}
else{
ResultException ex = new ResultException();
ex.addError("AttributeDefinition: " + d.getName() + " cannot have valueType HASHMAPPED/TREEMAPPED since the " + d.getType().getName() + " type does not have a specified keyClass.");
ex.setLocationInfo(d.getFile(), d.getLineNumber());
throw(ex);
}
}
}
}
}
Iterator<ClassDefinition> cdl = sd.getClassDefList();
if (cdl != null){
while(cdl.hasNext()){
ClassDefinition d = cdl.next();
try {
d.resolveReferences(this);
if (d.getAllowedParentsSize() > 0){
// The name must be hierarchic
if (d.getIsNamedBy() == null){
ResultException ex = new ResultException();
ex.addError("The following class indicates that it has allowed parents, but isn't a named object: " + d.getName());
throw(ex);
}
if (!d.getIsNamedBy().getType().getIsHierarchicName()){
ResultException ex = new ResultException();
ex.addError("The following class indicates that it has allowed parents, but its naming attribute isn't heirarchic: " + d.getName());
ex.result.lastResult().moreMessages("isNamedBy: " + d.getIsNamedBy().getName());
throw(ex);
}
}
} catch (DmcValueExceptionSet e) {
ResultException ex = new ResultException();
ex.addError("Unresolved references in ClassDefinition: " + d.getName());
ex.setLocationInfo(d.getFile(), d.getLineNumber());
for(DmcValueException dve : e.getExceptions()){
ex.moreMessages(dve.getMessage());
}
throw(ex);
}
}
}
Iterator<EnumDefinition> edl = sd.getEnumDefList();
if (edl != null){
while(edl.hasNext()){
EnumDefinition d = edl.next();
try {
d.resolveReferences(this);
} catch (DmcValueExceptionSet e) {
ResultException ex = new ResultException();
ex.addError("Unresolved references in EnumDefinition: " + d.getName());
ex.setLocationInfo(d.getFile(), d.getLineNumber());
for(DmcValueException dve : e.getExceptions()){
ex.moreMessages(dve.getMessage());
}
throw(ex);
}
}
}
Iterator<TypeDefinition> tdl = sd.getTypeDefList();
if (tdl != null){
while(tdl.hasNext()){
TypeDefinition d = tdl.next();
try {
d.resolveReferences(this);
} catch (DmcValueExceptionSet e) {
ResultException ex = new ResultException();
ex.addError("Unresolved references in TypeDefinition: " + d.getName());
ex.setLocationInfo(d.getFile(), d.getLineNumber());
for(DmcValueException dve : e.getExceptions()){
ex.moreMessages(dve.getMessage());
}
throw(ex);
}
}
}
// ctdl = sd.getComplexTypeDefList();
// if (ctdl != null){
// while(ctdl.hasNext()){
// ComplexTypeDefinition d = ctdl.next();
// try {
// d.resolveReferences(this);
// } catch (DmcValueExceptionSet e) {
// ResultException ex = new ResultException();
// ex.addError("Unresolved references in ComplexTypeDefinition: " + d.getName());
// ex.setLocationInfo(d.getFile(), d.getLineNumber());
//
// for(DmcValueException dve : e.getExceptions()){
// ex.moreMessages(dve.getMessage());
// }
// throw(ex);
// }
// }
// }
Iterator<SliceDefinition> sdl = sd.getSliceDefList();
if (sdl != null){
while(sdl.hasNext()){
SliceDefinition s = sdl.next();
try {
s.resolveReferences(this);
} catch (DmcValueExceptionSet e) {
ResultException ex = new ResultException();
ex.addError("Unresolved references in SliceDefinition: " + s.getName());
ex.setLocationInfo(s.getFile(), s.getLineNumber());
for(DmcValueException dve : e.getExceptions()){
ex.moreMessages(dve.getMessage());
}
throw(ex);
}
}
}