use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class ComponentTypeDescription method getDescription.
/**
* Gets the component type description.
*
* @return : the description
*/
public Element getDescription() {
Element desc = new Element("Factory", "");
desc.addAttribute(new Attribute("name", m_factory.getName()));
desc.addAttribute(new Attribute("bundle", Long.toString(m_factory.getBundleContext().getBundle().getBundleId())));
String state = "valid";
if (m_factory.getState() == Factory.INVALID) {
state = "invalid";
}
desc.addAttribute(new Attribute("state", state));
// Display required & missing handlers
Element req = new Element("RequiredHandlers", "");
req.addAttribute(new Attribute("list", m_factory.getRequiredHandlers().toString()));
Element missing = new Element("MissingHandlers", "");
missing.addAttribute(new Attribute("list", m_factory.getMissingHandlers().toString()));
desc.addElement(req);
desc.addElement(missing);
for (int i = 0; i < m_providedServiceSpecification.length; i++) {
Element prov = new Element("provides", "");
prov.addAttribute(new Attribute("specification", m_providedServiceSpecification[i]));
desc.addElement(prov);
}
for (int i = 0; i < m_properties.length; i++) {
Element prop = new Element("property", "");
prop.addAttribute(new Attribute("name", m_properties[i].getName()));
prop.addAttribute(new Attribute("type", m_properties[i].getType()));
if (m_properties[i].isMandatory() && m_properties[i].getValue() == null) {
prop.addAttribute(new Attribute("value", "REQUIRED"));
} else {
prop.addAttribute(new Attribute("value", m_properties[i].getValue()));
}
desc.addElement(prop);
}
if (m_handlerInfoSlot.size() > 0) {
Enumeration keys = m_handlerInfoSlot.keys();
while (keys.hasMoreElements()) {
String fullHandlerName = (String) keys.nextElement();
CustomHandlerInfo handlerInfo = (CustomHandlerInfo) m_handlerInfoSlot.get(fullHandlerName);
desc.addElement(handlerInfo.getDescription());
}
}
return desc;
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class InstanceDescription method getDescription.
/**
* Gets the instance description.
* @return the instance description
*/
public Element getDescription() {
Element instance = new Element("Instance", "");
// Name
instance.addAttribute(new Attribute("name", getName()));
int state = getState();
if (state == ComponentInstance.STOPPED) {
instance.addAttribute(new Attribute("state", "stopped"));
}
if (state == ComponentInstance.VALID) {
instance.addAttribute(new Attribute("state", "valid"));
}
if (state == ComponentInstance.INVALID) {
instance.addAttribute(new Attribute("state", "invalid"));
}
if (state == ComponentInstance.DISPOSED) {
instance.addAttribute(new Attribute("state", "disposed"));
}
// Bundle
instance.addAttribute(new Attribute("bundle", Long.toString(getBundleId())));
// Component Type
instance.addAttribute(new Attribute("component.type", m_type.getName()));
// Handlers
for (HandlerDescription description : m_handlers) {
instance.addElement(description.getHandlerInfo());
}
return instance;
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class TestDeclarationBuilderService method germanComponent.
/*
@Test
public void testTypeCreationFromAPI() throws Exception {
PrimitiveComponentType type = new PrimitiveComponentType()
.setClassName("org.apache.felix.ipojo.runtime.core.test.components.GermanHelloService")
.setComponentTypeName("german-service")
.addService(new Service());
Element description = type.getFactory().getComponentMetadata();
handle = builder.newType(description);
handle.publish();
DeclarationHandle instance = builder.newInstance("german-service")
.name("german-hello")
.build();
instance.publish();
String filter = format("(instance.name=%s)", "german-hello");
osgiHelper.waitForService(HelloService.class, filter, 1000);
HelloService service = osgiHelper.getServiceObject(HelloService.class, filter);
assertEquals(service.hello("Guillaume"), "Hallo Guillaume");
instance.retract();
}
*/
private Element germanComponent() {
Element component = new Element("component", null);
component.addAttribute(new Attribute("name", "german-service"));
component.addAttribute(new Attribute("classname", "org.apache.felix.ipojo.runtime.core.test.components.GermanHelloService"));
component.addElement(new Element("provides", null));
component.addElement(manipulation());
return component;
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class DefaultDeclarationBuilderServiceTestCase method testNewType.
public void testNewType() throws Exception {
DefaultDeclarationBuilderService service = new DefaultDeclarationBuilderService(m_bundleContext);
DeclarationHandle type = service.newType(new Element("component", null));
assertNotNull(type);
type.publish();
verify(m_bundleContext).registerService(eq(TypeDeclaration.class.getName()), anyObject(), isNull(Dictionary.class));
}
use of org.apache.felix.ipojo.metadata.Element in project felix by apache.
the class ManagedTypeTestCase method element.
private Element element(String type, String classname) {
Element root = new Element(type, null);
root.addAttribute(new Attribute("classname", classname));
return root;
}
Aggregations