From a3ce58076d0ce2d2f09c2331ea499554e9b5a9f9 Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 11 Sep 2008 04:13:16 +0000 Subject: Renaming branch git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@694108 13f79535-47bb-0310-9956-ffa450edef68 --- .../contribution/updater/impl/ArtifactsFinder.java | 51 --- .../updater/impl/ComponentUpdaterImpl.java | 381 --------------------- .../updater/impl/CompositeUpdaterImpl.java | 156 --------- .../impl/ContributionUpdaterFactoryImpl.java | 75 ---- .../updater/impl/ContributionUpdaterTestCase.java | 129 ------- .../contribution/updater/impl/GreetService.java | 26 -- .../contribution/updater/impl/HelloComponent.java | 39 --- .../updater/impl/MetaComponentHello.java | 61 ---- .../src/test/resources/HelloComposite.composite | 27 -- .../resources/repository/sample-calculator.jar | Bin 29164 -> 0 bytes 10 files changed, 945 deletions(-) delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ArtifactsFinder.java delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ComponentUpdaterImpl.java delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/CompositeUpdaterImpl.java delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterFactoryImpl.java delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterTestCase.java delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/GreetService.java delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/HelloComponent.java delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/MetaComponentHello.java delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/resources/HelloComposite.composite delete mode 100644 branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/resources/repository/sample-calculator.jar (limited to 'branches/sca-trunk-20080910/modules/contribution-updater-impl/src') diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ArtifactsFinder.java b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ArtifactsFinder.java deleted file mode 100644 index a23bf6f8cd..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ArtifactsFinder.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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.sca.contribution.updater.impl; - -import java.util.List; - -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.contribution.DeployedArtifact; -import org.apache.tuscany.sca.runtime.RuntimeComponent; - -public class ArtifactsFinder { - - public static Composite findComposite(String compositeURI, - List artifacts) { - for (Composite composite : artifacts) { - if (composite.getURI().equals(compositeURI)) - return composite; - } - return null; - } - - public static Component findComponent(Composite composite, - String componentName) { - for (Component component : composite.getComponents()) { - if (component.getName().equals(componentName)) { - return component; - - } - - } - return null; - } - -} diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ComponentUpdaterImpl.java b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ComponentUpdaterImpl.java deleted file mode 100644 index a6a6084f5f..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ComponentUpdaterImpl.java +++ /dev/null @@ -1,381 +0,0 @@ -/* - * 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.sca.contribution.updater.impl; - -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.util.List; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.DeployedArtifact; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.service.ContributionResolveException; -import org.apache.tuscany.sca.contribution.service.ContributionService; -import org.apache.tuscany.sca.contribution.updater.ComponentNotFoundException; -import org.apache.tuscany.sca.contribution.updater.ComponentUpdater; -import org.apache.tuscany.sca.contribution.updater.ComponentUpdaterException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.assembly.CompositeActivator; -import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; -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.contribution.updater.impl.ArtifactsFinder; -import org.apache.tuscany.sca.assembly.xml.MetaComponentProcessor; -import org.apache.tuscany.sca.provider.ImplementationProvider; -import org.apache.tuscany.sca.provider.ReferenceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.implementation.java.IntrospectionException; -import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper; - -public class ComponentUpdaterImpl implements ComponentUpdater { - - private String contribURI; - private String compositeURI; - private String componentName; - private JavaInterfaceFactory javaFactory; - private CompositeBuilder compositeBuilder; - private CompositeActivator compositeActivator; - private ContributionService contributionService; - private ExtensionPointRegistry registry; - private AssemblyFactory assemblyFactory; - private InterfaceContractMapper interfaceContractMapper; - private Contribution contrib; - - public ComponentUpdaterImpl(String contribURI, String compositeURI, - String componentName, AssemblyFactory assembly, - JavaInterfaceFactory javaFactory, - CompositeBuilder compositeBuilder, - CompositeActivator compositeActivator, - ContributionService contribService, - ExtensionPointRegistry registry, InterfaceContractMapper mapper) { - this.contribURI = contribURI; - this.compositeURI = compositeURI; - this.componentName = componentName; - this.javaFactory = javaFactory; - this.compositeBuilder = compositeBuilder; - this.compositeActivator = compositeActivator; - this.contributionService = contribService; - this.registry = registry; - this.assemblyFactory = assembly; - this.interfaceContractMapper = mapper; - this.contrib = this.contributionService.getContribution(contribURI); - } - - private void reconcileReference(Reference reference, - ComponentReference targetReference, String componentName) { - - targetReference.setReference(reference); - targetReference.setIsCallback(reference.isCallback()); - targetReference.setMultiplicity(reference.getMultiplicity()); - if (targetReference.getInterfaceContract() != null) { - if (!targetReference.getInterfaceContract().equals( - reference.getInterfaceContract())) { - if (!interfaceContractMapper.isCompatible(reference - .getInterfaceContract(), targetReference - .getInterfaceContract())) { - System.err - .println("Component reference interface incompatible with reference interface: " - + componentName - + "/" - + targetReference.getName()); - } - } - } else { - targetReference.setInterfaceContract(reference - .getInterfaceContract()); - } - if (targetReference.getBindings().isEmpty()) { - targetReference.getBindings().addAll(reference.getBindings()); - } - - // Reconcile callback bindings - if (targetReference.getCallback() == null) { - targetReference.setCallback(reference.getCallback()); - if (targetReference.getCallback() == null) { - targetReference.setCallback(assemblyFactory.createCallback()); - } - - } else if (targetReference.getCallback().getBindings().isEmpty() - && reference.getCallback() != null) { - targetReference.getCallback().getBindings().addAll( - reference.getCallback().getBindings()); - } - Contribution contrib = contributionService.getContribution(contribURI); - List artifacts = contrib.getArtifacts(); - // RuntimeComponent source = null; - Composite composite = ArtifactsFinder.findComposite(compositeURI, - artifacts); - Component c = ArtifactsFinder.findComponent(composite, componentName); - if (targetReference.getAutowire() == null) { - targetReference.setAutowire(c.getAutowire()); - } - - // Reconcile targets - if (targetReference.getTargets().isEmpty()) { - targetReference.getTargets().addAll(reference.getTargets()); - } - - } - - public org.apache.tuscany.sca.assembly.Reference buildReference( - String name, String className, Class businessInterface, - boolean required) throws Exception { - - Class rawType = contrib.getClassLoader().loadClass(className); - - if (rawType == null) - return null; - - org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory - .createReference(); - JavaInterfaceContract interfaceContract = javaFactory - .createJavaInterfaceContract(); - reference.setInterfaceContract(interfaceContract); - reference.setName(name); - - if (required) { - reference.setMultiplicity(Multiplicity.ONE_ONE); - } else { - reference.setMultiplicity(Multiplicity.ZERO_ONE); - } - Type[] interfaces = rawType.getGenericInterfaces(); - Type genericType = null; - - for (int i = 0; i < interfaces.length; ++i) { - Type tmp = interfaces[i]; - if (interfaces[i] instanceof ParameterizedType) { - ParameterizedType type = (ParameterizedType) tmp; - tmp = type.getRawType(); - } - if (tmp.getClass().getName().equals( - businessInterface.getClass().getName())) { - genericType = tmp; - } - } - if (genericType == null) - throw new ComponentUpdaterException( - "User has specified a wrong businessInterface:" - + businessInterface); - // baseType = JavaIntrospectionHelper.getBusinessInterface(baseType, - // genericType); - /* - * Class baseType = getBaseType(rawType, genericType); if - * (CallableReference.class.isAssignableFrom(baseType)) { if - * (Collection.class.isAssignableFrom(rawType)) { genericType = - * JavaIntrospectionHelper.getParameterType(genericType); } baseType = - * JavaIntrospectionHelper.getBusinessInterface(baseType, genericType); } - */ - try { - - JavaInterface callInterface = javaFactory - .createJavaInterface(JavaIntrospectionHelper - .getErasure(genericType)); - reference.getInterfaceContract().setInterface(callInterface); - if (callInterface.getCallbackClass() != null) { - JavaInterface callbackInterface = javaFactory - .createJavaInterface(callInterface.getCallbackClass()); - reference.getInterfaceContract().setCallbackInterface( - callbackInterface); - } - } catch (InvalidInterfaceException e) { - throw new IntrospectionException(e); - } - return reference; - } - - /* - * private org.apache.tuscany.sca.assembly.Reference - * createReference(JavaElementImpl element, String name) throws - * IntrospectionException { org.apache.tuscany.sca.assembly.Reference - * reference = assemblyFactory.createReference(); JavaInterfaceContract - * interfaceContract = javaFactory.createJavaInterfaceContract(); - * reference.setInterfaceContract(interfaceContract); - * // reference.setMember((Member)element.getAnchor()); boolean required = - * true; Reference ref = element.getAnnotation(Reference.class); if (ref != - * null) { required = ref.required(); } // reference.setRequired(required); - * reference.setName(name); Class rawType = element.getType(); if - * (rawType.isArray() || Collection.class.isAssignableFrom(rawType)) { if - * (required) { reference.setMultiplicity(Multiplicity.ONE_N); } else { - * reference.setMultiplicity(Multiplicity.ZERO_N); } } else { if (required) { - * reference.setMultiplicity(Multiplicity.ONE_ONE); } else { - * reference.setMultiplicity(Multiplicity.ZERO_ONE); } } Type genericType = - * element.getGenericType(); Class baseType = getBaseType(rawType, - * genericType); if (CallableReference.class.isAssignableFrom(baseType)) { - * if (Collection.class.isAssignableFrom(rawType)) { genericType = - * JavaIntrospectionHelper.getParameterType(genericType); } baseType = - * JavaIntrospectionHelper.getBusinessInterface(baseType, genericType); } - * try { JavaInterface callInterface = - * javaFactory.createJavaInterface(baseType); - * reference.getInterfaceContract().setInterface(callInterface); if - * (callInterface.getCallbackClass() != null) { JavaInterface - * callbackInterface = - * javaFactory.createJavaInterface(callInterface.getCallbackClass()); - * reference.getInterfaceContract().setCallbackInterface(callbackInterface); } } - * catch (InvalidInterfaceException e) { throw new - * IntrospectionException(e); } return reference; } - */ - public ComponentReference addReferenceWire(String referenceName, - String className, Class interfaceName, String targetComponent) - throws ComponentUpdaterException, ComponentNotFoundException { - - StAXArtifactProcessorExtensionPoint staxProcessors = registry - .getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - MetaComponentProcessor processor = (MetaComponentProcessor) staxProcessors - .getProcessor(Component.class); - - Contribution contrib = contributionService.getContribution(contribURI); - - List artifacts = contrib.getArtifacts(); - RuntimeComponent source = null; - Composite composite = ArtifactsFinder.findComposite(compositeURI, - artifacts); - // TODO error handling - if (composite != null) - source = (RuntimeComponent) ArtifactsFinder.findComponent( - composite, componentName); - else { - throw new ComponentNotFoundException("Not found component " - + componentName + " for update"); - } - if (source != null) { - // Debig this - RuntimeComponentReference targetReference = (RuntimeComponentReference) assemblyFactory - .createComponentReference(); - targetReference.setName(referenceName); - targetReference.setUnresolved(true); - Reference reference = null; - try { - reference = buildReference(referenceName, className, - interfaceName, true); - } catch (Exception e) { - throw new ComponentUpdaterException(e.getMessage()); - } - source.getImplementation().getReferences().add(reference); - - // targetService. - ComponentService targetService = assemblyFactory - .createComponentService(); - targetService.setUnresolved(true); - targetService.setName(targetComponent); - targetReference.getTargets().add(targetService); - - // reconciliate - reconcileReference(reference, targetReference, componentName); - // create component reference for the reference - source.getReferences().add(targetReference); - try { - processor.resolveReference(targetReference, contrib - .getModelResolver()); - } catch (ContributionResolveException e) { - throw new ComponentUpdaterException( - "Contribution Resolving Exception while updating.."); - } - - CompositeActivatorImpl activator = (CompositeActivatorImpl) compositeActivator; - compositeBuilder.attachWire(source, composite, targetReference); - activator.activate(source, targetReference); - synchronized (source) { - activator.configureComponentContext(source); - } - // RuntimeComponentReference runtimeRef = - // ((RuntimeComponentReference)ref); - // runtimeRef.setComponent(component); - for (Binding binding : targetReference.getBindings()) { - ReferenceBindingProvider bindingProvider = targetReference - .getBindingProvider(binding); - if (bindingProvider != null) { - bindingProvider.start(); - } - - } - - ImplementationProvider implementationProvider = source - .getImplementationProvider(); - if (implementationProvider != null) { - /* - * con la reflection cosi tolgo la dipendneza if - * ((implementationProvider.getClass().getName().equals("JavaImplementationProvider")) { - * Clazz cget } implementationProvider.getClass(). if - * (implementationProvider instanceof - * JavaImplementationProvider) { ((JavaImplementationProvider) - * implementationProvider). startReference(targetReference); } - */ - } - return targetReference; - } else { - throw new ComponentNotFoundException("Not found component " - + componentName + " for update"); - } - } - - public ComponentReference removeReferenceWire(String referenceName, - String targetComponent) throws ComponentUpdaterException, - ComponentNotFoundException { - List artifacts = contributionService.getContribution( - contribURI).getArtifacts(); - RuntimeComponent source = null; - Composite composite = ArtifactsFinder.findComposite(compositeURI, - artifacts); - ComponentReference toRemove = null; - - if (composite != null) { - source = (RuntimeComponent) ArtifactsFinder.findComponent( - composite, this.componentName); - } else { - throw new ComponentNotFoundException("Not found component " - + componentName + " for update"); - } - if ((source != null) && (targetComponent != null)) { - /* source target refenence */ - - List references = source.getReferences(); - for (ComponentReference ref : references) { - if (ref.getName().equals(targetComponent)) { - toRemove = ref; - break; - } - } - if (toRemove != null) { - CompositeActivatorImpl activator = (CompositeActivatorImpl) compositeActivator; - activator.stop(source, toRemove); - activator.deactivate(source, - (RuntimeComponentReference) toRemove); - compositeBuilder.detachWire(composite, source, toRemove); - } else { - throw new ComponentNotFoundException("Not found component " - + componentName + " for update"); - } - - } - return toRemove; - } -} diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/CompositeUpdaterImpl.java b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/CompositeUpdaterImpl.java deleted file mode 100644 index c5a15b5108..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/CompositeUpdaterImpl.java +++ /dev/null @@ -1,156 +0,0 @@ -/* - * 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.sca.contribution.updater.impl; - -import java.util.List; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.MetaComponent; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; -import org.apache.tuscany.sca.contribution.Artifact; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.DeployedArtifact; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.service.ContributionService; -import org.apache.tuscany.sca.contribution.updater.CompositeUpdater; -import org.apache.tuscany.sca.contribution.updater.CompositeUpdaterException; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.assembly.CompositeActivator; -import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl; -import org.apache.tuscany.sca.contribution.updater.impl.ArtifactsFinder; -import org.apache.tuscany.sca.assembly.xml.MetaComponentProcessor; -import org.apache.tuscany.sca.runtime.RuntimeComponent; - -public class CompositeUpdaterImpl implements CompositeUpdater { - - private CompositeBuilder compositeBuilder; - private String compositeURI; - private AssemblyFactory assemblyFactory; - private String contribURI; - private CompositeActivator compositeActivator; - private ExtensionPointRegistry registry; - private ContributionService contribService; - - public CompositeUpdaterImpl(AssemblyFactory assembly, String contribURI, - String compositeURI, CompositeBuilder compositeBuilder, - CompositeActivator compositeActivator, - ExtensionPointRegistry registry, ContributionService contribService) { - this.compositeBuilder = compositeBuilder; - this.compositeURI = compositeURI; - this.assemblyFactory = assembly; - this.contribURI = contribURI; - this.compositeActivator = compositeActivator; - this.registry = registry; - this.contribService = contribService; - } - - public Component addComponent(MetaComponent c) - throws CompositeUpdaterException { - StAXArtifactProcessorExtensionPoint staxProcessors = registry - .getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - MetaComponentProcessor processor = (MetaComponentProcessor) staxProcessors - .getProcessor(Component.class); - Contribution contrib = contribService.getContribution(contribURI); - List artifacts = contrib.getArtifacts(); - Composite composite = ArtifactsFinder.findComposite(compositeURI, - artifacts); - boolean found = false; - - if (composite == null) - throw new CompositeUpdaterException( - "Composite not found in contribution" + contribURI); - else { - processor.setComposite(composite); - try { - processor.read(c.build()); - } catch (Exception e) { - throw new CompositeUpdaterException( - "Component error parsing in contribution" + contribURI); - - } - found = true; - } - - if (found) { - Component component = processor.getParsedComponent(); - Composite augmentedComposite = processor.getParsedComposite(); - try { - processor.resolve(component, contrib.getModelResolver()); - compositeBuilder.attach(augmentedComposite, component); - ((CompositeActivatorImpl) compositeActivator) - .activateComponent(component); - } catch (Exception e) { - - throw new CompositeUpdaterException( - "Cannot activate the component"); - } - - return component; - } - return null; - } - - public Component findComponent(String componentName) { - Contribution contrib = contribService.getContribution(contribURI); - List artifacts = contrib.getDeployables(); - Composite composite = ArtifactsFinder.findComposite(compositeURI, - artifacts); - return ArtifactsFinder.findComponent(composite, componentName); - } - - public Component removeComponent(String componentName) - throws CompositeUpdaterException { - Contribution contrib = contribService.getContribution(contribURI); - List artifacts = contrib.getArtifacts(); - - Composite composite = ArtifactsFinder.findComposite(compositeURI, - artifacts); - List components = composite.getComponents(); - Component toRemove = null; - for (Component component : components) { - if (((RuntimeComponent) component).getName().equals(componentName)) { - toRemove = component; - break; - } - } - if (toRemove == null) { - throw new CompositeUpdaterException( - "Component not found in contribution" + contribURI); - } else { - // start again - try { - composite.getComponents().remove(toRemove); - CompositeActivatorImpl impl = (CompositeActivatorImpl) compositeActivator; - impl.stop(toRemove); - impl.deactivateComponent(toRemove); - CompositeBuilderImpl builder = (CompositeBuilderImpl) compositeBuilder; - builder.detach(composite, toRemove); - } catch (Exception e) { - throw new CompositeUpdaterException( - "Cannot remove composite from the contribution" - + contribURI); - } - return toRemove; - } - } - -} diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterFactoryImpl.java b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterFactoryImpl.java deleted file mode 100644 index 7f5870ad55..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterFactoryImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.sca.contribution.updater.impl; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; -import org.apache.tuscany.sca.contribution.service.ContributionService; -import org.apache.tuscany.sca.contribution.updater.ComponentUpdater; -import org.apache.tuscany.sca.contribution.updater.CompositeUpdater; -import org.apache.tuscany.sca.contribution.updater.ContributionUpdater; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.assembly.CompositeActivator; -import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; -import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; -import org.apache.tuscany.sca.contribution.updater.impl.ComponentUpdaterImpl; -import org.apache.tuscany.sca.contribution.updater.impl.CompositeUpdaterImpl; -import org.apache.tuscany.sca.host.embedded.impl.ReallySmallRuntime; - -public class ContributionUpdaterFactoryImpl implements ContributionUpdater { - private AssemblyFactory assembly; - private JavaInterfaceFactory javaFactory; - private CompositeActivator compositeActivator; - private CompositeBuilder compositeBuilder; - private ExtensionPointRegistry registry; - private ContributionService contribService; - private InterfaceContractMapper mapper; - - public ContributionUpdaterFactoryImpl(ReallySmallRuntime runtime) { - this.assembly = runtime.getAssemblyFactory(); - this.javaFactory = runtime.getExtensionPointRegistry() - .getExtensionPoint(ModelFactoryExtensionPoint.class) - .getFactory(JavaInterfaceFactory.class); - this.compositeActivator = runtime.getCompositeActivator(); - this.compositeBuilder = runtime.getCompositeBuilder(); - this.registry = runtime.getExtensionPointRegistry(); - this.contribService = runtime.getContributionService(); - this.mapper = runtime.getInterfaceContractMapper(); - } - - public void setContributionService(ContributionService s) { - this.contribService = s; - } - - public ComponentUpdater getComponentUpdater(String contribURI, - String compositeURI, String componentName) { - - return new ComponentUpdaterImpl(contribURI, compositeURI, - componentName, assembly, javaFactory, compositeBuilder, - compositeActivator, contribService, registry, mapper); - } - - public CompositeUpdater getCompositeUpdater(String contribURI, - String compositeURI) { - return new CompositeUpdaterImpl(assembly, contribURI, compositeURI, - compositeBuilder, compositeActivator, registry, contribService); - } - -} diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterTestCase.java b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterTestCase.java deleted file mode 100644 index 83d0224ad4..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterTestCase.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * 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.sca.contribution.updater.impl; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.ArrayList; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.node.SCANode; - -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * Test ContributionUpdater. - * - */ -public class ContributionUpdaterTestCase { - - // private static SCADomain domain; - private static SCANode node; - private static MetaComponentHello helloMeta; - - @Before - public void setUp() throws Exception { - /* - * System.out.println("Setting up domain"); - * - * SCADomainFactory domainFactory = SCADomainFactory.newInstance(); - * domain = domainFactory.createSCADomain("http://localhost:9999"); - * - * System.out.println("Setting up calculator nodes"); - * - * ClassLoader cl = ContributionUpdaterTestCase.class.getClassLoader(); - * - * SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - * log.info("Staring entropy handler"); prng = - * SecureRandom.getInstance("SHA1PRNG"); } catch - * (NoSuchAlgorithmException e) { // TODO Auto-generated catch block - * e.printStackTrace(); } componentName = - * "HelloComponent"+this.uniqueID(); - * t.setAttribute("componentName",componentName); - * - * node = nodeFactory.createSCANode("http://localhost:8100/nodeA", - * "http://localhost:9999"); node.addContribution("nodeA", - * cl.getResource("nodeA/")); node.addToDomainLevelComposite(new - * QName("http://test", "HelloComposite")); node.start(); - * SCADomainFinder domainFinder = SCADomainFinder.newInstance(); domain = - * domainFinder.getSCADomain("http://localhost:9999"); helloMeta = new - * MetaComponentHello(); - * helloMeta.setComponentClass("org.apache.tuscany.sca.contribution.updater.impl.HelloComponent"); - */ - } - - @After - public void tearDown() throws Exception { - - } - - @Test - public void testAddNewComponent() throws ClassNotFoundException, - MalformedURLException { - /* - * String helloComponent1 = "\n" + ""+ ""; - * MetaComponent mc = - * MetaComponentFactory.newMetaComponent("HelloComponent1",helloComponent1); - * try { ((SCANodeImpl) node).addComponentToComposite(mc, "nodeA", - * "HelloComposite.composite"); GreetService greet = - * node.getDomain().getService(GreetService.class, "HelloComponent1"); - * greet.sayHello("Italian").equals("Ciao"); } catch (Exception e) { - * Assert.fail(e.getMessage()); } - */ - Assert.assertEquals("skip", "skip"); - } - - @Test - public void testWireComponents() throws ClassNotFoundException, - MalformedURLException { - Assert.assertEquals("skip", "skip"); - /* - * String helloComponent1 = "\n" + ""+ ""; - * String helloComponent2 = "\n" + ""+ ""; - * MetaComponent mc1 = - * MetaComponentFactory.newMetaComponent("HelloComponent1",helloComponent1); - * MetaComponent mc2 = - * MetaComponentFactory.newMetaComponent("HelloComponent2",helloComponent2); - * - * try { ((SCANodeImpl) node).addComponentToComposite(mc1, "nodeA", - * "HelloComposite.composite"); ((SCANodeImpl) - * node).addComponentToComposite(mc2, "nodeA", - * "HelloComposite.composite"); GreetService greet = - * node.getDomain().getService(GreetService.class, "HelloComponent1"); - * greet.sayHello("Italian").equals("Ciao"); } catch (Exception e) { - * Assert.fail(e.getMessage()); } - */ - } - -} diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/GreetService.java b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/GreetService.java deleted file mode 100644 index 0eb7fb692b..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/GreetService.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * 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.sca.contribution.updater.impl; - -import org.osoa.sca.annotations.Remotable; - -@Remotable -public interface GreetService { - String sayHello(String language); -} diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/HelloComponent.java b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/HelloComponent.java deleted file mode 100644 index 38fa2721bb..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/HelloComponent.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.sca.contribution.updater.impl; - -import org.osoa.sca.annotations.Service; - -@Service(GreetService.class) -public class HelloComponent implements GreetService { - private String[][] languageGreets = { - { "English", "Italian", "Japanese", "German" }, - { "Hello!", "Ciao!", "Konnici wa!", "Hallo!" } }; - - public String sayHello(String language) { - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 4; ++j) { - if (language.equals(languageGreets[i][j])) { - return languageGreets[0][0]; - } - } - return "I don't speak your language"; - } - -} diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/MetaComponentHello.java b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/MetaComponentHello.java deleted file mode 100644 index 1495ff2cea..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/java/org/apache/tuscany/sca/contribution/updater/impl/MetaComponentHello.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.sca.contribution.updater.impl; - -import java.io.StringReader; -import java.net.URI; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.security.SecureRandom; -import java.util.logging.Logger; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.assembly.MetaComponent; - -public class MetaComponentHello implements MetaComponent { - private String componentName; - private String scdl; - private boolean loadedFromString = false; - private Logger log = Logger.getLogger(MetaComponentHello.class.getName()); - - public MetaComponentHello() { - } - - private MetaComponentHello(String scdl, boolean loadedFromString) { - this.scdl = scdl; - this.loadedFromString = loadedFromString; - } - - public MetaComponent fromSCDL(String scdl) { - return new MetaComponentHello(scdl, true); - } - - public XMLStreamReader build() throws Exception { - XMLInputFactory factory = XMLInputFactory.newInstance(); - return factory.createXMLStreamReader(new StringReader(scdl)); - } - - public String getName() { - - return componentName; - } - -} diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/resources/HelloComposite.composite b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/resources/HelloComposite.composite deleted file mode 100644 index 76714a0e9c..0000000000 --- a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/resources/HelloComposite.composite +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/resources/repository/sample-calculator.jar b/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/resources/repository/sample-calculator.jar deleted file mode 100644 index 9c46c679d2..0000000000 Binary files a/branches/sca-trunk-20080910/modules/contribution-updater-impl/src/test/resources/repository/sample-calculator.jar and /dev/null differ -- cgit v1.2.3