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 2009/06/29 19:01:37 UTC

svn commit: r789385 - /tuscany/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java

Author: rfeng
Date: Mon Jun 29 17:01:37 2009
New Revision: 789385

URL: http://svn.apache.org/viewvc?rev=789385&view=rev
Log:
Merge the change from r783575 in 2.x to fix TUSCANY-3095

Modified:
    tuscany/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java

Modified: tuscany/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java
URL: http://svn.apache.org/viewvc/tuscany/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java?rev=789385&r1=789384&r2=789385&view=diff
==============================================================================
--- tuscany/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java (original)
+++ tuscany/branches/sca-java-1.x/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java Mon Jun 29 17:01:37 2009
@@ -6,15 +6,15 @@
  * 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.    
+ * under the License.
  */
 
 package org.apache.tuscany.sca.assembly.xml;
@@ -51,10 +51,10 @@
  *
  * @version $Rev$ $Date$
  */
-public class DefaultBeanModelProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor {
+public class DefaultBeanModelProcessor<T> extends BaseAssemblyProcessor implements StAXArtifactProcessor<T> {
 
     private QName artifactType;
-    private Class<Implementation> modelClass;
+    private Class<T> modelClass;
     private Object modelFactory;
     private Method factoryMethod;
     private Map<String, Method> setterMethods = new HashMap<String, Method>();
@@ -64,17 +64,17 @@
     		                     ExtensionFactory extensionFactory,
                                      PolicyFactory policyFactory,
                                      QName artifactType,
-                                     Class<Implementation> modelClass,
+                                     Class<T> modelClass,
                                      Object modelFactory,
                                      Monitor monitor) {
         super(assemblyFactory, extensionFactory, policyFactory, null, null, monitor);
         this.artifactType = artifactType;
         this.modelClass = modelClass;
         this.modelFactory = modelFactory;
-        
+
         // Introspect the factory class and bean model class
         if (modelFactory != null) {
-            
+
             // Find the model create method
             for (Method method: modelFactory.getClass().getMethods()) {
                 if (method.getName().startsWith("create") && method.getReturnType() == modelClass) {
@@ -83,13 +83,13 @@
                 }
             }
         }
-        
+
         // Index the bean's setter methods
         for (Method method: modelClass.getMethods()) {
             Method getter;
             String name = method.getName();
             if (name.startsWith("set") && name.length() > 3) {
-                
+
                 // Get the corresponding getter method
                 try {
                     getter = modelClass.getMethod("get" + name.substring(3));
@@ -97,7 +97,7 @@
                     getter = null;
                     continue;
                 }
-                
+
                 // Get the property name
                 name = name.substring(3);
                 if (name.length() > 1) {
@@ -108,12 +108,12 @@
             } else {
                 continue;
             }
-            
-            // Map an uppercase property name to a lowercase attribute name 
+
+            // Map an uppercase property name to a lowercase attribute name
             if (name.toUpperCase().equals(name)) {
                 name = name.toLowerCase();
             }
-            
+
             // Trim trailing _ from property names
             if (name.endsWith("_")) {
                 name = name.substring(0, name.length()-1);
@@ -123,11 +123,11 @@
         }
     }
 
-    public Object read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+    public T read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
 
         // Read an element
         try {
-            
+
             // Create a new instance of the model
             Object model;
             if (modelFactory != null) {
@@ -153,19 +153,19 @@
             policyProcessor.readPolicies(model, reader);
 
             // FIXME read extension elements
-            
+
             // By default mark the model object unresolved
             if (model instanceof Base) {
                 ((Base)model).setUnresolved(true);
             }
-            
+
             // Skip to end element
             while (reader.hasNext()) {
                 if (reader.next() == END_ELEMENT && artifactType.equals(reader.getName())) {
                     break;
                 }
             }
-            return model;
+            return (T) model;
 
         } catch (Exception e) {
         	ContributionReadException ce = new ContributionReadException(e);
@@ -174,7 +174,7 @@
         }
     }
 
-    public void write(Object bean, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+    public void write(T bean, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
         try {
             // Write the bean properties as attributes
             List<XAttr> attrs = new ArrayList<XAttr>();
@@ -184,7 +184,7 @@
                     attrs.add(new XAttr(entry.getKey(), value));
                 }
             }
-            
+
             // Write element
             writeStart(writer, artifactType.getNamespaceURI(), artifactType.getLocalPart(),
                        policyProcessor.writePolicies(bean), new XAttr(null, attrs));
@@ -198,8 +198,8 @@
         }
     }
 
-    public void resolve(Object bean, ModelResolver resolver) throws ContributionResolveException {
-        
+    public void resolve(T bean, ModelResolver resolver) throws ContributionResolveException {
+
         // Resolve and merge the component type associated with an
         // implementation model
         if (bean instanceof Implementation) {
@@ -209,26 +209,26 @@
                 int d = uri.lastIndexOf('.');
                 if (d != -1) {
                     uri = uri.substring(0, d) + ".componentType";
-                    
+
                     // Resolve the component type
                     ComponentType componentType = assemblyFactory.createComponentType();
                     componentType.setURI(uri);
                     componentType.setUnresolved(true);
-                    
+
                     componentType = resolver.resolveModel(ComponentType.class, componentType);
                     if (componentType != null && !componentType.isUnresolved()) {
-                        
+
                         // We found a component type, merge it into the implementation model
                         implementation.getServices().addAll(componentType.getServices());
                         implementation.getReferences().addAll(componentType.getReferences());
                         implementation.getProperties().addAll(componentType.getProperties());
                         implementation.setConstrainingType(componentType.getConstrainingType());
-                        
+
                         if (implementation instanceof PolicySetAttachPoint &&
                                 componentType instanceof PolicySetAttachPoint ) {
                             PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation;
                             PolicySetAttachPoint policiedCompType = (PolicySetAttachPoint)componentType;
-                            
+
                             if ( policiedImpl.getPolicySets() != null) {
                                 policiedImpl.getPolicySets().addAll(policiedCompType.getPolicySets());
                             }
@@ -240,7 +240,7 @@
                 }
             }
         }
-        
+
         // Mark the model resolved
         if (bean instanceof Base) {
             ((Base)bean).setUnresolved(false);
@@ -251,7 +251,7 @@
         return artifactType;
     }
 
-    public Class<?> getModelType() {
+    public Class<T> getModelType() {
         return modelClass;
     }