use of org.apache.felix.ipojo.architecture.PropertyDescription in project felix by apache.
the class EventAdminSubscriberHandler method initializeComponentFactory.
/**
* Initializes the component type.
*
* @param cd component type description to populate.
* @param metadata component type metadata.
* @throws ConfigurationException if the metadata are 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();
cd.addProperty(new PropertyDescription(TOPICS_PROPERTY, Dictionary.class.getName(), dict.toString()));
dict = new Properties();
cd.addProperty(new PropertyDescription(FILTER_PROPERTY, Dictionary.class.getName(), dict.toString()));
// Get Metadata subscribers
Element[] subscribers = metadata.getElements("subscriber", NAMESPACE);
if (subscribers != null) {
// Maps used to check name and field are unique
Set nameSet = new HashSet();
Set callbackSet = new HashSet();
// Check all subscribers are well formed
for (int i = 0; i < subscribers.length; i++) {
// Check the subscriber configuration is correct by creating an
// unused subscriber metadata
EventAdminSubscriberMetadata subscriberMetadata = new EventAdminSubscriberMetadata(getFactory().getBundleContext(), subscribers[i]);
String name = subscriberMetadata.getName();
info(LOG_PREFIX + "Checking subscriber " + name);
// Determine the event callback prototype
PojoMetadata pojoMetadata = getPojoMetadata();
String callbackType;
if (subscriberMetadata.getDataKey() == null) {
callbackType = Event.class.getName();
} else {
callbackType = subscriberMetadata.getDataType().getName();
}
// Check the event callback method is present
MethodMetadata methodMetadata = pojoMetadata.getMethod(subscriberMetadata.getCallback(), new String[] { callbackType });
String callbackSignature = subscriberMetadata.getCallback() + "(" + callbackType + ")";
if (methodMetadata == null) {
throw new ConfigurationException("Cannot find callback method " + callbackSignature);
}
// Warn if the same callback is used by several subscribers
if (callbackSet.contains(callbackSignature)) {
warn("The callback method is already used by another subscriber : " + callbackSignature);
} else {
callbackSet.add(callbackSignature);
}
// Check name is unique
if (nameSet.contains(name)) {
throw new ConfigurationException("A subscriber with the same name already exists : " + name);
}
nameSet.add(name);
}
m_description = new EventAdminSubscriberHandlerDescription(this, subscribers);
} else {
info(LOG_PREFIX + "No subscriber to check");
}
}
use of org.apache.felix.ipojo.architecture.PropertyDescription 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.architecture.PropertyDescription in project felix by apache.
the class TestFactoryProperties method testProps.
@Test
public void testProps() {
ServiceReference ref1 = ipojoHelper.getServiceReferenceByName(Factory.class.getName(), "Factories-FooProviderType-Dyn2");
assertNotNull("The factory is available", ref1);
PropertyDescription[] pd = (PropertyDescription[]) ref1.getProperty("component.properties");
assertEquals("Check property list size", pd.length, 5);
// P0
assertEquals("0) Check name", "int", pd[0].getName());
assertEquals("0) Check type", "int", pd[0].getType());
assertEquals("0) Check value", "4", pd[0].getValue());
// P1
assertEquals("1) Check name", "boolean", pd[1].getName());
assertEquals("1) Check type", "boolean", pd[1].getType());
assertNull("1) Check value", pd[1].getValue());
// P2
assertEquals("2) Check name", "string", pd[2].getName());
assertEquals("2) Check type", String.class.getName(), pd[2].getType());
assertNull("2) Check value", pd[2].getValue());
// P3
assertEquals("3) Check name", "strAProp", pd[3].getName());
assertEquals("3) Check type", "java.lang.String[]", pd[3].getType());
assertNull("3) Check value", pd[3].getValue());
// P4
assertEquals("4) Check name", "intAProp", pd[4].getName());
assertEquals("4) Check type", "int[]", pd[4].getType());
}
use of org.apache.felix.ipojo.architecture.PropertyDescription in project felix by apache.
the class CheckServiceAndFieldInterceptorHandler method initializeComponentFactory.
public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) {
cd.addProperty(new PropertyDescription("csh.simple", "java.lang.String", null));
cd.addProperty(new PropertyDescription("csh.map", "java.util.Dictionary", null));
}
use of org.apache.felix.ipojo.architecture.PropertyDescription in project felix by apache.
the class CheckServiceHandler method initializeComponentFactory.
public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) {
cd.addProperty(new PropertyDescription("csh.simple", "java.lang.String", null));
cd.addProperty(new PropertyDescription("csh.map", "java.util.Dictionary", null));
}
Aggregations