You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2007/02/26 20:18:18 UTC
svn commit: r511955 - in
/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main:
java/org/apache/tuscany/core/databinding/impl/
java/org/apache/tuscany/core/databinding/xml/
resources/org/apache/tuscany/core/
Author: rfeng
Date: Mon Feb 26 11:18:17 2007
New Revision: 511955
URL: http://svn.apache.org/viewvc?view=rev&rev=511955
Log:
[sca-integration-branch] Make group databinding more extensible
Added:
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLGroupDataBinding.java (with props)
Removed:
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/CommonGroupDataBinding.java
Modified:
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/GroupDataBinding.java
incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/GroupDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/GroupDataBinding.java?view=diff&rev=511955&r1=511954&r2=511955
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/GroupDataBinding.java (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/impl/GroupDataBinding.java Mon Feb 26 11:18:17 2007
@@ -27,23 +27,26 @@
import org.apache.tuscany.spi.model.DataType;
/**
- * A DataBinding for the StAX
+ * The base class for a special databinding which represents a group of other databindings
*
* @version $Rev$ $Date$
*/
public abstract class GroupDataBinding extends DataBindingExtension {
public static final String NAME = "databinding:group";
- protected Class[] types;
+ /**
+ * Marker type is a java class or interface representing the data format.
+ */
+ protected Class[] markerTypes;
public GroupDataBinding(Class[] types) {
super(NAME, null, GroupDataBinding.class);
- this.types = types;
+ this.markerTypes = types;
}
@SuppressWarnings("unchecked")
public boolean introspect(DataType type, Annotation[] annotations) {
- if (types == null) {
+ if (markerTypes == null) {
return false;
}
Type physical = type.getPhysical();
@@ -54,21 +57,41 @@
return false;
}
Class cls = (Class)physical;
- for (Class<?> c : types) {
- if (c.isAssignableFrom(cls)) {
- type.setDataBinding(NAME);
- DataType realType = null;
- try {
- realType = (DataType)type.clone();
- } catch (CloneNotSupportedException e) {
- // Never happen
- assert false;
- }
- realType.setDataBinding(c.getName());
- type.setLogical(realType);
+ for (Class<?> c : markerTypes) {
+ if (isTypeOf(c, cls)) {
+ type.setDataBinding(getDataBinding(c));
+ type.setLogical(getLogical(cls, annotations));
+ return true;
}
}
return false;
}
+
+ /**
+ * Test if the given type is a subtype of the base type
+ * @param markerType
+ * @param type
+ * @return
+ */
+ protected boolean isTypeOf(Class<?> markerType, Class<?> type) {
+ return markerType.isAssignableFrom(type);
+ }
+
+ /**
+ * Derive the databinding name from a base class
+ * @param baseType
+ * @return
+ */
+ protected String getDataBinding(Class<?> baseType) {
+ return baseType.getName();
+ }
+
+ /**
+ * Get the logical type
+ * @param type The java type
+ * @param annotations
+ * @return
+ */
+ protected abstract Object getLogical(Class<?> type, Annotation[] annotations);
}
Added: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLGroupDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLGroupDataBinding.java?view=auto&rev=511955
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLGroupDataBinding.java (added)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLGroupDataBinding.java Mon Feb 26 11:18:17 2007
@@ -0,0 +1,58 @@
+/*
+ * 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.core.databinding.xml;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.lang.annotation.Annotation;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+
+import org.apache.tuscany.core.databinding.impl.GroupDataBinding;
+import org.apache.tuscany.spi.idl.XMLType;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+
+/**
+ * A Group DataBinding
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLGroupDataBinding extends GroupDataBinding {
+
+ public XMLGroupDataBinding() {
+ super(new Class[] {InputStream.class, OutputStream.class, Reader.class, Writer.class, Source.class,
+ Result.class, InputSource.class, ContentHandler.class, XMLStreamReader.class,
+ XMLStreamWriter.class, XMLEventReader.class, XMLEventWriter.class});
+ }
+
+ @Override
+ protected Object getLogical(Class<?> markerType, Annotation[] annotations) {
+ return XMLType.UNKNOWN;
+ }
+
+}
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLGroupDataBinding.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/java/org/apache/tuscany/core/databinding/xml/XMLGroupDataBinding.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl
URL: http://svn.apache.org/viewvc/incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl?view=diff&rev=511955&r1=511954&r2=511955
==============================================================================
--- incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl (original)
+++ incubator/tuscany/branches/sca-java-integration/sca/kernel/core/src/main/resources/org/apache/tuscany/core/databinding.scdl Mon Feb 26 11:18:17 2007
@@ -60,16 +60,16 @@
</component>
<!-- Group databindings -->
- <!--
- <component name="databinding.group.common">
- <system:implementation.system class="org.apache.tuscany.core.databinding.impl.CommonGroupDataBinding" />
+ <component name="databinding.group.xml">
+ <system:implementation.system class="org.apache.tuscany.core.databinding.xml.XMLGroupDataBinding" />
</component>
- -->
+<!-- Comment out the stax databinding as it's covered in the databinding.group.xml -->
+<!--
<component name="databinding.stax">
<system:implementation.system class="org.apache.tuscany.core.databinding.xml.StAXDataBinding" />
</component>
-
+-->
<component name="databinding.javabeans">
<system:implementation.system class="org.apache.tuscany.core.databinding.javabeans.JavaBeansDataBinding" />
</component>
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org