You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tuscany.apache.org by Giorgio Zoppi <gi...@gmail.com> on 2007/11/13 18:55:38 UTC

Adding Component Dynamically to an existing composite.

Hi,
that's ok. I'm able to add a component to a given composite in a given
contribution. I added a method in SCANodeImpl:

public void addComponentToComposite(MetaComponent c, String
contributionURI, String compositeURI) throws Exception
	{
		StAXArtifactProcessorExtensionPoint staxProcessors =
this.nodeRuntime.getExtensionPointRegistry().getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
		MetaComponentProcessor processor = (MetaComponentProcessor)
staxProcessors.getProcessor(Component.class);
		Contribution contrib =
nodeRuntime.getContributionService().getContribution(contributionURI);
		List<DeployedArtifact> artifacts = contrib.getArtifacts();
		boolean found = false;
		for (DeployedArtifact artifact: artifacts)
		{
			if (artifact.getModel() instanceof Composite)
			{
				Composite composite = (Composite) artifact.getModel();
				if (composite.getURI().equals(compositeURI))
				{
					processor.setComposite(composite);
					processor.read(c.build());
					found = true;
					break;
				}
			}	
		}
		if (found)
		{
			Component component = processor.getParsedComponent();
			Composite augmentedComposite = processor.getParsedComposite();
			processor.resolve(component, contrib.getModelResolver());
			nodeRuntime.getCompositeBuilder().attach(augmentedComposite, component);
			CompositeActivatorImpl impl = (CompositeActivatorImpl)
nodeRuntime.getCompositeActivator();
		    impl.activateComponent(component);
		    registerRemoteServicesByComponent(component);
		    resolveRemoteReferencesByComponent(component);
		    nodeRuntime.getCompositeActivator().start(component);
		}
	}

A new component processor in artifacts' processor registry and
modified parts of ConfigureBuilderImpl, WireBuilderImpl to adapt to a
single component.

My use case was : Given a MetaComponent (aka component definition ),
try to add a new component to a given composition. A MetaComponent is
like that:

public class AddServiceComponent1 implements MetaComponent {
	private String CMP_DEFINITION = "<component
xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"
name=\"AddServiceComponent1\">\n" +
			"<implementation.java class=\"calculator.AddServiceImpl\"/>"+
			"<service name=\"AddService\">"+
		    "<binding.sca uri=\"http://localhost:12000/AddServiceComponent1\"/>"+
		    "</service></component>";
	
	public XMLStreamReader build() throws Exception {
		System.out.println(CMP_DEFINITION);
		XMLInputFactory factory = XMLInputFactory.newInstance();
		return factory.createXMLStreamReader(new StringReader(CMP_DEFINITION));
		
	}
}
I'm updating my previous JIRA with a patch. Please in the patch, it
could be dummy changes, skim it and take the relevant part. I don't
remember all what i typed.
Cheers,
Giot

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