tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From meer...@apache.org
Subject svn commit: r503916 - in /incubator/tuscany/java/sca/kernel: core/src/main/java/org/apache/tuscany/core/builder/physical/ core/src/main/java/org/apache/tuscany/core/marshaller/ spi/src/main/java/org/apache/tuscany/spi/marshaller/
Date Mon, 05 Feb 2007 23:01:48 GMT
Author: meerajk
Date: Mon Feb  5 15:01:47 2007
New Revision: 503916

URL: http://svn.apache.org/viewvc?view=rev&rev=503916
Log:
Added the registry implementations

Added:
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java
  (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/JavaPhysicalComponentBuilder.java
  (with props)
    incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java
  (with props)
Modified:
    incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java?view=auto&rev=503916
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java
(added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java
Mon Feb  5 15:01:47 2007
@@ -0,0 +1,66 @@
+/*
+ * 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.builder.physical;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilder;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilderRegistry;
+import org.apache.tuscany.spi.component.Component;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+
+/**
+ * Default map-based implementation of the physical component builder registry. 
+ * 
+ * TODO may be we can factor out all the registries into a parameterized one.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class DefaultPhysicalComponentBuilderRegistry implements PhysicalComponentBuilderRegistry
{
+
+    // Internal cache
+    private Map<Class<? extends PhysicalComponentDefinition>, PhysicalComponentBuilder<?
extends PhysicalComponentDefinition, ? extends Component>> registry =
+        new ConcurrentHashMap<Class<? extends PhysicalComponentDefinition>, PhysicalComponentBuilder<?
extends PhysicalComponentDefinition, ? extends Component>>();
+
+    /**
+     * Registers a physical component builder.
+     * 
+     * @param <PCD> Type of the physical component definition.
+     * @param definitionClass Class of the physical component definition.
+     * @param builder Builder for the physical component definition.
+     */
+    public <PCD extends PhysicalComponentDefinition, C extends Component> void register(Class<PCD>
definitionClass,
+                                                                                        PhysicalComponentBuilder<PCD,
C> builder) {
+        registry.put(definitionClass, builder);
+    }
+
+    /**
+     * Gets a builder for the specified physical component builder.
+     * 
+     * @param <PCD> Type of the physical component definition.
+     * @param definitionClass Class of the physical component definition.
+     * @return Builder for the physical component definition.
+     */
+    @SuppressWarnings("unchecked")
+    public <PCD extends PhysicalComponentDefinition, C extends Component> PhysicalComponentBuilder<PCD,
C> getBuilder(Class<PCD> definitionClass) {
+        return (PhysicalComponentBuilder<PCD, C>)registry.get(definitionClass);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/DefaultPhysicalComponentBuilderRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/JavaPhysicalComponentBuilder.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/JavaPhysicalComponentBuilder.java?view=auto&rev=503916
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/JavaPhysicalComponentBuilder.java
(added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/JavaPhysicalComponentBuilder.java
Mon Feb  5 15:01:47 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.builder.physical;
+
+import org.apache.tuscany.core.component.JavaPhysicalComponentDefinition;
+import org.apache.tuscany.core.implementation.java.JavaAtomicComponent;
+import org.apache.tuscany.spi.builder.BuilderException;
+import org.apache.tuscany.spi.builder.physical.PhysicalComponentBuilder;
+
+/**
+ * Java physical component builder.
+ * 
+ * @version $Rev$ $Date$
+ *
+ */
+public class JavaPhysicalComponentBuilder implements
+    PhysicalComponentBuilder<JavaPhysicalComponentDefinition, JavaAtomicComponent>
{
+
+    /**
+     * Builds a component from its physical component definition.
+     * 
+     * @param componentDefinition Physical component definition of the component
+     *            to be built.
+     * @return A component instance that is ready to go live.
+     * @throws BuilderException If unable to build the component.
+     */
+    public JavaAtomicComponent build(JavaPhysicalComponentDefinition componentDefinition)
throws BuilderException {
+        
+        byte[] instanceFactoryByteCode = componentDefinition.getInstanceFactoryByteCode();
+        
+        // TODO I am sure this is not the right classloader.
+        InstanceFactoryLoader cl = new InstanceFactoryLoader();
+        Class instanceFactoryClass = cl.loadClass(instanceFactoryByteCode);
+        
+        
+        // TODO Do the rest
+        return null;
+    }
+    
+    /*
+     * Allows to load the class from byte code.
+     * 
+     * TODO Is there a better way to do this?
+     */
+    private class InstanceFactoryLoader extends ClassLoader {        
+        public Class loadClass(byte[] byteCode) {
+            return defineClass(null, byteCode, 0, byteCode.length);
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/JavaPhysicalComponentBuilder.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/builder/physical/JavaPhysicalComponentBuilder.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java?view=auto&rev=503916
==============================================================================
--- incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java
(added)
+++ incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java
Mon Feb  5 15:01:47 2007
@@ -0,0 +1,66 @@
+/*
+ * 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.marshaller;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.spi.marshaller.ModelMarshaller;
+import org.apache.tuscany.spi.marshaller.ModelMarshallerRegistry;
+import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
+
+/**
+ * Default map-based implementation of the model marshaller registry. 
+ * 
+ * TODO may be we can factor out all the registries into a parameterized one.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class DefaultModelMarshallerRegistry<P extends PhysicalComponentDefinition>
implements ModelMarshallerRegistry {
+
+    // Internal cache
+    private Map<Class<? extends PhysicalComponentDefinition>, ModelMarshaller<?
extends PhysicalComponentDefinition>> registry =
+        new ConcurrentHashMap<Class<? extends PhysicalComponentDefinition>, ModelMarshaller<?
extends PhysicalComponentDefinition>>();
+
+    /**
+     * Registers a physical component definition marshaller.
+     * 
+     * @param <PCD> Physical component definition.
+     * @param modelClass Physical component definition class.
+     * @param marshaller Marshaller responsible for marshalling.
+     */
+    public <PCD extends PhysicalComponentDefinition> void registerMarshaller(Class<PCD>
modelClass,
+                                                                             ModelMarshaller<PCD>
marshaller) {
+        registry.put(modelClass, marshaller);
+    }
+
+    /**
+     * Gets a marshaller for marshalling the registered type.
+     * 
+     * @param <PCD> Physical component definition.
+     * @param modelClass Type of the physical model definition that needs to be
+     *            marshalled.
+     * @return Marshaller capable for marshalling the specified type.
+     */
+    @SuppressWarnings("unchecked")
+    public <PCD extends PhysicalComponentDefinition> ModelMarshaller<PCD> getMarshaller(Class<PCD>
modelClass) {
+        return (ModelMarshaller<PCD>)registry.get(modelClass);
+    }
+
+}

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/kernel/core/src/main/java/org/apache/tuscany/core/marshaller/DefaultModelMarshallerRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java?view=diff&rev=503916&r1=503915&r2=503916
==============================================================================
--- incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java
(original)
+++ incubator/tuscany/java/sca/kernel/spi/src/main/java/org/apache/tuscany/spi/marshaller/ModelMarshallerRegistry.java
Mon Feb  5 15:01:47 2007
@@ -18,8 +18,6 @@
  */
 package org.apache.tuscany.spi.marshaller;
 
-import javax.xml.namespace.QName;
-
 import org.apache.tuscany.spi.model.physical.PhysicalComponentDefinition;
 
 /**
@@ -34,11 +32,9 @@
      * 
      * @param <PCD> Physical component definition.
      * @param modelClass Physical component definition class.
-     * @param qualifiedName Qualified name of the marshalled XML stream.
      * @param marshaller Marshaller responsible for marshalling.
      */
     <PCD extends PhysicalComponentDefinition> void registerMarshaller(Class<PCD>
modelClass,
-                                                                      QName qualifiedName,
                                                                       ModelMarshaller<PCD>
marshaller);
 
     /**



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


Mime
View raw message