本文整理了Java中org.apache.felix.ipojo.metadata.Element.getElements()
方法的一些代码示例,展示了Element.getElements()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getElements()
方法的具体详情如下:
包路径:org.apache.felix.ipojo.metadata.Element
类名称:Element
方法名:getElements
[英]Gets sub-elements. If no sub-elements, an empty array is returned.
[中]获取子元素。如果没有子元素,则返回空数组。
代码示例来源:origin: apache/felix
/**
* Get parsed metadata.
* The document must be parsed before calling this method.
* @return : all the metadata.
* @throws ParseException : occurs if an error occurs during the parsing.
*/
public Element[] getMetadata() throws ParseException {
return m_elements[0].getElements();
}
代码示例来源:origin: apache/felix
private boolean arePropertiesEmpty() {
return m_props.getElements().length == 0;
}
代码示例来源:origin: apache/felix
/**
* Gets the elements array of the element type given in parameter.
* @param name the type of the element to find (element name)
* @param ns the namespace of the element
* @return the resulting element array (<code>null</code> if the search failed)
*/
public Element[] getElements(String name, String ns) {
if (ns == null || ns.length() == 0) {
return getElements(name);
}
name = ns + ":" + name;
return getElements(name);
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo.metadata
/**
* Gets the elements array of the element type given in parameter.
* @param name the type of the element to find (element name)
* @param ns the namespace of the element
* @return the resulting element array (<code>null</code> if the search failed)
*/
public Element[] getElements(String name, String ns) {
if (ns == null || ns.length() == 0) {
return getElements(name);
}
name = ns + ":" + name;
return getElements(name);
}
代码示例来源:origin: apache/felix
private void collectStructuralFields(List<String> fieldsInStructure, Element structure) {
Element[] fields = structure.getElements("field");
if (fields != null) {
for (Element field : fields) {
fieldsInStructure.add(field.getAttribute("name"));
}
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo
/**
* Gets the array of component type metadata.
* @return the component metadata (composite & component).
* An empty array is returned if no component type declaration.
* @throws ParseException if a parsing error occurs
*/
public Element[] getComponentsMetadata() throws ParseException {
Element[] elems = m_elements[0].getElements();
List list = new ArrayList();
for (int i = 0; i < elems.length; i++) {
if (!"instance".equals(elems[i].getName())) {
list.add(elems[i]);
}
}
return (Element[]) list.toArray(new Element[list.size()]);
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo
/**
* Gets the array of instance configuration described in the metadata.
* @return the instances list or <code>null</code> if no instance configuration.
* @throws ParseException if the metadata cannot be parsed successfully
*/
public Dictionary[] getInstances() throws ParseException {
Element[] configs = m_elements[0].getElements("instance");
if (configs == null) {
return null;
}
Dictionary[] dicts = new Dictionary[configs.length];
for (int i = 0; i < configs.length; i++) {
dicts[i] = parseInstance(configs[i]);
}
return dicts;
}
代码示例来源:origin: apache/felix
/**
* Gets the array of component type metadata.
* @return the component metadata (composite & component).
* An empty array is returned if no component type declaration.
* @throws ParseException if a parsing error occurs
*/
public Element[] getComponentsMetadata() throws ParseException {
Element[] elems = m_elements[0].getElements();
List list = new ArrayList();
for (int i = 0; i < elems.length; i++) {
if (!"instance".equals(elems[i].getName())) {
list.add(elems[i]);
}
}
return (Element[]) list.toArray(new Element[list.size()]);
}
代码示例来源:origin: apache/felix
/**
* Gets the array of instance configuration described in the metadata.
* @return the instances list or <code>null</code> if no instance configuration.
* @throws ParseException if the metadata cannot be parsed successfully
*/
public Dictionary[] getInstances() throws ParseException {
Element[] configs = m_elements[0].getElements("instance");
if (configs == null) {
return null;
}
Dictionary[] dicts = new Dictionary[configs.length];
for (int i = 0; i < configs.length; i++) {
dicts[i] = parseInstance(configs[i]);
}
return dicts;
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo
/**
* Parses a complex property.
* This property will be built as a {@link Map}.
* The used {@link Map} implementation is {@link HashMap}.
* @param prop the property to parse
* @return the resulting Map
* @throws ParseException if an internal property is incorrect.
*/
private Map parseMap(Element prop) throws ParseException {
// Check if there is 'property' elements
Element[] subProps = prop.getElements("property");
if (subProps != null) {
Map map = new HashMap(); // Create an hashmap to store elements.
for (int i = 0; i < subProps.length; i++) {
parseProperty(subProps[i], map);
}
return map;
} else { // if not inject an empty map
return new HashMap(0);
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo
/**
* Parses a complex property. This property will be built as a {@link List}.
* The used {@link List} implementation is {@link ArrayList}.
* The order of elements is kept.
* @param prop the property to parse
* @return the resulting List
* @throws ParseException if an internal property is incorrect.
*/
private List parseList(Element prop) throws ParseException {
Element[] subProps = prop.getElements("property");
if (subProps != null) {
List list = new ArrayList(subProps.length); // Create a list to store elements.
for (int i = 0; i < subProps.length; i++) {
parseAnonymousProperty(subProps[i], list); // Anonymous properties.
}
return list;
} else {
// If no sub-properties, inject an empty list.
return new ArrayList(0);
}
}
代码示例来源:origin: apache/felix
/**
* Looks for 'field' attribute in the given metadata.
* @param fields discovered fields (accumulator)
* @param metadata metadata to inspect
*/
public static void findFields(List<String> fields, Element metadata) {
String field = metadata.getAttribute("field");
if (field != null && !fields.contains(field)) {
fields.add(field);
}
for (Element element : metadata.getElements()) {
findFields(fields, element);
}
}
代码示例来源:origin: apache/felix
/**
* Find all the values of the specified attribute in the given element.
* @param metadata Element to be traversed
* @param attributeName Search attribute name
* @return Set of attribute values (no duplicate).
*/
public static Set<String> findAttributes(Element metadata, String attributeName) {
Set<String> referred = new HashSet<String>();
// Search in the given element
if (metadata.containsAttribute(attributeName)) {
referred.add(metadata.getAttribute(attributeName));
}
// Search in children
for (Element elem : metadata.getElements()) {
Set<String> found = findAttributes(elem, attributeName);
referred.addAll(found);
}
// Return all found values
return referred;
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo.composite
/**
* Compute required handlers.
* @return the list of required handler.
*/
public List<RequiredHandler> getRequiredHandlerList() {
List<RequiredHandler> list = new ArrayList<RequiredHandler>();
Element[] elems = m_componentMetadata.getElements();
for (Element current : elems) {
RequiredHandler req = new RequiredHandler(current.getName(), current.getNameSpace());
if (!list.contains(req)) {
list.add(req);
}
}
// Add architecture if architecture != 'false'
String arch = m_componentMetadata.getAttribute("architecture");
if (arch == null || arch.equalsIgnoreCase("true")) {
RequiredHandler req = new RequiredHandler("architecture", null);
if (! list.contains(req)) { list.add(req); }
}
return list;
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo
/**
* Configure method.
* Look for the first 'controller' element.
* @param metadata : metadata
* @param configuration : configuration
* @throws ConfigurationException : the field attribute is missing or does not exist in the class.
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
Element[] controller = metadata.getElements("controller");
m_field = controller[0].getAttribute("field");
getInstanceManager().register(new FieldMetadata(m_field, "boolean"), this);
}
代码示例来源:origin: apache/felix
/**
* Configure method.
* Look for the first 'controller' element.
* @param metadata : metadata
* @param configuration : configuration
* @throws ConfigurationException : the field attribute is missing or does not exist in the class.
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
Element[] controller = metadata.getElements("controller");
m_field = controller[0].getAttribute("field");
getInstanceManager().register(new FieldMetadata(m_field, "boolean"), this);
}
代码示例来源:origin: apache/felix
private void addCallbacksToDependency(Element dependencyElement, Dependency dep) throws ConfigurationException {
Element[] cbs = dependencyElement.getElements("Callback");
for (int j = 0; cbs != null && j < cbs.length; j++) {
if (!cbs[j].containsAttribute("method") || !cbs[j].containsAttribute("type")) {
throw new ConfigurationException("Requirement Callback : a dependency callback must contain a method " +
"and a type (bind or unbind) attribute");
}
String method = cbs[j].getAttribute("method");
String type = cbs[j].getAttribute("type");
int methodType = DependencyCallback.UNBIND;
if ("bind".equalsIgnoreCase(type)) {
methodType = DependencyCallback.BIND;
} else if ("modified".equalsIgnoreCase(type)) {
methodType = DependencyCallback.MODIFIED;
}
dep.addDependencyCallback(createDependencyHandler(dep, method, methodType));
}
}
代码示例来源:origin: apache/felix
private Element getPropertyElement() {
// Gather all the <property> Elements
Element[] props = m_parent.getElements("property");
Element prop = null;
for (int i = 0; props != null && prop == null && i < props.length; i++) {
// Get the first one with the good name
String name = props[i].getAttribute("name");
if (name != null && name.equals(m_name)) {
prop = props[i];
}
}
// Create the Element if not present
if (prop == null) {
prop = new Element("property", "");
m_parent.addElement(prop);
if (m_name != null) {
prop.addAttribute(new Attribute("name", m_name));
}
}
return prop;
}
}
代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo
private void addCallbacksToDependency(Element dependencyElement, Dependency dep) throws ConfigurationException {
Element[] cbs = dependencyElement.getElements("Callback");
for (int j = 0; cbs != null && j < cbs.length; j++) {
if (!cbs[j].containsAttribute("method") || !cbs[j].containsAttribute("type")) {
throw new ConfigurationException("Requirement Callback : a dependency callback must contain a method " +
"and a type (bind or unbind) attribute");
}
String method = cbs[j].getAttribute("method");
String type = cbs[j].getAttribute("type");
int methodType = DependencyCallback.UNBIND;
if ("bind".equalsIgnoreCase(type)) {
methodType = DependencyCallback.BIND;
} else if ("modified".equalsIgnoreCase(type)) {
methodType = DependencyCallback.MODIFIED;
}
dep.addDependencyCallback(createDependencyHandler(dep, method, methodType));
}
}
代码示例来源:origin: apache/felix
private void renderElement(Element element, StringBuilder builder) {
// If the element is already here, do not re-add the element.
if(!isFiltered(element)) {
// Print the beginning of the element
startElement(element, builder);
// Render all attributes
for (Attribute attribute : element.getAttributes()) {
renderAttribute(attribute, builder);
}
// Render child elements
for (Element child : element.getElements()) {
renderElement(child, builder);
}
// Print the end of the element
endElement(builder);
}
}
内容来源于网络,如有侵权,请联系作者删除!