Return-Path: Delivered-To: apmail-ws-tuscany-commits-archive@locus.apache.org Received: (qmail 45184 invoked from network); 5 Jun 2007 16:00:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Jun 2007 16:00:47 -0000 Received: (qmail 65221 invoked by uid 500); 5 Jun 2007 16:00:51 -0000 Delivered-To: apmail-ws-tuscany-commits-archive@ws.apache.org Received: (qmail 65205 invoked by uid 500); 5 Jun 2007 16:00:50 -0000 Mailing-List: contact tuscany-commits-help@ws.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: tuscany-dev@ws.apache.org Delivered-To: mailing list tuscany-commits@ws.apache.org Received: (qmail 65196 invoked by uid 99); 5 Jun 2007 16:00:50 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jun 2007 09:00:50 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 05 Jun 2007 09:00:45 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 9DD541A981D; Tue, 5 Jun 2007 09:00:25 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r544528 - in /incubator/tuscany/java/sca: modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ samples/helloworld-ws-reference/src/main/java/helloworld/ samples/helloworld-ws-reference/src/main/resources/ samples/hellowor... Date: Tue, 05 Jun 2007 16:00:25 -0000 To: tuscany-commits@ws.apache.org From: antelder@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070605160025.9DD541A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: antelder Date: Tue Jun 5 09:00:23 2007 New Revision: 544528 URL: http://svn.apache.org/viewvc?view=rev&rev=544528 Log: Change implementation-crud sample to use extension-helper instead of core spi (hoping that may prompt some review comments on if the extension-helper needs changes) Added: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationActivator.java (with props) incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java (with props) incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator - copied, changed from r544134, incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator Removed: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationFactory.java incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/DefaultCRUDImplementationFactory.java incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/impl/ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/module/ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/provider/ incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator Modified: incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationsActivator.java incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/SCDLProcessor.java incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.java incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldws.composite incubator/tuscany/java/sca/samples/implementation-crud/pom.xml Modified: incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationsActivator.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationsActivator.java?view=diff&rev=544528&r1=544527&r2=544528 ============================================================================== --- incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationsActivator.java (original) +++ incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationsActivator.java Tue Jun 5 09:00:23 2007 @@ -68,7 +68,7 @@ Class implClass = implementationActivator.getImplementationClass(); QName scdlQName = implementationActivator.getSCDLQName(); - staxProcessors.addArtifactProcessor(new SCDLProcessor(assemblyFactory, scdlQName, implClass)); + staxProcessors.addArtifactProcessor(new SCDLProcessor(assemblyFactory, scdlQName, implClass, registry, factories)); if (implementationActivator.getImplementationClass() != null && providerFactories != null) { addImplementationProvider(implementationActivator, providerFactories); Modified: incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/SCDLProcessor.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/SCDLProcessor.java?view=diff&rev=544528&r1=544527&r2=544528 ============================================================================== --- incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/SCDLProcessor.java (original) +++ incubator/tuscany/java/sca/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/SCDLProcessor.java Tue Jun 5 09:00:23 2007 @@ -21,10 +21,13 @@ import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import java.util.List; import java.util.Map; import java.util.Set; @@ -37,6 +40,8 @@ import org.apache.tuscany.sca.assembly.Implementation; import org.apache.tuscany.sca.contribution.service.ContributionReadException; import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.spi.utils.AbstractStAXArtifactProcessor; import org.apache.tuscany.sca.spi.utils.DynamicImplementation; @@ -48,14 +53,18 @@ protected QName scdlQName; protected Class implementationClass; + protected ExtensionPointRegistry registry; + protected ModelFactoryExtensionPoint factories; protected Map attributeSetters; protected Method elementTextSetter; - public SCDLProcessor(AssemblyFactory assemblyFactory, QName scdlQName, Class implementationClass) { + public SCDLProcessor(AssemblyFactory assemblyFactory, QName scdlQName, Class implementationClass, ExtensionPointRegistry registry, ModelFactoryExtensionPoint factories) { super(assemblyFactory); this.scdlQName = scdlQName; this.implementationClass = implementationClass; + this.registry = registry; + this.factories = factories; initAttributes(); } @@ -72,6 +81,23 @@ } } + private Object[] getImplConstrArgs() { + Constructor[] cs = implementationClass.getConstructors(); + if (cs.length != 1) { + throw new IllegalArgumentException("Implementation class must have a single constructor: "+ implementationClass.getName()); + } + List args = new ArrayList(); + for (Class c : cs[0].getParameterTypes()) { + Object o = factories.getFactory(c); + if (o == null) { + o = registry.getExtensionPoint(c); + } + args.add(o); + } + return args.toArray(); + } + + public QName getArtifactType() { return scdlQName; } @@ -83,7 +109,7 @@ public Implementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { Implementation impl; try { - impl = implementationClass.newInstance(); + impl = (Implementation)implementationClass.getConstructors()[0].newInstance(getImplConstrArgs()); } catch (Exception e) { throw new RuntimeException(e); } Modified: incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.java?view=diff&rev=544528&r1=544527&r2=544528 ============================================================================== --- incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.java (original) +++ incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/java/helloworld/HelloWorldClient.java Tue Jun 5 09:00:23 2007 @@ -30,8 +30,10 @@ SCADomain scaDomain = SCADomain.newInstance("helloworldwsclient.composite"); HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldServiceComponent"); - String value = helloWorldService.getGreetings("World"); - System.out.println(value); +// String value = helloWorldService.getGreetings("World"); +// System.out.println(value); + + Thread.sleep(900000); scaDomain.close(); } Modified: incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite?view=diff&rev=544528&r1=544527&r2=544528 ============================================================================== --- incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite (original) +++ incubator/tuscany/java/sca/samples/helloworld-ws-reference/src/main/resources/helloworldwsclient.composite Tue Jun 5 09:00:23 2007 @@ -22,13 +22,18 @@ xmlns:hw="http://helloworld" name="helloworldwsclient"> + + + + + - + Modified: incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldws.composite URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldws.composite?view=diff&rev=544528&r1=544527&r2=544528 ============================================================================== --- incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldws.composite (original) +++ incubator/tuscany/java/sca/samples/helloworld-ws-service/src/main/resources/helloworldws.composite Tue Jun 5 09:00:23 2007 @@ -22,11 +22,12 @@ xmlns:hw="http://helloworld" name="helloworldws"> - - + + + Modified: incubator/tuscany/java/sca/samples/implementation-crud/pom.xml URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/pom.xml?view=diff&rev=544528&r1=544527&r2=544528 ============================================================================== --- incubator/tuscany/java/sca/samples/implementation-crud/pom.xml (original) +++ incubator/tuscany/java/sca/samples/implementation-crud/pom.xml Tue Jun 5 09:00:23 2007 @@ -36,15 +36,10 @@ - - org.apache.tuscany.sca - sca-api - 1.0-incubating-SNAPSHOT - org.apache.tuscany.sca - tuscany-host-embedded + tuscany-extension-helper 1.0-incubating-SNAPSHOT @@ -52,7 +47,7 @@ org.apache.tuscany.sca tuscany-interface-java-xml 1.0-incubating-SNAPSHOT - + junit Added: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java?view=auto&rev=544528 ============================================================================== --- incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java (added) +++ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementation.java Tue Jun 5 09:00:23 2007 @@ -0,0 +1,79 @@ +/* + * 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 crud; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint; +import org.apache.tuscany.sca.spi.utils.AbstractImplementation; + + +/** + * The model representing a sample CRUD implementation in an SCA assembly model. + */ +public class CRUDImplementation extends AbstractImplementation { + + private Service crudService; + private String directory; + + public CRUDImplementation(AssemblyFactory assemblyFactory, + JavaInterfaceIntrospectorExtensionPoint visitors) { + + // CRUD implementation always provide a single service exposing + // the CRUD interface, and have no references and properties + crudService = assemblyFactory.createService(); + crudService.setName("CRUD"); + + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + JavaInterfaceIntrospector introspector = new ExtensibleJavaInterfaceIntrospector(javaFactory, visitors); + + JavaInterface javaInterface; + try { + javaInterface = introspector.introspect(CRUD.class); + } catch (InvalidInterfaceException e) { + throw new IllegalArgumentException(e); + } + JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(javaInterface); + crudService.setInterfaceContract(interfaceContract); + } + + public String getDirectory() { + return directory; + } + + public void setDirectory(String directory) { + this.directory = directory; + } + + public List getServices() { + // The sample CRUD implementation provides a single fixed CRUD service + return Collections.singletonList(crudService); + } +} Added: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationActivator.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationActivator.java?view=auto&rev=544528 ============================================================================== --- incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationActivator.java (added) +++ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationActivator.java Tue Jun 5 09:00:23 2007 @@ -0,0 +1,51 @@ +/* + * 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 crud; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.spi.ImplementationActivator; +import org.apache.tuscany.sca.spi.InvokerFactory; + +import crud.backend.ResourceManager; + +public class CRUDImplementationActivator implements ImplementationActivator { + + private static final QName IMPLEMENTATION_CRUD = new QName("http://crud", "implementation.crud"); + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, final CRUDImplementation implementation) { + return new InvokerFactory() { + public Invoker createInvoker(Operation operation) { + return new CRUDInvoker(operation, new ResourceManager(implementation.getDirectory())); + }}; + } + + public Class getImplementationClass() { + return CRUDImplementation.class; + } + + public QName getSCDLQName() { + return IMPLEMENTATION_CRUD; + } + +} Propchange: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationActivator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDImplementationActivator.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Added: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java?view=auto&rev=544528 ============================================================================== --- incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java (added) +++ incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java Tue Jun 5 09:00:23 2007 @@ -0,0 +1,77 @@ +/* + * 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 crud; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import crud.backend.ResourceManager; + +/** + * Implements a target invoker for CRUD component implementations. + * + * The target invoker is responsible for dispatching invocations to the particular + * component implementation logic. In this example we are simply delegating the + * CRUD operation invocations to the corresponding methods on our fake + * resource manager. + */ +public class CRUDInvoker implements Invoker { + private Operation operation; + private ResourceManager resourceManager; + + public CRUDInvoker(Operation operation, ResourceManager resourceManager) { + this.operation = operation; + this.resourceManager = resourceManager; + } + + public Message invoke(Message msg) { + try { + Object[] args = msg.getBody(); + Object resp = doTheWork(args); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } + return msg; + } + + public Object doTheWork(Object[] args) throws InvocationTargetException { + if (operation.getName().equals("create")) { + return resourceManager.createResource(args[0]); + + } else if (operation.getName().equals("retrieve")) { + return resourceManager.retrieveResource((String)args[0]); + + } else if (operation.getName().equals("update")) { + return resourceManager.updateResource((String)args[0], args[1]); + + } else if (operation.getName().equals("delete")) { + resourceManager.deleteResource((String)args[0]); + return null; + + } else { + return null; + } + } + +} Propchange: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/tuscany/java/sca/samples/implementation-crud/src/main/java/crud/CRUDInvoker.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Copied: incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator (from r544134, incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator) URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator?view=diff&rev=544528&p1=incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator&r1=544134&p2=incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator&r2=544528 ============================================================================== --- incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator (original) +++ incubator/tuscany/java/sca/samples/implementation-crud/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator Tue Jun 5 09:00:23 2007 @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. # Implementation class for the ExtensionActivator -crud.module.CRUDModuleActivator +crud.CRUDImplementationActivator --------------------------------------------------------------------- To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org For additional commands, e-mail: tuscany-commits-help@ws.apache.org