KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > deployment > wsdd > WSDDElement


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.deployment.wsdd;
17
18 import org.apache.axis.encoding.SerializationContext;
19 import org.apache.axis.utils.Messages;
20 import org.w3c.dom.Element JavaDoc;
21 import org.w3c.dom.Node JavaDoc;
22 import org.w3c.dom.NodeList JavaDoc;
23
24 import javax.xml.namespace.QName JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.io.Serializable JavaDoc;
27 import java.util.Vector JavaDoc;
28
29
30 /**
31  * abstract class extended by all WSDD Element classes
32  */

33 public abstract class WSDDElement
34     extends WSDDConstants
35     implements Serializable JavaDoc
36 {
37     private String JavaDoc name;
38
39     /**
40      * Default constructor
41      */

42     public WSDDElement()
43     {
44     }
45     
46     /**
47      * Create an element in WSDD that wraps an extant DOM element
48      * @param e (Element) XXX
49      * @throws WSDDException XXX
50      */

51     public WSDDElement(Element JavaDoc e)
52         throws WSDDException
53     {
54         validateCandidateElement(e);
55     }
56
57     /**
58      * Return the element name of a particular subclass.
59      */

60     protected abstract QName JavaDoc getElementName();
61     
62     /**
63      * Make sure everything looks kosher with the element name.
64      */

65     private void validateCandidateElement(Element JavaDoc e)
66         throws WSDDException
67     {
68         QName JavaDoc name = getElementName();
69         
70         if ((null == e) || (null == e.getNamespaceURI())
71                 || (null == e.getLocalName())
72                 ||!e.getNamespaceURI().equals(name.getNamespaceURI())
73                 ||!e.getLocalName().equals(name.getLocalPart())) {
74             throw new WSDDException(Messages.getMessage("invalidWSDD00",
75                                     e.getLocalName(),
76                                     name.getLocalPart()));
77         }
78     }
79
80     public Element JavaDoc getChildElement(Element JavaDoc e, String JavaDoc name)
81     {
82         Element JavaDoc [] elements = getChildElements(e, name);
83         if (elements.length == 0)
84             return null;
85         return elements[0];
86     }
87     
88     public Element JavaDoc [] getChildElements(Element JavaDoc e, String JavaDoc name)
89     {
90         NodeList JavaDoc nl = e.getChildNodes();
91         Vector JavaDoc els = new Vector JavaDoc();
92         
93         for (int i = 0; i < nl.getLength(); i++) {
94             Node JavaDoc thisNode = nl.item(i);
95             if (!(thisNode instanceof Element JavaDoc))
96                 continue;
97             
98             Element JavaDoc el = (Element JavaDoc)thisNode;
99             if (el.getLocalName().equals(name)) {
100                 els.add(el);
101             }
102         }
103         
104         Element JavaDoc [] elements = new Element JavaDoc [els.size()];
105         els.toArray(elements);
106
107         return elements;
108     }
109
110     /**
111      * Write this element out to a SerializationContext
112      */

113     public abstract void writeToContext(SerializationContext context)
114         throws IOException JavaDoc;
115         
116 }
117
Popular Tags