KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sample > registry > model > impl > RegistryComponentImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.sample.registry.model.impl;
20
21 import java.util.List JavaDoc;
22 import javax.xml.XMLConstants JavaDoc;
23 import javax.xml.namespace.QName JavaDoc;
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 JavaDoc;
30 import org.w3c.dom.NodeList JavaDoc;
31
32 public abstract class RegistryComponentImpl extends AbstractDocumentComponent<RegistryComponent>
33             implements RegistryComponent {
34     
35     public RegistryComponentImpl(RegistryModelImpl model, Element JavaDoc element) {
36         super(model, element);
37     }
38     
39     public RegistryModelImpl getModel() {
40         return (RegistryModelImpl) super.getModel();
41     }
42
43     static public Element JavaDoc createElementNS(RegistryModel model, RegistryQNames rq) {
44         QName JavaDoc q = rq.getQName();
45         /*if (XMLConstants.NULL_NS_URI.equals(q.getNamespaceURI())) {
46             return model.getDocument().createElement(q.getLocalPart());
47         } else*/
{
48             return model.getDocument().createElementNS(q.getNamespaceURI(), rq.getQualifiedName());
49         }
50     }
51     
52     protected Object JavaDoc getAttributeValueOf(Attribute attr, String JavaDoc stringValue) {
53         return stringValue;
54     }
55
56     protected void populateChildren(List JavaDoc<RegistryComponent> children) {
57         NodeList JavaDoc nl = getPeer().getChildNodes();
58         if (nl != null){
59             for (int i = 0; i < nl.getLength(); i++) {
60                 org.w3c.dom.Node JavaDoc n = nl.item(i);
61                 if (n instanceof Element JavaDoc) {
62                     RegistryModel model = getModel();
63                     RegistryComponent comp = (RegistryComponent) model.getFactory().create((Element JavaDoc)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 JavaDoc element) {
74             super(model, element);
75         }
76         public String JavaDoc getName() {
77             return super.getAttribute(RegistryAttributes.NAME);
78         }
79         
80         public void setName(String JavaDoc name) {
81             super.setAttribute(Nameable.NAME_PROPERTY, RegistryAttributes.NAME, name);
82         }
83     }
84     
85 }
86
Popular Tags