diff options
Diffstat (limited to 'sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca')
4 files changed, 665 insertions, 0 deletions
diff --git a/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ArtifactsFinder.java b/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ArtifactsFinder.java new file mode 100644 index 0000000000..2587f9393a --- /dev/null +++ b/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ArtifactsFinder.java @@ -0,0 +1,54 @@ +/* + * 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<DeployedArtifact> artifacts) { + for (DeployedArtifact artifact : artifacts) { + if (artifact.getModel() instanceof Composite) { + Composite composite = (Composite) artifact.getModel(); + 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/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ComponentUpdaterImpl.java b/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ComponentUpdaterImpl.java new file mode 100644 index 0000000000..a6a6084f5f --- /dev/null +++ b/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ComponentUpdaterImpl.java @@ -0,0 +1,381 @@ +/* + * 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<DeployedArtifact> 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<DeployedArtifact> 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<DeployedArtifact> 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<ComponentReference> 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/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/CompositeUpdaterImpl.java b/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/CompositeUpdaterImpl.java new file mode 100644 index 0000000000..ccba6b5a98 --- /dev/null +++ b/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/CompositeUpdaterImpl.java @@ -0,0 +1,155 @@ +/* + * 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.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<DeployedArtifact> 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<DeployedArtifact> artifacts = contrib.getArtifacts(); + Composite composite = ArtifactsFinder.findComposite(compositeURI, + artifacts); + return ArtifactsFinder.findComponent(composite, componentName); + } + + public Component removeComponent(String componentName) + throws CompositeUpdaterException { + Contribution contrib = contribService.getContribution(contribURI); + List<DeployedArtifact> artifacts = contrib.getArtifacts(); + + Composite composite = ArtifactsFinder.findComposite(compositeURI, + artifacts); + List<Component> 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/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterFactoryImpl.java b/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterFactoryImpl.java new file mode 100644 index 0000000000..7f5870ad55 --- /dev/null +++ b/sca-java-1.x/tags/1.2/modules/contribution-updater-impl/src/main/java/org/apache/tuscany/sca/contribution/updater/impl/ContributionUpdaterFactoryImpl.java @@ -0,0 +1,75 @@ +/* + * 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); + } + +} |