Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/axis/deployment/wsdd/WSDDElement.java


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;
21  import org.w3c.dom.Node;
22  import org.w3c.dom.NodeList;
23  
24  import javax.xml.namespace.QName;
25  import java.io.IOException;
26  import java.io.Serializable;
27  import java.util.Vector;
28  
29  
30  /**
31   * abstract class extended by all WSDD Element classes
32   */
33  public abstract class WSDDElement
34      extends WSDDConstants
35      implements Serializable
36  {
37      private String 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 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 getElementName();
61      
62      /**
63       * Make sure everything looks kosher with the element name.
64       */
65      private void validateCandidateElement(Element e)
66          throws WSDDException
67      {
68          QName 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 getChildElement(Element e, String name)
81      {
82          Element [] elements = getChildElements(e, name);
83          if (elements.length == 0)
84              return null;
85          return elements[0];
86      }
87      
88      public Element [] getChildElements(Element e, String name)
89      {
90          NodeList nl = e.getChildNodes();
91          Vector els = new Vector();
92          
93          for (int i = 0; i < nl.getLength(); i++) {
94              Node thisNode = nl.item(i);
95              if (!(thisNode instanceof Element))
96                  continue;
97              
98              Element el = (Element)thisNode;
99              if (el.getLocalName().equals(name)) {
100                 els.add(el);
101             }
102         }
103         
104         Element [] elements = new Element [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;
115         
116 }