diff options
Diffstat (limited to 'branches/sca-java-1.3/modules/databinding-xstream/src/main/java')
9 files changed, 0 insertions, 597 deletions
diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java deleted file mode 100644 index 4c57cfe06b..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java +++ /dev/null @@ -1,37 +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.xstream; - -/** - * Wrapper for XObject - * @version $Rev$ $Date$ - */ -public interface MetaObject { - void setName(String name); - - String getName(); - - Class<?> getType(); - - String getID(); - - XObject getInstance(); - //byte[] getByteCode(); -} diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java deleted file mode 100644 index d223a4db23..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java +++ /dev/null @@ -1,95 +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.xstream; - -import java.io.FileNotFoundException; -import java.io.IOException; - -/** - * Implementation of a wrapper for XObject. - * - * @version $Rev$ $Date$ - */ -public class MetaObjectImpl implements MetaObject { - private String obID; - private String name; - private XObject obInstance; - - //private byte[] bytecode = null; - - public MetaObjectImpl() { - this.obID = Utils.uniqueID(); - } - - public MetaObjectImpl(XObject x) { - //this.name = path; - this.obID = Utils.uniqueID(); - this.obInstance = x; - - try { - initMetaOb(this.obInstance.getClass()); - - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - - private void initMetaOb(Class<?> class1) throws FileNotFoundException, IOException { - /* - File file = new File(cname); - DataInputStream cstream = new DataInputStream(new FileInputStream(file)); - bytecode = new byte[(int)file.length()]; - cstream.readFully(bytecode); - */ - name = class1.getName(); - - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - this.name = name; - } - - public String getID() { - return obID; - } - - public Class<?> getType() { - - return this.obInstance.getClass(); - } - - public XObject getInstance() { - return this.obInstance; - } - /* - * TODO Add bytecode with Serialization - public byte[] getByteCode() { - return bytecode; - } - */ - -} diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java deleted file mode 100644 index 2b7fa9d506..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java +++ /dev/null @@ -1,69 +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.xstream; - -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; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.Node; - -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.DomReader; - -/** - * DOM Node --> XStream transformer - * - * @version $Rev$ $Date$ - */ -public class Node2XObject extends BaseTransformer<Node, XObject> implements PullTransformer<Node, XObject> { - - public XObject transform(Node source, TransformationContext context) { - try { - DomReader in = null; - if (source instanceof Document) { - in = new DomReader((Document)source); - } else if (source instanceof Element) { - in = new DomReader((Element)source); - } - XStream xs = new XStream(); - return (XObject)xs.unmarshal(in); - } catch (Exception e) { - throw new TransformationException(e); - } - } - - @Override - public Class<Node> getSourceType() { - return Node.class; - } - - @Override - public Class<XObject> getTargetType() { - return XObject.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java deleted file mode 100644 index a465e92e65..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java +++ /dev/null @@ -1,76 +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.xstream; - -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.impl.BaseTransformer; - -import com.thoughtworks.xstream.XStream; - -/** - * Job DataObject --> AXIOM OMElement transformer - * - * @version $Rev$ $Date$ - */ -public class OMElement2XObject extends BaseTransformer<OMElement, XObject> implements - PullTransformer<OMElement, XObject> { - - public XObject transform(OMElement source, TransformationContext context) { - - XStream xs = new XStream(); - xs.alias("xobject", MetaObjectImpl.class); - MetaObjectImpl mo; - try { - java.io.StringWriter writer = new StringWriter(); - source.serialize(writer); - String w = writer.toString(); - // FIXME: a better way to get eliminate param0 - w = w.replaceAll("param0", "xobject"); - w = w.replaceAll("xmlns=\"\"", ""); - mo = (MetaObjectImpl)xs.fromXML(w.trim()); - return mo.getInstance(); - } catch (XMLStreamException e) { - - e.printStackTrace(); - } - return null; - } - - @Override - public Class<OMElement> getSourceType() { - return OMElement.class; - } - - @Override - public Class<XObject> getTargetType() { - return XObject.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java deleted file mode 100644 index d819975910..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java +++ /dev/null @@ -1,79 +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.xstream; - -import java.io.IOException; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; - -/** - * Utility methods. - * - * @version $Rev$ $Date$ - */ -public class Utils { - public static String toBase64(byte[] array) { - String code = null; - code = new sun.misc.BASE64Encoder().encode(array); - return code; - } - - public static byte[] fromBase64(String bytecode) { - byte[] dec = null; - try { - dec = new sun.misc.BASE64Decoder().decodeBuffer(bytecode); - } catch (IOException e) { - e.printStackTrace(); - } - return dec; - } - - public static String uniqueID() { - try { - //Initialize SecureRandom - //This is a lengthy operation, to be done only upon - //initialization of the application - SecureRandom prng = SecureRandom.getInstance("SHA1PRNG"); - - //generate a random number - String randomNum = Integer.toString(prng.nextInt()); - - //get its digest - MessageDigest sha = MessageDigest.getInstance("SHA-1"); - byte[] result = sha.digest(randomNum.getBytes()); - return hexEncode(result); - } catch (NoSuchAlgorithmException ex) { - ex.printStackTrace(); - } - return null; - } - - private static String hexEncode(byte[] aInput) { - StringBuffer result = new StringBuffer(); - char[] digits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; - for (int idx = 0; idx < aInput.length; ++idx) { - byte b = aInput[idx]; - result.append(digits[(b & 0xf0) >> 4]); - result.append(digits[b & 0x0f]); - } - return result.toString(); - } - -} diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java deleted file mode 100644 index 21112efcf5..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java +++ /dev/null @@ -1,28 +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.xstream; - -/** - * Marker interface for XStream Serializable objects - * - * @version $Rev$ $Date$ - */ -// FIXME: Why do we require a marker interface? -public interface XObject { -} diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java deleted file mode 100644 index 98e0e69f9b..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java +++ /dev/null @@ -1,69 +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.xstream; - -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; -import org.apache.tuscany.sca.databinding.impl.DOMHelper; -import org.w3c.dom.Document; -import org.w3c.dom.Node; - -import com.thoughtworks.xstream.XStream; -import com.thoughtworks.xstream.io.xml.DomWriter; - -/** - * XObject --> DOM Node transformer - * - * @version $Rev$ $Date$ - */ -public class XObject2Node extends BaseTransformer<XObject, Node> implements PullTransformer<XObject, Node> { - - public Node transform(XObject source, TransformationContext context) { - try { - MetaObject mj = new MetaObjectImpl(source); - Document root = DOMHelper.newDocument(); - DomWriter out = new DomWriter(DOMHelper.newDocument()); - XStream xs = new XStream(); - xs.alias("xobject", mj.getClass()); - xs.marshal(source, out); - DOMHelper.adjustElementName(context, root.getDocumentElement()); - return root; - } catch (Exception e) { - throw new TransformationException(e); - } - } - - @Override - public Class<XObject> getSourceType() { - return XObject.class; - } - - @Override - public Class<Node> getTargetType() { - return Node.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java deleted file mode 100644 index ff4305491a..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java +++ /dev/null @@ -1,106 +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.xstream; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; - -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.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; -import org.apache.tuscany.sca.interfacedef.DataType; -import org.apache.tuscany.sca.interfacedef.util.XMLType; - -import com.thoughtworks.xstream.XStream; - -/** - * XObject --> AXIOM OMElement transformer - * - * @version $Rev$ $Date$ - */ -public class XObject2OMElement extends BaseTransformer<XObject, OMElement> implements - PullTransformer<XObject, OMElement> { - - public OMElement transform(XObject source, TransformationContext context) { - MetaObject mj = new MetaObjectImpl(source); - OMElement element = null; - ByteArrayOutputStream out = new ByteArrayOutputStream(); - XStream xs = new XStream(); - xs.alias("xobject", mj.getClass()); - xs.toXML(mj, out); - /* TODO: Maybe a base64 conversion...? or not? - * ie. new ByteArrayInputStream(Utils.toBase64(out.toByteArray()).getBytes()) - */ - try { - // what's better this one: - StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(out.toByteArray())); - // or this one: - // StaAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(Utils.toBase64(out.toByteArray()).getBytes())) - element = builder.getDocumentElement(); - adjustElementName(context, element); - } catch (Exception e) { - throw new TransformationException(e); - } - return element; - - } - - private 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 exception 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()); - } - } - } - - @Override - public Class<XObject> getSourceType() { - return XObject.class; - } - - @Override - public Class<OMElement> getTargetType() { - return OMElement.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java b/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java deleted file mode 100644 index 6e5ac29423..0000000000 --- a/branches/sca-java-1.3/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java +++ /dev/null @@ -1,38 +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.xstream; - -import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; - -/** - * DataBinding for Jobs - * - * @version $Rev$ $Date$ - */ -public class XObjectDataBinding extends BaseDataBinding { - - public static final String NAME = XObject.class.getName(); - public static final String[] ALIASES = new String[] {"xobject"}; - - public XObjectDataBinding() { - super(NAME, ALIASES, XObject.class); - } - -} |