XPath xpath = xPathFactory.newXPath();
xpath.setNamespaceContext(reader.getNamespaceContext());
try {
componentProperty.setSourceXPathExpression(xpath.compile(source));
} catch (XPathExpressionException e) {
throw new ContributionReadException(e);
}
}
componentProperty.setFile(getString(reader, FILE));
policyProcessor.readPolicies(property, reader);
readAbstractProperty(componentProperty, reader);
// Read the property value
Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
property.setValue(value);
component.getProperties().add(componentProperty);
} else {
// Read a <composite><property>
property = assemblyFactory.createProperty();
policyProcessor.readPolicies(property, reader);
readAbstractProperty(property, reader);
// Read the property value
Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
property.setValue(value);
composite.getProperties().add(property);
}
// TUSCANY-1949
// If the proerty doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
property = null;
componentProperty = null;
}
} else if (COMPONENT_QNAME.equals(name)) {
// Read a <component>
component = assemblyFactory.createComponent();
component.setName(getString(reader, NAME));
if (isSet(reader, AUTOWIRE)) {
component.setAutowire(getBoolean(reader, AUTOWIRE));
}
if (isSet(reader, URI)) {
component.setURI(getString(reader, URI));
}
component.setConstrainingType(readConstrainingType(reader));
composite.getComponents().add(component);
policyProcessor.readPolicies(component, reader);
} else if (WIRE_QNAME.equals(name)) {
// Read a <wire>
wire = assemblyFactory.createWire();
ComponentReference source = assemblyFactory.createComponentReference();
source.setUnresolved(true);
source.setName(getString(reader, SOURCE));
wire.setSource(source);
ComponentService target = assemblyFactory.createComponentService();
target.setUnresolved(true);
target.setName(getString(reader, TARGET));
wire.setTarget(target);
composite.getWires().add(wire);
policyProcessor.readPolicies(wire, reader);
} else if (CALLBACK_QNAME.equals(name)) {
// Read a <callback>
callback = assemblyFactory.createCallback();
contract.setCallback(callback);
policyProcessor.readPolicies(callback, reader);
} else if (OPERATION_QNAME.equals(name)) {
// Read an <operation>
ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
operation.setName(getString(reader, NAME));
operation.setUnresolved(true);
if (callback != null) {
policyProcessor.readPolicies(operation, reader);
} else {
policyProcessor.readPolicies(operation, reader);
}
OperationsConfigurator opConfigurator = null;
if ( compositeService != null ) {
opConfigurator = compositeService;
} else if ( componentService != null ) {
opConfigurator = componentService;
} else if ( compositeReference != null ) {
opConfigurator = compositeReference;
} else if ( componentReference != null ) {
opConfigurator = componentReference;
}
opConfigurator.getConfiguredOperations().add(operation);
} else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
// Read an implementation.composite
Composite implementation = assemblyFactory.createComposite();
implementation.setName(getQName(reader, NAME));
implementation.setUnresolved(true);
component.setImplementation(implementation);
policyProcessor.readPolicies(implementation, reader);
} else {
// Read an extension element
Object extension = extensionProcessor.read(reader);
if (extension != null) {
if (extension instanceof InterfaceContract) {
// <service><interface> and
// <reference><interface>
if (contract != null) {
contract.setInterfaceContract((InterfaceContract)extension);
} else {
if (name.getNamespaceURI().equals(SCA10_NS)) {
throw new ContributionReadException(
"Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
} else {
composite.getExtensions().add(extension);
}
}
} else if (extension instanceof Binding) {
if ( extension instanceof PolicySetAttachPoint ) {
IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
bindingType.setName(name);
bindingType.setUnresolved(true);
((PolicySetAttachPoint)extension).setType(bindingType);
}
// <service><binding> and
// <reference><binding>
if (callback != null) {
callback.getBindings().add((Binding)extension);
} else {
if (contract != null) {
contract.getBindings().add((Binding)extension);
} else {
if (name.getNamespaceURI().equals(SCA10_NS)) {
throw new ContributionReadException(
"Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
} else {
composite.getExtensions().add(extension);
}
}
}
} else if (extension instanceof Implementation) {
if ( extension instanceof PolicySetAttachPoint ) {
IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
implType.setName(name);
implType.setUnresolved(true);
((PolicySetAttachPoint)extension).setType(implType);
}
// <component><implementation>
if (component != null) {
component.setImplementation((Implementation)extension);
} else {
if (name.getNamespaceURI().equals(SCA10_NS)) {
throw new ContributionReadException(
"Unexpected <implementation> element found. It should appear inside a <component> element");
} else {
composite.getExtensions().add(extension);
}
}