1 19 20 package org.netbeans.modules.schema2beansdev; 21 22 import org.netbeans.modules.schema2beans.*; 23 24 import java.util.*; 25 26 62 public class GraphNode { 63 68 private String name; 69 private String namespace = null; 70 71 74 private String uniqueName; 75 76 103 private GraphLink link; 104 105 112 private boolean created; 113 114 117 private int refCount; 118 119 122 private Object object; 123 124 127 private List attributes; 128 129 private boolean marked; 131 132 private String javaType; 135 136 private Map extendedProperties = new LinkedHashMap(); 137 138 private Set extraData = new LinkedHashSet(); 139 private boolean isUnion = false; 140 private boolean isAbstract = false; 141 142 private GraphNode extendsNode; 143 private GraphNode alias; 144 145 GraphNode(String name, String uniqueName) { 146 setName(name); 148 this.uniqueName = uniqueName; 149 this.created = false; 150 this.attributes = null; 151 this.marked = false; 152 } 153 154 void addAttribute(AttrProp attr) { 155 if (alias != null) { 156 alias.addAttribute(attr); 157 return; 158 } 159 if (this.attributes == null) 160 this.attributes = new ArrayList(); 161 this.attributes.add(attr); 162 } 164 165 AttrProp[] getAttributes() { 166 if (alias != null) { 167 return alias.getAttributes(); 168 } 169 int size = 0; 170 171 if (this.attributes != null) 172 size = this.attributes.size(); 173 174 AttrProp[] ret = new AttrProp[size]; 175 176 if (size > 0) 177 return (AttrProp[])this.attributes.toArray(ret); 178 else 179 return ret; 180 } 181 182 void setObject(Object obj) { 183 this.object = obj; 184 } 185 186 Object getObject() { 187 return this.object; 188 } 189 190 String getNameWithNamespace() { 191 if (namespace == null) 192 return name; 193 return "{"+namespace+"}"+name; 194 } 195 196 199 String getName() { 200 return name; 201 } 202 203 206 String getNamespace() { 207 if (alias != null) 208 return alias.getNamespace(); 209 return namespace; 210 } 211 212 void setName(String name) { 213 if (name.charAt(0) == '{') { 215 int closingBracket = name.indexOf('}'); 216 this.name = name.substring(closingBracket+1, name.length()); 217 this.namespace = name.substring(1, closingBracket); 218 } else { 219 this.name = name; 220 this.namespace = null; 221 } 222 } 223 224 GraphLink getGraphLink() { 225 if (alias != null) 226 return alias.getGraphLink(); 227 return this.link; 228 } 229 230 void setGraphLink(GraphLink l) { 231 if (alias != null) { 232 alias.setGraphLink(l); 233 return; 234 } 235 link = l; 236 } 237 238 void setMarked(boolean value) { 239 if (alias != null) { 240 alias.setMarked(value); 241 return; 242 } 243 marked = value; 244 } 245 246 boolean getMarked() { 247 if (alias != null) { 248 return alias.getMarked(); 249 } 250 return marked; 251 } 252 253 boolean isAbstract() { 254 return isAbstract; 255 } 256 257 void setAbstract(boolean value) { 258 isAbstract = value; 259 } 260 261 void setCreated(boolean value) { 262 if (alias != null) { 263 alias.setCreated(value); 264 return; 265 } 266 created = value; 267 } 268 269 boolean isCreated() { 270 if (alias != null) { 271 return alias.isCreated(); 272 } 273 return created; 274 } 275 276 280 public void setExtendedProperty(String name, Object value) { 281 if (alias != null) { 282 alias.setExtendedProperty(name, value); 283 return; 284 } 285 extendedProperties.put(name, value); 286 } 287 288 292 public Object getExtendedProperty(String name) { 293 if (alias != null) { 294 return alias.getExtendedProperty(name); 295 } 296 return extendedProperties.get(name); 297 } 298 299 void incrRefCount() { 300 306 ++refCount; 307 } 308 309 int getRefCount() { 310 315 return refCount; 316 } 317 318 void setAlias(GraphNode n) { 319 alias = n; 320 } 321 322 GraphNode getAlias() { 323 return alias; 324 } 325 326 332 GraphNode[] getNodes() { 333 if (alias != null) 334 return alias.getNodes(); 335 Map list = new HashMap(); 336 gatherElements(this.link, list); 337 GraphNode[] ret = new GraphNode[list.size()]; 338 return (GraphNode[])list.values().toArray(ret); 339 } 340 341 private void gatherElements(GraphLink l, Map list) { 346 while (l != null) { 347 if (l.element != null) 348 list.put(l.element.getName(), l.element); 349 350 gatherElements(l.getFirstChild(), list); 351 352 l = l.getSibling(); 353 } 354 } 355 356 public void setJavaType(String jt) { 357 if (alias != null) { 358 alias.setJavaType(jt); 359 return; 360 } 361 javaType = jt; 362 } 363 364 public String getJavaType() { 365 if (alias != null) { 366 return alias.getJavaType(); 367 } 368 return javaType; 369 } 370 371 public void setExtension(GraphNode extendsNode) { 372 if (alias != null) { 373 alias.setExtension(extendsNode); 374 return; 375 } 376 this.extendsNode = extendsNode; 377 } 378 379 public GraphNode getExtension() { 380 if (alias != null) 381 return alias.extendsNode; 382 return extendsNode; 383 } 384 385 public boolean isUnion() { 386 return isUnion; 387 } 388 389 public void setUnion(boolean value) { 390 isUnion = value; 391 } 392 393 public void addExtraData(Object data) { 394 extraData.add(data); 395 } 396 397 public void addExtraDataIncludeAlias(Object data) { 398 extraData.add(data); 399 if (alias != null) 400 alias.addExtraData(data); 401 } 402 403 public Object searchExtraData(Class type) { 404 for (Iterator it = extraData.iterator(); it.hasNext(); ) { 405 Object o = it.next(); 406 if (type.isAssignableFrom(o.getClass())) 408 return o; 409 } 410 return null; 411 } 412 413 public Iterator extraDataIterator() { 414 return extraData.iterator(); 415 } 416 417 public Set getExtraData() { 418 return extraData; 419 } 420 421 public String toString() { 422 if (alias != null) { 423 return name+" (is a "+alias.toString()+")"; 424 } 425 return getNameWithNamespace(); 426 } 427 } 428 | Popular Tags |