KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > xmleditor > XmlEditorTreeDefinitionNode


1 package com.calipso.xmleditor;
2
3 import org.exolab.castor.xml.schema.AttributeDecl;
4 import org.exolab.castor.xml.schema.SimpleTypesFactory;
5
6 import java.util.*;
7
8 /**
9  *
10  * User: soliveri
11  * Date: 25-sep-2003
12  * Time: 14:19:12
13  *
14  */

15
16 public class XmlEditorTreeDefinitionNode {
17
18   private Map subNodes;
19   private String JavaDoc value;
20   private boolean mustHaveChilds;
21   private Vector itemsKeys;
22   private HashMap items;
23
24   public XmlEditorTreeDefinitionNode(String JavaDoc value) {
25     this.value = value;
26   }
27
28   /**
29    * Agrega un nodo a los hijos del nodo.
30    * @param value
31    * @return
32    */

33   public XmlEditorTreeDefinitionNode addNodeFrom(String JavaDoc value) {
34     XmlEditorTreeDefinitionNode node = null;
35     node = new XmlEditorTreeDefinitionNode(value);
36     getSubnodes().put(value, node);
37     return node;
38   }
39
40   /**
41    * Agrega los atributos al nodo.
42    * @param enumeration
43    * @throws XmlEditorException
44    */

45   public void addNodeAttributes(Enumeration enumeration) throws XmlEditorException{
46     while(enumeration.hasMoreElements()) {
47       AttributeDecl attributeDecl = (AttributeDecl) enumeration.nextElement();
48       int type = attributeDecl.getSimpleType().getBuiltInBaseType().getTypeCode();
49       switch(type){
50         case SimpleTypesFactory.STRING_TYPE:
51           getItems().put(attributeDecl.getName(), new XmlEditorTreeNodeItemDefinition(attributeDecl.getName().toUpperCase(), attributeDecl.isOptional(), XmlEditorDataType.STRING , attributeDecl.getName()));
52           break;
53         case SimpleTypesFactory.NMTOKEN_TYPE:
54           Enumeration facets = attributeDecl.getSimpleType().getLocalFacets();
55           getItems().put(attributeDecl.getName(), new XmlEditorTreeNodeItemDefinition(attributeDecl.getName().toUpperCase(), attributeDecl.isOptional(), XmlEditorDataType.TOKENS, facets));
56           break;
57         case SimpleTypesFactory.BOOLEAN_TYPE:
58           getItems().put(attributeDecl.getName(), new XmlEditorTreeNodeItemDefinition(attributeDecl.getName().toUpperCase(), attributeDecl.isOptional(), XmlEditorDataType.BOOLEAN, attributeDecl.getName()));
59           break;
60         case SimpleTypesFactory.INTEGER_TYPE:
61         case SimpleTypesFactory.INT_TYPE:
62         case SimpleTypesFactory.DECIMAL_TYPE: //Todo: Mejorar el tratamiento de este tipo en particular
63
getItems().put(attributeDecl.getName(), new XmlEditorTreeNodeItemDefinition(attributeDecl.getName().toUpperCase(), attributeDecl.isOptional(), XmlEditorDataType.INTEGER, attributeDecl.getName()));
64           break;
65         default: throw new XmlEditorException("No existe el tipo de dato solicitado");
66       }
67 /* if(attributeDecl.getSimpleType().getBuiltInBaseType().getTypeCode() == SimpleTypesFactory.STRING_TYPE) {
68         getItems().put(attributeDecl.getName(), new XmlEditorTreeNodeItemDefinition(attributeDecl.getName().toUpperCase(), attributeDecl.isOptional(), XmlEditorDataType.STRING, attributeDecl.getName()));
69       } else if (attributeDecl.getSimpleType().getBuiltInBaseType().getTypeCode() == SimpleTypesFactory.NMTOKEN_TYPE) {
70         Enumeration facets = attributeDecl.getSimpleType().getLocalFacets();
71         getItems().put(attributeDecl.getName(), new XmlEditorTreeNodeItemDefinition(attributeDecl.getName().toUpperCase(), attributeDecl.isOptional(), XmlEditorDataType.TOKENS, facets));
72       } else if (attributeDecl.getSimpleType().getBuiltInBaseType().getTypeCode() == SimpleTypesFactory.BOOLEAN_TYPE) {
73         getItems().put(attributeDecl.getName(), new XmlEditorTreeNodeItemDefinition(attributeDecl.getName().toUpperCase(), attributeDecl.isOptional(), XmlEditorDataType.BOOLEAN, attributeDecl.getName()));
74       }*/

75       getItemsKeys().add(attributeDecl.getName());
76     }
77   }
78
79   public String JavaDoc getValue() {
80     return value;
81   }
82
83   public void setMustHaveChilds(int childs) {
84     if(childs >= 1) {
85       this.mustHaveChilds = true;
86     } else {
87       this.mustHaveChilds = false;
88     }
89   }
90
91   public Map getSubnodes() {
92     if(subNodes == null) {
93       subNodes = new HashMap();
94     }
95     return subNodes;
96   }
97
98   public Vector getItemsKeys() {
99     if(itemsKeys == null) {
100       itemsKeys = new Vector();
101     }
102     return itemsKeys;
103   }
104
105   public HashMap getItems() {
106     if(items == null) {
107       items = new HashMap();
108     }
109     return items;
110   }
111 }
112
Popular Tags