View Javadoc

1   package es.inteco.eni.xml;
2   
3   import java.util.Iterator;
4   import java.util.LinkedHashMap;
5   import java.util.Map;
6   
7   import org.xml.sax.Attributes;
8   
9   /**
10   * Clase que representa un node del arbol
11   * 
12   * 
13   *
14   */
15  public class XmlNode {
16  
17  	/**
18  	 * Uri del nodo
19  	 */
20  	private String uri;
21  	/**
22  	 * QName del nodo
23  	 */
24  	private String qName;
25  	/**
26  	 * LName del nodo
27  	 */
28  	private String lName;
29  	/**
30  	 * Valor del nodo
31  	 */
32  	private String value;
33  	/**
34  	 * Atributos del nodo
35  	 */
36  	private Attributes attributes;
37  	/**
38  	 * Hijos del nodo
39  	 */
40  	private Map<String, XmlNode> childs = new LinkedHashMap<String, XmlNode>();
41  	
42  	/**
43  	 * Padre
44  	 */
45  	private XmlNode parent;
46  	
47  	/**
48  	 * Profundidad del nodo
49  	 */
50  	private Integer deep;
51  	/**
52  	 * Numero total de hojas descendientes del nodo
53  	 */
54  	private Integer totalLeafDescendants;
55  
56  	/**
57  	 * @return Devuelve el valor del campo uri
58  	 */
59  	public String getUri() {
60  		return uri;
61  	}
62  
63  	/**
64  	 * @param Asigna al campo uri el valor del parámetro uri
65  	 */
66  	public void setUri(String uri) {
67  		this.uri = uri;
68  	}
69  
70  	/**
71  	 * @return Devuelve el valor del campo qName
72  	 */
73  	public String getqName() {
74  		return qName;
75  	}
76  
77  	/**
78  	 * @param Asigna al campo qName el valor del parámetro qName
79  	 */
80  	public void setqName(String qName) {
81  		this.qName = qName;
82  	}
83  
84  	/**
85  	 * @return Devuelve el valor del campo lName
86  	 */
87  	public String getlName() {
88  		return lName;
89  	}
90  
91  	/**
92  	 * @param Asigna al campo lName el valor del parámetro lName
93  	 */
94  	public void setlName(String lName) {
95  		this.lName = lName;
96  	}
97  
98  	/**
99  	 * @return Devuelve el valor del campo attributes
100 	 */
101 	public Attributes getAttributes() {
102 		return attributes;
103 	}
104 
105 	/**
106 	 * @param Asigna al campo attributes el valor del parámetro attributes
107 	 */
108 	public void setAttributes(Attributes attributes) {
109 		this.attributes = attributes;
110 	}
111 
112 	/**
113 	 * @return Devuelve el valor del campo childs
114 	 */
115 	public Map<String, XmlNode> getChilds() {
116 		return childs;
117 	}
118 
119 	/**
120 	 * @param Asigna al campo childs el valor del parámetro childs
121 	 */
122 	public void setChilds(Map<String, XmlNode> childs) {
123 		this.childs = childs;
124 	}
125 	
126 	
127 	/**
128 	 * @return Devuelve el valor del campo parent
129 	 */
130 	public XmlNode getParent() {
131 		return parent;
132 	}
133 
134 	/**
135 	 * @param Asigna al campo parent el valor del parámetro parent
136 	 */
137 	public void setParent(XmlNode parent) {
138 		this.parent = parent;
139 	}
140 
141 	/**
142 	 * @return Devuelve el valor del campo deep
143 	 */
144 	public Integer getDeep() {
145 		return deep;
146 	}
147 
148 	/**
149 	 * @param Asigna al campo deep el valor del parámetro deep
150 	 */
151 	public void setDeep(Integer deep) {
152 		this.deep = deep;
153 	}
154 	
155 	/**
156 	 * @return Devuelve el valor del campo value
157 	 */
158 	public String getValue() {
159 		return value;
160 	}
161 
162 	/**
163 	 * @param Asigna al campo value el valor del parámetro value
164 	 */
165 	public void setValue(String value) {
166 		this.value = value;
167 	}
168 
169 	/**
170 	 * @return Devuelve el valor del campo totalDescendants
171 	 */
172 	public Integer getTotalLeafDescendants() {
173 		Integer result = this.totalLeafDescendants;
174 		if(result==null){
175 			result=0;
176 			Iterator<String> it = childs.keySet().iterator();
177 			if(childs.size()==0){
178 				result++;
179 			}
180 			while(it.hasNext()){
181 				String nodeId = it.next();
182 				result+=childs.get(nodeId).getTotalLeafDescendants();
183 			}
184 			this.totalLeafDescendants = result;
185 		}
186 		
187 		return result;
188 	}
189 
190 	/**
191 	 * @param Asigna al campo totalLeafDescendants el valor del parámetro totalLeafDescendants
192 	 */
193 	public void setTotalDescendants(Integer totalLeafDescendants) {
194 		this.totalLeafDescendants = totalLeafDescendants;
195 	}
196 }