diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:19 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2009-11-11 23:07:19 +0000 |
commit | 6fadbc9cd1fcf03d0b3630f772d91df149b70428 (patch) | |
tree | 32752e491abb97fc8ef4f246455e3b5fd2814862 /branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org | |
parent | 5559ef5edbf8d3616f7a4b497b2a459b0ee4082b (diff) |
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835123 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org')
10 files changed, 0 insertions, 758 deletions
diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java deleted file mode 100644 index dd90b079d0..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java +++ /dev/null @@ -1,65 +0,0 @@ -/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.tuscany.sca.databinding.axiom;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.tuscany.sca.databinding.ExceptionHandler;
-import org.apache.tuscany.sca.databinding.WrapperHandler;
-import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
-
-/**
- * DataBinding for AXIOM
- */
-public class AxiomDataBinding extends BaseDataBinding {
-
- public static final String NAME = OMElement.class.getName();
- public static final String[] ALIASES = new String[] {"axiom"};
-
- public AxiomDataBinding() {
- super(NAME, ALIASES, OMElement.class);
- }
-
- /**
- * @see org.apache.tuscany.sca.databinding.impl.BaseDataBinding#getWrapperHandler()
- */
- @Override
- public WrapperHandler getWrapperHandler() {
- return new OMElementWrapperHandler();
- }
-
- @Override
- public Object copy(Object source) {
- if ( OMElement.class.isAssignableFrom(source.getClass()) ) {
- try {
- OMElement sourceElement = (OMElement)source;
- return sourceElement.cloneOMElement();
- } catch ( Exception e ) {
- throw new IllegalArgumentException(e);
- }
- }
- return super.copy(source);
- }
-
- @Override
- public ExceptionHandler getExceptionHandler() {
- return new AxiomExceptionHandler();
- }
-
-}
diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java deleted file mode 100644 index fccf6c530d..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.databinding.axiom; - -import org.apache.axiom.om.OMElement; -import org.apache.tuscany.sca.databinding.ExceptionHandler; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.apache.tuscany.sca.interfacedef.util.FaultException; -import org.apache.tuscany.sca.interfacedef.util.XMLType; - -/** - * AXIOM implementation of ExceptionHandler - * - * @version $Rev$ $Date$ - */ -public class AxiomExceptionHandler implements ExceptionHandler { - - public Exception createException(DataType<DataType> exceptionType, String message, Object faultInfo, Throwable cause) { - return new FaultException(message, faultInfo, cause); - } - - public Object getFaultInfo(Exception exception) { - if (exception == null) { - return null; - } - FaultException faultException = (FaultException)exception; - return faultException.getFaultInfo(); - - } - - public DataType<?> getFaultType(DataType exceptionType) { - if (FaultException.class == exceptionType.getPhysical()) { - XMLType type = XMLType.UNKNOWN; - if(exceptionType.getLogical() instanceof XMLType) { - type = (XMLType) exceptionType.getLogical(); - } - DataType<XMLType> faultType = new DataTypeImpl<XMLType>(AxiomDataBinding.NAME, OMElement.class, type); - return faultType; - } else { - return null; - } - } -} diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java deleted file mode 100644 index f120d66b0d..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.databinding.axiom; - -import javax.xml.namespace.QName; - -import org.apache.axiom.om.OMAbstractFactory; -import org.apache.axiom.om.OMDataSource; -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMFactory; -import org.apache.axiom.om.OMNamespace; -import org.apache.axiom.om.OMXMLParserWrapper; -import org.apache.axiom.om.impl.builder.StAXBuilder; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.util.XMLType; - -/** - * Helper for AXIOM - * - * @version $Rev$ $Date$ - */ -public class AxiomHelper { - private static final String DEFAULT_PREFIX = "_ns_"; - - private AxiomHelper() { - } - - /** - * See http://issues.apache.org/jira/browse/WSCOMMONS-240 - * @param om - */ - public static void completeAndClose(OMElement om) { - // Get the builder associated with the om element - OMXMLParserWrapper builder = om.getBuilder(); - if (builder != null) { - if (builder instanceof StAXBuilder) { - ((StAXBuilder)builder).releaseParserOnClose(true); - } - OMElement document = builder.getDocumentElement(); - if (document != null) { - document.build(); - } - } - if (builder instanceof StAXBuilder) { - ((StAXBuilder)builder).close(); - } - } - - /** - * This method will close the builder immediately. Any subsequent Axiom objects won't - * be built or accessible. - */ - public static void closeImmediately(OMElement om) { - // Get the builder associated with the om element - OMXMLParserWrapper builder = om.getBuilder(); - if (builder != null) { - if (builder instanceof StAXBuilder) { - ((StAXBuilder)builder).releaseParserOnClose(true); - ((StAXBuilder)builder).close(); - } - // builder.close(); - } - } - - /** - * @param context - * @param element - */ - public static void adjustElementName(TransformationContext context, OMElement element) { - if (context != null) { - DataType dataType = context.getTargetDataType(); - Object logical = dataType == null ? null : dataType.getLogical(); - if (!(logical instanceof XMLType)) { - return; - } - XMLType xmlType = (XMLType)logical; - if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) { - // FIXME:: Throw expection or switch to the new Element? - OMFactory factory = OMAbstractFactory.getOMFactory(); - QName name = xmlType.getElementName(); - OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); - element.setNamespace(namespace); - element.setLocalName(name.getLocalPart()); - } - } - } - - public static OMElement createOMElement(OMFactory factory, QName element) { - String localName = element.getLocalPart(); - OMNamespace ns = createOMNamespace(factory, element); - - return factory.createOMElement(localName, ns); - - } - - public static OMElement createOMElement(OMFactory factory, QName element, OMDataSource dataSource) { - String localName = element.getLocalPart(); - OMNamespace ns = createOMNamespace(factory, element); - - return factory.createOMElement(dataSource, localName, ns); - - } - - /** - * @param factory - * @param name - * @return - */ - public static OMNamespace createOMNamespace(OMFactory factory, QName name) { - String namespaceURI = name.getNamespaceURI(); - String prefix = name.getPrefix(); - - OMNamespace ns = null; - if (namespaceURI.length() != 0) { - // Qualified Element: we need an OMNamespace - if (prefix.length() == 0) { - // The prefix does not appear to be specified, let's create one - prefix = DEFAULT_PREFIX; - } - ns = factory.createOMNamespace(namespaceURI, prefix); - } - return ns; - } -} diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java deleted file mode 100644 index c119e55dc5..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.databinding.axiom; - -import org.apache.axiom.om.OMElement; -import org.apache.tuscany.sca.databinding.impl.SimpleType2JavaTransformer; - -/** - * Transformer to convert data from a simple java bject to OMElement - */ -public class OMElement2Object extends SimpleType2JavaTransformer<OMElement> { - - /** - * @see org.apache.tuscany.sca.databinding.impl.SimpleType2JavaTransformer#close(java.lang.Object) - */ - @Override - protected void close(OMElement source) { - if (source != null) { - AxiomHelper.completeAndClose(source); - } - } - - @Override - protected String getText(OMElement source) { - return source.getText(); - } - - @Override - public Class getSourceType() { - return OMElement.class; - } -} diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java deleted file mode 100755 index f5c657e29d..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.databinding.axiom; - -import java.io.StringWriter; - -import javax.xml.stream.XMLStreamException; - -import org.apache.axiom.om.OMElement; -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; - -/** - * Transformer to convert data from an OMElement to XML String - */ -public class OMElement2String extends BaseTransformer<OMElement, String> implements PullTransformer<OMElement, String> { - // private XmlOptions options; - - public String transform(OMElement source, TransformationContext context) { - try { - StringWriter writer = new StringWriter(); - source.serialize(writer); - return writer.toString(); - } catch (XMLStreamException e) { - throw new TransformationException(e); - } - } - - @Override - public Class getSourceType() { - return OMElement.class; - } - - @Override - public Class getTargetType() { - return String.class; - } - - @Override - public int getWeight() { - return 40; - } - -} diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java deleted file mode 100755 index c1c94a1828..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.databinding.axiom; - -import javax.xml.stream.XMLStreamReader; - -import org.apache.axiom.om.OMElement; -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; - -public class OMElement2XMLStreamReader extends BaseTransformer<OMElement, XMLStreamReader> implements PullTransformer<OMElement, XMLStreamReader> { - // private XmlOptions options; - - public XMLStreamReader transform(OMElement source, TransformationContext context) { - return source.getXMLStreamReader(); - } - - @Override - public Class getSourceType() { - return OMElement.class; - } - - @Override - public Class getTargetType() { - return XMLStreamReader.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java deleted file mode 100644 index c3d7dbd873..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.databinding.axiom; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import javax.xml.namespace.QName; - -import org.apache.axiom.om.OMAbstractFactory; -import org.apache.axiom.om.OMAttribute; -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMFactory; -import org.apache.axiom.om.OMNamespace; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.WrapperHandler; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; -import org.apache.tuscany.sca.interfacedef.util.ElementInfo; -import org.apache.tuscany.sca.interfacedef.util.TypeInfo; -import org.apache.tuscany.sca.interfacedef.util.XMLType; - -/** - * OMElement wrapper handler implementation - */ -public class OMElementWrapperHandler implements WrapperHandler<OMElement> { - - private OMFactory factory; - - public OMElementWrapperHandler() { - super(); - this.factory = OMAbstractFactory.getOMFactory(); - } - - public OMElement create(ElementInfo element, TransformationContext context) { - OMElement wrapper = AxiomHelper.createOMElement(factory, element.getQName()); - return wrapper; - } - - public void setChild(OMElement wrapper, int i, ElementInfo childElement, Object value) { - OMElement element = (OMElement)value; - QName elementName = childElement.getQName(); - OMNamespace namespace = factory.createOMNamespace(elementName.getNamespaceURI(), elementName.getPrefix()); - element.setNamespace(namespace); - element.setLocalName(childElement.getQName().getLocalPart()); - wrapper.addChild((OMElement)value); - } - - public List getChildren(OMElement wrapper, List<ElementInfo> childElements, TransformationContext context) { - List<Object> elements = new ArrayList<Object>(); - int i = 0; - for (ElementInfo e : childElements) { - elements.add(getChild(wrapper, e, i, context)); - i++; - } - return elements; - } - - /** - * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(org.apache.tuscany.sca.interfacedef.util.ElementInfo, List, org.apache.tuscany.sca.databinding.TransformationContext) - */ - public DataType getWrapperType(ElementInfo element, List<ElementInfo> childElements, TransformationContext context) { - DataType<XMLType> wrapperType = - new DataTypeImpl<XMLType>(AxiomDataBinding.NAME, OMElement.class, new XMLType(element)); - return wrapperType; - } - - public boolean isInstance(Object wrapperObj, - ElementInfo element, - List<ElementInfo> childElements, - TransformationContext context) { - OMElement wrapper = (OMElement)wrapperObj; - if (!element.getQName().equals(wrapper.getQName())) { - return false; - } - Set<QName> names = new HashSet<QName>(); - for (ElementInfo e : childElements) { - names.add(e.getQName()); - } - for (Iterator i = wrapper.getChildElements(); i.hasNext();) { - OMElement child = (OMElement)i.next(); - if (!names.contains(child.getQName())) { - return false; - } - } - return true; - } - - private static final QName XSI_TYPE_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"); - - public Object getChild(OMElement wrapper, ElementInfo childElement, int index, TransformationContext context) { - int pos = 0; - String wrapperNS = wrapper.getQName().getNamespaceURI(); - for (Iterator i = wrapper.getChildElements(); i.hasNext();) { - OMElement e = (OMElement)i.next(); - if (pos == index) { - TypeInfo type = childElement.getType(); - if (!childElement.getQName().equals(e.getQName()) && type != null) { - OMAttribute attr = e.getAttribute(XSI_TYPE_QNAME); - if (attr == null) { - String typeNS = type.getQName().getNamespaceURI(); - if (wrapperNS != null) { - // FIXME: [rfeng] Workaround for TUSCANY-1713, assuming the type - // namespace is the same as the wrapper - typeNS = wrapperNS; - } - OMNamespace ns = e.getOMFactory().createOMNamespace(typeNS, "_typens_"); - e.declareNamespace(ns); - OMNamespace xsiNS = - e.getOMFactory().createOMNamespace(XSI_TYPE_QNAME.getNamespaceURI(), - XSI_TYPE_QNAME.getPrefix()); - e.declareNamespace(xsiNS); - attr = - e.getOMFactory().createOMAttribute("type", - xsiNS, - "_typens_:" + type.getQName().getLocalPart()); - e.addAttribute(attr); - } - } - return e; - } - pos++; - } - return null; - } -} diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java deleted file mode 100644 index f7ccb13e6e..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.databinding.axiom; - -import javax.xml.namespace.QName; - -import org.apache.axiom.om.OMAbstractFactory; -import org.apache.axiom.om.OMAttribute; -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.OMFactory; -import org.apache.axiom.om.OMNamespace; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.impl.Java2SimpleTypeTransformer; - -/** - * Transformer to convert data from an simple OMElement to Java Object - */ -public class Object2OMElement extends Java2SimpleTypeTransformer<OMElement> { - - private OMFactory factory; - - public Object2OMElement() { - super(); - factory = OMAbstractFactory.getOMFactory(); - } - - @Override - protected OMElement createElement(QName element, String text, TransformationContext context) { - OMElement omElement = AxiomHelper.createOMElement(factory, element); - if (text == null) { - OMNamespace xsi = factory.createOMNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi"); - OMAttribute nil = factory.createOMAttribute("nil", xsi, "true"); - omElement.addAttribute(nil); - } else { - factory.createOMText(omElement, text); - } - return omElement; - } - - @Override - public Class getTargetType() { - return OMElement.class; - } - -} diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java deleted file mode 100755 index 224c956fcb..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.databinding.axiom; - -import java.io.ByteArrayInputStream; - -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.impl.builder.StAXOMBuilder; -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; - -public class String2OMElement extends BaseTransformer<String, OMElement> implements - PullTransformer<String, OMElement> { - - @SuppressWarnings("unchecked") - public OMElement transform(String source, TransformationContext context) { - try { - StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(source.getBytes())); - OMElement element = builder.getDocumentElement(); - AxiomHelper.adjustElementName(context, element); - return element; - } catch (Exception e) { - throw new TransformationException(e); - } - } - - @Override - public Class getTargetType() { - return OMElement.class; - } - - @Override - public Class getSourceType() { - return String.class; - } - - @Override - public int getWeight() { - return 40; - } - -} diff --git a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java b/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java deleted file mode 100755 index 0b3bc7a414..0000000000 --- a/branches/sca-java-1.0.1/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.databinding.axiom; - -import javax.xml.stream.XMLStreamReader; - -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.impl.builder.StAXOMBuilder; -import org.apache.tuscany.sca.databinding.PullTransformer; -import org.apache.tuscany.sca.databinding.TransformationContext; -import org.apache.tuscany.sca.databinding.TransformationException; -import org.apache.tuscany.sca.databinding.impl.BaseTransformer; - -public class XMLStreamReader2OMElement extends BaseTransformer<XMLStreamReader, OMElement> implements - PullTransformer<XMLStreamReader, OMElement> { - - public XMLStreamReader2OMElement() { - super(); - } - - public OMElement transform(XMLStreamReader source, TransformationContext context) { - try { - StAXOMBuilder builder = new StAXOMBuilder(source); - OMElement element = builder.getDocumentElement(); - AxiomHelper.adjustElementName(context, element); - return element; - } catch (Exception e) { - throw new TransformationException(e); - } - } - - @Override - public Class getTargetType() { - return OMElement.class; - } - - @Override - public Class getSourceType() { - return XMLStreamReader.class; - } - - @Override - public int getWeight() { - return 10; - } - -} |