use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class TestBadConfigurations method dumpElement.
// DEBUG
private String dumpElement(int level, Element element) {
StringBuilder sb = new StringBuilder();
// Enter tag
for (int i = 0; i < level; i++) {
sb.append(" ");
}
sb.append('<');
sb.append(element.getName());
Attribute[] attributes = element.getAttributes();
for (int i = 0; i < attributes.length; i++) {
Attribute attribute = attributes[i];
sb.append(' ');
sb.append(attribute.getName());
sb.append('=');
sb.append(attribute.getValue());
}
sb.append(">\n");
// Children
Element[] elements = element.getElements();
for (int i = 0; i < elements.length; i++) {
sb.append(dumpElement(level + 1, elements[i]));
}
// Exit tag
for (int i = 0; i < level; i++) {
sb.append(" ");
}
sb.append("</" + element.getName() + ">\n");
return sb.toString();
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class EventAdminPublisherHandler method initializeComponentFactory.
/**
* Initializes the component type.
*
* @param cd the component type description to populate
* @param metadata the component type metadata
* @throws ConfigurationException if the given metadata is incorrect.
* @see org.apache.felix.ipojo.Handler#initializeComponentFactory(
* org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
*/
public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
// Update the current component description
Dictionary dict = new Properties();
PropertyDescription pd = new PropertyDescription(TOPICS_PROPERTY, Dictionary.class.getName(), dict.toString());
cd.addProperty(pd);
// Get Metadata publishers
Element[] publishers = metadata.getElements("publisher", NAMESPACE);
// if publisher is null, look for 'publishes' elements
if (publishers == null || publishers.length == 0) {
publishers = metadata.getElements("publishes", NAMESPACE);
}
if (publishers != null) {
// Maps used to check name and field are unique
Set nameSet = new HashSet();
Set fieldSet = new HashSet();
// Check all publishers are well formed
for (int i = 0; i < publishers.length; i++) {
// Check the publisher configuration is correct by creating an
// unused publisher metadata
EventAdminPublisherMetadata publisherMetadata = new EventAdminPublisherMetadata(publishers[i]);
String name = publisherMetadata.getName();
info(LOG_PREFIX + "Checking publisher " + name);
// Check field existence and type
String field = publisherMetadata.getField();
FieldMetadata fieldMetadata = getPojoMetadata().getField(publisherMetadata.getField(), Publisher.class.getName());
if (fieldMetadata == null) {
throw new ConfigurationException("Field not found in the component : " + Publisher.class.getName() + " " + field);
}
// Check name and field are unique
if (nameSet.contains(name)) {
throw new ConfigurationException("A publisher with the same name already exists : " + name);
} else if (fieldSet.contains(field)) {
throw new ConfigurationException("The field " + field + " is already associated to a publisher");
}
nameSet.add(name);
fieldSet.add(field);
}
} else {
info(LOG_PREFIX + "No publisher to check");
}
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class EventAdminPublisherHandler method configure.
/**
* Constructor.
*
* @param metadata the component type metadata
* @param conf the instance configuration
* @throws ConfigurationException if one event publication is not correct
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(Element metadata, Dictionary conf) throws ConfigurationException {
// Store the component manager
m_manager = getInstanceManager();
// Get the topics instance configuration
Dictionary instanceTopics = (Dictionary) conf.get(TOPICS_PROPERTY);
// Get Metadata publishers
Element[] publishers = metadata.getElements("publisher", NAMESPACE);
// if publisher is null, look for 'publishes' elements
if (publishers == null || publishers.length == 0) {
publishers = metadata.getElements("publishes", NAMESPACE);
}
if (publishers != null) {
// map
for (int i = 0; i < publishers.length; i++) {
// Extract the publisher configuration
EventAdminPublisherMetadata publisherMetadata = new EventAdminPublisherMetadata(publishers[i]);
String name = publisherMetadata.getName();
info(LOG_PREFIX + "Configuring publisher " + name);
// Get the topic instance configuration if redefined
String topicsString = (instanceTopics != null) ? (String) instanceTopics.get(name) : null;
if (topicsString != null) {
publisherMetadata.setTopics(topicsString);
}
// Check the publisher is correctly configured
publisherMetadata.check();
// Create the associated Publisher and insert it in the
// publisher map
Publisher publisher = new PublisherImpl(this, publisherMetadata.getTopics(), publisherMetadata.isSynchronous(), publisherMetadata.getDataKey(), m_manager.getInstanceName());
m_publishersByField.put(publisherMetadata.getField(), publisher);
// Register the callback that return the publisher
// reference when the specified field is read by the
// POJO.
FieldMetadata fieldMetadata = getPojoMetadata().getField(publisherMetadata.getField(), Publisher.class.getName());
m_manager.register(fieldMetadata, this);
}
} else {
info(LOG_PREFIX + "No publisher to configure");
}
setValidity(true);
debug(LOG_PREFIX + "Setup description....");
// Initialize the description.
m_description = new EventAdminPublisherHandlerDescription(this, m_publishersByField.values());
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class EventAdminPublisherHandlerDescription method getHandlerInfo.
/**
* Gets the handler description.
* @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
*/
public Element getHandlerInfo() {
Element root = super.getHandlerInfo();
for (int i = 0; i < m_publishersDescriptions.size(); i++) {
PublisherDescription p = (PublisherDescription) m_publishersDescriptions.get(i);
Element publisher = new Element("Publisher", "");
publisher.addAttribute(new Attribute("name", p.getName()));
publisher.addAttribute(new Attribute("synchronous", String.valueOf(p.isSynchronous())));
publisher.addAttribute(new Attribute("data_key", p.getDataKey()));
Element topics = new Element("Topics", "");
if (p.getTopics() != null) {
for (int j = 0; j < p.getTopics().length; j++) {
String topic = p.getTopics()[j];
Element e_topic = new Element("topic", "");
topics.addElement(e_topic);
e_topic.addAttribute(new Attribute("name", topic));
}
}
publisher.addElement(topics);
root.addElement(publisher);
}
return root;
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class TestManipulationMetadata method testGetMetadata.
@Test
public void testGetMetadata() {
String header = (String) getTestBundle().getHeaders().get("iPOJO-Components");
Element elem = null;
try {
elem = ManifestMetadataParser.parseHeaderMetadata(header);
} catch (ParseException e) {
fail("Parse Exception when parsing iPOJO-Component");
}
assertNotNull("Check elem not null", elem);
Element manip = getManipulationForComponent(elem, "ManipulationMetadata-FooProviderType-1");
assertNotNull("Check manipulation metadata not null for " + "FooProviderType-1", manip);
}
Aggregations