From fdaae3ffaa2f06063d0afe27b38aa05af398835f Mon Sep 17 00:00:00 2001 From: rsivaram Date: Thu, 16 Oct 2008 13:50:40 +0000 Subject: Event prototype: subset modules and change version to 1.4-EVENT-SNAPSHOT git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@705244 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/databinding/xstream/MetaObject.java | 37 ------- .../sca/databinding/xstream/MetaObjectImpl.java | 95 ------------------ .../sca/databinding/xstream/Node2XObject.java | 69 -------------- .../sca/databinding/xstream/OMElement2XObject.java | 76 --------------- .../tuscany/sca/databinding/xstream/Utils.java | 79 --------------- .../tuscany/sca/databinding/xstream/XObject.java | 28 ------ .../sca/databinding/xstream/XObject2Node.java | 69 -------------- .../sca/databinding/xstream/XObject2OMElement.java | 106 --------------------- .../databinding/xstream/XObjectDataBinding.java | 37 ------- 9 files changed, 596 deletions(-) delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java delete mode 100644 sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java (limited to 'sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany') diff --git a/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObject.java deleted file mode 100644 index 4c57cfe06b..0000000000 --- a/sandbox/event/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/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/MetaObjectImpl.java deleted file mode 100644 index d223a4db23..0000000000 --- a/sandbox/event/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/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Node2XObject.java deleted file mode 100644 index 2b7fa9d506..0000000000 --- a/sandbox/event/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 implements PullTransformer { - - 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 getSourceType() { - return Node.class; - } - - @Override - public Class getTargetType() { - return XObject.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/OMElement2XObject.java deleted file mode 100644 index a465e92e65..0000000000 --- a/sandbox/event/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 implements - PullTransformer { - - 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 getSourceType() { - return OMElement.class; - } - - @Override - public Class getTargetType() { - return XObject.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/Utils.java deleted file mode 100644 index d819975910..0000000000 --- a/sandbox/event/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/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject.java deleted file mode 100644 index 21112efcf5..0000000000 --- a/sandbox/event/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/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2Node.java deleted file mode 100644 index 98e0e69f9b..0000000000 --- a/sandbox/event/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 implements PullTransformer { - - 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 getSourceType() { - return XObject.class; - } - - @Override - public Class getTargetType() { - return Node.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObject2OMElement.java deleted file mode 100644 index ff4305491a..0000000000 --- a/sandbox/event/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 implements - PullTransformer { - - 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 getSourceType() { - return XObject.class; - } - - @Override - public Class getTargetType() { - return OMElement.class; - } - - @Override - public int getWeight() { - return 10; - } - -} diff --git a/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java b/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.java deleted file mode 100644 index b319c7d557..0000000000 --- a/sandbox/event/modules/databinding-xstream/src/main/java/org/apache/tuscany/sca/databinding/xstream/XObjectDataBinding.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; - -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 XObjectDataBinding() { - super(NAME, XObject.class); - } - -} -- cgit v1.2.3