From 6d0e93c68d3aeaeb4bb6d96ac0460eec40ef786e Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:13:23 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835143 13f79535-47bb-0310-9956-ffa450edef68 --- .../tuscany/databinding/castor/Castor2Node.java | 63 ++++++++++ .../tuscany/databinding/castor/Castor2SAX.java | 63 ++++++++++ .../tuscany/databinding/castor/Castor2Writer.java | 62 ++++++++++ .../databinding/castor/InputSource2Castor.java | 63 ++++++++++ .../tuscany/databinding/castor/Node2Castor.java | 63 ++++++++++ .../tuscany/databinding/castor/Reader2Castor.java | 64 ++++++++++ .../databinding/castor/Castor2NodeTestCase.java | 46 +++++++ .../src/test/resources/binding.xml | 27 ++++ .../databinding-castor/src/test/resources/ipo.xsd | 136 +++++++++++++++++++++ .../exolab/castor/builder/castorbuilder.properties | 81 ++++++++++++ 10 files changed, 668 insertions(+) create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/binding.xml create mode 100755 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties (limited to 'sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src') diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java new file mode 100755 index 0000000000..9ae0335ada --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Node.java @@ -0,0 +1,63 @@ +/* + * 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.databinding.castor; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.DOMHelper; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public class Castor2Node extends TransformerExtension implements PullTransformer { + private Class type; + + public Castor2Node(Class type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return Node.class; + } + + public Class getSourceType() { + return type; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public Node transform(Object source, TransformationContext context) { + try { + Document document = DOMHelper.newDocument(); + Marshaller.marshal(source, document); + return document; + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java new file mode 100644 index 0000000000..643d6fb4ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2SAX.java @@ -0,0 +1,63 @@ +/* + * 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.databinding.castor; + +import java.io.Writer; + +import org.apache.tuscany.spi.databinding.PushTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; + +public class Castor2SAX extends TransformerExtension implements PushTransformer { + private Class type; + + /** + * @param type + */ + public Castor2SAX(Class type) { + super(); + this.type = type; + } + + public Class getSourceType() { + return type; + } + + public Class getTargetType() { + return Writer.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public void transform(T source, Writer writer, TransformationContext context) { + try { + Marshaller.marshal(source, writer); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java new file mode 100644 index 0000000000..f477273387 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Castor2Writer.java @@ -0,0 +1,62 @@ +/* + * 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.databinding.castor; + +import org.apache.tuscany.spi.databinding.PushTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Marshaller; +import org.xml.sax.ContentHandler; + +public class Castor2Writer extends TransformerExtension implements PushTransformer { + private Class type; + + /** + * @param type + */ + public Castor2Writer(Class type) { + super(); + this.type = type; + } + + public Class getSourceType() { + return type; + } + + public Class getTargetType() { + return ContentHandler.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public void transform(T source, ContentHandler contentHandler, TransformationContext context) { + try { + Marshaller.marshal(source, contentHandler); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java new file mode 100644 index 0000000000..61bac7d20f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/InputSource2Castor.java @@ -0,0 +1,63 @@ +/* + * 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.databinding.castor; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; +import org.xml.sax.InputSource; + +public class InputSource2Castor extends TransformerExtension implements PullTransformer { + private Class type; + + /** + * @param type + */ + public InputSource2Castor(Class type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return InputSource.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(InputSource source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java new file mode 100644 index 0000000000..fa5a15b3ba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Node2Castor.java @@ -0,0 +1,63 @@ +/* + * 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.databinding.castor; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; +import org.w3c.dom.Node; + +public class Node2Castor extends TransformerExtension implements PullTransformer { + private Class type; + + /** + * @param type + */ + public Node2Castor(Class type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return Node.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(Node source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.java new file mode 100644 index 0000000000..a8ade1bda5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/main/java/org/apache/tuscany/databinding/castor/Reader2Castor.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.databinding.castor; + +import java.io.Reader; + +import org.apache.tuscany.spi.databinding.PullTransformer; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.TransformationException; +import org.apache.tuscany.spi.databinding.extension.TransformerExtension; +import org.exolab.castor.xml.Unmarshaller; + +public class Reader2Castor extends TransformerExtension implements PullTransformer { + private Class type; + + /** + * @param type + */ + public Reader2Castor(Class type) { + super(); + this.type = type; + } + + public Class getTargetType() { + return type; + } + + public Class getSourceType() { + return Reader.class; + } + + public int getWeight() { + return 40; + } + + /** + * @see org.apache.tuscany.spi.databinding.PullTransformer#transform(java.lang.Object, org.apache.tuscany.spi.databinding.TransformationContext) + */ + public T transform(Reader source, TransformationContext context) { + try { + Object object = Unmarshaller.unmarshal(type, source); + return type.cast(object); + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.java b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.java new file mode 100644 index 0000000000..378e89866a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/java/org/apache/tuscany/databinding/castor/Castor2NodeTestCase.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.databinding.castor; + +import junit.framework.TestCase; + +public class Castor2NodeTestCase extends TestCase { + private static final String IPO_XML = "" + "" + + " " + " Helen Zoe" + " 47 Eden Street" + + " Cambridge" + " CB1 1JR" + " " + " " + + " Robert Smith" + " 8 Oak Avenue" + " Old Town" + " PA" + + " 95819" + " " + " " + " " + + " Lapis necklace" + " 1" + " 99.95" + + " Want this for the holidays" + " 1999-12-05" + " " + " " + + ""; + + public void testTransform() throws Exception { + // FIXME: There's a bug in the castor-generated code which cannot handle subutype correctly + // http://jira.codehaus.org/browse/CASTOR-1475 + // shipTo should be able to accept UKAddress +// Reader2Castor t1 = new Reader2Castor(PurchaseOrder.class); +// PurchaseOrder po = t1.transform(new StringReader(IPO_XML), null); + /* + * Castor2Node t2 = new Castor2Node(); Node node = t2.transform(po, null); Assert.assertNotNull(node); + */ + + } +} diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/binding.xml b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/binding.xml new file mode 100755 index 0000000000..3517e71692 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/binding.xml @@ -0,0 +1,27 @@ + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties new file mode 100644 index 0000000000..3f9f2eabb7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-M2/sca/services/databinding/databinding-castor/src/test/resources/org/exolab/castor/builder/castorbuilder.properties @@ -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. +# +# +# Property file for SourceCodeGenerator +# +# $Id: castorbuilder.properties,v 1.3 2004/05/06 08:20:51 kvisco Exp $ + +# To enable bound properties uncomment the following line. Please +# note that currently *all* fields will be treated as bound properties +# when enabled. This will change in the future when we introduce +# fine grained control over each class and it's properties. +# +#org.exolab.castor.builder.boundproperties=true + +# Java class mapping of 's and 's +# +org.exolab.castor.builder.javaclassmapping=type + +# This property allows one to specify the super class of *all* +# generated classes +# +#org.exolab.castor.builder.superclass=com.xyz.BaseObject + +# XML namespace mapping to Java packages +# +#org.exolab.castor.builder.nspackages=\ + http://www.xyz.com/schemas/project=com.xyz.schemas.project,\ + http://www.xyz.com/schemas/person=com.xyz.schemas.person + +# Set to true if you want to generate the equals method +# for each generated class +# false by default +# +#org.exolab.castor.builder.equalsmethod=true + +# Set to true if you want to use Object Wrappers instead +# of primitives (e.g Float instead of float). +# false by default. +# +#org.exolab.castor.builder.primitivetowrapper=false + +# Set to true if you want the generated class descriptors to +# expose the element and attribute names they contain. +# false by default. +# +#org.exolab.castor.builder.classdescfieldnames=false + +# Set to true if you want the generated source code to contain +# Extra methods for the collection fields, such as get/set using +# the collection type in addition to the type-safe array. +# Set this to true if you want your code to be more compatible +# with Castor JDO. This is false by default. +# +#org.exolab.castor.builder.extraCollectionMethods=true + +# Use old-style (Castor 0.9.3.9) of naming that uppercases +# names after an underscore +# +#org.exolab.castor.xml.JavaNaming.upperCaseAfterUnderscore=true + +# This property specifies whether generated enumerated type +# classes implement the EnumeratedTypeAccess interface. +# false by default +#org.exolab.castor.builder.enumTypeAccessInterface=true + -- cgit v1.2.3