1 19 package org.sample.registry.model.impl; 20 21 import java.util.List ; 22 import javax.xml.XMLConstants ; 23 import javax.xml.namespace.QName ; 24 import org.netbeans.modules.xml.xam.Nameable; 25 import org.netbeans.modules.xml.xam.dom.AbstractDocumentComponent; 26 import org.netbeans.modules.xml.xam.dom.Attribute; 27 import org.sample.registry.model.RegistryComponent; 28 import org.sample.registry.model.RegistryModel; 29 import org.w3c.dom.Element ; 30 import org.w3c.dom.NodeList ; 31 32 public abstract class RegistryComponentImpl extends AbstractDocumentComponent<RegistryComponent> 33 implements RegistryComponent { 34 35 public RegistryComponentImpl(RegistryModelImpl model, Element element) { 36 super(model, element); 37 } 38 39 public RegistryModelImpl getModel() { 40 return (RegistryModelImpl) super.getModel(); 41 } 42 43 static public Element createElementNS(RegistryModel model, RegistryQNames rq) { 44 QName q = rq.getQName(); 45 { 48 return model.getDocument().createElementNS(q.getNamespaceURI(), rq.getQualifiedName()); 49 } 50 } 51 52 protected Object getAttributeValueOf(Attribute attr, String stringValue) { 53 return stringValue; 54 } 55 56 protected void populateChildren(List <RegistryComponent> children) { 57 NodeList nl = getPeer().getChildNodes(); 58 if (nl != null){ 59 for (int i = 0; i < nl.getLength(); i++) { 60 org.w3c.dom.Node n = nl.item(i); 61 if (n instanceof Element ) { 62 RegistryModel model = getModel(); 63 RegistryComponent comp = (RegistryComponent) model.getFactory().create((Element )n, this); 64 if (comp != null) { 65 children.add(comp); 66 } 67 } 68 } 69 } 70 } 71 72 public static abstract class Named extends RegistryComponentImpl implements Nameable<RegistryComponent> { 73 public Named(RegistryModelImpl model, Element element) { 74 super(model, element); 75 } 76 public String getName() { 77 return super.getAttribute(RegistryAttributes.NAME); 78 } 79 80 public void setName(String name) { 81 super.setAttribute(Nameable.NAME_PROPERTY, RegistryAttributes.NAME, name); 82 } 83 } 84 85 } 86 | Popular Tags |