1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/model/ExternalMetadataReader.java Wed Apr 27 01:27:09 2016 +0800 1.3 @@ -0,0 +1,549 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + */ 1.28 + 1.29 +package com.sun.xml.internal.ws.model; 1.30 + 1.31 +import com.oracle.xmlns.internal.webservices.jaxws_databinding.JavaMethod; 1.32 +import com.oracle.xmlns.internal.webservices.jaxws_databinding.JavaParam; 1.33 +import com.oracle.xmlns.internal.webservices.jaxws_databinding.JavaWsdlMappingType; 1.34 +import com.oracle.xmlns.internal.webservices.jaxws_databinding.ObjectFactory; 1.35 +import com.sun.xml.internal.bind.api.JAXBRIContext; 1.36 +import com.sun.xml.internal.ws.streaming.XMLStreamReaderUtil; 1.37 +import com.sun.xml.internal.ws.util.xml.XmlUtil; 1.38 +import org.w3c.dom.Element; 1.39 +import org.xml.sax.SAXException; 1.40 + 1.41 +import javax.xml.bind.JAXBContext; 1.42 +import javax.xml.bind.JAXBElement; 1.43 +import javax.xml.bind.JAXBException; 1.44 +import javax.xml.bind.Unmarshaller; 1.45 +import javax.xml.bind.util.JAXBResult; 1.46 +import javax.xml.stream.XMLInputFactory; 1.47 +import javax.xml.stream.XMLStreamException; 1.48 +import javax.xml.stream.XMLStreamReader; 1.49 +import javax.xml.transform.Source; 1.50 +import javax.xml.transform.Transformer; 1.51 +import javax.xml.transform.TransformerException; 1.52 +import javax.xml.transform.TransformerFactory; 1.53 +import javax.xml.transform.stream.StreamSource; 1.54 +import javax.xml.validation.Schema; 1.55 +import javax.xml.validation.SchemaFactory; 1.56 +import java.io.*; 1.57 +import java.lang.annotation.Annotation; 1.58 +import java.lang.reflect.Method; 1.59 +import java.net.URL; 1.60 +import java.util.*; 1.61 + 1.62 +import static com.oracle.xmlns.internal.webservices.jaxws_databinding.ExistingAnnotationsType.MERGE; 1.63 + 1.64 +/** 1.65 + * Metadata Reader able to read from either class annotations or external metadata files or combine both, 1.66 + * depending on configuration provided in xml file itself. 1.67 + * 1.68 + * @author shih-chang.chen@oracle.com, miroslav.kos@oracle.com 1.69 + */ 1.70 +public class ExternalMetadataReader extends ReflectAnnotationReader { 1.71 + 1.72 + private static final String NAMESPACE_WEBLOGIC_WSEE_DATABINDING = "http://xmlns.oracle.com/weblogic/weblogic-wsee-databinding"; 1.73 + private static final String NAMESPACE_JAXWS_RI_EXTERNAL_METADATA = "http://xmlns.oracle.com/webservices/jaxws-databinding"; 1.74 + 1.75 + /** 1.76 + * map of readers for defined java types 1.77 + */ 1.78 + private Map<String, JavaWsdlMappingType> readers = new HashMap<String, JavaWsdlMappingType>(); 1.79 + 1.80 + public ExternalMetadataReader(Collection<File> files, Collection<String> resourcePaths, ClassLoader classLoader, 1.81 + boolean xsdValidation, boolean disableXmlSecurity) { 1.82 + 1.83 + if (files != null) { 1.84 + for (File file : files) { 1.85 + try { 1.86 + String namespace = Util.documentRootNamespace(newSource(file), disableXmlSecurity); 1.87 + JavaWsdlMappingType externalMapping = parseMetadata(xsdValidation, newSource(file), namespace, disableXmlSecurity); 1.88 + readers.put(externalMapping.getJavaTypeName(), externalMapping); 1.89 + } catch (Exception e) { 1.90 + throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", file.getAbsolutePath()); 1.91 + } 1.92 + } 1.93 + } 1.94 + 1.95 + if (resourcePaths != null) { 1.96 + for (String resourcePath : resourcePaths) { 1.97 + try { 1.98 + String namespace = Util.documentRootNamespace(newSource(resourcePath, classLoader), disableXmlSecurity); 1.99 + JavaWsdlMappingType externalMapping = parseMetadata(xsdValidation, newSource(resourcePath, classLoader), namespace, disableXmlSecurity); 1.100 + readers.put(externalMapping.getJavaTypeName(), externalMapping); 1.101 + } catch (Exception e) { 1.102 + throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", resourcePath); 1.103 + } 1.104 + } 1.105 + } 1.106 + } 1.107 + 1.108 + private StreamSource newSource(String resourcePath, ClassLoader classLoader) { 1.109 + InputStream is = classLoader.getResourceAsStream(resourcePath); 1.110 + return new StreamSource(is); 1.111 + } 1.112 + 1.113 + private JavaWsdlMappingType parseMetadata(boolean xsdValidation, StreamSource source, String namespace, boolean disableXmlSecurity) throws JAXBException, IOException, TransformerException { 1.114 + if (NAMESPACE_WEBLOGIC_WSEE_DATABINDING.equals(namespace)) { 1.115 + return Util.transformAndRead(source, disableXmlSecurity); 1.116 + } if (NAMESPACE_JAXWS_RI_EXTERNAL_METADATA.equals(namespace)) { 1.117 + return Util.read(source, xsdValidation, disableXmlSecurity); 1.118 + } else { 1.119 + throw new RuntimeModelerException("runtime.modeler.external.metadata.unsupported.schema", namespace, Arrays.asList(NAMESPACE_WEBLOGIC_WSEE_DATABINDING, NAMESPACE_JAXWS_RI_EXTERNAL_METADATA).toString()); 1.120 + } 1.121 + } 1.122 + 1.123 + private StreamSource newSource(File file) { 1.124 + try { 1.125 + return new StreamSource(new FileInputStream(file)); 1.126 + } catch (FileNotFoundException e) { 1.127 + throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", file.getAbsolutePath()); 1.128 + } 1.129 + } 1.130 + 1.131 + public <A extends Annotation> A getAnnotation(Class<A> annType, Class<?> cls) { 1.132 + JavaWsdlMappingType r = reader(cls); 1.133 + return r == null ? super.getAnnotation(annType, cls) : Util.annotation(r, annType); 1.134 + } 1.135 + 1.136 + private JavaWsdlMappingType reader(Class<?> cls) { 1.137 + return readers.get(cls.getName()); 1.138 + } 1.139 + 1.140 + Annotation[] getAnnotations(List<Object> objects) { 1.141 + ArrayList<Annotation> list = new ArrayList<Annotation>(); 1.142 + for (Object a : objects) { 1.143 + if (Annotation.class.isInstance(a)) { 1.144 + list.add(Annotation.class.cast(a)); 1.145 + } 1.146 + } 1.147 + return list.toArray(new Annotation[list.size()]); 1.148 + } 1.149 + 1.150 + public Annotation[] getAnnotations(final Class<?> c) { 1.151 + 1.152 + Merger<Annotation[]> merger = new Merger<Annotation[]>(reader(c)) { 1.153 + Annotation[] reflection() { 1.154 + return ExternalMetadataReader.super.getAnnotations(c); 1.155 + } 1.156 + 1.157 + Annotation[] external() { 1.158 + return getAnnotations(reader.getClassAnnotation()); 1.159 + } 1.160 + }; 1.161 + return merger.merge(); 1.162 + } 1.163 + 1.164 + public Annotation[] getAnnotations(final Method m) { 1.165 + Merger<Annotation[]> merger = new Merger<Annotation[]>(reader(m.getDeclaringClass())) { 1.166 + Annotation[] reflection() { 1.167 + return ExternalMetadataReader.super.getAnnotations(m); 1.168 + } 1.169 + 1.170 + Annotation[] external() { 1.171 + JavaMethod jm = getJavaMethod(m, reader); 1.172 + return (jm == null) ? new Annotation[0] : getAnnotations(jm.getMethodAnnotation()); 1.173 + } 1.174 + }; 1.175 + return merger.merge(); 1.176 + } 1.177 + 1.178 + @SuppressWarnings("unchecked") 1.179 + public <A extends Annotation> A getAnnotation(final Class<A> annType, final Method m) { 1.180 + Merger<Annotation> merger = new Merger<Annotation>(reader(m.getDeclaringClass())) { 1.181 + Annotation reflection() { 1.182 + return ExternalMetadataReader.super.getAnnotation(annType, m); 1.183 + } 1.184 + 1.185 + Annotation external() { 1.186 + JavaMethod jm = getJavaMethod(m, reader); 1.187 + return Util.annotation(jm, annType); 1.188 + } 1.189 + }; 1.190 + return (A) merger.merge(); 1.191 + } 1.192 + 1.193 + public Annotation[][] getParameterAnnotations(final Method m) { 1.194 + Merger<Annotation[][]> merger = new Merger<Annotation[][]>(reader(m.getDeclaringClass())) { 1.195 + Annotation[][] reflection() { 1.196 + return ExternalMetadataReader.super.getParameterAnnotations(m); 1.197 + } 1.198 + 1.199 + Annotation[][] external() { 1.200 + JavaMethod jm = getJavaMethod(m, reader); 1.201 + Annotation[][] a = m.getParameterAnnotations(); 1.202 + for (int i = 0; i < m.getParameterTypes().length; i++) { 1.203 + if (jm == null) continue; 1.204 + JavaParam jp = jm.getJavaParams().getJavaParam().get(i); 1.205 + a[i] = getAnnotations(jp.getParamAnnotation()); 1.206 + } 1.207 + return a; 1.208 + } 1.209 + }; 1.210 + return merger.merge(); 1.211 + } 1.212 + 1.213 + public void getProperties(final Map<String, Object> prop, final Class<?> cls) { 1.214 + 1.215 + JavaWsdlMappingType r = reader(cls); 1.216 + 1.217 + // no external reader or it requires annotations merging ... 1.218 + if (r == null || MERGE.equals(r.getExistingAnnotations())) { 1.219 + super.getProperties(prop, cls); 1.220 + } 1.221 + 1.222 + } 1.223 + 1.224 + public void getProperties(final Map<String, Object> prop, final Method m) { 1.225 + 1.226 + JavaWsdlMappingType r = reader(m.getDeclaringClass()); 1.227 + 1.228 + // no external reader or it requires annotations merging ... 1.229 + if (r == null || MERGE.equals(r.getExistingAnnotations())) { 1.230 + super.getProperties(prop, m); 1.231 + } 1.232 + 1.233 + if (r != null) { 1.234 + JavaMethod jm = getJavaMethod(m, r); 1.235 + Element[] e = Util.annotation(jm); 1.236 + prop.put("eclipselink-oxm-xml.xml-element", findXmlElement(e)); 1.237 + } 1.238 + 1.239 + } 1.240 + 1.241 + public void getProperties(final Map<String, Object> prop, final Method m, int pos) { 1.242 + 1.243 + JavaWsdlMappingType r = reader(m.getDeclaringClass()); 1.244 + 1.245 + // no external reader or it requires annotations merging ... 1.246 + if (r == null || MERGE.equals(r.getExistingAnnotations())) { 1.247 + super.getProperties(prop, m, pos); 1.248 + } 1.249 + 1.250 + if (r != null) { 1.251 + JavaMethod jm = getJavaMethod(m, r); 1.252 + if (jm == null) return; 1.253 + JavaParam jp = jm.getJavaParams().getJavaParam().get(pos); 1.254 + Element[] e = Util.annotation(jp); 1.255 + prop.put("eclipselink-oxm-xml.xml-element", findXmlElement(e)); 1.256 + } 1.257 + } 1.258 + 1.259 + JavaMethod getJavaMethod(Method method, JavaWsdlMappingType r) { 1.260 + 1.261 + JavaWsdlMappingType.JavaMethods javaMethods = r.getJavaMethods(); 1.262 + if (javaMethods == null) { 1.263 + return null; 1.264 + } 1.265 + 1.266 + List<JavaMethod> sameName = new ArrayList<JavaMethod>(); 1.267 + for (JavaMethod jm : javaMethods.getJavaMethod()) { 1.268 + if (method.getName().equals(jm.getName())) { 1.269 + sameName.add(jm); 1.270 + } 1.271 + } 1.272 + 1.273 + if (sameName.isEmpty()) { 1.274 + return null; 1.275 + } else { 1.276 + if (sameName.size() == 1) { 1.277 + return sameName.get(0); 1.278 + } else { 1.279 + Class<?>[] argCls = method.getParameterTypes(); 1.280 + for (JavaMethod jm : sameName) { 1.281 + JavaMethod.JavaParams params = jm.getJavaParams(); 1.282 + if (params != null && params.getJavaParam() != null && params.getJavaParam().size() == argCls.length) { 1.283 + int count = 0; 1.284 + for (int i = 0; i < argCls.length; i++) { 1.285 + JavaParam jp = params.getJavaParam().get(i); 1.286 + if (argCls[i].getName().equals(jp.getJavaType())) { 1.287 + count++; 1.288 + } 1.289 + } 1.290 + if (count == argCls.length) { 1.291 + return jm; 1.292 + } 1.293 + } 1.294 + } 1.295 + } 1.296 + } 1.297 + return null; 1.298 + } 1.299 + 1.300 + Element findXmlElement(Element[] xa) { 1.301 + if (xa == null) return null; 1.302 + for (Element e : xa) { 1.303 + if (e.getLocalName().equals("java-type")) return e; 1.304 + if (e.getLocalName().equals("xml-element")) return e; 1.305 + } 1.306 + return null; 1.307 + } 1.308 + 1.309 + /** 1.310 + * Helper class to merge two different arrays of annotation objects. It merges annotations based on attribute 1.311 + * <code>existing-annotations</code> in external customization file. 1.312 + * <p/> 1.313 + * We suppose that in the result array there wouldn't be two annotations of same type: 1.314 + * annotation.annotationType().getName(); if there are found such annotations the one from reflection is 1.315 + * considered overriden and is thrown away. 1.316 + * <p/> 1.317 + * The helper can work either with one and two dimensional array, but it can be used for two single Annotation 1.318 + * objects; 1.319 + */ 1.320 + static abstract class Merger<T> { 1.321 + 1.322 + JavaWsdlMappingType reader; 1.323 + 1.324 + Merger(JavaWsdlMappingType r) { 1.325 + this.reader = r; 1.326 + } 1.327 + 1.328 + abstract T reflection(); 1.329 + 1.330 + abstract T external(); 1.331 + 1.332 + @SuppressWarnings("unchecked") 1.333 + T merge() { 1.334 + T reflection = reflection(); 1.335 + if (reader == null) { 1.336 + return reflection; 1.337 + } 1.338 + 1.339 + T external = external(); 1.340 + if (!MERGE.equals(reader.getExistingAnnotations())) { 1.341 + return external; 1.342 + } 1.343 + 1.344 + if (reflection instanceof Annotation) { 1.345 + return (T) doMerge((Annotation) reflection, (Annotation) external); 1.346 + } else if (reflection instanceof Annotation[][]) { 1.347 + return (T) doMerge((Annotation[][]) reflection, (Annotation[][]) external); 1.348 + } else { 1.349 + return (T) doMerge((Annotation[]) reflection, (Annotation[]) external); 1.350 + } 1.351 + } 1.352 + 1.353 + private Annotation doMerge(Annotation reflection, Annotation external) { 1.354 + return external != null ? external : reflection; 1.355 + } 1.356 + 1.357 + private Annotation[][] doMerge(Annotation[][] reflection, Annotation[][] external) { 1.358 + for (int i = 0; i < reflection.length; i++) { 1.359 + reflection[i] = doMerge(reflection[i], external.length > i ? external[i] : null); 1.360 + } 1.361 + return reflection; 1.362 + } 1.363 + 1.364 + private Annotation[] doMerge(Annotation[] annotations, Annotation[] externalAnnotations) { 1.365 + HashMap<String, Annotation> mergeMap = new HashMap<String, Annotation>(); 1.366 + if (annotations != null) { 1.367 + for (Annotation reflectionAnnotation : annotations) { 1.368 + mergeMap.put(reflectionAnnotation.annotationType().getName(), reflectionAnnotation); 1.369 + } 1.370 + } 1.371 + 1.372 + // overriding happens here, based on annotationType().getName() ... 1.373 + if (externalAnnotations != null) { 1.374 + for (Annotation externalAnnotation : externalAnnotations) { 1.375 + mergeMap.put(externalAnnotation.annotationType().getName(), externalAnnotation); 1.376 + } 1.377 + } 1.378 + Collection<Annotation> values = mergeMap.values(); 1.379 + int size = values.size(); 1.380 + return size == 0 ? null : values.toArray(new Annotation[size]); 1.381 + } 1.382 + 1.383 + } 1.384 + 1.385 + static class Util { 1.386 + 1.387 + //private static final String DATABINDING_XSD = "com/sun/xml/internal/ws/model/jaxws-databinding.xsd"; 1.388 + private static final String DATABINDING_XSD = "jaxws-databinding.xsd"; 1.389 + //private static final String TRANSLATE_NAMESPACES_XSL = "/com/sun/xml/internal/ws/model/jaxws-databinding-translate-namespaces.xml"; 1.390 + private static final String TRANSLATE_NAMESPACES_XSL = "jaxws-databinding-translate-namespaces.xml"; 1.391 + 1.392 + static Schema schema; 1.393 + static JAXBContext jaxbContext; 1.394 + 1.395 + static { 1.396 + SchemaFactory sf = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); 1.397 + try { 1.398 + URL xsdUrl = getResource(); 1.399 + if (xsdUrl != null) { 1.400 + schema = sf.newSchema(xsdUrl); 1.401 + } 1.402 + } catch (SAXException e1) { 1.403 + // e1.printStackTrace(); 1.404 + } 1.405 + 1.406 + jaxbContext = createJaxbContext(false); 1.407 + } 1.408 + 1.409 + private static URL getResource() { 1.410 + ClassLoader classLoader = Util.class.getClassLoader(); 1.411 + return classLoader != null ? classLoader.getResource(DATABINDING_XSD) : ClassLoader.getSystemResource(DATABINDING_XSD); 1.412 + } 1.413 + 1.414 + private static JAXBContext createJaxbContext(boolean disableXmlSecurity) { 1.415 + Class[] cls = {ObjectFactory.class}; 1.416 + try { 1.417 + if (disableXmlSecurity) { 1.418 + Map<String, Object> properties = new HashMap<String, Object>(); 1.419 + properties.put(JAXBRIContext.DISABLE_XML_SECURITY, disableXmlSecurity); 1.420 + return JAXBContext.newInstance(cls, properties); 1.421 + } else { 1.422 + return JAXBContext.newInstance(cls); 1.423 + } 1.424 + } catch (JAXBException e) { 1.425 + e.printStackTrace(); 1.426 + return null; 1.427 + } 1.428 + } 1.429 + 1.430 + @SuppressWarnings("unchecked") 1.431 + public static JavaWsdlMappingType read(Source src, boolean xsdValidation, boolean disableXmlSecurity) throws IOException, JAXBException { 1.432 + JAXBContext ctx = jaxbContext(disableXmlSecurity); 1.433 + try { 1.434 + Unmarshaller um = ctx.createUnmarshaller(); 1.435 + if (xsdValidation) { 1.436 + if (schema == null) { 1.437 + //TODO 0 warning for schema == null 1.438 + } 1.439 + um.setSchema(schema); 1.440 + } 1.441 + Object o = um.unmarshal(src); 1.442 + return getJavaWsdlMapping(o); 1.443 + } catch (JAXBException e) { 1.444 + // throw new 1.445 + // WebServiceException(WsDatabindingMessages.mappingFileCannotRead 1.446 + // (src.getSystemId()), e); 1.447 + URL url = new URL(src.getSystemId()); 1.448 + Source s = new StreamSource(url.openStream()); 1.449 + Unmarshaller um = ctx.createUnmarshaller(); 1.450 + if (xsdValidation) { 1.451 + if (schema == null) { 1.452 + //TODO 0 warning for schema == null 1.453 + } 1.454 + um.setSchema(schema); 1.455 + } 1.456 + Object o = um.unmarshal(s); 1.457 + return getJavaWsdlMapping(o); 1.458 + } 1.459 + } 1.460 + 1.461 + private static JAXBContext jaxbContext(boolean disableXmlSecurity) { 1.462 + // as it is supposed to have security enabled in most cases, we create and don't cache 1.463 + // "insecure" JAXBContext - these should be corner cases 1.464 + return disableXmlSecurity ? createJaxbContext(true) : jaxbContext; 1.465 + } 1.466 + 1.467 + public static JavaWsdlMappingType transformAndRead(Source src, boolean disableXmlSecurity) throws TransformerException, JAXBException { 1.468 + Source xsl = new StreamSource(Util.class.getResourceAsStream(TRANSLATE_NAMESPACES_XSL)); 1.469 + JAXBResult result = new JAXBResult(jaxbContext(disableXmlSecurity)); 1.470 + TransformerFactory tf = XmlUtil.newTransformerFactory(!disableXmlSecurity); 1.471 + Transformer transformer = tf.newTemplates(xsl).newTransformer(); 1.472 + transformer.transform(src, result); 1.473 + return getJavaWsdlMapping(result.getResult()); 1.474 + } 1.475 + 1.476 + 1.477 + static JavaWsdlMappingType getJavaWsdlMapping(Object o) { 1.478 + Object val = (o instanceof JAXBElement) ? ((JAXBElement) o).getValue() : o; 1.479 + if (val instanceof JavaWsdlMappingType) return (JavaWsdlMappingType) val; 1.480 + // else if (val instanceof JavaWsdlMappings) 1.481 + // for (JavaWsdlMappingType m: ((JavaWsdlMappings) val).getJavaWsdlMapping()) 1.482 + // if (seiName.equals(m.javaTypeName)) return m; 1.483 + return null; 1.484 + } 1.485 + 1.486 + static <T> T findInstanceOf(Class<T> type, List<Object> objects) { 1.487 + for (Object o : objects) { 1.488 + if (type.isInstance(o)) { 1.489 + return type.cast(o); 1.490 + } 1.491 + } 1.492 + return null; 1.493 + } 1.494 + 1.495 + static public <T> T annotation(JavaWsdlMappingType jwse, Class<T> anntype) { 1.496 + if (jwse == null || jwse.getClassAnnotation() == null) { 1.497 + return null; 1.498 + } 1.499 + return findInstanceOf(anntype, jwse.getClassAnnotation()); 1.500 + } 1.501 + 1.502 + static public <T> T annotation(JavaMethod jm, Class<T> anntype) { 1.503 + if (jm == null || jm.getMethodAnnotation() == null) { 1.504 + return null; 1.505 + } 1.506 + return findInstanceOf(anntype, jm.getMethodAnnotation()); 1.507 + } 1.508 + 1.509 + static public <T> T annotation(JavaParam jp, Class<T> anntype) { 1.510 + if (jp == null || jp.getParamAnnotation() == null) { 1.511 + return null; 1.512 + } 1.513 + return findInstanceOf(anntype, jp.getParamAnnotation()); 1.514 + } 1.515 + 1.516 + static public Element[] annotation(JavaMethod jm) { 1.517 + if (jm == null || jm.getMethodAnnotation() == null) { 1.518 + return null; 1.519 + } 1.520 + return findElements(jm.getMethodAnnotation()); 1.521 + } 1.522 + 1.523 + static public Element[] annotation(JavaParam jp) { 1.524 + if (jp == null || jp.getParamAnnotation() == null) { 1.525 + return null; 1.526 + } 1.527 + return findElements(jp.getParamAnnotation()); 1.528 + } 1.529 + 1.530 + private static Element[] findElements(List<Object> objects) { 1.531 + List<Element> elems = new ArrayList<Element>(); 1.532 + for (Object o : objects) { 1.533 + if (o instanceof Element) { 1.534 + elems.add((Element) o); 1.535 + } 1.536 + } 1.537 + return elems.toArray(new Element[elems.size()]); 1.538 + } 1.539 + 1.540 + static String documentRootNamespace(Source src, boolean disableXmlSecurity) throws XMLStreamException { 1.541 + XMLInputFactory factory; 1.542 + factory = XmlUtil.newXMLInputFactory(!disableXmlSecurity); 1.543 + XMLStreamReader streamReader = factory.createXMLStreamReader(src); 1.544 + XMLStreamReaderUtil.nextElementContent(streamReader); 1.545 + String namespaceURI = streamReader.getName().getNamespaceURI(); 1.546 + XMLStreamReaderUtil.close(streamReader); 1.547 + return namespaceURI; 1.548 + } 1.549 + } 1.550 + 1.551 + 1.552 +}