obj = getValueFromObject(xeo, getTargetAppName(), fieldName, new Object[] {iParm}, new Class[] {Integer.TYPE});
}
if (obj instanceof String) {
fieldValue = (String)obj;
Element eChildOutput = new Element(fieldName);
// Have to do this to validate the data since the object we're dealing
// with may not have had an EnterpriseFields object when it was populated.
try {
String tempValue = removeXmlEscapes(fieldValue);
// 4/4/2002 fix
// in this case, we really do want to set the value in the vector at the index
// so we don't keep adding items to it
setVariableValue(xeo, fieldName, tempValue , String.class, i);
}
catch (Exception e) {
throw new EnterpriseLayoutException("Error setting " + objectName + "/" + fieldName +
" to the value " + fieldValue + " Exception: " + e.getMessage(), e);
}
// Now, we have to get the value from the object again since it may have been
// modified when the setter methods are called above. Otherwise, we'll be
// creating the XML using the "non enterprise" value.
if (getTargetAppName() == null) {
fieldValue = (String)getValueFromObject(xeo, fieldName, new Object[] {iParm}, new Class[] {Integer.TYPE});
}
else {
fieldValue = (String)getValueFromObject(xeo, getTargetAppName(), fieldName, new Object[] {iParm}, new Class[] {Integer.TYPE});
}
eChildOutput.setText(fieldValue);
eOutput.addContent(eChildOutput);
}
else {
// should never get here.
}
}
if (numObjects == 0) {
// Have to check the parent field (if one exists) for situations
// where the Parent field isn't required but children of that Parent
// are. Example is DeceasedDate in BasicPerson. DeceasedDate is optional
// but Month,Day,Year are required if DeceasedDate is present...
if (isRequired && parentIsRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
throw new EnterpriseLayoutException("The " + fieldType + " " +
elementName + "/" + fieldName + " is required but it has no value. NumObjects: " + numObjects);
}
else {
logger.debug(fieldName + " on " + elementName + " is required but " + elementName + " isn't so we can ignore this missing field.");
}
}
}
else {
Object obj = null;
if (getTargetAppName() == null) {
obj = getValueFromObject(xeo, fieldName);
}
else {
obj = getValueFromObject(xeo, getTargetAppName(), fieldName);
}
if (obj instanceof String) {
fieldValue = (String)obj;
}
else {
}
if (fieldValue == null || fieldValue.trim().length() == 0) {
// Have to check the parent field (if one exists) for situations
// where the Parent field isn't required but children of that Parent
// are. Example is DeceasedDate in BasicPerson. DeceasedDate is optional
// but Month,Day,Year are required if DeceasedDate is present...
if (isRequired && parentIsRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
throw new EnterpriseLayoutException("The " + fieldType + " " +
elementName + "/" + fieldName + " is required but it has no value.");
}
else {
logger.debug(fieldName + " on " + elementName + " is required but " + elementName + " isn't so we can ignore this missing field.");
// Don't even add the Element since it's not required and there is no
// data in the object's field.
return;
}
}
// Have to do this to validate the data since the object we're dealing
// with may not have had an EnterpriseFields object when it was populated.
try {
String tempValue = removeXmlEscapes(fieldValue);
setVariableValue(xeo, fieldName, tempValue , String.class);
}
catch (Exception e) {
throw new EnterpriseLayoutException("Error setting " + objectName + "/" + fieldName +
" to the value " + fieldValue + " Exception: " + e.getMessage(), e);
}
// Now, we have to get the value from the object again since it may have been
// modified when the setter methods are called above. Otherwise, we'll be
// creating the XML using the "non enterprise" value.
if (getTargetAppName() == null) {
fieldValue = (String)getValueFromObject(xeo, fieldName);
}
else {
fieldValue = (String)getValueFromObject(xeo, getTargetAppName(), fieldName);
}
logger.debug("[buildElement] Adding Element (" + fieldName + ") with a value of " +
fieldValue + " to Element " + elementName + " passed in.");
eOutput.addContent(new Element(fieldName).setText(fieldValue));
}
}
else if (fieldType.equals("Attribute")) {
StringBuffer sBuf = new StringBuffer();
sBuf.append(fieldName.substring(0,1).toLowerCase());
sBuf.append(fieldName.substring(1));
String attrName = new String(sBuf);
Object obj = null;
if (getTargetAppName() == null) {
obj = getValueFromObject(xeo, fieldName);
}
else {
obj = getValueFromObject(xeo, getTargetAppName(), fieldName);
}
if (obj instanceof String) {
fieldValue = (String)obj;
}
else {
}
if (fieldValue == null || fieldValue.trim().length() == 0) {
// Have to check the parent field (if one exists) for situations
// where the Parent field isn't required but children of that Parent
// are. Example is DeceasedDate in BasicPerson. DeceasedDate is optional
// but Month,Day,Year are required if DeceasedDate is present...
// 8/6/01 - this won't work for things like Address@type, type is required but Address isn't
// need to figure out a better way to do this.....
if (isRequired && parentIsRequired && xeo.getEnterpriseFields().ignoreValidation() == false) {
throw new EnterpriseLayoutException("The " + fieldType + " " +
elementName + "/" + fieldName + " is required but it has no value.");
}
else {
logger.debug(fieldName + " on " + elementName + " is required but " + elementName + " isn't so we can ignore this missing field.");
// Don't even add the Attribute since it's not required and there is no
// data in the object's field.
return;
}
}
// Have to do this to validate the data since the object we're dealing
// with may not have had an EnterpriseFields object when it was populated.
try {
String tempValue = removeXmlEscapes(fieldValue);
setVariableValue(xeo, fieldName, tempValue , String.class);
}
catch (Exception e) {
throw new EnterpriseLayoutException("Error setting " + objectName + "/" + fieldName +
" to the value " + fieldValue + " Exception: " + e.getMessage(), e);
}
// Now, we have to get the value from the object again since it may have been
// modified when the setter methods are called above. Otherwise, we'll be
// creating the XML using the "non enterprise" value.
if (getTargetAppName() == null) {
fieldValue = (String)getValueFromObject(xeo, fieldName);
}
else {
fieldValue = (String)getValueFromObject(xeo, getTargetAppName(), fieldName);
}
logger.debug("[buildElement] Adding Attribute (" + attrName + ") with a value of " +
fieldValue + " to Element " + elementName + " passed in.");
eOutput.setAttribute(attrName, fieldValue);
}
else if (fieldType.equals("Object")) {
// If we can't find the ObjectDefinition as a child,
// look for it at the root of the document. If it's
// not there, then we have an error situation.
Element eObjDef = eField.getChild("ObjectDefinition");
if (eObjDef == null) {
eObjDef = getLayout(getLayoutRoot(), fieldName);
if (eObjDef == null) {
throw new EnterpriseLayoutException("Can't find an ObjectDefinition in the Layout Document for " +
objectName + "/" + fieldName);
}
}
java.util.List lFields = eObjDef.getChildren("Field");
String layoutName = eObjDef.getAttribute("name").getValue();
logger.debug("There are " + lFields.size() + " Fields in the " + layoutName + " Layout.");
if (isRepeating(xeo, fieldName)) {
int numObjects = getLength(xeo, fieldName);
java.util.List sortedIndexes = getSortedIndexes(xeo, numObjects, fieldName);
logger.debug("XmlLayout: sortedIndexes.size: " + sortedIndexes.size());
for (int i=0; i<sortedIndexes.size(); i++) {
String nextIndex = (String)sortedIndexes.get(i);
logger.debug("Sorted Index [" + i + "] is " + nextIndex);
Integer iParm = new Integer(nextIndex);
// the rest is the same????
Object obj = null;
obj = getValueFromObject(xeo, fieldName, new Object[] {iParm}, new Class[] {Integer.TYPE});
if (obj instanceof XmlEnterpriseObject) {
XmlEnterpriseObject aNewXeo = (XmlEnterpriseObject)obj;
try {
aNewXeo.setEnterpriseFields((EnterpriseFields)xeo.getEnterpriseFields().clone());
}
catch (Exception e) {
throw new EnterpriseLayoutException("Exception cloning EnterpriseFields object for object " + objectName + "." +
" Exception: " + e.getMessage(), e);
}
String newXeoClassName = aNewXeo.getClass().getName();
String newXeoObjectName = newXeoClassName.substring(newXeoClassName.lastIndexOf('.') + 1);
Element eChildOutput = new Element(fieldName);
for (int j=0; j<lFields.size(); j++) {
Element eChildField = (Element)lFields.get(j);
buildElement(aNewXeo, eChildOutput, eChildField, isRequired);
}
logger.debug("[buildElement] Adding [" + i + "] Element " + fieldName + " to the " + elementName + " passed in.");
eOutput.addContent(eChildOutput);
}
else {
// should never get here.
}
}
}
else {
Object obj = null;
obj = getValueFromObject(xeo, fieldName);
if (obj instanceof XmlEnterpriseObject) {
XmlEnterpriseObject aNewXeo = (XmlEnterpriseObject)obj;
try {
aNewXeo.setEnterpriseFields((EnterpriseFields)xeo.getEnterpriseFields().clone());
}
catch (Exception e) {
throw new EnterpriseLayoutException("Exception cloning EnterpriseFields object for object " + objectName + "." +
" Exception: " + e.getMessage(), e);
}
try {
if (aNewXeo.isEmpty()) {
logger.debug("No need to try and add the " + fieldName + " to the element passed in.");
if (isRequired == false || parentIsRequired == false) {
return;
}
}
else {
logger.debug("Object " + fieldName + " isn't empty so we have to try and add it.");
}
}
catch (XmlEnterpriseObjectException e) {
throw new EnterpriseLayoutException("Error checking if object " + objectName + "/" +
fieldName + " is empty. Exception: " + e.getMessage(), e);
}
String newXeoClassName = aNewXeo.getClass().getName();
String newXeoObjectName = newXeoClassName.substring(newXeoClassName.lastIndexOf('.') + 1);
Element eChildOutput = new Element(fieldName);
for (int i=0; i<lFields.size(); i++) {
Element eChildField = (Element)lFields.get(i);
buildElement(aNewXeo, eChildOutput, eChildField, isRequired);
}
logger.debug("[buildElement] Adding Element " + fieldName + " to the " + elementName + " passed in.");
eOutput.addContent(eChildOutput);
}