summaryrefslogtreecommitdiffstats
path: root/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache')
-rw-r--r--sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4X2OMElement.java49
-rw-r--r--sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4X2Object.java46
-rw-r--r--sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4XDataBinding.java56
-rw-r--r--sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4XWrapperHandler.java81
-rw-r--r--sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/OMElement2E4X.java70
-rw-r--r--sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/Object2E4X.java57
6 files changed, 359 insertions, 0 deletions
diff --git a/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4X2OMElement.java b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4X2OMElement.java
new file mode 100644
index 0000000000..82d4f0b9a4
--- /dev/null
+++ b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4X2OMElement.java
@@ -0,0 +1,49 @@
+/*
+ * 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.extensions.script.databinding.e4x;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.mozilla.javascript.xmlimpl.XML;
+import org.osoa.sca.annotations.Service;
+
+@Service(Transformer.class)
+public class E4X2OMElement extends TransformerExtension<XML, OMElement> implements PullTransformer<XML, OMElement> {
+
+ public OMElement transform(XML source, TransformationContext context) {
+ return (OMElement)source.getAxiomFromXML();
+ }
+
+ public Class getSourceType() {
+ return XML.class;
+ }
+
+ public Class getTargetType() {
+ return OMElement.class;
+ }
+
+ public int getWeight() {
+ return 10;
+ }
+
+
+}
diff --git a/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4X2Object.java b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4X2Object.java
new file mode 100644
index 0000000000..06c578866d
--- /dev/null
+++ b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4X2Object.java
@@ -0,0 +1,46 @@
+/*
+ * 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.extensions.script.databinding.e4x;
+
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.SimpleType2JavaTransformer;
+import org.mozilla.javascript.xmlimpl.XML;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Transformer to convert data from a simple java bject to OMElement
+ */
+@Service(Transformer.class)
+public class E4X2Object extends SimpleType2JavaTransformer<XML> {
+
+ private E4X2OMElement e4x2om;
+
+ public E4X2Object() {
+ e4x2om = new E4X2OMElement();
+ }
+
+ @Override
+ protected String getText(XML source) {
+ return e4x2om.transform(source, null).getText();
+ }
+
+ public Class getSourceType() {
+ return XML.class;
+ }
+}
diff --git a/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4XDataBinding.java b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4XDataBinding.java
new file mode 100644
index 0000000000..8118cd26e3
--- /dev/null
+++ b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4XDataBinding.java
@@ -0,0 +1,56 @@
+/*
+ * 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.extensions.script.databinding.e4x;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.databinding.extension.DataBindingExtension;
+import org.mozilla.javascript.xmlimpl.XML;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * DataBinding for E4X
+ *
+ * This requires Rhino using the WSO2 Axiom based E4X impl
+ */
+@Service(DataBinding.class)
+public class E4XDataBinding extends DataBindingExtension {
+
+ public static final String NAME = XML.class.getName();
+
+ public E4XDataBinding() {
+ super(NAME, XML.class);
+ }
+
+ /**
+ * @see org.apache.tuscany.spi.databinding.extension.DataBindingExtension#getWrapperHandler()
+ */
+ @Override
+ public WrapperHandler getWrapperHandler() {
+ return new E4XWrapperHandler();
+ }
+
+ /**
+ * Treat E4X as pass-by-ref
+ */
+ public Object copy(Object source) {
+ return source;
+ }
+}
diff --git a/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4XWrapperHandler.java b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4XWrapperHandler.java
new file mode 100644
index 0000000000..94c22db8b9
--- /dev/null
+++ b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/E4XWrapperHandler.java
@@ -0,0 +1,81 @@
+/*
+ * 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.extensions.script.databinding.e4x;
+
+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.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.WrapperHandler;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.mozilla.javascript.xmlimpl.XML;
+
+/**
+ * OMElement wrapper handler implementation
+ */
+public class E4XWrapperHandler implements WrapperHandler<XML> {
+
+ private OMFactory factory;
+ private OMElement2E4X om2e4x;
+ private E4X2OMElement e4x2om;
+
+ public E4XWrapperHandler() {
+ this.factory = OMAbstractFactory.getOMFactory();
+ om2e4x = new OMElement2E4X();
+ e4x2om = new E4X2OMElement();
+ }
+
+ public XML create(ElementInfo element, TransformationContext context) {
+ OMElement wrapper = factory.createOMElement(element.getQName(), null);
+ return om2e4x.transform(wrapper, null);
+ }
+
+ public void setChild(XML wrapper, int i, ElementInfo childElement, Object value) {
+ OMElement omWrapper = e4x2om.transform(wrapper, null);
+ OMElement element = e4x2om.transform((XML)value, null);
+ QName elementName = childElement.getQName();
+ OMNamespace namespace = factory.createOMNamespace(elementName.getNamespaceURI(), elementName.getPrefix());
+ element.setNamespace(namespace);
+ element.setLocalName(childElement.getQName().getLocalPart());
+ omWrapper.addChild(element);
+ }
+
+ public List getChildren(XML wrapper) {
+ OMElement omWrapper = e4x2om.transform(wrapper, null);
+ List<Object> elements = new ArrayList<Object>();
+ for (Iterator i = omWrapper.getChildElements(); i.hasNext();) {
+ elements.add(om2e4x.transform((OMElement)i.next(), null));
+ }
+ return elements;
+ }
+
+ public Object getChild(XML wrapper, int i, ElementInfo element) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/OMElement2E4X.java b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/OMElement2E4X.java
new file mode 100644
index 0000000000..6ab0e42a75
--- /dev/null
+++ b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/OMElement2E4X.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.extensions.script.databinding.e4x;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.tuscany.spi.databinding.PullTransformer;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ScriptableObject;
+import org.mozilla.javascript.xmlimpl.XML;
+import org.osoa.sca.annotations.Service;
+
+@Service(Transformer.class)
+public class OMElement2E4X extends TransformerExtension<OMElement, XML> implements PullTransformer<OMElement, XML> {
+
+ private ScriptableObject scope;
+
+ public OMElement2E4X() {
+ Context cx = Context.enter();
+ try {
+
+ this.scope = cx.initStandardObjects();
+
+ } finally {
+ Context.exit();
+ }
+ }
+
+ public Class getSourceType() {
+ return OMElement.class;
+ }
+
+ public Class getTargetType() {
+ return XML.class;
+ }
+
+ public int getWeight() {
+ return 10;
+ }
+
+ public XML transform(OMElement source, TransformationContext context) {
+ Context cx = Context.enter();
+ try {
+
+ return (XML)cx.newObject(scope, "XML", new Object[] {source});
+
+ } finally {
+ Context.exit();
+ }
+ }
+
+}
diff --git a/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/Object2E4X.java b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/Object2E4X.java
new file mode 100644
index 0000000000..b66208d54e
--- /dev/null
+++ b/sandbox/old/contrib/implementation-script/databinding.e4x/src/main/java/org/apache/tuscany/extensions/script/databinding/e4x/Object2E4X.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.extensions.script.databinding.e4x;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.Transformer;
+import org.apache.tuscany.spi.databinding.extension.Java2SimpleTypeTransformer;
+import org.apache.tuscany.spi.model.ElementInfo;
+import org.mozilla.javascript.xmlimpl.XML;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Transformer to convert data from an simple OMElement to Java Object
+ */
+@Service(Transformer.class)
+public class Object2E4X extends Java2SimpleTypeTransformer<XML> {
+
+ private OMFactory factory;
+ private OMElement2E4X om2e4x;
+
+ public Object2E4X() {
+ factory = OMAbstractFactory.getOMFactory();
+ om2e4x = new OMElement2E4X();
+ }
+
+ @Override
+ public Class getTargetType() {
+ return XML.class;
+ }
+
+ @Override
+ protected XML createElement(ElementInfo element, String literal, TransformationContext context) {
+ OMElement omElement = factory.createOMElement(element.getQName(), null);
+ factory.createOMText(omElement, literal);
+ return om2e4x.transform(omElement, context);
+ }
+
+}