for (Service service : compositeServices) {
// Set default binding names
// Create default SCA binding
if (service.getBindings().isEmpty()) {
SCABinding scaBinding = createSCABinding();
service.getBindings().add(scaBinding);
}
// Initialize binding names and URIs
for (Binding binding : service.getBindings()) {
// Binding name defaults to the service name
if (binding.getName() == null) {
binding.setName(service.getName());
}
String bindingURI;
if (binding.getURI() == null) {
if (compositeServices.size() > 1) {
// Binding URI defaults to parent URI / binding name
bindingURI = String.valueOf(binding.getName());
if (parentURI != null) {
bindingURI = URI.create(parentURI + '/').resolve(bindingURI).toString();
}
} else {
// If there's only one service then binding URI defaults
// to the parent URI
if (parentURI != null) {
bindingURI = parentURI;
} else {
bindingURI = String.valueOf(binding.getName());
}
}
} else {
// Combine the specified binding URI with the component URI
bindingURI = binding.getURI();
if (parentURI != null) {
bindingURI = URI.create(parentURI + '/').resolve(bindingURI).toString();
}
}
binding.setURI(bindingURI);
}
if (service.getCallback() != null) {
for (Binding binding : service.getCallback().getBindings()) {
if (binding.getName() == null) {
binding.setName(service.getName());
}
}
}
}
// Initialize reference bindings
for (Reference reference : composite.getReferences()) {
// Create default SCA binding
if (reference.getBindings().isEmpty()) {
SCABinding scaBinding = createSCABinding();
reference.getBindings().add(scaBinding);
}
// Set binding names
for (Binding binding : reference.getBindings()) {
if (binding.getName() == null) {
binding.setName(reference.getName());
}
}
if (reference.getCallback() != null) {
for (Binding binding : reference.getCallback().getBindings()) {
if (binding.getName() == null) {
binding.setName(reference.getName());
}
}
}
}
// Initialize all component services and references
Map<String, Component> components = new HashMap<String, Component>();
for (Component component : composite.getComponents()) {
// Index all components and check for duplicates
if (components.containsKey(component.getName())) {
warning("Duplicate component name: " + composite.getName()
+ " : "
+ component.getName(), composite);
} else {
components.put(component.getName(), component);
}
// Propagate the autowire flag from the composite to components
if (component.getAutowire() == null) {
component.setAutowire(composite.getAutowire());
}
if (component.getImplementation() instanceof ComponentPreProcessor) {
((ComponentPreProcessor)component.getImplementation()).preProcess(component);
}
// Index properties, services and references
Map<String, Service> services = new HashMap<String, Service>();
Map<String, Reference> references = new HashMap<String, Reference>();
Map<String, Property> properties = new HashMap<String, Property>();
indexImplementationPropertiesServicesAndReferences(component,
services,
references,
properties);
// Index component services, references and properties
// Also check for duplicates
Map<String, ComponentService> componentServices =
new HashMap<String, ComponentService>();
Map<String, ComponentReference> componentReferences =
new HashMap<String, ComponentReference>();
Map<String, ComponentProperty> componentProperties =
new HashMap<String, ComponentProperty>();
indexComponentPropertiesServicesAndReferences(component,
componentServices,
componentReferences,
componentProperties);
// Reconcile component services/references/properties and
// implementation services/references and create component
// services/references/properties for the services/references
// declared by the implementation
reconcileServices(component, services, componentServices);
reconcileReferences(component, references, componentReferences);
reconcileProperties(component, properties, componentProperties);
// Configure or create callback services for component's references
// with callbacks
configureCallbackServices(component, componentServices);
// Configure or create callback references for component's services
// with callbacks
configureCallbackReferences(component, componentReferences);
// Create self references to the component's services
// if (!(component.getImplementation() instanceof Composite)) {
// createSelfReferences(component);
// }
// Initialize service bindings
for (ComponentService componentService : component.getServices()) {
// Create default SCA binding
if (componentService.getBindings().isEmpty()) {
SCABinding scaBinding = createSCABinding();
componentService.getBindings().add(scaBinding);
}
// Set binding names and URIs
for (Binding binding : componentService.getBindings()) {
// Binding name defaults to the service name
if (binding.getName() == null) {
binding.setName(componentService.getName());
}
String bindingURI;
if (binding.getURI() == null) {
//if (componentServices.size() > 1) {
if (component.getServices().size() > 1) {
// Binding URI defaults to component URI / binding name
bindingURI = String.valueOf(binding.getName());
bindingURI = URI.create(component.getURI() + '/').resolve(bindingURI).toString();
} else {
// If there's only one service then binding URI defaults
// to the component URI
bindingURI = component.getURI();
}
} else {
// Combine the specified binding URI with the component URI
bindingURI = binding.getURI();
bindingURI = URI.create(component.getURI() + '/').resolve(bindingURI).toString();
}
binding.setURI(bindingURI);
}
if (componentService.getCallback() != null) {
for (Binding binding : componentService.getCallback().getBindings()) {
if (binding.getName() == null) {
binding.setName(componentService.getName());
}
}
}
}
// Initialize reference bindings
for (ComponentReference componentReference : component.getReferences()) {
// Create default SCA binding
if (componentReference.getBindings().isEmpty()) {
SCABinding scaBinding = createSCABinding();
componentReference.getBindings().add(scaBinding);
}
// Set binding names
for (Binding binding : componentReference.getBindings()) {