You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sv...@apache.org on 2007/02/01 09:20:37 UTC

svn commit: r502158 - in /incubator/tuscany/java/sca/services/databinding/databinding-javabeans: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/tuscany/ src/main/java/org/apache/tuscany/databindin...

Author: svkrish
Date: Thu Feb  1 00:20:36 2007
New Revision: 502158

URL: http://svn.apache.org/viewvc?view=rev&rev=502158
Log:
JavaBeans databinding to support transformations from JavaBeans to say XML

Added:
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/LICENSE.txt
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/NOTICE.txt
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/pom.xml
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/DOMNode2JavaBean.java
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/Java2XMLMapperException.java
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBean2DOMNode.java
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBeansDataBinding.java
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XML2JavaMapperException.java
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtension.java
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/databinding.javabeans.scdl
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/default.scdl
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/tuscany/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/tuscany/databinding/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/tuscany/databinding/javabeans/
    incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtensionTestCase.java

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/LICENSE.txt
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/LICENSE.txt?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/LICENSE.txt (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/LICENSE.txt Thu Feb  1 00:20:36 2007
@@ -0,0 +1,202 @@
+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed 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.

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/NOTICE.txt
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/NOTICE.txt?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/NOTICE.txt (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/NOTICE.txt Thu Feb  1 00:20:36 2007
@@ -0,0 +1,14 @@
+${pom.name}
+Copyright (c) 2005 - 2006 The Apache Software Foundation
+
+Apache Tuscany is an effort undergoing incubation at The Apache Software
+Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is
+required of all newly accepted projects until a further review indicates that
+the infrastructure, communications, and decision making process have stabilized
+in a manner consistent with other successful ASF projects. While incubation
+status is not necessarily a reflection of the completeness or stability of the
+code, it does indicate that the project has yet to be fully endorsed by the ASF.
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/pom.xml?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/pom.xml (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/pom.xml Thu Feb  1 00:20:36 2007
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<project>
+	<parent>
+		<groupId>org.apache.tuscany.sca.services.databinding</groupId>
+		<artifactId>parent</artifactId>
+		<version>1.0-incubator-SNAPSHOT</version>
+	</parent>
+	<modelVersion>4.0.0</modelVersion>
+	<artifactId>databinding-javabeans</artifactId>
+	<name>Apache Tuscany Data Binding for JavaBeans</name>
+	<description>Tuscany JavaBeans Data Binding</description>
+
+	<dependencies>
+        <dependency>
+            <groupId>org.apache.tuscany.sca.kernel</groupId>
+            <artifactId>tuscany-spi</artifactId>
+            <version>${pom.version}</version>
+            <scope>compile</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.1</version>
+            <scope>test</scope>
+        </dependency>	
+        
+        <dependency>
+            <groupId>org.easymock</groupId>
+            <artifactId>easymock</artifactId>
+        </dependency>	
+	</dependencies>
+
+</project>

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/DOMNode2JavaBean.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/DOMNode2JavaBean.java?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/DOMNode2JavaBean.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/DOMNode2JavaBean.java Thu Feb  1 00:20:36 2007
@@ -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.databinding.javabeans;
+
+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.apache.tuscany.spi.idl.ElementInfo;
+import org.apache.tuscany.spi.idl.TypeInfo;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Node;
+
+/**
+ * Transformer to convert data from DOM Node to JavaBean
+ */
+@Service(Transformer.class)
+public class DOMNode2JavaBean extends TransformerExtension<Node, Object> implements PullTransformer<Node, Object> {
+
+    protected XMLTypeMapperExtension<Node> mapper;
+    
+    public DOMNode2JavaBean() {
+        this.mapper = new XMLTypeMapperExtension<Node>();
+    }
+    
+    public Object transform(Node source, TransformationContext context) {
+        TypeInfo xmlType = (TypeInfo)context.getSourceDataType().getMetadata(TypeInfo.class.getName());
+        if (xmlType == null) {
+            ElementInfo element =
+                (ElementInfo)context.getSourceDataType().getMetadata(ElementInfo.class.getName());
+            xmlType = (TypeInfo)element.getType();
+        }
+        
+        return mapper.toJavaObject(xmlType, source, context);
+    }
+    
+    public Class getSourceType() {
+        return Node.class;
+    }
+    
+    public Class getTargetType() {
+        return Object.class;
+    }
+}

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/Java2XMLMapperException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/Java2XMLMapperException.java?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/Java2XMLMapperException.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/Java2XMLMapperException.java Thu Feb  1 00:20:36 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.javabeans;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * This exception is used to encapsulate and rethrow exceptions that arise out of converting
+ * JavaBean objects to XML
+ *
+ */
+public class Java2XMLMapperException extends TuscanyRuntimeException {
+    
+    public Java2XMLMapperException() {
+        
+    }
+    
+    public Java2XMLMapperException(String message) {
+        super(message);
+    }
+    
+    
+    public Java2XMLMapperException(Throwable cause) {
+        super(cause);
+    }
+
+}

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBean2DOMNode.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBean2DOMNode.java?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBean2DOMNode.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBean2DOMNode.java Thu Feb  1 00:20:36 2007
@@ -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.javabeans;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+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.Transformer;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.databinding.extension.TransformerExtension;
+import org.apache.tuscany.spi.idl.ElementInfo;
+import org.apache.tuscany.spi.idl.TypeInfo;
+import org.osoa.sca.annotations.Service;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Transformer to convert data from a JavaBean object to DOM Node
+ */
+@Service(Transformer.class)
+public class JavaBean2DOMNode extends TransformerExtension<Object, Node> implements PullTransformer<Object, Node> {
+
+    protected XMLTypeMapperExtension<Node> mapper;
+    private Document factory;
+    
+    public JavaBean2DOMNode() {
+        this.mapper = new XMLTypeMapperExtension<Node>();
+        try {
+            factory = DOMHelper.newDocument();
+        } catch (ParserConfigurationException e) {
+            throw new TransformationException(e);
+        }
+    }
+    
+    public Node transform(Object source, TransformationContext context) {
+       return mapper.toDOMNode(source, context);
+    }
+    
+    public Class getTargetType() {
+        return Node.class;
+    }
+    
+    public Class getSourceType() {
+        return Object.class;
+    }
+}

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBeansDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBeansDataBinding.java?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBeansDataBinding.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/JavaBeansDataBinding.java Thu Feb  1 00:20:36 2007
@@ -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.databinding.javabeans;
+
+import org.apache.tuscany.spi.databinding.DataBinding;
+import org.apache.tuscany.spi.databinding.extension.DataBindingExtension;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * DataBinding for JavaBeans
+ */
+@Service(DataBinding.class)
+public class JavaBeansDataBinding extends DataBindingExtension {
+    
+    public static final String NAME = Object.class.getName();
+
+    public JavaBeansDataBinding() {
+        super(Object.class);
+    }
+}

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XML2JavaMapperException.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XML2JavaMapperException.java?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XML2JavaMapperException.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XML2JavaMapperException.java Thu Feb  1 00:20:36 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.javabeans;
+
+import org.apache.tuscany.api.TuscanyRuntimeException;
+
+/**
+ * This exception is used to encapsulate and rethrow exceptions that arise out of converting
+ * XML Data to Java Objects.  
+ *
+ */
+public class XML2JavaMapperException extends TuscanyRuntimeException {
+    
+    public XML2JavaMapperException() {
+        
+    }
+    
+    public XML2JavaMapperException(String message) {
+        super(message);
+    }
+    
+    
+    public XML2JavaMapperException(Throwable cause) {
+        super(cause);
+    }
+
+}

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtension.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtension.java?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtension.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtension.java Thu Feb  1 00:20:36 2007
@@ -0,0 +1,365 @@
+/*
+ * 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.javabeans;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+import org.apache.tuscany.spi.idl.ElementInfo;
+import org.apache.tuscany.spi.idl.TypeInfo;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ *  This class maps JavaBeans objects to XML data represented physically as DOM Nodes and vice versa.  It 
+ *  uses JavaBeans Introspection for this mapping.
+ */
+public class XMLTypeMapperExtension<T> extends SimpleTypeMapperExtension<T> {
+
+    private Document factory;
+
+    protected Node getFragment(T source) {
+        return ((Document) source).getDocumentElement();
+    }
+
+    public Node toDOMNode(Object javaObject, TransformationContext context) {
+        QName rootElementName =
+                (QName) context.getTargetDataType().getMetadata("RootElementName");
+        if ( rootElementName == null ) {
+            rootElementName = new QName(resolveRootElementName(javaObject.getClass()));
+        }
+        try {
+            factory = DOMHelper.newDocument();
+            Node root = DOMHelper.createElement(factory, rootElementName);
+            appendChildElements(root, resolveElementName(javaObject.getClass()), javaObject.getClass(), javaObject, context);
+            return root;
+        } catch ( ParserConfigurationException e ) {
+            Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e);
+            java2xmlEx.addContextName("tranforming to xml, a java instance of" + javaObject.getClass().getName());
+            throw java2xmlEx;
+        }
+    }
+
+    private void appendChildElements(Node parent, String elementName, Class javaType, Object javaObject, TransformationContext context)  {
+        Node elementNode = null;
+        if ( javaObject != null ) {
+            if (javaType.isPrimitive() || isSimpleJavaType(javaObject)) {
+                parent.appendChild(factory.createTextNode(toXMLLiteral(null, javaObject, context)));
+            } else if ( javaType.isArray() ) {
+                boolean arrayDone = false;
+                Object arrayObject = null;
+                for (int count = 0 ; !arrayDone ; ++count) {
+                    try {
+                        arrayObject = Array.get(javaObject, count);
+                        elementNode = factory.createElement(elementName);
+                        parent.appendChild(elementNode);
+                        appendChildElements(elementNode, elementName, javaType.getComponentType(), arrayObject, context);
+                    } catch (ArrayIndexOutOfBoundsException e1 ) {
+                        arrayDone = true;
+                    }
+                }
+            } else {
+                Field[] javaFields = javaType.getFields();
+                for (Field aField : javaFields) {
+                   try {
+                       if (!aField.getType().isArray()) {
+                           elementNode = factory.createElement(aField.getName());
+                           parent.appendChild(elementNode);
+                           appendChildElements(elementNode, aField.getName(), aField.getType(), aField.get(javaObject), context);
+                       } else {
+                           appendChildElements(parent, aField.getName(), aField.getType(), aField.get(javaObject), context);
+                       }
+                    } catch ( IllegalAccessException e ) {
+                        Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e);
+                        java2xmlEx.addContextName("tranforming " + aField.getName() + " of " + javaType.getName());
+                        throw java2xmlEx;
+                    }
+                }
+            }
+        }
+    }
+
+    @Override
+    public Object toJavaObject(TypeInfo xmlType, T xmlNode, TransformationContext context) {
+        if (xmlType.isSimpleType()) {
+            return super.toJavaObject(xmlType, xmlNode, context);
+        } else {
+            Class<?> javaType = (Class<?>) context.getTargetDataType().getLogical();
+            return createJavaObject(getFragment(xmlNode), javaType, context);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private <L> L createJavaObject(Node valueFragment,
+                                   Class<L> javaType,
+                                   TransformationContext context) throws XML2JavaMapperException {
+        NodeList childNodes = valueFragment.getChildNodes();
+        if (childNodes.getLength() == 1 && childNodes.item(0).getNodeType() == 3) {
+
+            return (L) super.toJavaObject(getXMLType(javaType), (T) childNodes.item(0), context);
+        } else {
+            try {
+                L javaInstance = javaType.newInstance();
+                Map<Field, List<Object>> arrayFields = new Hashtable<Field, List<Object>>();
+                Map<Method, List<Object>> arraySetters = new Hashtable<Method, List<Object>>();
+                for (int count = 0; count < childNodes.getLength(); ++count) {
+                    if (childNodes.item(count).getNodeType() != 3) {
+                        String fieldName = childNodes.item(count).getNodeName();
+                        try {
+                            Field javaField = javaType.getField(fieldName);
+                            setFieldValue(javaInstance,
+                                          javaField,
+                                          childNodes.item(count),
+                                          arrayFields,
+                                          context);
+
+                        } catch (NoSuchFieldException e1) {
+                            setFieldValueUsingSetter(javaType,
+                                                     javaInstance,
+                                                     fieldName,
+                                                     childNodes.item(count),
+                                                     arraySetters,
+                                                     context);
+                        }
+                    }
+                }
+
+                setArrayValues(javaInstance, arrayFields, arraySetters);
+                return javaInstance;
+            } catch (XML2JavaMapperException e3) {
+                throw e3;
+            } catch (Exception e2) {
+                XML2JavaMapperException xml2JavaEx = new XML2JavaMapperException(e2);
+                xml2JavaEx.addContextName("configuring " + javaType.getName());
+                throw xml2JavaEx;
+            }
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void setFieldValueUsingSetter(Class javaType,
+                                          Object javaInstance,
+                                          String fieldName,
+                                          Node fieldValue,
+                                          Map<Method, List<Object>> arraySetters,
+                                          TransformationContext context) throws IllegalAccessException,
+                                                                        InvocationTargetException {
+        char firstChar = Character.toUpperCase(fieldName.charAt(0));
+        StringBuilder methodName = new StringBuilder(SET + fieldName);
+        methodName.setCharAt(SET.length(), firstChar);
+        boolean methodNotFound = true;
+
+        for (int methodCount = 0; methodNotFound && methodCount < javaType.getMethods().length; ++methodCount) {
+            Method aMethod = javaType.getMethods()[methodCount];
+            if (aMethod.getName().equals(methodName.toString())
+                    && aMethod.getParameterTypes().length == 1) {
+                Class paramType = aMethod.getParameterTypes()[0];
+
+                if (paramType.isArray()) {
+                    Class componentType = paramType.getComponentType();
+                    List<Object> setterValueArray = null;
+                    if ((setterValueArray = arraySetters.get(aMethod)) == null) {
+                        setterValueArray = new ArrayList();
+                        arraySetters.put(aMethod, setterValueArray);
+                    }
+                    setterValueArray.add(createJavaObject(fieldValue, componentType, context));
+                } else {
+                    aMethod.invoke(javaInstance, new Object[] { createJavaObject(fieldValue,
+                                                                                 paramType,
+                                                                                 context) });
+                }
+                methodNotFound = false;
+            }
+        }
+
+        if (methodNotFound) {
+            XML2JavaMapperException xml2JavaEx =
+                    new XML2JavaMapperException("no field or setter method to configure property value <"
+                            + fieldName + "> in Java class <" + javaType.getName() + ">");
+            xml2JavaEx.addContextName("configuring " + javaType.getName());
+            throw xml2JavaEx;
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private void setFieldValue(Object javaInstance,
+                               Field javaField,
+                               Node fieldValue,
+                               Map<Field, List<Object>> arrayFields,
+                               TransformationContext context) throws IllegalAccessException {
+        Class<?> javaFieldType = (Class<?>) javaField.getType();
+
+        if (javaFieldType.isArray()) {
+            Class componentType = javaFieldType.getComponentType();
+            List<Object> fldValueArray = null;
+            if ((fldValueArray = arrayFields.get(javaField)) == null) {
+                fldValueArray = new ArrayList();
+                arrayFields.put(javaField, fldValueArray);
+            }
+            fldValueArray.add(createJavaObject(fieldValue, componentType, context));
+        } else {
+            javaField.setAccessible(true);
+            javaField.set(javaInstance, createJavaObject(fieldValue, javaFieldType, context));
+        }
+    }
+
+    private void setArrayValues(Object javaInstance,
+                                Map<Field, List<Object>> arrayFields,
+                                Map<Method, List<Object>> arraySetters) throws IllegalAccessException,
+                                                                       InvocationTargetException {
+        if (arrayFields.size() > 0) {
+            for (Field javaField : arrayFields.keySet()) {
+                javaField.setAccessible(true);
+
+                if (javaField.getType().getComponentType().isPrimitive()) {
+                    javaField.set(javaInstance, createPrimitiveArray(javaField.getType()
+                                                                              .getComponentType(),
+                                                                     arrayFields.get(javaField)));
+                } else {
+                    javaField.set(javaInstance,
+                                  createNonPrimitiveArray(javaField.getType().getComponentType(),
+                                                          arrayFields.get(javaField)));
+                }
+            }
+        }
+
+        if (arraySetters.size() > 0) {
+            for (Method aMethod : arraySetters.keySet()) {
+                Class paramType = aMethod.getParameterTypes()[0];
+                if (paramType.getComponentType().isPrimitive()) {
+                    aMethod.invoke(javaInstance,
+                                   new Object[] { createPrimitiveArray(paramType.getComponentType(),
+                                                                       arraySetters.get(aMethod)) });
+                } else {
+                    aMethod.invoke(javaInstance,
+                                   new Object[] { createNonPrimitiveArray(paramType.getComponentType(),
+                                                                          arraySetters.get(aMethod)) });
+                }
+            }
+        }
+    }
+
+    private Object createNonPrimitiveArray(Class fieldType, List values) {
+        Object objectArray = Array.newInstance(fieldType, values.size());
+        for (int count = 0; count < values.size(); ++count) {
+            Array.set(objectArray, count, values.get(count));
+        }
+        return objectArray;
+    }
+
+    private Object createPrimitiveArray(Class fieldType, List values) {
+        if (fieldType.isPrimitive()) {
+            if (fieldType.getName().equals("int")) {
+                int[] primitiveValues = new int[values.size()];
+                for (int count = 0; count < values.size(); ++count) {
+                    primitiveValues[count] = ((Integer) values.get(count)).intValue();
+                }
+                return primitiveValues;
+            } else if (fieldType.getName().equals("float")) {
+                float[] primitiveValues = new float[values.size()];
+                for (int count = 0; count < values.size(); ++count) {
+                    primitiveValues[count] = ((Float) values.get(count)).floatValue();
+                }
+                return primitiveValues;
+            } else if (fieldType.getName().equals("boolean")) {
+                boolean[] primitiveValues = new boolean[values.size()];
+                for (int count = 0; count < values.size(); ++count) {
+                    primitiveValues[count] = ((Boolean) values.get(count)).booleanValue();
+                }
+                return primitiveValues;
+            } else if (fieldType.getName().equals("char")) {
+                char[] primitiveValues = new char[values.size()];
+                for (int count = 0; count < values.size(); ++count) {
+                    primitiveValues[count] = ((Character) values.get(count)).charValue();
+                }
+                return primitiveValues;
+            } else if (fieldType.getName().equals("byte")) {
+                byte[] primitiveValues = new byte[values.size()];
+                for (int count = 0; count < values.size(); ++count) {
+                    primitiveValues[count] = ((Byte) values.get(count)).byteValue();
+                }
+                return primitiveValues;
+            } else if (fieldType.getName().equals("short")) {
+                short[] primitiveValues = new short[values.size()];
+                for (int count = 0; count < values.size(); ++count) {
+                    primitiveValues[count] = ((Short) values.get(count)).shortValue();
+                }
+                return primitiveValues;
+            } else if (fieldType.getName().equals("long")) {
+                long[] primitiveValues = new long[values.size()];
+                for (int count = 0; count < values.size(); ++count) {
+                    primitiveValues[count] = ((Long) values.get(count)).longValue();
+                }
+                return primitiveValues;
+            } else if (fieldType.getName().equals("double")) {
+                double[] primitiveValues = new double[values.size()];
+                for (int count = 0; count < values.size(); ++count) {
+                    primitiveValues[count] = ((Double) values.get(count)).doubleValue();
+                }
+                return primitiveValues;
+            }
+        }
+        return values;
+    }
+    
+    private String resolveRootElementName(Class javaType) {
+        if ( javaType.isArray() ) {
+            return javaType.getComponentType().getSimpleName() + "_collection";
+        } else {
+            return javaType.getSimpleName() + "_instance";
+        }
+    }
+    
+    private String resolveElementName(Class javaType) {
+        if ( javaType.isArray() ) {
+            return javaType.getComponentType().getSimpleName();
+        } else {
+            return javaType.getSimpleName();
+        }
+    }
+    
+    private boolean isSimpleJavaType(Object javaObject) {
+        if ( javaObject instanceof String ||
+                javaObject instanceof Float || javaObject instanceof Double || 
+                javaObject instanceof GregorianCalendar || javaObject instanceof Date || 
+                javaObject instanceof XMLGregorianCalendar || javaObject instanceof byte[] || 
+                javaObject instanceof QName) {
+            return true;
+        }
+        return false;
+    }
+
+}

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/databinding.javabeans.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/databinding.javabeans.scdl?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/databinding.javabeans.scdl (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/databinding.javabeans.scdl Thu Feb  1 00:20:36 2007
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<!-- This is the copy ot be included by other extensions -->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+    name="org.apache.tuscany.databinding.javabeans.include">
+
+    <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+        <group>org.apache.tuscany.sca.services.databinding</group>
+        <name>databinding-javabeans</name>
+        <version>1.0-incubator-SNAPSHOT</version>
+    </dependency>
+
+    <component name="databinding.javabeans">
+        <system:implementation.system class="org.apache.tuscany.databinding.axiom.JavaBeansDataBinding" />
+    </component>
+
+    <component name="transformer.DOMNode2JavaBean">
+        <system:implementation.system class="org.apache.tuscany.databinding.javabeans.DOMNode2JavaBean" />
+    </component>
+</composite>
\ No newline at end of file

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/default.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/default.scdl?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/default.scdl (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/main/resources/META-INF/sca/default.scdl Thu Feb  1 00:20:36 2007
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.    
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:system="http://tuscany.apache.org/xmlns/system/1.0-SNAPSHOT"
+    name="org.apache.tuscany.databinding.javabeans">
+
+    <dependency xmlns="http://tuscany.apache.org/xmlns/1.0-SNAPSHOT">
+        <group>org.apache.tuscany.sca.services.databinding</group>
+        <name>databinding-javabeans</name>
+        <version>1.0-incubator-SNAPSHOT</version>
+    </dependency>
+
+    <component name="databinding.javabeans">
+        <system:implementation.system class="org.apache.tuscany.databinding.axiom.JavaBeansDataBinding" />
+    </component>
+
+    <component name="transformer.DOMNode2JavaBean">
+        <system:implementation.system class="org.apache.tuscany.databinding.javabeans.DOMNode2JavaBean" />
+    </component>
+    
+</composite>
\ No newline at end of file

Added: incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtensionTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtensionTestCase.java?view=auto&rev=502158
==============================================================================
--- incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtensionTestCase.java (added)
+++ incubator/tuscany/java/sca/services/databinding/databinding-javabeans/src/test/java/org/apache/tuscany/databinding/javabeans/XMLTypeMapperExtensionTestCase.java Thu Feb  1 00:20:36 2007
@@ -0,0 +1,192 @@
+/*
+ * 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.javabeans;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.databinding.TransformationContext;
+import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+import org.apache.tuscany.spi.idl.TypeInfo;
+import org.apache.tuscany.spi.model.DataType;
+import org.easymock.EasyMock;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Testcase to test the XMLTypeMapperExtension which is the back bone for all transformations supported
+ * by the JavaBeans Databinding.
+ */
+public class XMLTypeMapperExtensionTestCase extends TestCase {
+    
+    XMLTypeMapperExtension<Node> extension = new XMLTypeMapperExtension<Node>();
+    
+    /**
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+    }
+
+    public void testFieldSettings() throws Exception {
+        String samplePropertyXML = "<property name=\"prop2\" >" 
+                                            + "<integerNumber>27</integerNumber>" 
+                                            + "<floatNumber>79.34</floatNumber>" 
+                                            + "<doubleNumber>184.52</doubleNumber>" 
+                                            + "<innerProperty>" 
+                                            + "<integerNumber>54</integerNumber>" 
+                                            + "<floatNumber>158.68</floatNumber>" 
+                                            + "<doubleNumber>369.04</doubleNumber>" 
+                                            + "</innerProperty>" 
+                                            + "<stringArray>TestString_1</stringArray>" 
+                                            + "<stringArray>TestString_2</stringArray>" 
+                                            + "<boolArray>true</boolArray>" 
+                                            + "<boolArray>false</boolArray>" 
+                                    + "</property>";
+        
+        DocumentBuilder builder = DOMHelper.newDocumentBuilder();
+        InputSource inputSource = new InputSource(new StringReader(samplePropertyXML));
+        Node samplePropertyNode =  builder.parse(inputSource);
+        TypeInfo typeInfo = new TypeInfo(null, false, null);
+        
+        TransformationContext context = EasyMock.createMock(TransformationContext.class);
+        DataType<Class> dataType = new DataType<Class>(null, SamplePropertyBean.class);
+        EasyMock.expect(context.getTargetDataType()).andReturn(dataType).anyTimes();
+        EasyMock.replay(context);
+        
+        Object javaObject = extension.toJavaObject(typeInfo, samplePropertyNode, context);
+        
+        assertTrue(javaObject instanceof SamplePropertyBean);
+        SamplePropertyBean samplePropBean = (SamplePropertyBean)javaObject;
+        assertEquals(samplePropBean.getIntegerNumber(), 27);
+        assertEquals((float)79.34, (float)samplePropBean.getFloatNumber());
+        assertEquals((double)samplePropBean.getInnerProperty().getDoubleNumber(), (double)369.04);
+        
+        assertEquals(samplePropBean.getStringArray()[0], "TestString_1");
+        assertEquals(samplePropBean.boolArray[0], true);
+        
+        javax.xml.transform.Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        Node aNode = extension.toDOMNode(javaObject, context);
+        StringWriter sw = new StringWriter();
+        transformer.transform(new DOMSource(aNode), new StreamResult(sw));
+        String nodeString = sw.toString();
+        //System.out.println(nodeString);
+        
+        assertTrue(nodeString.indexOf("<stringArray>TestString_1</stringArray>" 
+                                         + "<stringArray>TestString_2</stringArray>") != -1);
+        assertTrue(nodeString.indexOf("<integerNumber>27</integerNumber>") != -1);
+        
+        int startIndex = nodeString.indexOf("<innerProperty>");
+        int endIndex = nodeString.indexOf("</innerProperty>");
+        String fragment = nodeString.substring(startIndex, endIndex);
+        assertTrue(fragment.indexOf("<integerNumber>54</integerNumber>") != -1);
+        
+        //System.out.println(sw.toString());
+        
+        
+    }
+    
+    public void testJava2NodeMapping() throws Exception {
+        SamplePropertyBean propertyBean = new SamplePropertyBean();
+        TransformationContext context = EasyMock.createMock(TransformationContext.class);
+        DataType<Class> dataType = new DataType<Class>(null, SamplePropertyBean.class);
+        EasyMock.expect(context.getTargetDataType()).andReturn(dataType).anyTimes();
+        EasyMock.replay(context);
+        
+        javax.xml.transform.Transformer transformer = TransformerFactory.newInstance().newTransformer();
+        Object data = new int[]{10, 20, 30, 40};
+        Node aNode = extension.toDOMNode(data, context);
+        StringWriter sw = new StringWriter();
+        transformer.transform(new DOMSource(aNode), new StreamResult(sw));
+        
+        //System.out.println(sw.toString());
+        assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><int_collection><int>10</int><int>20</int><int>30</int><int>40</int></int_collection>", sw.toString());
+    }
+    
+    public static class SamplePropertyBean  {
+        
+        public float floatNumber = 50;
+        public double doubleNumber = 75;
+        public boolean[] boolArray = null;
+        public int integerNumber = 25;
+        public String[] stringArray;
+        
+        public SamplePropertyBean innerProperty;
+        
+        public SamplePropertyBean() {
+            
+        }
+
+        public double getDoubleNumber() {
+            return doubleNumber;
+        }
+
+        public void setDoubleNumber(double doubleNumber) {
+            this.doubleNumber = doubleNumber;
+        }
+
+        public float getFloatNumber() {
+            return floatNumber;
+        }
+
+        public void setFloatNumber(float floatNumber) {
+            this.floatNumber = floatNumber;
+        }
+
+        public int getIntegerNumber() {
+            return integerNumber;
+        }
+
+        public void setIntegerNumber(int integerNumber) {
+            this.integerNumber = integerNumber;
+        }
+
+        public SamplePropertyBean getInnerProperty() {
+            return innerProperty;
+        }
+
+        public void setInnerProperty(SamplePropertyBean prop) {
+            this.innerProperty = prop;
+        }
+        
+        public String toString() {
+            return Double.toString(integerNumber + floatNumber + doubleNumber) + " & " 
+            + ((innerProperty == null) ? "" : innerProperty.toString());
+        }
+
+        public String[] getStringArray() {
+            return stringArray;
+        }
+
+        public void setStringArray(String[] stringArray) {
+            this.stringArray = stringArray;
+        }
+        
+    }
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org