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

svn commit: r505531 - in /incubator/tuscany/sandbox/isilval/notification/local: ./ src/main/java/org/apache/tuscany/notification/local/ src/test/java/org/apache/tuscany/notification/local/ src/test/resources/

Author: isilval
Date: Fri Feb  9 14:16:14 2007
New Revision: 505531

URL: http://svn.apache.org/viewvc?view=rev&rev=505531
Log:
Add loaders

Added:
    incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentType.java
    incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentTypeLoader.java
    incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementation.java
    incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementationLoader.java
    incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/NotificationImplementationLoaderTestCase.java
    incubator/tuscany/sandbox/isilval/notification/local/src/test/resources/
    incubator/tuscany/sandbox/isilval/notification/local/src/test/resources/TrafficAdvisoryNotification.componentType
Modified:
    incubator/tuscany/sandbox/isilval/notification/local/pom.xml

Modified: incubator/tuscany/sandbox/isilval/notification/local/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/pom.xml?view=diff&rev=505531&r1=505530&r2=505531
==============================================================================
--- incubator/tuscany/sandbox/isilval/notification/local/pom.xml (original)
+++ incubator/tuscany/sandbox/isilval/notification/local/pom.xml Fri Feb  9 14:16:14 2007
@@ -42,12 +42,23 @@
             <scope>compile</scope>
         </dependency>
         <dependency>
+            <groupId>org.apache.tuscany.sca.kernel</groupId>
+            <artifactId>tuscany-host-api</artifactId>
+            <version>1.0-incubator-SNAPSHOT</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
             <groupId>org.osoa</groupId>
             <artifactId>sca-api-r1.0</artifactId>
             <version>1.0-incubator-SNAPSHOT</version>
             <scope>compile</scope>
         </dependency>
-        
+        <dependency>
+            <groupId>stax</groupId>
+            <artifactId>stax-api</artifactId>
+            <version>1.0.1</version>
+        </dependency>
+		        
         <!-- test dependencies -->
         <dependency>
             <groupId>junit</groupId>

Added: incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentType.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentType.java?view=auto&rev=505531
==============================================================================
--- incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentType.java (added)
+++ incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentType.java Fri Feb  9 14:16:14 2007
@@ -0,0 +1,38 @@
+/*
+ * 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.notification.local;
+
+import org.apache.tuscany.spi.model.ComponentType;
+import org.apache.tuscany.spi.model.Property;
+import org.apache.tuscany.spi.model.ReferenceDefinition;
+import org.apache.tuscany.spi.model.Scope;
+import org.apache.tuscany.spi.model.ServiceDefinition;
+
+/**
+ * 
+ * @version $Rev$ $Date$
+ *
+ */
+public class NotificationComponentType extends
+    ComponentType<ServiceDefinition, ReferenceDefinition, Property<?>> {
+
+    public NotificationComponentType() {
+        implementationScope = Scope.COMPOSITE;
+    }
+}

Added: incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentTypeLoader.java?view=auto&rev=505531
==============================================================================
--- incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentTypeLoader.java (added)
+++ incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationComponentTypeLoader.java Fri Feb  9 14:16:14 2007
@@ -0,0 +1,69 @@
+/*
+ * 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.notification.local;
+
+import java.net.URL;
+
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.model.ComponentType;
+import org.osoa.sca.annotations.Constructor;
+
+/**
+ * 
+ * @version $Rev$ $Date$
+ * 
+ */
+public class NotificationComponentTypeLoader extends ComponentTypeLoaderExtension<NotificationImplementation> {
+
+    @Constructor({"registry"})
+    public NotificationComponentTypeLoader(@Autowire LoaderRegistry loaderRegistry) {
+        super(loaderRegistry);
+    }
+
+    @Override
+    protected Class<NotificationImplementation> getImplementationClass() {
+        return NotificationImplementation.class;
+    }
+
+    public void load(CompositeComponent parent,
+                     NotificationImplementation implementation,
+                     DeploymentContext deploymentContext) throws LoaderException {
+        Class<?> implClass = this.getClass(); // FIXME Hack, for Java, this is the implClass, Ruby uses the script class loader
+        URL resource = implClass.getClassLoader().getResource(implementation.getComponentTypeName() + ".componentType");
+        NotificationComponentType componentType;
+        if (resource == null) {
+            throw new LoaderException("Can't locate component type side file");
+        } else {
+            componentType = loadFromSidefile(parent, resource, deploymentContext);
+        }
+        implementation.setComponentType(componentType);
+    }
+
+    protected NotificationComponentType loadFromSidefile(CompositeComponent parent,
+                                                 URL url,
+                                                 DeploymentContext deploymentContext) throws LoaderException {
+        NotificationComponentType componentType = new NotificationComponentType();
+        return (NotificationComponentType)loaderRegistry.load(parent, componentType, url, ComponentType.class, deploymentContext);
+    }
+}

Added: incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementation.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementation.java?view=auto&rev=505531
==============================================================================
--- incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementation.java (added)
+++ incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementation.java Fri Feb  9 14:16:14 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.notification.local;
+
+import org.apache.tuscany.spi.model.AtomicImplementation;
+
+/**
+ * Model object for a Notification implementation.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class NotificationImplementation extends AtomicImplementation<NotificationComponentType> {
+
+    private String componentTypeName;
+    
+    public String getComponentTypeName() {
+        return componentTypeName;
+    }
+    
+    public void setComponentTypeName(String componentTypeName) {
+        this.componentTypeName = componentTypeName;
+    }
+}

Added: incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementationLoader.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementationLoader.java?view=auto&rev=505531
==============================================================================
--- incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementationLoader.java (added)
+++ incubator/tuscany/sandbox/isilval/notification/local/src/main/java/org/apache/tuscany/notification/local/NotificationImplementationLoader.java Fri Feb  9 14:16:14 2007
@@ -0,0 +1,68 @@
+/*
+ * 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.notification.local;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.spi.annotation.Autowire;
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.LoaderUtil;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.osoa.sca.annotations.Constructor;
+
+/**
+ * Loader for handling Notification <implementation.notification> elements.
+ * 
+ * @version $Rev$ $Date$
+ */
+public class NotificationImplementationLoader extends LoaderExtension<NotificationImplementation> {
+
+    protected static final QName IMPLEMENTATION_NOTIFICATION =
+        new QName("http://tuscany.apache.org/xmlns/notification/1.0", "implementation.notification");
+
+    @Constructor({"registry"})
+    public NotificationImplementationLoader(@Autowire LoaderRegistry registry) {
+        super(registry);
+    }
+
+    public QName getXMLType() {
+        return IMPLEMENTATION_NOTIFICATION;
+    }
+
+    public NotificationImplementation load(CompositeComponent parent,
+                                           ModelObject object,
+                                           XMLStreamReader reader,
+                                           DeploymentContext deploymentContext) throws XMLStreamException,
+                                                                                       LoaderException {
+        assert IMPLEMENTATION_NOTIFICATION.equals(reader.getName());
+        String componentTypeName = reader.getAttributeValue(null, "name");
+
+        NotificationImplementation implementation = new NotificationImplementation();
+        implementation.setComponentTypeName(componentTypeName);
+        registry.loadComponentType(parent, implementation, deploymentContext);
+        LoaderUtil.skipToEndElement(reader);
+        return implementation;
+    }
+}

Added: incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/NotificationImplementationLoaderTestCase.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/NotificationImplementationLoaderTestCase.java?view=auto&rev=505531
==============================================================================
--- incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/NotificationImplementationLoaderTestCase.java (added)
+++ incubator/tuscany/sandbox/isilval/notification/local/src/test/java/org/apache/tuscany/notification/local/NotificationImplementationLoaderTestCase.java Fri Feb  9 14:16:14 2007
@@ -0,0 +1,128 @@
+/*
+ * 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.notification.local;
+
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.spi.component.CompositeComponent;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.loader.ComponentTypeLoader;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.LoaderRegistry;
+import org.apache.tuscany.spi.loader.StAXElementLoader;
+import org.apache.tuscany.spi.loader.UnrecognizedComponentTypeException;
+import org.apache.tuscany.spi.model.Implementation;
+import org.apache.tuscany.spi.model.ModelObject;
+import org.easymock.EasyMock;
+
+/**
+ * 
+ * @version $Rev$ $Date$
+ *
+ */
+public class NotificationImplementationLoaderTestCase extends TestCase {
+
+    public void testLoad() throws Exception {
+        CompositeComponent parent = EasyMock.createMock(CompositeComponent.class);
+        EasyMock.replay(parent);
+        DeploymentContext deploymentContext = EasyMock.createMock(DeploymentContext.class);
+        EasyMock.replay(deploymentContext);
+
+        LoaderRegistry registry = new MockLoaderRegistry();
+        NotificationComponentTypeLoader componentTypeLoader = new NotificationComponentTypeLoader(registry);
+        componentTypeLoader.start();
+        NotificationImplementationLoader implementationLoader = new NotificationImplementationLoader(registry);
+        implementationLoader.start();
+
+        XMLStreamReader reader = EasyMock.createMock(XMLStreamReader.class);
+        EasyMock.expect(reader.getName()).andReturn(NotificationImplementationLoader.IMPLEMENTATION_NOTIFICATION);
+        EasyMock.expect(reader.getAttributeValue(null, "name")).andReturn("TrafficAdvisoryNotification");
+        EasyMock.expect(reader.next()).andReturn(XMLStreamConstants.END_ELEMENT);
+        EasyMock.replay(reader);
+        
+        ModelObject modelObject = null;
+        Implementation impl = implementationLoader.load(parent, modelObject, reader, deploymentContext);
+        Assert.assertNotNull(impl);
+        
+        componentTypeLoader.stop();
+        implementationLoader.stop();
+    }
+    
+    class MockLoaderRegistry implements LoaderRegistry {
+        
+        private final Map<Class<? extends Implementation<?>>,
+            ComponentTypeLoader<? extends Implementation<?>>> componentTypeLoaders =
+            new HashMap<Class<? extends Implementation<?>>, ComponentTypeLoader<? extends Implementation<?>>>();
+
+        public MockLoaderRegistry() {
+        }
+
+        public <T extends ModelObject> void registerLoader(QName element, StAXElementLoader<T> loader) {
+        }
+
+        public <T extends ModelObject> void unregisterLoader(QName element, StAXElementLoader<T> loader) {
+        }
+
+        public ModelObject load(CompositeComponent parent,
+                                ModelObject object,
+                                XMLStreamReader reader,
+                                DeploymentContext deploymentContext) throws XMLStreamException, LoaderException {
+            return null;
+        }
+
+        public <MO extends ModelObject> MO load(CompositeComponent parent,
+                                                ModelObject object,
+                                                URL url,
+                                                Class<MO> type,
+                                                DeploymentContext ctx) throws LoaderException {
+            return null;
+        }
+
+        public <I extends Implementation<?>> void registerLoader(Class<I> key, ComponentTypeLoader<I> loader) {
+            componentTypeLoaders.put(key, loader);
+        }
+
+        public <I extends Implementation<?>> void unregisterLoader(Class<I> key) {
+            componentTypeLoaders.remove(key);
+        }
+
+        @SuppressWarnings("unchecked")
+        public <I extends Implementation<?>> void loadComponentType(CompositeComponent parent,
+                                                                    I implementation,
+                                                                    DeploymentContext deploymentContext)
+            throws LoaderException {
+            Class<I> key = (Class<I>) implementation.getClass();
+            ComponentTypeLoader<I> loader = (ComponentTypeLoader<I>) componentTypeLoaders.get(key);
+            if (loader == null) {
+                throw new UnrecognizedComponentTypeException(key);
+            }
+            loader.load(parent, implementation, deploymentContext);
+        }
+    }
+}

Added: incubator/tuscany/sandbox/isilval/notification/local/src/test/resources/TrafficAdvisoryNotification.componentType
URL: http://svn.apache.org/viewvc/incubator/tuscany/sandbox/isilval/notification/local/src/test/resources/TrafficAdvisoryNotification.componentType?view=auto&rev=505531
==============================================================================
--- incubator/tuscany/sandbox/isilval/notification/local/src/test/resources/TrafficAdvisoryNotification.componentType (added)
+++ incubator/tuscany/sandbox/isilval/notification/local/src/test/resources/TrafficAdvisoryNotification.componentType Fri Feb  9 14:16:14 2007
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * 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.    
+-->
+
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+     <service name="TrafficAdvisoryNotificationService">
+           <interface.java interface="org.apache.tuscany.notification.local.TrafficAdvisory"/>
+     </service>
+
+     <reference name="TrafficAdvisoryNotificationReference">
+           <interface.java interface="org.apache.tuscany.notification.local.TrafficAdvisory"/>
+     </reference>
+</componentType>



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