use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class TestBadServiceDependencies method getBadField.
private Element getBadField() {
Element elem = new Element("component", "");
elem.addAttribute(new Attribute("classname", clazz));
Element callback = new Element("requires", "");
// missing field.
callback.addAttribute(new Attribute("field", "BAD_FIELD"));
elem.addElement(callback);
elem.addElement(manipulation);
return elem;
}
use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class CompositeInstanceDescription method getInternalServices.
/**
* Gets the list of internally published services.
* @return the list of published services.
*/
public Element getInternalServices() {
Element services = new Element("services", "");
ServiceContext internal = ((CompositeManager) m_instance).getServiceContext();
try {
ServiceReference[] refs = internal.getServiceReferences((String) null, "(!(objectclass=" + Factory.class.getName() + "))");
for (int i = 0; refs != null && i < refs.length; i++) {
Element svc = new Element("service", "");
String[] keys = refs[i].getPropertyKeys();
for (int j = 0; j < keys.length; j++) {
Object v = refs[i].getProperty(keys[j]);
if (v instanceof String[]) {
List l = Arrays.asList((String[]) v);
svc.addAttribute(new Attribute(keys[j], l.toString()));
} else {
svc.addAttribute(new Attribute(keys[j], v.toString()));
}
}
services.addElement(svc);
}
} catch (InvalidSyntaxException e) {
// Cannot happen
}
return services;
}
use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class InstanceHandlerDescription method getHandlerInfo.
/**
* Build handler description.
* @return the handler description
* @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
*/
public Element getHandlerInfo() {
Element instances = super.getHandlerInfo();
for (int i = 0; i < m_configurations.length; i++) {
ManagedConfiguration inst = m_configurations[i];
Element instance = new Element("Instance", "");
if (inst.getInstance() == null) {
instance.addAttribute(new Attribute("Factory", inst.getConfiguration().get("component").toString()));
instance.addAttribute(new Attribute("State", "Not Available"));
} else {
instance.addAttribute(new Attribute("Factory", inst.getFactory()));
instance.addAttribute(new Attribute("Name", inst.getInstance().getInstanceName()));
String state = null;
switch(inst.getInstance().getState()) {
case ComponentInstance.DISPOSED:
state = "disposed";
break;
case ComponentInstance.STOPPED:
state = "stopped";
break;
case ComponentInstance.VALID:
state = "valid";
break;
case ComponentInstance.INVALID:
state = "invalid";
break;
default:
break;
}
instance.addAttribute(new Attribute("State", state));
// The instance description is already contained inside parent instance description.
// instance.addElement(inst.getInstance().getInstanceDescription().getDescription());
}
instances.addElement(instance);
}
return instances;
}
use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class CompositionMetadata method buildMetadata.
/**
* Build service implementation metadata.
* @param name : name of the future instance (used to avoid cycle)
* @return Component Type metadata.
*/
protected Element buildMetadata(String name) {
Element elem = new Element("component", "");
Attribute className = new Attribute("classname", m_name);
Attribute factory = new Attribute("public", "false");
elem.addAttribute(className);
elem.addAttribute(factory);
// Add architecture for debug
elem.addAttribute(new Attribute("architecture", "true"));
// Provides
Element provides = new Element("provides", "");
provides.addAttribute(new Attribute("specification", m_specification.getName()));
elem.addElement(provides);
// Dependencies
List fields = getFieldList();
for (int i = 0; i < fields.size(); i++) {
FieldMetadata field = (FieldMetadata) fields.get(i);
if (field.isUseful() && field.getSpecification().isInterface()) {
Element dep = new Element("requires", "");
dep.addAttribute(new Attribute("field", field.getName()));
dep.addAttribute(new Attribute("scope", "composite"));
dep.addAttribute(new Attribute("proxy", "false"));
if (field.getSpecification().isOptional()) {
dep.addAttribute(new Attribute("optional", "true"));
}
dep.addAttribute(new Attribute("filter", "(!(instance.name=" + name + "))"));
elem.addElement(dep);
}
}
Element properties = new Element("properties", "");
for (int i = 0; i < fields.size(); i++) {
FieldMetadata field = (FieldMetadata) fields.get(i);
if (field.isUseful() && !field.getSpecification().isInterface()) {
Element prop = new Element("Property", "");
prop.addAttribute(new Attribute("field", field.getName()));
properties.addElement(prop);
}
}
if (properties.getElements().length != 0) {
elem.addElement(properties);
}
// Insert information to metadata
elem.addElement(m_manipulation);
return elem;
}
use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class ProvidedServiceHandlerDescription method getHandlerInfo.
/**
* Get the handler description.
* @return the provided service handler description
* @see org.apache.felix.ipojo.architecture.HandlerDescription#getHandlerInfo()
*/
public Element getHandlerInfo() {
Element services = super.getHandlerInfo();
for (int i = 0; i < m_services.size(); i++) {
ProvidedService svc = (ProvidedService) m_services.get(i);
Element service = new Element("service", "");
String state = "unregistered";
if (svc.isRegistered()) {
state = "registered";
}
String spec = "[" + svc.getSpecification() + "]";
service.addAttribute(new Attribute("Specification", spec));
service.addAttribute(new Attribute("State", state));
services.addElement(service);
}
for (int i = 0; i < m_exports.size(); i++) {
ServiceExporter exp = (ServiceExporter) m_exports.get(i);
Element expo = new Element("Exports", "");
expo.addAttribute(new Attribute("Specification", exp.getSpecification().getName()));
expo.addAttribute(new Attribute("Filter", exp.getFilter()));
if (exp.getState() == DependencyModel.RESOLVED) {
expo.addAttribute(new Attribute("State", "resolved"));
} else {
expo.addAttribute(new Attribute("State", "unresolved"));
}
services.addElement(expo);
}
return services;
}
Aggregations