1 19 26 27 package org.netbeans.modules.schema2beansdev.metadd; 28 29 public class MetaProperty implements org.netbeans.modules.schema2beansdev.metadd.CommonBean { 30 public static final String BEAN_NAME = "BeanName"; public static final String DEFAULT_VALUE = "DefaultValue"; public static final String KNOWN_VALUE = "KnownValue"; public static final String KEY = "Key"; public static final String VETOABLE = "Vetoable"; 36 private String _BeanName; 37 private java.util.List _DefaultValue = new java.util.ArrayList (); private java.util.List _KnownValue = new java.util.ArrayList (); private boolean _Key; 40 private boolean _isSet_Key = false; 41 private boolean _Vetoable; 42 private boolean _isSet_Vetoable = false; 43 44 47 public MetaProperty() { 48 _BeanName = ""; 49 } 50 51 54 public MetaProperty(String beanName) { 55 _BeanName = beanName; 56 } 57 58 61 public MetaProperty(org.netbeans.modules.schema2beansdev.metadd.MetaProperty source) { 62 this(source, false); 63 } 64 65 69 public MetaProperty(org.netbeans.modules.schema2beansdev.metadd.MetaProperty source, boolean justData) { 70 _BeanName = source._BeanName; 71 for (java.util.Iterator it = source._DefaultValue.iterator(); 72 it.hasNext(); ) { 73 String srcElement = (String )it.next(); 74 _DefaultValue.add(srcElement); 75 } 76 for (java.util.Iterator it = source._KnownValue.iterator(); 77 it.hasNext(); ) { 78 String srcElement = (String )it.next(); 79 _KnownValue.add(srcElement); 80 } 81 _Key = source._Key; 82 _isSet_Key = source._isSet_Key; 83 _Vetoable = source._Vetoable; 84 _isSet_Vetoable = source._isSet_Vetoable; 85 } 86 87 public void setBeanName(String value) { 89 _BeanName = value; 90 } 91 92 public String getBeanName() { 93 return _BeanName; 94 } 95 96 public void setDefaultValue(String [] value) { 98 if (value == null) 99 value = new String [0]; 100 _DefaultValue.clear(); 101 ((java.util.ArrayList ) _DefaultValue).ensureCapacity(value.length); 102 for (int i = 0; i < value.length; ++i) { 103 _DefaultValue.add(value[i]); 104 } 105 } 106 107 public void setDefaultValue(int index, String value) { 108 _DefaultValue.set(index, value); 109 } 110 111 public String [] getDefaultValue() { 112 String [] arr = new String [_DefaultValue.size()]; 113 return (String []) _DefaultValue.toArray(arr); 114 } 115 116 public java.util.List fetchDefaultValueList() { 117 return _DefaultValue; 118 } 119 120 public String getDefaultValue(int index) { 121 return (String )_DefaultValue.get(index); 122 } 123 124 public int sizeDefaultValue() { 126 return _DefaultValue.size(); 127 } 128 129 public int addDefaultValue(String value) { 130 _DefaultValue.add(value); 131 int positionOfNewItem = _DefaultValue.size()-1; 132 return positionOfNewItem; 133 } 134 135 138 public int removeDefaultValue(String value) { 139 int pos = _DefaultValue.indexOf(value); 140 if (pos >= 0) { 141 _DefaultValue.remove(pos); 142 } 143 return pos; 144 } 145 146 public void setKnownValue(String [] value) { 148 if (value == null) 149 value = new String [0]; 150 _KnownValue.clear(); 151 ((java.util.ArrayList ) _KnownValue).ensureCapacity(value.length); 152 for (int i = 0; i < value.length; ++i) { 153 _KnownValue.add(value[i]); 154 } 155 } 156 157 public void setKnownValue(int index, String value) { 158 _KnownValue.set(index, value); 159 } 160 161 public String [] getKnownValue() { 162 String [] arr = new String [_KnownValue.size()]; 163 return (String []) _KnownValue.toArray(arr); 164 } 165 166 public java.util.List fetchKnownValueList() { 167 return _KnownValue; 168 } 169 170 public String getKnownValue(int index) { 171 return (String )_KnownValue.get(index); 172 } 173 174 public int sizeKnownValue() { 176 return _KnownValue.size(); 177 } 178 179 public int addKnownValue(String value) { 180 _KnownValue.add(value); 181 int positionOfNewItem = _KnownValue.size()-1; 182 return positionOfNewItem; 183 } 184 185 188 public int removeKnownValue(String value) { 189 int pos = _KnownValue.indexOf(value); 190 if (pos >= 0) { 191 _KnownValue.remove(pos); 192 } 193 return pos; 194 } 195 196 public void setKey(boolean value) { 198 _Key = value; 199 _isSet_Key = true; 200 } 201 202 public boolean isKey() { 203 return _Key; 204 } 205 206 public void setVetoable(boolean value) { 208 _Vetoable = value; 209 _isSet_Vetoable = true; 210 } 211 212 public boolean isVetoable() { 213 return _Vetoable; 214 } 215 216 public void writeNode(java.io.Writer out) throws java.io.IOException { 217 String myName; 218 myName = "meta-property"; 219 writeNode(out, myName, ""); } 221 222 public void writeNode(java.io.Writer out, String nodeName, String indent) throws java.io.IOException { 223 writeNode(out, nodeName, null, indent, new java.util.HashMap ()); 224 } 225 226 229 public void writeNode(java.io.Writer out, String nodeName, String namespace, String indent, java.util.Map namespaceMap) throws java.io.IOException { 230 out.write(indent); 231 out.write("<"); 232 if (namespace != null) { 233 out.write((String )namespaceMap.get(namespace)); 234 out.write(":"); 235 } 236 out.write(nodeName); 237 out.write(">\n"); 238 String nextIndent = indent + " "; 239 if (_BeanName != null) { 240 out.write(nextIndent); 241 out.write("<bean-name"); out.write(">"); org.netbeans.modules.schema2beansdev.metadd.MetaDD.writeXML(out, _BeanName, false); 244 out.write("</bean-name>\n"); } 246 for (java.util.Iterator it = _DefaultValue.iterator(); 247 it.hasNext(); ) { 248 String element = (String )it.next(); 249 if (element != null) { 250 out.write(nextIndent); 251 out.write("<default-value"); out.write(">"); org.netbeans.modules.schema2beansdev.metadd.MetaDD.writeXML(out, element, false); 254 out.write("</default-value>\n"); } 256 } 257 for (java.util.Iterator it = _KnownValue.iterator(); it.hasNext(); 258 ) { 259 String element = (String )it.next(); 260 if (element != null) { 261 out.write(nextIndent); 262 out.write("<known-value"); out.write(">"); org.netbeans.modules.schema2beansdev.metadd.MetaDD.writeXML(out, element, false); 265 out.write("</known-value>\n"); } 267 } 268 if (_isSet_Key) { 269 if (_Key) { 270 out.write(nextIndent); 271 out.write("<key"); out.write("/>\n"); } 274 } 275 if (_isSet_Vetoable) { 276 if (_Vetoable) { 277 out.write(nextIndent); 278 out.write("<vetoable"); out.write("/>\n"); } 281 } 282 out.write(indent); 283 out.write("</"); 284 if (namespace != null) { 285 out.write((String )namespaceMap.get(namespace)); 286 out.write(":"); 287 } 288 out.write(nodeName); 289 out.write(">\n"); 290 } 291 292 public void readNode(org.w3c.dom.Node node) { 293 readNode(node, new java.util.HashMap ()); 294 } 295 296 public void readNode(org.w3c.dom.Node node, java.util.Map namespacePrefixes) { 297 if (node.hasAttributes()) { 298 org.w3c.dom.NamedNodeMap attrs = node.getAttributes(); 299 org.w3c.dom.Attr attr; 300 java.lang.String attrValue; 301 boolean firstNamespaceDef = true; 302 for (int attrNum = 0; attrNum < attrs.getLength(); ++attrNum) { 303 attr = (org.w3c.dom.Attr ) attrs.item(attrNum); 304 String attrName = attr.getName(); 305 if (attrName.startsWith("xmlns:")) { 306 if (firstNamespaceDef) { 307 firstNamespaceDef = false; 308 namespacePrefixes = new java.util.HashMap (namespacePrefixes); 310 } 311 String attrNSPrefix = attrName.substring(6, attrName.length()); 312 namespacePrefixes.put(attrNSPrefix, attr.getValue()); 313 } 314 } 315 } 316 org.w3c.dom.NodeList children = node.getChildNodes(); 317 for (int i = 0, size = children.getLength(); i < size; ++i) { 318 org.w3c.dom.Node childNode = children.item(i); 319 String childNodeName = (childNode.getLocalName() == null ? childNode.getNodeName().intern() : childNode.getLocalName().intern()); 320 String childNodeValue = ""; 321 if (childNode.getFirstChild() != null) { 322 childNodeValue = childNode.getFirstChild().getNodeValue(); 323 } 324 if (childNodeName == "bean-name") { 325 _BeanName = childNodeValue; 326 } 327 else if (childNodeName == "default-value") { 328 String aDefaultValue; 329 aDefaultValue = childNodeValue; 330 _DefaultValue.add(aDefaultValue); 331 } 332 else if (childNodeName == "known-value") { 333 String aKnownValue; 334 aKnownValue = childNodeValue; 335 _KnownValue.add(aKnownValue); 336 } 337 else if (childNodeName == "key") { 338 if (childNode.getFirstChild() == null) 339 _Key = true; 340 else 341 _Key = java.lang.Boolean.valueOf(childNodeValue).booleanValue(); 342 _isSet_Key = true; 343 } 344 else if (childNodeName == "vetoable") { 345 if (childNode.getFirstChild() == null) 346 _Vetoable = true; 347 else 348 _Vetoable = java.lang.Boolean.valueOf(childNodeValue).booleanValue(); 349 _isSet_Vetoable = true; 350 } 351 else { 352 } 354 } 355 } 356 357 public void validate() throws org.netbeans.modules.schema2beansdev.metadd.MetaDD.ValidateException { 358 boolean restrictionFailure = false; 359 boolean restrictionPassed = false; 360 if (getBeanName() == null) { 362 throw new org.netbeans.modules.schema2beansdev.metadd.MetaDD.ValidateException("getBeanName() == null", org.netbeans.modules.schema2beansdev.metadd.MetaDD.ValidateException.FailureType.NULL_VALUE, "beanName", this); } 364 } 369 370 public void changePropertyByName(String name, Object value) { 371 if (name == null) return; 372 name = name.intern(); 373 if (name == "beanName") 374 setBeanName((String )value); 375 else if (name == "defaultValue") 376 addDefaultValue((String )value); 377 else if (name == "defaultValue[]") 378 setDefaultValue((String []) value); 379 else if (name == "knownValue") 380 addKnownValue((String )value); 381 else if (name == "knownValue[]") 382 setKnownValue((String []) value); 383 else if (name == "key") 384 setKey(((java.lang.Boolean )value).booleanValue()); 385 else if (name == "vetoable") 386 setVetoable(((java.lang.Boolean )value).booleanValue()); 387 else 388 throw new IllegalArgumentException (name+" is not a valid property name for MetaProperty"); 389 } 390 391 public Object fetchPropertyByName(String name) { 392 if (name == "beanName") 393 return getBeanName(); 394 if (name == "defaultValue[]") 395 return getDefaultValue(); 396 if (name == "knownValue[]") 397 return getKnownValue(); 398 if (name == "key") 399 return (isKey() ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE); 400 if (name == "vetoable") 401 return (isVetoable() ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE); 402 throw new IllegalArgumentException (name+" is not a valid property name for MetaProperty"); 403 } 404 405 public String nameSelf() { 406 return "MetaProperty"; 407 } 408 409 public String nameChild(Object childObj) { 410 return nameChild(childObj, false, false); 411 } 412 413 418 public String nameChild(Object childObj, boolean returnConstName, boolean returnSchemaName) { 419 return nameChild(childObj, returnConstName, returnSchemaName, false); 420 } 421 422 427 public String nameChild(Object childObj, boolean returnConstName, boolean returnSchemaName, boolean returnXPathName) { 428 if (childObj instanceof java.lang.String ) { 429 java.lang.String child = (java.lang.String ) childObj; 430 if (child == _BeanName) { 431 if (returnConstName) { 432 return BEAN_NAME; 433 } else if (returnSchemaName) { 434 return "bean-name"; 435 } else if (returnXPathName) { 436 return "bean-name"; 437 } else { 438 return "BeanName"; 439 } 440 } 441 int index = 0; 442 for (java.util.Iterator it = _DefaultValue.iterator(); 443 it.hasNext(); ) { 444 String element = (String )it.next(); 445 if (child == element) { 446 if (returnConstName) { 447 return DEFAULT_VALUE; 448 } else if (returnSchemaName) { 449 return "default-value"; 450 } else if (returnXPathName) { 451 return "default-value[position()="+index+"]"; 452 } else { 453 return "DefaultValue."+Integer.toHexString(index); 454 } 455 } 456 ++index; 457 } 458 index = 0; 459 for (java.util.Iterator it = _KnownValue.iterator(); 460 it.hasNext(); ) { 461 String element = (String )it.next(); 462 if (child == element) { 463 if (returnConstName) { 464 return KNOWN_VALUE; 465 } else if (returnSchemaName) { 466 return "known-value"; 467 } else if (returnXPathName) { 468 return "known-value[position()="+index+"]"; 469 } else { 470 return "KnownValue."+Integer.toHexString(index); 471 } 472 } 473 ++index; 474 } 475 } 476 if (childObj instanceof java.lang.Boolean ) { 477 java.lang.Boolean child = (java.lang.Boolean ) childObj; 478 if (((java.lang.Boolean )child).booleanValue() == _Key) { 479 if (returnConstName) { 480 return KEY; 481 } else if (returnSchemaName) { 482 return "key"; 483 } else if (returnXPathName) { 484 return "key"; 485 } else { 486 return "Key"; 487 } 488 } 489 if (((java.lang.Boolean )child).booleanValue() == _Vetoable) { 490 if (returnConstName) { 491 return VETOABLE; 492 } else if (returnSchemaName) { 493 return "vetoable"; 494 } else if (returnXPathName) { 495 return "vetoable"; 496 } else { 497 return "Vetoable"; 498 } 499 } 500 } 501 return null; 502 } 503 504 507 public org.netbeans.modules.schema2beansdev.metadd.CommonBean[] childBeans(boolean recursive) { 508 java.util.List children = new java.util.LinkedList (); 509 childBeans(recursive, children); 510 org.netbeans.modules.schema2beansdev.metadd.CommonBean[] result = new org.netbeans.modules.schema2beansdev.metadd.CommonBean[children.size()]; 511 return (org.netbeans.modules.schema2beansdev.metadd.CommonBean[]) children.toArray(result); 512 } 513 514 517 public void childBeans(boolean recursive, java.util.List beans) { 518 } 519 520 public boolean equals(Object o) { 521 return o instanceof org.netbeans.modules.schema2beansdev.metadd.MetaProperty && equals((org.netbeans.modules.schema2beansdev.metadd.MetaProperty) o); 522 } 523 524 public boolean equals(org.netbeans.modules.schema2beansdev.metadd.MetaProperty inst) { 525 if (inst == this) { 526 return true; 527 } 528 if (inst == null) { 529 return false; 530 } 531 if (!(_BeanName == null ? inst._BeanName == null : _BeanName.equals(inst._BeanName))) { 532 return false; 533 } 534 if (sizeDefaultValue() != inst.sizeDefaultValue()) 535 return false; 536 for (java.util.Iterator it = _DefaultValue.iterator(), it2 = inst._DefaultValue.iterator(); 538 it.hasNext() && it2.hasNext(); ) { 539 String element = (String )it.next(); 540 String element2 = (String )it2.next(); 541 if (!(element == null ? element2 == null : element.equals(element2))) { 542 return false; 543 } 544 } 545 if (sizeKnownValue() != inst.sizeKnownValue()) 546 return false; 547 for (java.util.Iterator it = _KnownValue.iterator(), it2 = inst._KnownValue.iterator(); 549 it.hasNext() && it2.hasNext(); ) { 550 String element = (String )it.next(); 551 String element2 = (String )it2.next(); 552 if (!(element == null ? element2 == null : element.equals(element2))) { 553 return false; 554 } 555 } 556 if (_isSet_Key != inst._isSet_Key) { 557 return false; 558 } 559 if (_isSet_Key) { 560 if (!(_Key == inst._Key)) { 561 return false; 562 } 563 } 564 if (_isSet_Vetoable != inst._isSet_Vetoable) { 565 return false; 566 } 567 if (_isSet_Vetoable) { 568 if (!(_Vetoable == inst._Vetoable)) { 569 return false; 570 } 571 } 572 return true; 573 } 574 575 public int hashCode() { 576 int result = 17; 577 result = 37*result + (_BeanName == null ? 0 : _BeanName.hashCode()); 578 result = 37*result + (_DefaultValue == null ? 0 : _DefaultValue.hashCode()); 579 result = 37*result + (_KnownValue == null ? 0 : _KnownValue.hashCode()); 580 result = 37*result + (_isSet_Key ? 0 : (_Key ? 0 : 1)); 581 result = 37*result + (_isSet_Vetoable ? 0 : (_Vetoable ? 0 : 1)); 582 return result; 583 } 584 585 public String toString() { 586 java.io.StringWriter sw = new java.io.StringWriter (); 587 try { 588 writeNode(sw); 589 } catch (java.io.IOException e) { 590 throw new RuntimeException (e); 592 } 593 return sw.toString(); 594 } 595 596 } 597 598 599 689 | Popular Tags |