if (LOG.isDebugEnabled()) {
LOG.debug("includeField(: " + log("place", place) + andlog("fieldNames", fieldNames) + andlog("annotation", annotation) + ")");
}
final ObjectAdapter object = place.getObject();
final Element xmlElement = place.getXmlElement();
// we use a copy of the path so that we can safely traverse collections
// without side-effects
final Vector originalNames = fieldNames;
final Vector names = new Vector();
for (final java.util.Enumeration e = originalNames.elements(); e.hasMoreElements();) {
names.addElement(e.nextElement());
}
// see if we have any fields to process
if (names.size() == 0) {
return true;
}
// take the first field name from the list, and remove
final String fieldName = (String) names.elementAt(0);
names.removeElementAt(0);
if (LOG.isDebugEnabled()) {
LOG.debug("includeField(Pl, Vec, Str):" + log("processing field", fieldName) + andlog("left", "" + names.size()));
}
// locate the field in the object's class
final ObjectSpecification nos = object.getSpecification();
ObjectAssociation field = null;
try {
// HACK: really want a ObjectSpecification.hasField method to
// check first.
field = nos.getAssociation(fieldName);
} catch (final ObjectSpecificationException ex) {
if (LOG.isInfoEnabled()) {
LOG.info("includeField(Pl, Vec, Str): could not locate field, skipping");
}
return false;
}
// locate the corresponding XML element
// (the corresponding XSD element will later be attached to xmlElement
// as its userData)
if (LOG.isDebugEnabled()) {
LOG.debug("includeField(Pl, Vec, Str): locating corresponding XML element");
}
final Vector xmlFieldElements = elementsUnder(xmlElement, field.getId());
if (xmlFieldElements.size() != 1) {
if (LOG.isInfoEnabled()) {
LOG.info("includeField(Pl, Vec, Str): could not locate " + log("field", field.getId()) + andlog("xmlFieldElements.size", "" + xmlFieldElements.size()));
}
return false;
}
final Element xmlFieldElement = (Element) xmlFieldElements.elementAt(0);
if (names.size() == 0 && annotation != null) {
// nothing left in the path, so we will apply the annotation now
isisMetaModel.setAnnotationAttribute(xmlFieldElement, annotation);
}
final Place fieldPlace = new Place(object, xmlFieldElement);
if (field instanceof OneToOneAssociation) {
if (field.getSpecification().getAssociations(Contributed.EXCLUDED).size() == 0) {
if (LOG.isDebugEnabled()) {
LOG.debug("includeField(Pl, Vec, Str): field is value; done");
}
return false;
}
if (LOG.isDebugEnabled()) {
LOG.debug("includeField(Pl, Vec, Str): field is 1->1");
}
final OneToOneAssociation oneToOneAssociation = ((OneToOneAssociation) field);
final ObjectAdapter referencedObject = oneToOneAssociation.get(fieldPlace.getObject());
if (referencedObject == null) {
return true; // not a failure if the reference was null
}
final boolean appendedXml = appendXmlThenIncludeRemaining(fieldPlace, referencedObject, names, annotation);
if (LOG.isDebugEnabled()) {
LOG.debug("includeField(Pl, Vec, Str): 1->1: invoked appendXmlThenIncludeRemaining for " + log("referencedObj", referencedObject) + andlog("returned", "" + appendedXml));
}
return appendedXml;
} else if (field instanceof OneToManyAssociation) {
if (LOG.isDebugEnabled()) {
LOG.debug("includeField(Pl, Vec, Str): field is 1->M");
}
final OneToManyAssociation oneToManyAssociation = (OneToManyAssociation) field;
final ObjectAdapter collection = oneToManyAssociation.get(fieldPlace.getObject());
final CollectionFacet facet = collection.getSpecification().getFacet(CollectionFacet.class);
if (LOG.isDebugEnabled()) {
LOG.debug("includeField(Pl, Vec, Str): 1->M: " + log("collection.size", "" + facet.size(collection)));
}
boolean allFieldsNavigated = true;