KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > xmlEngine > AttributeComponentTemplate


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.xmlEngine;
13
14 import java.util.Enumeration JavaDoc;
15
16 import org.apache.log4j.Logger ;
17
18 /**
19   Class that store the information of the attributes of the configuration file
20   */

21 class AttributeComponentTemplate implements XmlComponentTemplate, IDComponent {
22   // private FieldComponent fieldComponent = null;
23
private FunctionTemplate functionTemplate = null;
24   private XmlComponentTemplate xmlComponentTemplate = null;
25   private String JavaDoc attributeName;
26   private String JavaDoc strReplace;
27   private String JavaDoc strBooleanAttribute;
28   private XmlComponentTemplate xmlComponentBooleanWithId;
29
30   static Logger log4jAttributeComponentTemplate = Logger.getLogger(AttributeComponentTemplate.class);
31
32   public AttributeComponentTemplate(FunctionTemplate functionTemplate, String JavaDoc attributeName, String JavaDoc strReplace,
33       String JavaDoc 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 JavaDoc attributeName, String JavaDoc strReplace,
43       String JavaDoc 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 JavaDoc attributeName() {
64     return attributeName;
65   }
66
67   public String JavaDoc replace() {
68     return strReplace;
69   }
70
71   public String JavaDoc attributeBooleanName() {
72     return strBooleanAttribute;
73   }
74
75   public XmlComponentTemplate booleanWithId() {
76     return xmlComponentBooleanWithId;
77   }
78
79   /* replaced 21/04/2002
80      public XmlComponentValue createXmlComponentValue(XmlDocument xmlDocument) {
81      return new AttributeComponentValue(this, xmlDocument);
82      }
83
84 */

85
86   // XmlEngineNP: XmlComponentTemplate is used as FieldTemplate. It must be made based in the original Id's
87
public FieldValue createAttributeComponentValue(XmlDocument xmlDocument) {
88     for (Enumeration JavaDoc<DataValue> e1 = xmlDocument.hasDataValue.elements() ; e1.hasMoreElements();) {
89       DataValue dataValue = e1.nextElement();
90       for (Enumeration JavaDoc 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     // log4jAttributeComponentTemplate.debug("Instanceof: " + (xmlComponentTemplate instanceof FieldTemplate) +
105
// " Function: " + (xmlComponentTemplate instanceof FunctionTemplate)+
106
// " Function subtract: " + (xmlComponentTemplate instanceof FunctionSubtractTemplate));
107
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