73 * map of readers for defined java types |
73 * map of readers for defined java types |
74 */ |
74 */ |
75 private Map<String, JavaWsdlMappingType> readers = new HashMap<String, JavaWsdlMappingType>(); |
75 private Map<String, JavaWsdlMappingType> readers = new HashMap<String, JavaWsdlMappingType>(); |
76 |
76 |
77 public ExternalMetadataReader(Collection<File> files, Collection<String> resourcePaths, ClassLoader classLoader, |
77 public ExternalMetadataReader(Collection<File> files, Collection<String> resourcePaths, ClassLoader classLoader, |
78 boolean xsdValidation, boolean disableSecureXmlProcessing) { |
78 boolean xsdValidation, boolean disableXmlSecurity) { |
79 |
79 |
80 if (files != null) { |
80 if (files != null) { |
81 for (File file : files) { |
81 for (File file : files) { |
82 try { |
82 try { |
83 String namespace = Util.documentRootNamespace(newSource(file), disableSecureXmlProcessing); |
83 String namespace = Util.documentRootNamespace(newSource(file), disableXmlSecurity); |
84 JavaWsdlMappingType externalMapping = parseMetadata(xsdValidation, newSource(file), namespace, disableSecureXmlProcessing); |
84 JavaWsdlMappingType externalMapping = parseMetadata(xsdValidation, newSource(file), namespace, disableXmlSecurity); |
85 readers.put(externalMapping.getJavaTypeName(), externalMapping); |
85 readers.put(externalMapping.getJavaTypeName(), externalMapping); |
86 } catch (Exception e) { |
86 } catch (Exception e) { |
87 throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", file.getAbsolutePath()); |
87 throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", file.getAbsolutePath()); |
88 } |
88 } |
89 } |
89 } |
90 } |
90 } |
91 |
91 |
92 if (resourcePaths != null) { |
92 if (resourcePaths != null) { |
93 for (String resourcePath : resourcePaths) { |
93 for (String resourcePath : resourcePaths) { |
94 try { |
94 try { |
95 String namespace = Util.documentRootNamespace(newSource(resourcePath, classLoader), disableSecureXmlProcessing); |
95 String namespace = Util.documentRootNamespace(newSource(resourcePath, classLoader), disableXmlSecurity); |
96 JavaWsdlMappingType externalMapping = parseMetadata(xsdValidation, newSource(resourcePath, classLoader), namespace, disableSecureXmlProcessing); |
96 JavaWsdlMappingType externalMapping = parseMetadata(xsdValidation, newSource(resourcePath, classLoader), namespace, disableXmlSecurity); |
97 readers.put(externalMapping.getJavaTypeName(), externalMapping); |
97 readers.put(externalMapping.getJavaTypeName(), externalMapping); |
98 } catch (Exception e) { |
98 } catch (Exception e) { |
99 throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", resourcePath); |
99 throw new RuntimeModelerException("runtime.modeler.external.metadata.unable.to.read", resourcePath); |
100 } |
100 } |
101 } |
101 } |
105 private StreamSource newSource(String resourcePath, ClassLoader classLoader) { |
105 private StreamSource newSource(String resourcePath, ClassLoader classLoader) { |
106 InputStream is = classLoader.getResourceAsStream(resourcePath); |
106 InputStream is = classLoader.getResourceAsStream(resourcePath); |
107 return new StreamSource(is); |
107 return new StreamSource(is); |
108 } |
108 } |
109 |
109 |
110 private JavaWsdlMappingType parseMetadata(boolean xsdValidation, StreamSource source, String namespace, boolean disableSecureXmlProcessing) throws JAXBException, IOException, TransformerException { |
110 private JavaWsdlMappingType parseMetadata(boolean xsdValidation, StreamSource source, String namespace, boolean disableXmlSecurity) throws JAXBException, IOException, TransformerException { |
111 if (NAMESPACE_WEBLOGIC_WSEE_DATABINDING.equals(namespace)) { |
111 if (NAMESPACE_WEBLOGIC_WSEE_DATABINDING.equals(namespace)) { |
112 return Util.transformAndRead(source, disableSecureXmlProcessing); |
112 return Util.transformAndRead(source, disableXmlSecurity); |
113 } if (NAMESPACE_JAXWS_RI_EXTERNAL_METADATA.equals(namespace)) { |
113 } if (NAMESPACE_JAXWS_RI_EXTERNAL_METADATA.equals(namespace)) { |
114 return Util.read(source, xsdValidation, disableSecureXmlProcessing); |
114 return Util.read(source, xsdValidation, disableXmlSecurity); |
115 } else { |
115 } else { |
116 throw new RuntimeModelerException("runtime.modeler.external.metadata.unsupported.schema", namespace, Arrays.asList(NAMESPACE_WEBLOGIC_WSEE_DATABINDING, NAMESPACE_JAXWS_RI_EXTERNAL_METADATA).toString()); |
116 throw new RuntimeModelerException("runtime.modeler.external.metadata.unsupported.schema", namespace, Arrays.asList(NAMESPACE_WEBLOGIC_WSEE_DATABINDING, NAMESPACE_JAXWS_RI_EXTERNAL_METADATA).toString()); |
117 } |
117 } |
118 } |
118 } |
119 |
119 |
423 return null; |
423 return null; |
424 } |
424 } |
425 } |
425 } |
426 |
426 |
427 @SuppressWarnings("unchecked") |
427 @SuppressWarnings("unchecked") |
428 public static JavaWsdlMappingType read(Source src, boolean xsdValidation, boolean disableSecureXmlProcessing) throws IOException, JAXBException { |
428 public static JavaWsdlMappingType read(Source src, boolean xsdValidation, boolean disableXmlSecurity) throws IOException, JAXBException { |
429 JAXBContext ctx = jaxbContext(disableSecureXmlProcessing); |
429 JAXBContext ctx = jaxbContext(disableXmlSecurity); |
430 try { |
430 try { |
431 Unmarshaller um = ctx.createUnmarshaller(); |
431 Unmarshaller um = ctx.createUnmarshaller(); |
432 if (xsdValidation) { |
432 if (xsdValidation) { |
433 if (schema == null) { |
433 if (schema == null) { |
434 //TODO 0 warning for schema == null |
434 //TODO 0 warning for schema == null |
453 Object o = um.unmarshal(s); |
453 Object o = um.unmarshal(s); |
454 return getJavaWsdlMapping(o); |
454 return getJavaWsdlMapping(o); |
455 } |
455 } |
456 } |
456 } |
457 |
457 |
458 private static JAXBContext jaxbContext(boolean disableSecureXmlProcessing) { |
458 private static JAXBContext jaxbContext(boolean disableXmlSecurity) { |
459 // as it is supposed to have security enabled in most cases, we create and don't cache |
459 // as it is supposed to have security enabled in most cases, we create and don't cache |
460 // "insecure" JAXBContext - these should be corner cases |
460 // "insecure" JAXBContext - these should be corner cases |
461 return disableSecureXmlProcessing ? createJaxbContext(true) : jaxbContext; |
461 return disableXmlSecurity ? createJaxbContext(true) : jaxbContext; |
462 } |
462 } |
463 |
463 |
464 public static JavaWsdlMappingType transformAndRead(Source src, boolean disableSecureXmlProcessing) throws TransformerException, JAXBException { |
464 public static JavaWsdlMappingType transformAndRead(Source src, boolean disableXmlSecurity) throws TransformerException, JAXBException { |
465 Source xsl = new StreamSource(Util.class.getResourceAsStream(TRANSLATE_NAMESPACES_XSL)); |
465 Source xsl = new StreamSource(Util.class.getResourceAsStream(TRANSLATE_NAMESPACES_XSL)); |
466 JAXBResult result = new JAXBResult(jaxbContext(disableSecureXmlProcessing)); |
466 JAXBResult result = new JAXBResult(jaxbContext(disableXmlSecurity)); |
467 TransformerFactory tf = XmlUtil.newTransformerFactory(!disableSecureXmlProcessing); |
467 TransformerFactory tf = XmlUtil.newTransformerFactory(!disableXmlSecurity); |
468 Transformer transformer = tf.newTemplates(xsl).newTransformer(); |
468 Transformer transformer = tf.newTemplates(xsl).newTransformer(); |
469 transformer.transform(src, result); |
469 transformer.transform(src, result); |
470 return getJavaWsdlMapping(result.getResult()); |
470 return getJavaWsdlMapping(result.getResult()); |
471 } |
471 } |
472 |
472 |
532 } |
532 } |
533 } |
533 } |
534 return elems.toArray(new Element[elems.size()]); |
534 return elems.toArray(new Element[elems.size()]); |
535 } |
535 } |
536 |
536 |
537 static String documentRootNamespace(Source src, boolean disableSecureXmlProcessing) throws XMLStreamException { |
537 static String documentRootNamespace(Source src, boolean disableXmlSecurity) throws XMLStreamException { |
538 XMLInputFactory factory; |
538 XMLInputFactory factory; |
539 factory = XmlUtil.newXMLInputFactory(!disableSecureXmlProcessing); |
539 factory = XmlUtil.newXMLInputFactory(!disableXmlSecurity); |
540 XMLStreamReader streamReader = factory.createXMLStreamReader(src); |
540 XMLStreamReader streamReader = factory.createXMLStreamReader(src); |
541 XMLStreamReaderUtil.nextElementContent(streamReader); |
541 XMLStreamReaderUtil.nextElementContent(streamReader); |
542 String namespaceURI = streamReader.getName().getNamespaceURI(); |
542 String namespaceURI = streamReader.getName().getNamespaceURI(); |
543 XMLStreamReaderUtil.close(streamReader); |
543 XMLStreamReaderUtil.close(streamReader); |
544 return namespaceURI; |
544 return namespaceURI; |