in modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java [585:932]
public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
// Write <composite> element
writeStartDocument(writer,
COMPOSITE,
writeConstrainingType(composite),
new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()),
new XAttr(NAME, composite.getName().getLocalPart()),
new XAttr(LOCAL, composite.isLocal() ? Boolean.TRUE : null),
new XAttr(AUTOWIRE, composite.getAutowire()),
policyProcessor.writePolicies(composite));
//write extended attributes
this.writeExtendedAttributes(writer, composite, extensionAttributeProcessor);
// Write <include> elements
for (Composite include : composite.getIncludes()) {
String uri = include.isUnresolved()? include.getURI() : null;
writeStart(writer,
INCLUDE,
new XAttr(NAME, include.getName()),
new XAttr(URI, uri));
//write extended attributes
this.writeExtendedAttributes(writer, include, extensionAttributeProcessor);
writeEnd(writer);
}
// Write <service> elements
for (Service service : composite.getServices()) {
CompositeService compositeService = (CompositeService)service;
Component promotedComponent = compositeService.getPromotedComponent();
ComponentService promotedService = compositeService.getPromotedService();
String promote;
if (promotedService != null) {
if (promotedService.getName() != null) {
promote = promotedComponent.getName() + '/' + promotedService.getName();
} else {
promote = promotedComponent.getName();
}
} else {
promote = null;
}
writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote),
policyProcessor.writePolicies(service));
//write extended attributes
this.writeExtendedAttributes(writer, service, extensionAttributeProcessor);
// Write service interface
extensionProcessor.write(service.getInterfaceContract(), writer);
// Write bindings
for (Binding binding : service.getBindings()) {
extensionProcessor.write(binding, writer);
}
// Write <callback> element
if (service.getCallback() != null) {
Callback callback = service.getCallback();
writeStart(writer, CALLBACK,
policyProcessor.writePolicies(callback));
//write extended attributes
this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
// Write callback bindings
for (Binding binding : callback.getBindings()) {
extensionProcessor.write(binding, writer);
}
// Write extensions
for (Object extension : callback.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
// Write extensions
for (Object extension : service.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
// Write <component> elements
for (Component component : composite.getComponents()) {
writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()),
new XAttr(URI, component.getURI()),
new XAttr(AUTOWIRE, component.getAutowire()),
policyProcessor.writePolicies(component));
//write extended attributes
this.writeExtendedAttributes(writer, component, extensionAttributeProcessor);
// Write the component implementation
Implementation implementation = component.getImplementation();
// check that we really have CompositeImpl and treat this specially. Some
// extension extend CompositeImpl and we want these to be treated by the extension
// processor.
if ((implementation != null ) && (implementation.getClass().equals(CompositeImpl.class))) {
writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, ((Composite)implementation).getName()));
//write extended attributes
this.writeExtendedAttributes(writer, (Composite)implementation, extensionAttributeProcessor);
writeEnd(writer);
} else {
extensionProcessor.write(component.getImplementation(), writer);
}
for (Object extension : component.getExtensions()) {
extensionProcessor.write(extension, writer);
}
// Write <service> elements
for (ComponentService service : component.getServices()) {
if (service.isCallback() == false){
writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
policyProcessor.writePolicies(service));
//write extended attributes
this.writeExtendedAttributes(writer, service, extensionAttributeProcessor);
// Write service interface
extensionProcessor.write(service.getInterfaceContract(), writer);
// Write bindings
for (Binding binding : service.getBindings()) {
extensionProcessor.write(binding, writer);
}
// Write <callback> element
if (service.getCallback() != null) {
Callback callback = service.getCallback();
writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
//write extended attributes
this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
// Write bindings
for (Binding binding : callback.getBindings()) {
extensionProcessor.write(binding, writer);
}
// Write extensions
for (Object extension : callback.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
// Write extensions
for (Object extension : service.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
}
// Write <reference> elements
for (ComponentReference reference : component.getReferences()) {
if (reference.isCallback() == false){
writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
new XAttr(AUTOWIRE, reference.getAutowire()),
writeMultiplicity(reference),
writeTargets(reference),
policyProcessor.writePolicies(reference));
//write extended attributes
this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor);
// Write reference interface
extensionProcessor.write(reference.getInterfaceContract(), writer);
// Write bindings
for (Binding binding : reference.getBindings()) {
extensionProcessor.write(binding, writer);
}
// Write callback
if (reference.getCallback() != null) {
Callback callback = reference.getCallback();
writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
//write extended attributes
this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
// Write callback bindings
for (Binding binding : callback.getBindings()) {
extensionProcessor.write(binding, writer);
}
// Write extensions
for (Object extensions : callback.getExtensions()) {
extensionProcessor.write(extensions, writer);
}
writeEnd(writer);
}
// Write extensions
for (Object extensions : reference.getExtensions()) {
extensionProcessor.write(extensions, writer);
}
writeEnd(writer);
}
}
// Write <property> elements
for (ComponentProperty property : component.getProperties()) {
writeStart(writer,
PROPERTY,
new XAttr(NAME, property.getName()),
new XAttr(MUST_SUPPLY, property.isMustSupply()),
new XAttr(MANY, property.isMany()),
new XAttr(TYPE, property.getXSDType()),
new XAttr(ELEMENT, property.getXSDElement()),
new XAttr(SOURCE, property.getSource()),
new XAttr(FILE, property.getFile()),
policyProcessor.writePolicies(property));
//write extended attributes
this.writeExtendedAttributes(writer, property, extensionAttributeProcessor);
// Write property value
writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
// Write extensions
for (Object extension : property.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
writeEnd(writer);
}
// Write <reference> elements
for (Reference reference : composite.getReferences()) {
CompositeReference compositeReference = (CompositeReference)reference;
// Write list of promoted references
List<String> promote = new ArrayList<String>();
for (ComponentReference promoted: compositeReference.getPromotedReferences()) {
promote.add(promoted.getName());
}
// Write <reference> element
writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
new XAttr(PROMOTE, promote),
writeMultiplicity(reference),
policyProcessor.writePolicies(reference));
//write extended attributes
this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor);
// Write reference interface
extensionProcessor.write(reference.getInterfaceContract(), writer);
// Write bindings
for (Binding binding : reference.getBindings()) {
extensionProcessor.write(binding, writer);
}
// Write <callback> element
if (reference.getCallback() != null) {
Callback callback = reference.getCallback();
writeStart(writer, CALLBACK);
//write extended attributes
this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
// Write callback bindings
for (Binding binding : callback.getBindings()) {
extensionProcessor.write(binding, writer);
}
// Write extensions
for (Object extension : callback.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
// Write extensions
for (Object extension : reference.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
// Write <property> elements
for (Property property : composite.getProperties()) {
writeStart(writer,
PROPERTY,
new XAttr(NAME, property.getName()),
new XAttr(MUST_SUPPLY, property.isMustSupply()),
new XAttr(MANY, property.isMany()),
new XAttr(TYPE, property.getXSDType()),
new XAttr(ELEMENT, property.getXSDElement()),
policyProcessor.writePolicies(property));
//write extended attributes
this.writeExtendedAttributes(writer, property, extensionAttributeProcessor);
// Write property value
writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
// Write extensions
for (Object extension : property.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
// Write <wire> elements
for (Wire wire : composite.getWires()) {
writeStart(writer, WIRE, new XAttr(SOURCE, wire.getSource().getName()), new XAttr(TARGET, wire
.getTarget().getName()));
//write extended attributes
this.writeExtendedAttributes(writer, wire, extensionAttributeProcessor);
// Write extensions
for (Object extension : wire.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEnd(writer);
}
for (Object extension : composite.getExtensions()) {
extensionProcessor.write(extension, writer);
}
writeEndDocument(writer);
}