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 15 16 public class XmlEditorTreeDefinitionNode { 17 18 private Map subNodes; 19 private String value; 20 private boolean mustHaveChilds; 21 private Vector itemsKeys; 22 private HashMap items; 23 24 public XmlEditorTreeDefinitionNode(String value) { 25 this.value = value; 26 } 27 28 33 public XmlEditorTreeDefinitionNode addNodeFrom(String value) { 34 XmlEditorTreeDefinitionNode node = null; 35 node = new XmlEditorTreeDefinitionNode(value); 36 getSubnodes().put(value, node); 37 return node; 38 } 39 40 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: 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 75 getItemsKeys().add(attributeDecl.getName()); 76 } 77 } 78 79 public String 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 |