* @throws DmcValueException
* @throws ClassNotFoundException
* @throws ClassNotFoundException
*/
public DmcObject createObject(DmcUncheckedObject uco) throws ResultException, DmcValueException, ClassNotFoundException {
DmcObject dmo = null;
ClassDefinition cd = null;
AttributeDefinition ad = null;
if ((cd = schema.isClass((String)uco.classes.get(0))) == null){
ResultException ex = new ResultException();
ex.result.addResult(Result.ERROR,"Unknown class: " + uco.classes.get(0));
throw(ex);
}
// DebugInfo.debug(uco.toOIF(15));
dmo = cd.newDMOInstance();
// Add the object class
DmcTypeClassDefinitionREFMV cref = new DmcTypeClassDefinitionREFMV();
cref.add(cd.getObjectName());
dmo.add(DmcObject.__objectClass, cref);
// And add any auxiliary classes if we have them
for(int i=1; i<uco.classes.size(); i++){
if ((cd = schema.isClass((String)uco.classes.get(i))) == null){
ResultException ex = new ResultException();
ex.result.addResult(Result.ERROR,"Unknown class: " + uco.classes.get(i));
throw(ex);
}
cref.add(cd.getObjectName());
dmo.add("objectClass", cref);
}
Iterator<String> names = uco.getAttributeNames();
while(names.hasNext()){
String n = names.next();
ad = schema.adef(n);
if (ad == null){
ResultException ex = new ResultException();
ex.result.addResult(Result.ERROR,"Unknown attribute: " + n);
throw(ex);
}
DmcAttributeInfo ai = dmo.getAttributeInfo(n);
if (ai == null){
ai = ad.getAttributeInfo();
}
// DmcAttributeInfo ai = DmcOmni.instance().getInfo(ad.getDmdID());
if (ai == null)
throw(new IllegalStateException("Unknown attribute id: " + ad.getDmdID() + " for attribute: " + ad.getName()));
NamedStringArray values = null;
switch(ad.getValueType()){
case SINGLE:
values = uco.get(n);
try {
// Try to get the attribute
// DmcAttribute<?> attr = dmo.get(ad.getName().getNameString());
DmcAttribute<?> attr = dmo.get(ai);
// If we can't find the attribute container, create it
if (attr == null)
attr = ad.getType().getAttributeHolder(ai);
// Set the value
attr.set(values.get(0));
// Store the attribute
dmo.set(ai, attr);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (DmcValueException e) {
throw(e);
}
break;
case MULTI:
case HASHMAPPED:
case TREEMAPPED:
case HASHSET:
case TREESET:
values = uco.get(n);
for (String attrVal: values){
try {
// Try to get the attribute
// DmcAttribute<?> attr = dmo.get(ad.getName().getNameString());
DmcAttribute<?> attr = dmo.get(ai);
// If we can't find the attribute container, create it
if (attr == null)
attr = ad.getType().getAttributeHolder(ai);
// Add the value to the container
attr.add(attrVal);
// Store the attribute
dmo.add(ai, attr);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (DmcValueException e) {