use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class Instance method addProperty.
/**
* Adds a dictionary property.
* @param name the property name
* @param values the dictionary
* @return the current instance
*/
public Instance addProperty(String name, Dictionary values) {
Element elem = new Element("property", "");
elem.addAttribute(new Attribute("name", name));
elem.addAttribute(new Attribute("type", "dictionary"));
m_conf.add(elem);
Enumeration e = values.keys();
while (e.hasMoreElements()) {
Element el = new Element("property", "");
elem.addElement(el);
String n = (String) e.nextElement();
Object v = values.get(n);
if (v instanceof String) {
el.addAttribute(new Attribute("name", n));
el.addAttribute(new Attribute("value", v.toString()));
} else {
// TODO
throw new UnsupportedOperationException("Complex properties are not supported yet");
}
}
return this;
}
use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class Instance method addProperty.
/**
* Adds an array property.
* @param name the property name
* @param values the array
* @return the current instance
*/
public Instance addProperty(String name, String[] values) {
Element elem = new Element("property", "");
elem.addAttribute(new Attribute("name", name));
elem.addAttribute(new Attribute("type", "array"));
m_conf.add(elem);
for (int i = 0; i < values.length; i++) {
Object obj = values[i];
Element e = new Element("property", "");
elem.addElement(e);
e.addAttribute(new Attribute("value", obj.toString()));
}
return this;
}
use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class InstantiatedService method addProperty.
/**
* Adds a dictionary property.
* @param name the property name
* @param values the property value
* @return the current instantiated sub-service
*/
public InstantiatedService addProperty(String name, Dictionary values) {
Element elem = new Element("property", "");
elem.addAttribute(new Attribute("name", name));
elem.addAttribute(new Attribute("type", "dictionary"));
m_conf.add(elem);
Enumeration e = values.keys();
while (e.hasMoreElements()) {
Element el = new Element("property", "");
elem.addElement(el);
String n = (String) e.nextElement();
Object v = values.get(n);
if (v instanceof String) {
el.addAttribute(new Attribute("name", n));
el.addAttribute(new Attribute("value", v.toString()));
} else {
// TODO
throw new UnsupportedOperationException("Complex properties are not supported yet");
}
}
return this;
}
use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class InstantiatedService method getElement.
/**
* Gets the dependency metadata.
* @return the 'subservice' element describing the current
* instantiated service.
*/
public Element getElement() {
ensureValidity();
Element dep = new Element("subservice", "");
dep.addAttribute(new Attribute("action", "instantiate"));
dep.addAttribute(new Attribute("specification", m_specification));
if (m_filter != null) {
dep.addAttribute(new Attribute("filter", m_filter));
}
if (m_comparator != null) {
dep.addAttribute(new Attribute("comparator", m_comparator));
}
if (m_optional) {
dep.addAttribute(new Attribute("optional", "true"));
}
if (m_aggregate) {
dep.addAttribute(new Attribute("aggregate", "true"));
}
if (m_policy == DependencyModel.DYNAMIC_BINDING_POLICY) {
dep.addAttribute(new Attribute("policy", "dynamic"));
} else if (m_policy == DependencyModel.STATIC_BINDING_POLICY) {
dep.addAttribute(new Attribute("policy", "static"));
} else if (m_policy == DependencyModel.DYNAMIC_PRIORITY_BINDING_POLICY) {
dep.addAttribute(new Attribute("policy", "dynamic-priority"));
}
for (int i = 0; i < m_conf.size(); i++) {
Element elem = (Element) m_conf.get(i);
dep.addElement(elem);
}
return dep;
}
use of org.apache.felix.ipojo.metadata.Attribute in project felix by apache.
the class InstantiatedService method addProperty.
/**
* Adds a list property.
* @param name the property name
* @param values the property value
* @return the current instantiated sub-service
*/
public InstantiatedService addProperty(String name, List values) {
Element elem = new Element("property", "");
elem.addAttribute(new Attribute("name", name));
elem.addAttribute(new Attribute("type", "list"));
m_conf.add(elem);
for (int i = 0; i < values.size(); i++) {
Object obj = values.get(i);
Element e = new Element("property", "");
elem.addElement(e);
if (obj instanceof String) {
e.addAttribute(new Attribute("value", obj.toString()));
} else {
// TODO
throw new UnsupportedOperationException("Complex properties are not supported yet");
}
}
return this;
}
Aggregations