You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2006/03/02 02:12:05 UTC

svn commit: r382216 - in /incubator/tuscany/java/sca/model/src/main: java/org/apache/tuscany/model/assembly/ java/org/apache/tuscany/model/assembly/impl/ java/org/apache/tuscany/model/scdl/loader/impl/ resources/model/

Author: jsdelfino
Date: Wed Mar  1 17:12:03 2006
New Revision: 382216

URL: http://svn.apache.org/viewcvs?rev=382216&view=rev
Log:
integrated support for all the SDO supported simple types in component properties

Modified:
    incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/Property.java
    incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PropertyImpl.java
    incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/SCDLModelContentHandlerImpl.java
    incubator/tuscany/java/sca/model/src/main/resources/model/sca-core.xsd

Modified: incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/Property.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/Property.java?rev=382216&r1=382215&r2=382216&view=diff
==============================================================================
--- incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/Property.java (original)
+++ incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/Property.java Wed Mar  1 17:12:03 2006
@@ -17,6 +17,7 @@
 package org.apache.tuscany.model.assembly;
 
 
+
 /**
  * A description of a property that can be used to configure a component.
  */

Modified: incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PropertyImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PropertyImpl.java?rev=382216&r1=382215&r2=382216&view=diff
==============================================================================
--- incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PropertyImpl.java (original)
+++ incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/assembly/impl/PropertyImpl.java Wed Mar  1 17:12:03 2006
@@ -16,7 +16,17 @@
  */
 package org.apache.tuscany.model.assembly.impl;
 
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.model.assembly.AssemblyModelContext;
 import org.apache.tuscany.model.assembly.Property;
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.Type;
 
 /**
  * An implementation of Property.
@@ -28,6 +38,8 @@
     private boolean many;
     private boolean required;
     private Class type;
+    
+    private Type sdoType;
 
     /**
      * Constructor
@@ -108,5 +120,59 @@
         checkNotFrozen();
         type=value;
     }
+
+    /**
+     * @param sdoType The sdoType to set.
+     */
+    public void setSDOType(Type sdoType) {
+        checkNotFrozen();
+        this.sdoType = sdoType;
+    }
     
+    /**
+     * @return Returns the sdoType.
+     */
+    public Type getSDOType() {
+        return sdoType;
+    }
+    
+    private final static Map<Class, Type> typeMapping=new HashMap<Class, Type>();
+    
+    static {
+        typeMapping.put(BigDecimal.class, SDOUtil.getXSDSDOType("decimal"));
+        typeMapping.put(BigInteger.class, SDOUtil.getXSDSDOType("integer"));
+        typeMapping.put(boolean.class, SDOUtil.getXSDSDOType("boolean"));
+        typeMapping.put(Boolean.class, SDOUtil.getXSDSDOType("boolean"));
+        typeMapping.put(byte.class, SDOUtil.getXSDSDOType("byte"));
+        typeMapping.put(Byte.class, SDOUtil.getXSDSDOType("Byte"));
+        typeMapping.put(byte[].class, SDOUtil.getXSDSDOType("hexBinary"));
+        typeMapping.put(char.class, SDOUtil.getXSDSDOType("string"));
+        typeMapping.put(Character.class, SDOUtil.getXSDSDOType("string"));
+        typeMapping.put(Date.class, SDOUtil.getXSDSDOType("dateTime"));
+        typeMapping.put(double.class, SDOUtil.getXSDSDOType("double"));
+        typeMapping.put(Double.class, SDOUtil.getXSDSDOType("double"));
+        typeMapping.put(float.class, SDOUtil.getXSDSDOType("float"));
+        typeMapping.put(Float.class, SDOUtil.getXSDSDOType("float"));
+        typeMapping.put(int.class, SDOUtil.getXSDSDOType("int"));
+        typeMapping.put(Integer.class, SDOUtil.getXSDSDOType("int"));
+        typeMapping.put(long.class, SDOUtil.getXSDSDOType("long"));
+        typeMapping.put(Long.class, SDOUtil.getXSDSDOType("long"));
+        typeMapping.put(short.class, SDOUtil.getXSDSDOType("short"));
+        typeMapping.put(Short.class, SDOUtil.getXSDSDOType("short"));
+        typeMapping.put(String.class, SDOUtil.getXSDSDOType("string"));
+    }
+
+    /*
+     * @see org.apache.tuscany.model.assembly.impl.ExtensibleImpl#initialize(org.apache.tuscany.model.assembly.AssemblyModelContext)
+     */
+    public void initialize(AssemblyModelContext modelContext) {
+        if (isInitialized())
+            return;
+        super.initialize(modelContext);
+
+        // Get the SDO type corresponding to the property's Java type
+        if (sdoType==null) {
+            sdoType=typeMapping.get(type);
+        }
+    }
 }

Modified: incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/SCDLModelContentHandlerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/SCDLModelContentHandlerImpl.java?rev=382216&r1=382215&r2=382216&view=diff
==============================================================================
--- incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/SCDLModelContentHandlerImpl.java (original)
+++ incubator/tuscany/java/sca/model/src/main/java/org/apache/tuscany/model/scdl/loader/impl/SCDLModelContentHandlerImpl.java Wed Mar  1 17:12:03 2006
@@ -38,6 +38,7 @@
 import org.apache.tuscany.model.assembly.ServiceURI;
 import org.apache.tuscany.model.assembly.SimpleComponent;
 import org.apache.tuscany.model.assembly.Wire;
+import org.apache.tuscany.model.assembly.impl.PropertyImpl;
 import org.apache.tuscany.model.scdl.Binding;
 import org.apache.tuscany.model.scdl.Component;
 import org.apache.tuscany.model.scdl.ComponentType;
@@ -66,10 +67,12 @@
 import org.apache.tuscany.model.types.wsdl.WSDLServiceContract;
 import org.apache.tuscany.model.types.wsdl.impl.WSDLServiceContractImpl;
 import org.apache.tuscany.model.util.ModelContentHandler;
+import org.apache.tuscany.sdo.util.SDOUtil;
 import org.eclipse.emf.ecore.EObject;
 
 import commonj.sdo.DataObject;
 import commonj.sdo.Sequence;
+import commonj.sdo.Type;
 
 /**
  * A model content handler that transforms an SCDL model into an assembly model.
@@ -350,8 +353,17 @@
         property.setDefaultValue(object.getDefault());
         property.setMany(object.isMany());
         property.setRequired(object.isRequired());
-        //FIXME derive the Java type from the XSD type name
-        property.setType(String.class);
+        
+        Object dataType=object.getDataType();
+        if (dataType!=null) {
+            String typeName=dataType.toString();
+            typeName=typeName.substring(typeName.indexOf(':')+1);
+            Type type=SDOUtil.getXSDSDOType(typeName);
+            ((PropertyImpl)property).setSDOType(type);
+            property.setType(type.getInstanceClass());
+        } else {
+            property.setType(String.class);
+        }
         
         linkers.add(new Runnable() {
             public void run() {
@@ -443,11 +455,17 @@
                     }
 
                     // Get the property value text and convert to the expected java type
-                    //FIXME just handle strings for now
                     Sequence text = propertyElement.getSequence("any");
                     if (text != null && text.size() != 0) {
-                        Object rawValue = text.getValue(0);
-                        configuredProperty.setValue(rawValue);
+                        String rawValue = text.getValue(0).toString();
+                        Type type=((PropertyImpl)configuredProperty.getProperty()).getSDOType();
+                        Object value;
+                        if (type!=null) {
+                            value=SDOUtil.createFromString(type, rawValue);
+                        } else {
+                            value=rawValue;
+                        }
+                        configuredProperty.setValue(value);
                     }
                 }
             }

Modified: incubator/tuscany/java/sca/model/src/main/resources/model/sca-core.xsd
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sca/model/src/main/resources/model/sca-core.xsd?rev=382216&r1=382215&r2=382216&view=diff
==============================================================================
--- incubator/tuscany/java/sca/model/src/main/resources/model/sca-core.xsd (original)
+++ incubator/tuscany/java/sca/model/src/main/resources/model/sca-core.xsd Wed Mar  1 17:12:03 2006
@@ -41,7 +41,7 @@
 		<anyAttribute namespace="##any" processContents="lax"/>
 	</complexType>
 
-	<complexType name="Property" abstract="true">
+	<complexType name="Property">
 		<sequence>
 		    <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
 		</sequence>