From: <jbo...@li...> - 2006-07-05 09:22:38
|
Author: hei...@jb... Date: 2006-07-05 05:22:32 -0400 (Wed, 05 Jul 2006) New Revision: 561 Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/JBossXBMarshallerImpl.java branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/JBossXBSupport.java branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/XercesXSMarshallerImpl.java Log: cleanup XB API usage Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/JBossXBMarshallerImpl.java =================================================================== --- branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/JBossXBMarshallerImpl.java 2006-07-05 08:27:29 UTC (rev 560) +++ branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/JBossXBMarshallerImpl.java 2006-07-05 09:22:32 UTC (rev 561) @@ -26,23 +26,18 @@ import org.jboss.logging.Logger; import org.jboss.util.NotImplementedException; import org.jboss.ws.WSException; -import org.jboss.ws.xop.XOPMarshallerImpl; import org.jboss.ws.metadata.jaxrpcmapping.JavaWsdlMapping; import org.jboss.ws.metadata.jaxrpcmapping.JavaXmlTypeMapping; import org.jboss.ws.metadata.jaxrpcmapping.VariableMapping; import org.jboss.ws.utils.JavaUtils; +import org.jboss.ws.xop.XOPMarshallerImpl; import org.jboss.xb.binding.Constants; -import org.jboss.xb.binding.MappingObjectModelProvider; -import org.jboss.xb.binding.MarshallingContext; -import org.jboss.xb.binding.ObjectLocalMarshaller; import org.jboss.xb.binding.introspection.ClassInfos; import org.jboss.xb.binding.sunday.marshalling.MarshallerImpl; import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding; -import org.jboss.xb.util.Dom2Sax; -import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; + import javax.xml.namespace.QName; import java.io.OutputStream; import java.io.OutputStreamWriter; @@ -76,7 +71,6 @@ delegate.setProperty(org.jboss.xb.binding.Marshaller.PROP_OUTPUT_INDENTATION, "false"); delegate.declareNamespace("xsi", Constants.NS_XML_SCHEMA_INSTANCE); delegate.setSupportNil(true); - //delegate.setSimpleContentProperty("_value"); } /** @@ -104,11 +98,8 @@ delegate.declareNamespace(prefix, nsURI); } - MappingObjectModelProvider provider = new MappingObjectModelProvider(); - provider.setIgnoreLowLine(false); - provider.setIgnoreNotFoundField(false); - - // todo complete wsdl mapping merge + // wildcards still need to be mapped + // todo: cleanup XB API JavaWsdlMapping wsdlMapping = (JavaWsdlMapping)getProperty(JAXBConstants.JAXB_JAVA_MAPPING); if (wsdlMapping != null) { @@ -123,42 +114,14 @@ { String clsName = javaXmlMapping.getJavaType(); Class cls = JavaUtils.loadJavaType(clsName, Thread.currentThread().getContextClassLoader()); - QName clsQName = javaXmlMapping.getRootTypeQName() != null ? javaXmlMapping.getRootTypeQName() : javaXmlMapping.getAnonymousTypeQName(); - if (clsQName != null) - { - if ("element".equals(javaXmlMapping.getQnameScope())) - { - delegate.mapClassToGlobalElement(cls, clsQName.getLocalPart(), clsQName.getNamespaceURI(), null, provider); - } - else - { - delegate.mapClassToGlobalType(cls, clsQName.getLocalPart(), clsQName.getNamespaceURI(), null, provider); - delegate.mapClassToXsiType(cls, clsQName.getNamespaceURI(), clsQName.getLocalPart()); - } - } - for (int j = 0; j < variableMappings.length; ++j) { VariableMapping variableMapping = variableMappings[j]; - String javaName = variableMapping.getJavaVariableName(); - if (variableMapping.getXmlElementName() != null) + if (variableMapping.getXmlWildcard()) { - String xmlElementName = variableMapping.getXmlElementName(); - provider.mapFieldToElement(cls, javaName, "", xmlElementName, null); + delegate.mapFieldToWildcard(cls, "_any", JBossXBSupport.getWildcardMarshaller()); } - else if (variableMapping.getXmlAttributeName() != null) - { - log.trace("Unmapped attribute: " + javaName); - } - else if (variableMapping.getXmlWildcard()) - { - delegate.mapFieldToWildcard(cls, "_any", getWildcardMarshaller()); - } - else - { - log.warn("Unmapped variable: " + javaName); - } } } } @@ -168,7 +131,7 @@ // the actual marshalling SchemaBinding schemaBinding = JBossXBSupport.getOrCreateSchemaBinding(properties); schemaBinding.setXopMarshaller(new XOPMarshallerImpl()); - delegate.marshal(schemaBinding, provider, obj, writer); + delegate.marshal(schemaBinding, null, obj, writer); } catch (RuntimeException e) { @@ -180,53 +143,6 @@ } } - private ObjectLocalMarshaller getWildcardMarshaller() - { - ObjectLocalMarshaller wildcardMarshaller = new ObjectLocalMarshaller() { - public void marshal(MarshallingContext ctx, Object o) - { - if (o == null) - { - return; - } - - Element e = (Element)o; - ContentHandler ch = ctx.getContentHandler(); - try - { - Dom2Sax.dom2sax(e, ch); - } - catch (SAXException e1) - { - throw new IllegalStateException("Failed to marshal DOM element " + new QName(e.getNamespaceURI(), e.getLocalName()) + ": " + e1.getMessage()); - } - /* - DOMSource domSource = new DOMSource(e); - SAXResult streamResult = new SAXResult(ch); - // if i use the system default transformer then it works - // the one that is actually used does not declare namespaces - //System.setProperty("javax.xml.transform.TransformerFactory", "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); - TransformerFactory tf = TransformerFactory.newInstance(); - Transformer serializer = null; - try - { - serializer = tf.newTransformer(); - serializer.transform(domSource, streamResult); - } - catch(TransformerConfigurationException e1) - { - throw new JBossXBRuntimeException("Failed to create transformer", e1); - } - catch(TransformerException e1) - { - throw new JBossXBRuntimeException("Failed to marshal with transform", e1); - } - */ - } - }; - return wildcardMarshaller; - } - /** * Marshal the content tree rooted at obj into SAX2 events. */ Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/JBossXBSupport.java =================================================================== --- branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/JBossXBSupport.java 2006-07-05 08:27:29 UTC (rev 560) +++ branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/JBossXBSupport.java 2006-07-05 09:22:32 UTC (rev 561) @@ -1,6 +1,9 @@ package org.jboss.ws.jaxb; import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding; +import org.jboss.xb.binding.ObjectLocalMarshaller; +import org.jboss.xb.binding.MarshallingContext; +import org.jboss.xb.util.Dom2Sax; import org.jboss.ws.soap.SOAPMessageContextImpl; import org.jboss.ws.soap.MessageContextAssociation; import org.jboss.ws.metadata.OperationMetaData; @@ -8,6 +11,10 @@ import org.jboss.ws.metadata.ServiceMetaData; import org.jboss.ws.metadata.jaxrpcmapping.JavaWsdlMapping; import org.jboss.ws.metadata.wsdl.xmlschema.JBossXSModel; +import org.jboss.ws.WSException; +import org.w3c.dom.Element; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; import javax.xml.namespace.QName; import java.util.Map; @@ -61,7 +68,39 @@ // by various operations with different xml types, we have to add the // element binding on every invocation. bindingBuilder.bindParameterToElement(schemaBinding, xmlName, xmlType); - + return schemaBinding; } + + /** + * Create a Marshaller that serializes + * <code>org.w3c.dom.Element</code>'s to a <code>org.xml.sax.ContentHandler</code> + * + * @return ObjectLocalMarshaller + * + * @see org.jboss.xb.binding.MarshallingContext#getContentHandler() + */ + public static ObjectLocalMarshaller getWildcardMarshaller() + { + return new ObjectLocalMarshaller() { + public void marshal(MarshallingContext ctx, Object o) + { + if (o == null) + { + return; + } + + Element e = (Element)o; + ContentHandler ch = ctx.getContentHandler(); + try + { + Dom2Sax.dom2sax(e, ch); + } + catch (SAXException e1) + { + throw new IllegalStateException("Failed to marshal DOM element " + new QName(e.getNamespaceURI(), e.getLocalName()) + ": " + e1.getMessage()); + } + } + }; + } } Modified: branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/XercesXSMarshallerImpl.java =================================================================== --- branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/XercesXSMarshallerImpl.java 2006-07-05 08:27:29 UTC (rev 560) +++ branches/jbossws-1.0/src/main/java/org/jboss/ws/jaxb/XercesXSMarshallerImpl.java 2006-07-05 09:22:32 UTC (rev 561) @@ -23,13 +23,6 @@ // $Id$ -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.Writer; -import java.util.HashMap; - -import javax.xml.namespace.QName; - import org.apache.xerces.xs.XSModel; import org.jboss.logging.Logger; import org.jboss.util.NotImplementedException; @@ -40,15 +33,16 @@ import org.jboss.ws.utils.JavaUtils; import org.jboss.xb.binding.Constants; import org.jboss.xb.binding.MappingObjectModelProvider; -import org.jboss.xb.binding.MarshallingContext; -import org.jboss.xb.binding.ObjectLocalMarshaller; import org.jboss.xb.binding.XercesXsMarshaller; -import org.jboss.xb.util.Dom2Sax; -import org.w3c.dom.Element; import org.w3c.dom.Node; import org.xml.sax.ContentHandler; -import org.xml.sax.SAXException; +import javax.xml.namespace.QName; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.Writer; +import java.util.HashMap; + /** * An implementation of a JAXB Marshaller that user XercesXSMarshaller impl. * @@ -150,7 +144,7 @@ } else if (variableMapping.getXmlWildcard()) { - delegate.mapFieldToWildcard(cls, "_any", getWildcardMarshaller()); + delegate.mapFieldToWildcard(cls, "_any", JBossXBSupport.getWildcardMarshaller()); } else { @@ -178,31 +172,6 @@ } } - private ObjectLocalMarshaller getWildcardMarshaller() - { - ObjectLocalMarshaller wildcardMarshaller = new ObjectLocalMarshaller() { - public void marshal(MarshallingContext ctx, Object o) - { - if (o == null) - { - return; - } - - Element e = (Element)o; - ContentHandler ch = ctx.getContentHandler(); - try - { - Dom2Sax.dom2sax(e, ch); - } - catch (SAXException e1) - { - throw new IllegalStateException("Failed to marshal DOM element " + new QName(e.getNamespaceURI(), e.getLocalName()) + ": " + e1.getMessage()); - } - } - }; - return wildcardMarshaller; - } - /** * Marshal the content tree rooted at obj into SAX2 events. */ |