}
if (scope != null && current != Scope.INSTANCE) {
scope = current;
}
}
ContextFactory contextFactory;
try {
contextFactory = createContextFactory(component.getName(), component.getImplementation(), scope);
// create target-side wire invocation chains for each service offered by the implementation
for (ConfiguredService configuredService : component.getConfiguredServices()) {
Service service = configuredService.getPort();
TargetWireFactory wireFactory = wireFactoryService.createTargetFactory(configuredService);
contextFactory.addTargetWireFactory(service.getName(), wireFactory);
}
// handle properties
List<ConfiguredProperty> configuredProperties = component.getConfiguredProperties();
if (configuredProperties != null) {
for (ConfiguredProperty property : configuredProperties) {
contextFactory.addProperty(property.getName(), property.getValue());
}
}
// handle references and source side reference chains
List<ConfiguredReference> configuredReferences = component.getConfiguredReferences();
if (configuredReferences != null) {
for (ConfiguredReference reference : configuredReferences) {
if (reference.getPort().getMultiplicity() == Multiplicity.ZERO_N || reference.getPort().getMultiplicity() == Multiplicity.ZERO_ONE){
if (reference.getTargetConfiguredServices().size() < 1 && reference.getTargets().size() <1 ){
continue; // not required, not configured fix TUSCANY-299
}
}
List<SourceWireFactory> wireFactories = wireFactoryService.createSourceFactory(reference);
String refName = reference.getPort().getName();
Class refClass = reference.getPort().getServiceContract().getInterface();
boolean multiplicity = reference.getPort().getMultiplicity() == Multiplicity.ONE_N
|| reference.getPort().getMultiplicity() == Multiplicity.ZERO_N;
contextFactory.addSourceWireFactories(refName, refClass, wireFactories, multiplicity);
}
}
component.setContextFactory(contextFactory);
} catch (BuilderException e) {
e.addContextName(component.getName());