1 12 package org.openbravo.xmlEngine; 13 14 import java.util.Enumeration ; 15 16 import org.apache.log4j.Logger ; 17 18 21 class AttributeComponentTemplate implements XmlComponentTemplate, IDComponent { 22 private FunctionTemplate functionTemplate = null; 24 private XmlComponentTemplate xmlComponentTemplate = null; 25 private String attributeName; 26 private String strReplace; 27 private String strBooleanAttribute; 28 private XmlComponentTemplate xmlComponentBooleanWithId; 29 30 static Logger log4jAttributeComponentTemplate = Logger.getLogger(AttributeComponentTemplate.class); 31 32 public AttributeComponentTemplate(FunctionTemplate functionTemplate, String attributeName, String strReplace, 33 String strBooleanAttribute, XmlComponentTemplate xmlComponentBooleanWithId) { 34 this.functionTemplate = functionTemplate; 35 this.xmlComponentTemplate = functionTemplate; 36 this.attributeName = attributeName; 37 this.strReplace = strReplace; 38 this.strBooleanAttribute = strBooleanAttribute; 39 this.xmlComponentBooleanWithId = xmlComponentBooleanWithId; 40 } 41 42 public AttributeComponentTemplate(XmlComponentTemplate xmlComponent, String attributeName, String strReplace, 43 String strBooleanAttribute, XmlComponentTemplate xmlComponentBooleanWithId) { 44 this.xmlComponentTemplate = xmlComponent; 45 this.attributeName = attributeName; 46 this.strReplace = strReplace; 47 this.strBooleanAttribute = strBooleanAttribute; 48 this.xmlComponentBooleanWithId = xmlComponentBooleanWithId; 49 } 50 51 public int type() { 52 return ATTRIBUTE; 53 } 54 55 public FunctionTemplate functionTemplate() { 56 return functionTemplate; 57 } 58 59 public XmlComponentTemplate xmlComponentTemplate() { 60 return xmlComponentTemplate; 61 } 62 63 public String attributeName() { 64 return attributeName; 65 } 66 67 public String replace() { 68 return strReplace; 69 } 70 71 public String attributeBooleanName() { 72 return strBooleanAttribute; 73 } 74 75 public XmlComponentTemplate booleanWithId() { 76 return xmlComponentBooleanWithId; 77 } 78 79 85 86 public FieldValue createAttributeComponentValue(XmlDocument xmlDocument) { 88 for (Enumeration <DataValue> e1 = xmlDocument.hasDataValue.elements() ; e1.hasMoreElements();) { 89 DataValue dataValue = e1.nextElement(); 90 for (Enumeration e2 = dataValue.vecFieldValue.elements() ; e2.hasMoreElements();) { 91 FieldValue fieldValue = (FieldValue)e2.nextElement(); 92 log4jAttributeComponentTemplate.debug("Comparing: " + ((FieldTemplate)xmlComponentTemplate).name() + " & " + fieldValue.fieldTemplate.name()); 93 if (fieldValue.fieldTemplate.name().equals(((FieldTemplate)xmlComponentTemplate).name())) { 94 return fieldValue; 95 } 96 } 97 } 98 log4jAttributeComponentTemplate.info("New FieldValue: " + ((FieldTemplate)xmlComponentTemplate).name()); 99 FieldValue fieldValue = new FieldValue((FieldTemplate)(this.xmlComponentTemplate), xmlDocument); 100 return fieldValue; 101 } 102 103 public XmlComponentValue createXmlComponentValue(XmlDocument xmlDocument) { 104 if (xmlComponentTemplate instanceof FunctionTemplate) { 108 return ((FunctionTemplate)xmlComponentTemplate).createFunctionValue(xmlDocument); 109 } else if (xmlComponentTemplate instanceof ParameterTemplate) { 110 return ((ParameterTemplate)xmlComponentTemplate).createParameterValue(xmlDocument); 111 } else if (xmlComponentTemplate instanceof FieldTemplate) { 112 return createAttributeComponentValue(xmlDocument); 113 } else { 114 log4jAttributeComponentTemplate.warn("Instance type not found"); 115 return null; 116 } 117 } 118 119 } 120 | Popular Tags |