src/share/jaxws_classes/com/sun/tools/internal/xjc/util/DOMUtils.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 105     NodeList children = parent.getElementsByTagName(name);
 106     if(children.getLength() >= 1)
 107       return (Element)children.item(0);
 108     return null;
 109   }
 110 
 111   public static Element getElement(Document parent, QName qname){
 112     NodeList children = parent.getElementsByTagNameNS(qname.getNamespaceURI(), qname.getLocalPart());
 113     if(children.getLength() >= 1)
 114       return (Element)children.item(0);
 115     return null;
 116   }
 117 
 118   public static Element getElement(Document parent, String namespaceURI,
 119                        String localName) {
 120     NodeList children = parent.getElementsByTagNameNS(namespaceURI, localName);
 121     if(children.getLength() >= 1)
 122       return (Element)children.item(0);
 123     return null;
 124   }
 125 
 126 // these implementations look wrong to me, since getElementsByTagName returns
 127 // all the elements in descendants, not just children.
 128 //
 129 //   public static Element[] getChildElements(Element parent, QName qname) {
 130 //    NodeList children = parent.getElementsByTagNameNS(qname.uri, qname.localpart);
 131 //    return getElements(children);
 132 //  }
 133 //
 134 //  public static Element[] getChildElements(Element parent, String namespaceURI,
 135 //                       String localName) {
 136 //    NodeList children = parent.getElementsByTagNameNS(namespaceURI, localName);
 137 //    return getElements(children);
 138 //  }
 139 //
 140 //  public static Element[] getChildElements(Element parent, String name) {
 141 //    NodeList children = parent.getElementsByTagName(name);
 142 //    return getElements(children);
 143 //  }
 144 
 145     public static Element[] getElements(NodeList children) {
 146         Element[] elements = null;
 147         int len = 0;
 148         for (int i = 0; i < children.getLength(); ++i) {
 149             if (elements == null)
 150                 elements = new Element[1];
 151             if (elements.length == len) {
 152                 Element[] buf = new Element[elements.length + 1];
 153                 System.arraycopy(elements, 0, buf, 0, elements.length);
 154                 elements = buf;
 155             }
 156             elements[len++] = (Element)children.item(i);
 157         }
 158         return elements;
 159     }
 160 }
   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 105     NodeList children = parent.getElementsByTagName(name);
 106     if(children.getLength() >= 1)
 107       return (Element)children.item(0);
 108     return null;
 109   }
 110 
 111   public static Element getElement(Document parent, QName qname){
 112     NodeList children = parent.getElementsByTagNameNS(qname.getNamespaceURI(), qname.getLocalPart());
 113     if(children.getLength() >= 1)
 114       return (Element)children.item(0);
 115     return null;
 116   }
 117 
 118   public static Element getElement(Document parent, String namespaceURI,
 119                        String localName) {
 120     NodeList children = parent.getElementsByTagNameNS(namespaceURI, localName);
 121     if(children.getLength() >= 1)
 122       return (Element)children.item(0);
 123     return null;
 124   }



















 125 
 126     public static Element[] getElements(NodeList children) {
 127         Element[] elements = null;
 128         int len = 0;
 129         for (int i = 0; i < children.getLength(); ++i) {
 130             if (elements == null)
 131                 elements = new Element[1];
 132             if (elements.length == len) {
 133                 Element[] buf = new Element[elements.length + 1];
 134                 System.arraycopy(elements, 0, buf, 0, elements.length);
 135                 elements = buf;
 136             }
 137             elements[len++] = (Element)children.item(i);
 138         }
 139         return elements;
 140     }
 141 }