From 0f3f9b59b310833f31ba234ee4aefa808649833c Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:06:50 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835120 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/databinding/axiom/AxiomDataBinding.java | 64 ++++++++++++++++++++ .../databinding/axiom/AxiomExceptionHandler.java | 61 +++++++++++++++++++ .../tuscany/sca/databinding/axiom/AxiomHelper.java | 64 ++++++++++++++++++++ .../sca/databinding/axiom/OMElement2Object.java | 37 ++++++++++++ .../sca/databinding/axiom/OMElement2String.java | 59 ++++++++++++++++++ .../axiom/OMElement2XMLStreamReader.java | 47 +++++++++++++++ .../databinding/axiom/OMElementWrapperHandler.java | 70 ++++++++++++++++++++++ .../sca/databinding/axiom/Object2OMElement.java | 52 ++++++++++++++++ .../sca/databinding/axiom/String2OMElement.java | 57 ++++++++++++++++++ .../axiom/XMLStreamReader2OMElement.java | 60 +++++++++++++++++++ .../module/AxiomDataBindingModuleActivator.java | 61 +++++++++++++++++++ 11 files changed, 632 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/module/AxiomDataBindingModuleActivator.java (limited to 'sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom') diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java new file mode 100644 index 0000000000..72fc90d187 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java @@ -0,0 +1,64 @@ +/* + * 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(); + } + + 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/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java new file mode 100644 index 0000000000..dd4553fc6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java @@ -0,0 +1,61 @@ +/* + * 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 exceptionType, String message, Object faultInfo, Throwable cause) { + return new FaultException(message, (OMElement)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 faultType = new DataTypeImpl(AxiomDataBinding.NAME, OMElement.class, type); + return faultType; + } else { + return null; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java new file mode 100644 index 0000000000..28141cd144 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java @@ -0,0 +1,64 @@ +/* + * 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.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.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Helper for AXIOM + * + * @version $Rev$ $Date$ + */ +public class AxiomHelper { + + private AxiomHelper() { + } + + /** + * @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())) { + // TODO: 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()); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java new file mode 100644 index 0000000000..4d2bc2b4d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java @@ -0,0 +1,37 @@ +/* + * 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 { + + @Override + protected String getText(OMElement source) { + return source.getText(); + } + + public Class getSourceType() { + return OMElement.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java new file mode 100755 index 0000000000..3eb5878de3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java @@ -0,0 +1,59 @@ +/* + * 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 implements PullTransformer { + // 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); + } + } + + public Class getSourceType() { + return OMElement.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java new file mode 100755 index 0000000000..c72bee62e2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java @@ -0,0 +1,47 @@ +/* + * 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 implements PullTransformer { + // private XmlOptions options; + + public XMLStreamReader transform(OMElement source, TransformationContext context) { + return source.getXMLStreamReader(); + } + + public Class getSourceType() { + return OMElement.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java new file mode 100644 index 0000000000..91d00c4c79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java @@ -0,0 +1,70 @@ +/* + * 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.Iterator; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +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.util.ElementInfo; + +/** + * OMElement wrapper handler implementation + */ +public class OMElementWrapperHandler implements WrapperHandler { + + private OMFactory factory; + + public OMElementWrapperHandler() { + super(); + this.factory = OMAbstractFactory.getOMFactory(); + } + + public OMElement create(ElementInfo element, TransformationContext context) { + OMElement wrapper = factory.createOMElement(element.getQName(), null); + 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 elements = new ArrayList(); + for (Iterator i = wrapper.getChildElements(); i.hasNext();) { + elements.add(i.next()); + } + return elements; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java new file mode 100644 index 0000000000..50ac0ecae6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java @@ -0,0 +1,52 @@ +/* + * 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.OMElement; +import org.apache.axiom.om.OMFactory; +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 { + + private OMFactory factory; + + public Object2OMElement() { + super(); + factory = OMAbstractFactory.getOMFactory(); + } + + protected OMElement createElement(QName element, String text, TransformationContext context) { + OMElement omElement = factory.createOMElement(element, null); + factory.createOMText(omElement, text); + return omElement; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java new file mode 100755 index 0000000000..b2549029f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java @@ -0,0 +1,57 @@ +/* + * 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 implements + PullTransformer { + + @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); + } + } + + public Class getTargetType() { + return OMElement.class; + } + + public Class getSourceType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java new file mode 100755 index 0000000000..ffb31aae0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java @@ -0,0 +1,60 @@ +/* + * 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 implements + PullTransformer { + + 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); + } + } + + public Class getTargetType() { + return OMElement.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/module/AxiomDataBindingModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/module/AxiomDataBindingModuleActivator.java new file mode 100644 index 0000000000..8dd3cb0f51 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/module/AxiomDataBindingModuleActivator.java @@ -0,0 +1,61 @@ +/* + * 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.module; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.axiom.AxiomDataBinding; +import org.apache.tuscany.sca.databinding.axiom.OMElement2Object; +import org.apache.tuscany.sca.databinding.axiom.OMElement2String; +import org.apache.tuscany.sca.databinding.axiom.OMElement2XMLStreamReader; +import org.apache.tuscany.sca.databinding.axiom.Object2OMElement; +import org.apache.tuscany.sca.databinding.axiom.String2OMElement; +import org.apache.tuscany.sca.databinding.axiom.XMLStreamReader2OMElement; + +/** + * Module activator for AXIOM databinding + * + * @version $Rev$ $Date$ + */ +public class AxiomDataBindingModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + return null; + } + + public void start(ExtensionPointRegistry registry) { + DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + dataBindings.addDataBinding(new AxiomDataBinding()); + + TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + transformers.addTransformer(new Object2OMElement()); + transformers.addTransformer(new OMElement2Object()); + transformers.addTransformer(new OMElement2String()); + transformers.addTransformer(new OMElement2XMLStreamReader()); + transformers.addTransformer(new String2OMElement()); + transformers.addTransformer(new XMLStreamReader2OMElement()); + } + + public void stop(ExtensionPointRegistry registry) { + } + +} -- cgit v1.2.3