alanb@368: /* alanb@368: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. alanb@368: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. alanb@368: * alanb@368: * This code is free software; you can redistribute it and/or modify it alanb@368: * under the terms of the GNU General Public License version 2 only, as alanb@368: * published by the Free Software Foundation. Oracle designates this alanb@368: * particular file as subject to the "Classpath" exception as provided alanb@368: * by Oracle in the LICENSE file that accompanied this code. alanb@368: * alanb@368: * This code is distributed in the hope that it will be useful, but WITHOUT alanb@368: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or alanb@368: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License alanb@368: * version 2 for more details (a copy is included in the LICENSE file that alanb@368: * accompanied this code). alanb@368: * alanb@368: * You should have received a copy of the GNU General Public License version alanb@368: * 2 along with this work; if not, write to the Free Software Foundation, alanb@368: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. alanb@368: * alanb@368: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA alanb@368: * or visit www.oracle.com if you need additional information or have any alanb@368: * questions. alanb@368: */ alanb@368: alanb@368: package com.sun.xml.internal.ws.model; alanb@368: alanb@368: import com.oracle.xmlns.internal.webservices.jaxws_databinding.JavaMethod; alanb@368: import com.oracle.xmlns.internal.webservices.jaxws_databinding.JavaParam; alanb@368: import com.oracle.xmlns.internal.webservices.jaxws_databinding.JavaWsdlMappingType; alanb@368: import com.oracle.xmlns.internal.webservices.jaxws_databinding.ObjectFactory; alanb@368: import com.sun.xml.internal.bind.api.JAXBRIContext; alanb@368: import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; alanb@368: import com.sun.xml.internal.ws.util.xml.XmlUtil; alanb@368: import org.w3c.dom.Element; alanb@368: import org.xml.sax.SAXException; alanb@368: alanb@368: import javax.xml.bind.JAXBContext; alanb@368: import javax.xml.bind.JAXBElement; alanb@368: import javax.xml.bind.JAXBException; alanb@368: import javax.xml.bind.Unmarshaller; alanb@368: import javax.xml.bind.util.JAXBResult; alanb@368: import javax.xml.stream.XMLInputFactory; alanb@368: import javax.xml.stream.XMLStreamException; alanb@368: import javax.xml.stream.XMLStreamReader; alanb@368: import javax.xml.transform.Source; alanb@368: import javax.xml.transform.Transformer; alanb@368: import javax.xml.transform.TransformerException; alanb@368: import javax.xml.transform.TransformerFactory; alanb@368: import javax.xml.transform.stream.StreamSource; alanb@368: import javax.xml.validation.Schema; alanb@368: import javax.xml.validation.SchemaFactory; alanb@368: import java.io.*; alanb@368: import java.lang.annotation.Annotation; alanb@368: import java.lang.reflect.Method; alanb@368: import java.net.URL; alanb@368: import java.util.*; alanb@368: alanb@368: import static com.oracle.xmlns.internal.webservices.jaxws_databinding.ExistingAnnotationsType.MERGE; alanb@368: alanb@368: /** alanb@368: * Metadata Reader able to read from either class annotations or external metadata files or combine both, alanb@368: * depending on configuration provided in xml file itself. alanb@368: * alanb@368: * @author shih-chang.chen@oracle.com, miroslav.kos@oracle.com alanb@368: */ alanb@368: public class ExternalMetadataReader extends ReflectAnnotationReader { alanb@368: alanb@368: private static final String NAMESPACE_WEBLOGIC_WSEE_DATABINDING = "http://xmlns.oracle.com/weblogic/weblogic-wsee-databinding"; alanb@368: private static final String NAMESPACE_JAXWS_RI_EXTERNAL_METADATA = "http://xmlns.oracle.com/webservices/jaxws-databinding"; alanb@368: alanb@368: /** alanb@368: * map of readers for defined java types alanb@368: */ alanb@368: private Map readers = new HashMap(); alanb@368: alanb@368: public ExternalMetadataReader(Collection files, Collection resourcePaths, ClassLoader classLoader, alanb@368: boolean xsdValidation, boolean disableSecureXmlProcessing) { alanb@368: alanb@368: if (files != null) { alanb@368: for (File file : files) { alanb@368: try { alanb@368: String namespace = Util.documentRootNamespace(newSource(file), disableSecureXmlProcessing); alanb@368: JavaWsdlMappingType externalMapping = parseMetadata(xsdValidation, newSource(file), namespace, disableSecureXmlProcessing); alanb@368: readers.put(externalMapping.getJavaTypeName(), externalMapping); alanb@368: } catch (Exception e) { alanb@368: throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", file.getAbsolutePath()); alanb@368: } alanb@368: } alanb@368: } alanb@368: alanb@368: if (resourcePaths != null) { alanb@368: for (String resourcePath : resourcePaths) { alanb@368: try { alanb@368: String namespace = Util.documentRootNamespace(newSource(resourcePath, classLoader), disableSecureXmlProcessing); alanb@368: JavaWsdlMappingType externalMapping = parseMetadata(xsdValidation, newSource(resourcePath, classLoader), namespace, disableSecureXmlProcessing); alanb@368: readers.put(externalMapping.getJavaTypeName(), externalMapping); alanb@368: } catch (Exception e) { alanb@368: throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", resourcePath); alanb@368: } alanb@368: } alanb@368: } alanb@368: } alanb@368: alanb@368: private StreamSource newSource(String resourcePath, ClassLoader classLoader) { alanb@368: InputStream is = classLoader.getResourceAsStream(resourcePath); alanb@368: return new StreamSource(is); alanb@368: } alanb@368: alanb@368: private JavaWsdlMappingType parseMetadata(boolean xsdValidation, StreamSource source, String namespace, boolean disableSecureXmlProcessing) throws JAXBException, IOException, TransformerException { alanb@368: if (NAMESPACE_WEBLOGIC_WSEE_DATABINDING.equals(namespace)) { alanb@368: return Util.transformAndRead(source, disableSecureXmlProcessing); alanb@368: } if (NAMESPACE_JAXWS_RI_EXTERNAL_METADATA.equals(namespace)) { alanb@368: return Util.read(source, xsdValidation, disableSecureXmlProcessing); alanb@368: } else { alanb@368: throw new RuntimeModelerException("runtime.modeler.external.metadata.unsupported.schema", namespace, Arrays.asList(NAMESPACE_WEBLOGIC_WSEE_DATABINDING, NAMESPACE_JAXWS_RI_EXTERNAL_METADATA).toString()); alanb@368: } alanb@368: } alanb@368: alanb@368: private StreamSource newSource(File file) { alanb@368: try { alanb@368: return new StreamSource(new FileInputStream(file)); alanb@368: } catch (FileNotFoundException e) { alanb@368: throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", file.getAbsolutePath()); alanb@368: } alanb@368: } alanb@368: alanb@368: public A getAnnotation(Class annType, Class cls) { alanb@368: JavaWsdlMappingType r = reader(cls); alanb@368: return r == null ? super.getAnnotation(annType, cls) : Util.annotation(r, annType); alanb@368: } alanb@368: alanb@368: private JavaWsdlMappingType reader(Class cls) { alanb@368: return readers.get(cls.getName()); alanb@368: } alanb@368: alanb@368: Annotation[] getAnnotations(List objects) { alanb@368: ArrayList list = new ArrayList(); alanb@368: for (Object a : objects) { alanb@368: if (Annotation.class.isInstance(a)) { alanb@368: list.add(Annotation.class.cast(a)); alanb@368: } alanb@368: } alanb@368: return list.toArray(new Annotation[list.size()]); alanb@368: } alanb@368: alanb@368: public Annotation[] getAnnotations(final Class c) { alanb@368: alanb@368: Merger merger = new Merger(reader(c)) { alanb@368: Annotation[] reflection() { alanb@368: return ExternalMetadataReader.super.getAnnotations(c); alanb@368: } alanb@368: alanb@368: Annotation[] external() { alanb@368: return getAnnotations(reader.getClassAnnotation()); alanb@368: } alanb@368: }; alanb@368: return merger.merge(); alanb@368: } alanb@368: alanb@368: public Annotation[] getAnnotations(final Method m) { alanb@368: Merger merger = new Merger(reader(m.getDeclaringClass())) { alanb@368: Annotation[] reflection() { alanb@368: return ExternalMetadataReader.super.getAnnotations(m); alanb@368: } alanb@368: alanb@368: Annotation[] external() { alanb@368: JavaMethod jm = getJavaMethod(m, reader); alanb@368: return (jm == null) ? new Annotation[0] : getAnnotations(jm.getMethodAnnotation()); alanb@368: } alanb@368: }; alanb@368: return merger.merge(); alanb@368: } alanb@368: alanb@368: @SuppressWarnings("unchecked") alanb@368: public A getAnnotation(final Class annType, final Method m) { alanb@368: Merger merger = new Merger(reader(m.getDeclaringClass())) { alanb@368: Annotation reflection() { alanb@368: return ExternalMetadataReader.super.getAnnotation(annType, m); alanb@368: } alanb@368: alanb@368: Annotation external() { alanb@368: JavaMethod jm = getJavaMethod(m, reader); alanb@368: return Util.annotation(jm, annType); alanb@368: } alanb@368: }; alanb@368: return (A) merger.merge(); alanb@368: } alanb@368: alanb@368: public Annotation[][] getParameterAnnotations(final Method m) { alanb@368: Merger merger = new Merger(reader(m.getDeclaringClass())) { alanb@368: Annotation[][] reflection() { alanb@368: return ExternalMetadataReader.super.getParameterAnnotations(m); alanb@368: } alanb@368: alanb@368: Annotation[][] external() { alanb@368: JavaMethod jm = getJavaMethod(m, reader); alanb@368: Annotation[][] a = m.getParameterAnnotations(); alanb@368: for (int i = 0; i < m.getParameterTypes().length; i++) { alanb@368: if (jm == null) continue; alanb@368: JavaParam jp = jm.getJavaParams().getJavaParam().get(i); alanb@368: a[i] = getAnnotations(jp.getParamAnnotation()); alanb@368: } alanb@368: return a; alanb@368: } alanb@368: }; alanb@368: return merger.merge(); alanb@368: } alanb@368: alanb@368: public void getProperties(final Map prop, final Class cls) { alanb@368: alanb@368: JavaWsdlMappingType r = reader(cls); alanb@368: alanb@368: // no external reader or it requires annotations merging ... alanb@368: if (r == null || MERGE.equals(r.getExistingAnnotations())) { alanb@368: super.getProperties(prop, cls); alanb@368: } alanb@368: alanb@368: } alanb@368: alanb@368: public void getProperties(final Map prop, final Method m) { alanb@368: alanb@368: JavaWsdlMappingType r = reader(m.getDeclaringClass()); alanb@368: alanb@368: // no external reader or it requires annotations merging ... alanb@368: if (r == null || MERGE.equals(r.getExistingAnnotations())) { alanb@368: super.getProperties(prop, m); alanb@368: } alanb@368: alanb@368: if (r != null) { alanb@368: JavaMethod jm = getJavaMethod(m, r); alanb@368: Element[] e = Util.annotation(jm); alanb@368: prop.put("eclipselink-oxm-xml.xml-element", findXmlElement(e)); alanb@368: } alanb@368: alanb@368: } alanb@368: alanb@368: public void getProperties(final Map prop, final Method m, int pos) { alanb@368: alanb@368: JavaWsdlMappingType r = reader(m.getDeclaringClass()); alanb@368: alanb@368: // no external reader or it requires annotations merging ... alanb@368: if (r == null || MERGE.equals(r.getExistingAnnotations())) { alanb@368: super.getProperties(prop, m, pos); alanb@368: } alanb@368: alanb@368: if (r != null) { alanb@368: JavaMethod jm = getJavaMethod(m, r); alanb@368: if (jm == null) return; alanb@368: JavaParam jp = jm.getJavaParams().getJavaParam().get(pos); alanb@368: Element[] e = Util.annotation(jp); alanb@368: prop.put("eclipselink-oxm-xml.xml-element", findXmlElement(e)); alanb@368: } alanb@368: } alanb@368: alanb@368: JavaMethod getJavaMethod(Method method, JavaWsdlMappingType r) { alanb@368: alanb@368: JavaWsdlMappingType.JavaMethods javaMethods = r.getJavaMethods(); alanb@368: if (javaMethods == null) { alanb@368: return null; alanb@368: } alanb@368: alanb@368: List sameName = new ArrayList(); alanb@368: for (JavaMethod jm : javaMethods.getJavaMethod()) { alanb@368: if (method.getName().equals(jm.getName())) { alanb@368: sameName.add(jm); alanb@368: } alanb@368: } alanb@368: alanb@368: if (sameName.isEmpty()) { alanb@368: return null; alanb@368: } else { alanb@368: if (sameName.size() == 1) { alanb@368: return sameName.get(0); alanb@368: } else { alanb@368: Class[] argCls = method.getParameterTypes(); alanb@368: for (JavaMethod jm : sameName) { alanb@368: JavaMethod.JavaParams params = jm.getJavaParams(); alanb@368: if (params != null && params.getJavaParam() != null && params.getJavaParam().size() == argCls.length) { alanb@368: int count = 0; alanb@368: for (int i = 0; i < argCls.length; i++) { alanb@368: JavaParam jp = params.getJavaParam().get(i); alanb@368: if (argCls[i].getName().equals(jp.getJavaType())) { alanb@368: count++; alanb@368: } alanb@368: } alanb@368: if (count == argCls.length) { alanb@368: return jm; alanb@368: } alanb@368: } alanb@368: } alanb@368: } alanb@368: } alanb@368: return null; alanb@368: } alanb@368: alanb@368: Element findXmlElement(Element[] xa) { alanb@368: if (xa == null) return null; alanb@368: for (Element e : xa) { alanb@368: if (e.getLocalName().equals("java-type")) return e; alanb@368: if (e.getLocalName().equals("xml-element")) return e; alanb@368: } alanb@368: return null; alanb@368: } alanb@368: alanb@368: /** alanb@368: * Helper class to merge two different arrays of annotation objects. It merges annotations based on attribute alanb@368: * existing-annotations in external customization file. alanb@368: *

alanb@368: * We suppose that in the result array there wouldn't be two annotations of same type: alanb@368: * annotation.annotationType().getName(); if there are found such annotations the one from reflection is alanb@368: * considered overriden and is thrown away. alanb@368: *

alanb@368: * The helper can work either with one and two dimensional array, but it can be used for two single Annotation alanb@368: * objects; alanb@368: */ alanb@368: static abstract class Merger { alanb@368: alanb@368: JavaWsdlMappingType reader; alanb@368: alanb@368: Merger(JavaWsdlMappingType r) { alanb@368: this.reader = r; alanb@368: } alanb@368: alanb@368: abstract T reflection(); alanb@368: alanb@368: abstract T external(); alanb@368: alanb@368: @SuppressWarnings("unchecked") alanb@368: T merge() { alanb@368: T reflection = reflection(); alanb@368: if (reader == null) { alanb@368: return reflection; alanb@368: } alanb@368: alanb@368: T external = external(); alanb@368: if (!MERGE.equals(reader.getExistingAnnotations())) { alanb@368: return external; alanb@368: } alanb@368: alanb@368: if (reflection instanceof Annotation) { alanb@368: return (T) doMerge((Annotation) reflection, (Annotation) external); alanb@368: } else if (reflection instanceof Annotation[][]) { alanb@368: return (T) doMerge((Annotation[][]) reflection, (Annotation[][]) external); alanb@368: } else { alanb@368: return (T) doMerge((Annotation[]) reflection, (Annotation[]) external); alanb@368: } alanb@368: } alanb@368: alanb@368: private Annotation doMerge(Annotation reflection, Annotation external) { alanb@368: return external != null ? external : reflection; alanb@368: } alanb@368: alanb@368: private Annotation[][] doMerge(Annotation[][] reflection, Annotation[][] external) { alanb@368: for (int i = 0; i < reflection.length; i++) { alanb@368: reflection[i] = doMerge(reflection[i], external.length > i ? external[i] : null); alanb@368: } alanb@368: return reflection; alanb@368: } alanb@368: alanb@368: private Annotation[] doMerge(Annotation[] annotations, Annotation[] externalAnnotations) { alanb@368: HashMap mergeMap = new HashMap(); alanb@368: if (annotations != null) { alanb@368: for (Annotation reflectionAnnotation : annotations) { alanb@368: mergeMap.put(reflectionAnnotation.annotationType().getName(), reflectionAnnotation); alanb@368: } alanb@368: } alanb@368: alanb@368: // overriding happens here, based on annotationType().getName() ... alanb@368: if (externalAnnotations != null) { alanb@368: for (Annotation externalAnnotation : externalAnnotations) { alanb@368: mergeMap.put(externalAnnotation.annotationType().getName(), externalAnnotation); alanb@368: } alanb@368: } alanb@368: Collection values = mergeMap.values(); alanb@368: int size = values.size(); alanb@368: return size == 0 ? null : values.toArray(new Annotation[size]); alanb@368: } alanb@368: alanb@368: } alanb@368: alanb@368: static class Util { alanb@368: alanb@368: //private static final String DATABINDING_XSD = "com/sun/xml/internal/ws/model/jaxws-databinding.xsd"; alanb@368: private static final String DATABINDING_XSD = "jaxws-databinding.xsd"; alanb@368: //private static final String TRANSLATE_NAMESPACES_XSL = "/com/sun/xml/internal/ws/model/jaxws-databinding-translate-namespaces.xml"; alanb@368: private static final String TRANSLATE_NAMESPACES_XSL = "jaxws-databinding-translate-namespaces.xml"; alanb@368: alanb@368: static Schema schema; alanb@368: static JAXBContext jaxbContext; alanb@368: alanb@368: static { alanb@368: SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); alanb@368: try { alanb@368: URL xsdUrl = getResource(); alanb@368: if (xsdUrl != null) { alanb@368: schema = sf.newSchema(xsdUrl); alanb@368: } alanb@368: } catch (SAXException e1) { alanb@368: // e1.printStackTrace(); alanb@368: } alanb@368: alanb@368: jaxbContext = createJaxbContext(false); alanb@368: } alanb@368: alanb@368: private static URL getResource() { alanb@368: ClassLoader classLoader = Util.class.getClassLoader(); alanb@368: return classLoader != null ? classLoader.getResource(DATABINDING_XSD) : ClassLoader.getSystemResource(DATABINDING_XSD); alanb@368: } alanb@368: alanb@368: private static JAXBContext createJaxbContext(boolean disableXmlSecurity) { alanb@368: Class[] cls = {ObjectFactory.class}; alanb@368: try { alanb@368: if (disableXmlSecurity) { alanb@368: Map properties = new HashMap(); alanb@368: properties.put(JAXBRIContext.DISABLE_XML_SECURITY, disableXmlSecurity); alanb@368: return JAXBContext.newInstance(cls, properties); alanb@368: } else { alanb@368: return JAXBContext.newInstance(cls); alanb@368: } alanb@368: } catch (JAXBException e) { alanb@368: e.printStackTrace(); alanb@368: return null; alanb@368: } alanb@368: } alanb@368: alanb@368: @SuppressWarnings("unchecked") alanb@368: public static JavaWsdlMappingType read(Source src, boolean xsdValidation, boolean disableSecureXmlProcessing) throws IOException, JAXBException { alanb@368: JAXBContext ctx = jaxbContext(disableSecureXmlProcessing); alanb@368: try { alanb@368: Unmarshaller um = ctx.createUnmarshaller(); alanb@368: if (xsdValidation) { alanb@368: if (schema == null) { alanb@368: //TODO 0 warning for schema == null alanb@368: } alanb@368: um.setSchema(schema); alanb@368: } alanb@368: Object o = um.unmarshal(src); alanb@368: return getJavaWsdlMapping(o); alanb@368: } catch (JAXBException e) { alanb@368: // throw new alanb@368: // WebServiceException(WsDatabindingMessages.mappingFileCannotRead alanb@368: // (src.getSystemId()), e); alanb@368: URL url = new URL(src.getSystemId()); alanb@368: Source s = new StreamSource(url.openStream()); alanb@368: Unmarshaller um = ctx.createUnmarshaller(); alanb@368: if (xsdValidation) { alanb@368: if (schema == null) { alanb@368: //TODO 0 warning for schema == null alanb@368: } alanb@368: um.setSchema(schema); alanb@368: } alanb@368: Object o = um.unmarshal(s); alanb@368: return getJavaWsdlMapping(o); alanb@368: } alanb@368: } alanb@368: alanb@368: private static JAXBContext jaxbContext(boolean disableSecureXmlProcessing) { alanb@368: // as it is supposed to have security enabled in most cases, we create and don't cache alanb@368: // "insecure" JAXBContext - these should be corner cases alanb@368: return disableSecureXmlProcessing ? createJaxbContext(true) : jaxbContext; alanb@368: } alanb@368: alanb@368: public static JavaWsdlMappingType transformAndRead(Source src, boolean disableSecureXmlProcessing) throws TransformerException, JAXBException { alanb@368: Source xsl = new StreamSource(Util.class.getResourceAsStream(TRANSLATE_NAMESPACES_XSL)); alanb@368: JAXBResult result = new JAXBResult(jaxbContext(disableSecureXmlProcessing)); alanb@368: TransformerFactory tf = XmlUtil.newTransformerFactory(!disableSecureXmlProcessing); alanb@368: Transformer transformer = tf.newTemplates(xsl).newTransformer(); alanb@368: transformer.transform(src, result); alanb@368: return getJavaWsdlMapping(result.getResult()); alanb@368: } alanb@368: alanb@368: alanb@368: static JavaWsdlMappingType getJavaWsdlMapping(Object o) { alanb@368: Object val = (o instanceof JAXBElement) ? ((JAXBElement) o).getValue() : o; alanb@368: if (val instanceof JavaWsdlMappingType) return (JavaWsdlMappingType) val; alanb@368: // else if (val instanceof JavaWsdlMappings) alanb@368: // for (JavaWsdlMappingType m: ((JavaWsdlMappings) val).getJavaWsdlMapping()) alanb@368: // if (seiName.equals(m.javaTypeName)) return m; alanb@368: return null; alanb@368: } alanb@368: alanb@368: static T findInstanceOf(Class type, List objects) { alanb@368: for (Object o : objects) { alanb@368: if (type.isInstance(o)) { alanb@368: return type.cast(o); alanb@368: } alanb@368: } alanb@368: return null; alanb@368: } alanb@368: alanb@368: static public T annotation(JavaWsdlMappingType jwse, Class anntype) { alanb@368: if (jwse == null || jwse.getClassAnnotation() == null) { alanb@368: return null; alanb@368: } alanb@368: return findInstanceOf(anntype, jwse.getClassAnnotation()); alanb@368: } alanb@368: alanb@368: static public T annotation(JavaMethod jm, Class anntype) { alanb@368: if (jm == null || jm.getMethodAnnotation() == null) { alanb@368: return null; alanb@368: } alanb@368: return findInstanceOf(anntype, jm.getMethodAnnotation()); alanb@368: } alanb@368: alanb@368: static public T annotation(JavaParam jp, Class anntype) { alanb@368: if (jp == null || jp.getParamAnnotation() == null) { alanb@368: return null; alanb@368: } alanb@368: return findInstanceOf(anntype, jp.getParamAnnotation()); alanb@368: } alanb@368: alanb@368: static public Element[] annotation(JavaMethod jm) { alanb@368: if (jm == null || jm.getMethodAnnotation() == null) { alanb@368: return null; alanb@368: } alanb@368: return findElements(jm.getMethodAnnotation()); alanb@368: } alanb@368: alanb@368: static public Element[] annotation(JavaParam jp) { alanb@368: if (jp == null || jp.getParamAnnotation() == null) { alanb@368: return null; alanb@368: } alanb@368: return findElements(jp.getParamAnnotation()); alanb@368: } alanb@368: alanb@368: private static Element[] findElements(List objects) { alanb@368: List elems = new ArrayList(); alanb@368: for (Object o : objects) { alanb@368: if (o instanceof Element) { alanb@368: elems.add((Element) o); alanb@368: } alanb@368: } alanb@368: return elems.toArray(new Element[elems.size()]); alanb@368: } alanb@368: alanb@368: static String documentRootNamespace(Source src, boolean disableSecureXmlProcessing) throws XMLStreamException { alanb@368: XMLInputFactory factory; alanb@368: factory = XmlUtil.newXMLInputFactory(!disableSecureXmlProcessing); alanb@368: XMLStreamReader streamReader = factory.createXMLStreamReader(src); alanb@368: XMLStreamReaderUtil.nextElementContent(streamReader); alanb@368: String namespaceURI = streamReader.getName().getNamespaceURI(); alanb@368: XMLStreamReaderUtil.close(streamReader); alanb@368: return namespaceURI; alanb@368: } alanb@368: } alanb@368: alanb@368: alanb@368: }