* Gets the component type description.
*/
@Override
public Element getDescription() {
Element description = super.getDescription();
if (getFactory().declaration != null) {
ComponentDeclaration declaration = getFactory().declaration;
Element componentDescription = new Element(COMPONENT_DECLARATION_PROPERTY, APAM_NAMESPACE);
componentDescription.addAttribute(new Attribute("name",declaration.getName()));
componentDescription.addAttribute(new Attribute("type",declaration.getClass().getSimpleName()));
if (declaration instanceof ImplementationDeclaration) {
ImplementationDeclaration implementation = (ImplementationDeclaration) declaration;
if (implementation.getSpecification() != null ) {
componentDescription.addAttribute(new Attribute("specification",implementation.getSpecification().getName()));
}
}
if (declaration instanceof CompositeDeclaration) {
CompositeDeclaration composite = (CompositeDeclaration) declaration;
if (composite.getSpecification() != null && composite.getMainComponent() != null) {
componentDescription.addAttribute(new Attribute("main",composite.getMainComponent().getName()));
}
}
if (declaration instanceof InstanceDeclaration) {
InstanceDeclaration instance = (InstanceDeclaration) declaration;
if (instance.getImplementation() != null ) {
componentDescription.addAttribute(new Attribute("implementation",instance.getImplementation().getName()));
}
}
Element providesDescription = new Element("provides", APAM_NAMESPACE);;
for (ResourceReference resource : declaration.getProvidedResources()) {
Element provideDescription = new Element("provides", APAM_NAMESPACE);
provideDescription.addAttribute(new Attribute("resource", resource.toString()));
providesDescription.addElement(provideDescription);
}
componentDescription.addElement(providesDescription);
Element relationsDescription = new Element("dependencies", APAM_NAMESPACE);;
for (RelationDeclaration relationDeclaration : declaration.getRelations()) {
Element relationDescription = new Element("relation", APAM_NAMESPACE);
relationDescription.addAttribute(new Attribute("id", relationDeclaration.getIdentifier()));
relationDescription.addAttribute(new Attribute("resource", relationDeclaration.getTarget().toString()));
relationDescription.addAttribute(new Attribute("multiple", Boolean.toString(relationDeclaration.isMultiple())));
Element injectionsDescription = new Element("instrumentations", APAM_NAMESPACE);
for (RequirerInstrumentation injectionDeclaration : relationDeclaration.getInstrumentations()) {
Element injectionDescription = new Element("instrumentation", APAM_NAMESPACE);
injectionDescription.addAttribute(new Attribute("name", injectionDeclaration.getName()));
injectionDescription.addAttribute(new Attribute("resource", injectionDeclaration.getRequiredResource().toString()));
injectionDescription.addAttribute(new Attribute("multiple", Boolean.toString(injectionDeclaration.acceptMultipleProviders())));
injectionsDescription.addElement(injectionDescription);
}
relationDescription.addElement(injectionsDescription);
Element constraintsDescription = new Element("constraints", APAM_NAMESPACE);
for (String constraint : relationDeclaration.getImplementationConstraints()) {
Element constraintDescription = new Element("implementation", APAM_NAMESPACE);
constraintDescription.addAttribute(new Attribute("filter", constraint));
constraintsDescription.addElement(constraintDescription);
}
for (String constraint : relationDeclaration.getInstanceConstraints()) {
Element constraintDescription = new Element("instance", APAM_NAMESPACE);
constraintDescription.addAttribute(new Attribute("filter", constraint));
constraintsDescription.addElement(constraintDescription);
}
relationDescription.addElement(constraintsDescription);
Element preferencesDescription = new Element("preferences", APAM_NAMESPACE);
int priority=0;
for ( String preference : relationDeclaration.getImplementationPreferences()) {
Element preferenceDescription = new Element("implementation", APAM_NAMESPACE);
preferenceDescription.addAttribute(new Attribute("filter", preference));
preferenceDescription.addAttribute(new Attribute("priority", Integer.toString(priority++)));
preferencesDescription.addElement(preferenceDescription);
}
priority=0;
for (String preference : relationDeclaration.getInstancePreferences()) {
Element preferenceDescription = new Element("instance", APAM_NAMESPACE);
preferenceDescription.addAttribute(new Attribute("filter", preference));
preferenceDescription.addAttribute(new Attribute("priority", Integer.toString(priority++)));
preferencesDescription.addElement(preferenceDescription);
}
relationDescription.addElement(preferencesDescription);
relationsDescription.addElement(relationDescription);
}
componentDescription.addElement(relationsDescription);
Element definitionsDescription = new Element("definitions", APAM_NAMESPACE);;
for (PropertyDefinition propertyDeclaration : declaration.getPropertyDefinitions()) {
Element definitionDescription = new Element("property", APAM_NAMESPACE);
definitionDescription.addAttribute(new Attribute("name", propertyDeclaration.getName()));
definitionDescription.addAttribute(new Attribute("type", propertyDeclaration.getType()));
if (propertyDeclaration.hasDefaultValue())
definitionDescription.addAttribute(new Attribute("value", propertyDeclaration.getDefaultValue().toString()));
definitionsDescription.addElement(definitionDescription);
}
componentDescription.addElement(definitionsDescription);
Element propertiesDescription = new Element("properties", APAM_NAMESPACE);;
for (Entry<String,String> propertyEntry : declaration.getProperties().entrySet()) {
Element propertyDescription = new Element("property", APAM_NAMESPACE);
propertyDescription.addAttribute(new Attribute("name", propertyEntry.getKey()));
if (propertyEntry.getValue() != null)
propertyDescription.addAttribute(new Attribute("value", propertyEntry.getValue().toString()));
propertiesDescription.addElement(propertyDescription);
}
componentDescription.addElement(propertiesDescription);
description.addElement(componentDescription);