View Javadoc

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.geronimo.ews.ws4j2ee.context.webservices.server;
17  
18  import org.apache.geronimo.ews.ws4j2ee.context.webservices.server.interfaces.WSCFConstants;
19  import org.w3c.dom.Element;
20  import org.w3c.dom.Node;
21  import org.w3c.dom.NodeList;
22  
23  import java.util.Vector;
24  
25  /***
26   * This will represent an Element in the WebService.xml configuration file.
27   * EVERY concrete Element class in the configuration file will directly or indirectlt
28   * will extend this class and will show the polymorphic behavior defined here.
29   * The class has been taken from the axis WSDDElement class
30   */
31  public abstract class WSCFElement implements WSCFConstants {
32  
33      public WSCFElement() {
34      }
35  
36      public WSCFElement(Element e) throws WSCFException {
37          //TODO validate for the naspaces and the URIs
38      }
39  
40      /***
41       * Gets the child element of name <code>name<\code> from the element passed <code>e</code>
42       *
43       * @param e    Element
44       * @param name name of the child element to be searched
45       * @return child Element
46       */
47      public Element getChildElement(Element e, String name) {
48          Element[] elements = getChildElements(e, name);
49          if (elements.length == 0)
50              return null;
51          return elements[0];
52      }
53  
54      /***
55       * Gets the child elements of name <code>name<\code> from the element passed <code>e</code>
56       *
57       * @param e    Element
58       * @param name name of the child element to be searched
59       * @return child Elements
60       */
61      public Element[] getChildElements(Element e, String name) {
62          NodeList nl = e.getChildNodes();
63          Vector els = new Vector();
64          for (int i = 0; i < nl.getLength(); i++) {
65              Node thisNode = nl.item(i);
66              if (!(thisNode instanceof Element))
67                  continue;
68              Element el = (Element) thisNode;
69              if (el.getLocalName().equals(name)) {
70                  els.add(el);
71              }
72          }
73          Element[] elements = new Element[els.size()];
74          els.toArray(elements);
75          return elements;
76      }
77  }