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

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

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