if (slotValue == null) {
// This slot isn't an aggregate
throw new NotAnAggregate();
}
AbsAggregate absAggregate = null;
Class valueClass = slotValue.getClass();
// Check if slot is typized
boolean slotTypized = false;
if (schema != null) {
SlotAccessData slotAccessData = accessors.get(new SlotKey(schema.getTypeName(), slotName));
slotTypized = slotAccessData.isTypized();
}
// Try to manage as array
if (valueClass.isArray() && valueClass != byte[].class) {
// In the case of array and slot not typized --> throw exception
// (Only java collection are permitted)
if (!slotTypized) {
throw new OntologyException("Impossible manage array into a not typized slot");
}
absAggregate = new AbsAggregate(BasicOntology.SEQUENCE);
for (int i = 0; i < Array.getLength(slotValue); i++) {
Object object = Array.get(slotValue, i);
absAggregate.add((AbsTerm)Ontology.externalizeSlotValue(object, this, referenceOnto));
}
} else {
Iterator iter;
String aggregateType;
if (slotValue instanceof java.util.Collection) {
iter = ((java.util.Collection)slotValue).iterator();
if (slotValue instanceof java.util.List) {
aggregateType = BasicOntology.SEQUENCE;
} else {
aggregateType = BasicOntology.SET;
}
} else if (slotValue instanceof jade.util.leap.Collection) {
// In the case of array and slot not typized --> throw exception
// (Only java collection are permitted)
if (!slotTypized) {
throw new OntologyException("Impossible manage jade collection into a not typized slot");
}
iter = ((jade.util.leap.Collection)slotValue).iterator();
if (slotValue instanceof jade.util.leap.List) {
aggregateType = BasicOntology.SEQUENCE;
} else {
aggregateType = BasicOntology.SET;
}
} else {
// This slot isn't an aggregate
throw new NotAnAggregate();
}
if (iter.hasNext() || schema.isMandatory(slotName)) {
absAggregate = new AbsAggregate(aggregateType);
try {
while (iter.hasNext()) {
Object object = iter.next();
absAggregate.add((AbsTerm)Ontology.externalizeSlotValue(object, this, referenceOnto));
}
} catch (ClassCastException cce) {
throw new OntologyException("Non term object in aggregate");
}
}