org.apache.felix.ipojo.metadata.Element.getElements()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(602)

本文整理了Java中org.apache.felix.ipojo.metadata.Element.getElements()方法的一些代码示例,展示了Element.getElements()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Element.getElements()方法的具体详情如下:
包路径:org.apache.felix.ipojo.metadata.Element
类名称:Element
方法名:getElements

Element.getElements介绍

[英]Gets sub-elements. If no sub-elements, an empty array is returned.
[中]获取子元素。如果没有子元素,则返回空数组。

代码示例

代码示例来源:origin: apache/felix

  1. /**
  2. * Get parsed metadata.
  3. * The document must be parsed before calling this method.
  4. * @return : all the metadata.
  5. * @throws ParseException : occurs if an error occurs during the parsing.
  6. */
  7. public Element[] getMetadata() throws ParseException {
  8. return m_elements[0].getElements();
  9. }

代码示例来源:origin: apache/felix

  1. private boolean arePropertiesEmpty() {
  2. return m_props.getElements().length == 0;
  3. }

代码示例来源:origin: apache/felix

  1. /**
  2. * Gets the elements array of the element type given in parameter.
  3. * @param name the type of the element to find (element name)
  4. * @param ns the namespace of the element
  5. * @return the resulting element array (<code>null</code> if the search failed)
  6. */
  7. public Element[] getElements(String name, String ns) {
  8. if (ns == null || ns.length() == 0) {
  9. return getElements(name);
  10. }
  11. name = ns + ":" + name;
  12. return getElements(name);
  13. }

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo.metadata

  1. /**
  2. * Gets the elements array of the element type given in parameter.
  3. * @param name the type of the element to find (element name)
  4. * @param ns the namespace of the element
  5. * @return the resulting element array (<code>null</code> if the search failed)
  6. */
  7. public Element[] getElements(String name, String ns) {
  8. if (ns == null || ns.length() == 0) {
  9. return getElements(name);
  10. }
  11. name = ns + ":" + name;
  12. return getElements(name);
  13. }

代码示例来源:origin: apache/felix

  1. private void collectStructuralFields(List<String> fieldsInStructure, Element structure) {
  2. Element[] fields = structure.getElements("field");
  3. if (fields != null) {
  4. for (Element field : fields) {
  5. fieldsInStructure.add(field.getAttribute("name"));
  6. }
  7. }
  8. }

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo

  1. /**
  2. * Gets the array of component type metadata.
  3. * @return the component metadata (composite & component).
  4. * An empty array is returned if no component type declaration.
  5. * @throws ParseException if a parsing error occurs
  6. */
  7. public Element[] getComponentsMetadata() throws ParseException {
  8. Element[] elems = m_elements[0].getElements();
  9. List list = new ArrayList();
  10. for (int i = 0; i < elems.length; i++) {
  11. if (!"instance".equals(elems[i].getName())) {
  12. list.add(elems[i]);
  13. }
  14. }
  15. return (Element[]) list.toArray(new Element[list.size()]);
  16. }

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo

  1. /**
  2. * Gets the array of instance configuration described in the metadata.
  3. * @return the instances list or <code>null</code> if no instance configuration.
  4. * @throws ParseException if the metadata cannot be parsed successfully
  5. */
  6. public Dictionary[] getInstances() throws ParseException {
  7. Element[] configs = m_elements[0].getElements("instance");
  8. if (configs == null) {
  9. return null;
  10. }
  11. Dictionary[] dicts = new Dictionary[configs.length];
  12. for (int i = 0; i < configs.length; i++) {
  13. dicts[i] = parseInstance(configs[i]);
  14. }
  15. return dicts;
  16. }

代码示例来源:origin: apache/felix

  1. /**
  2. * Gets the array of component type metadata.
  3. * @return the component metadata (composite & component).
  4. * An empty array is returned if no component type declaration.
  5. * @throws ParseException if a parsing error occurs
  6. */
  7. public Element[] getComponentsMetadata() throws ParseException {
  8. Element[] elems = m_elements[0].getElements();
  9. List list = new ArrayList();
  10. for (int i = 0; i < elems.length; i++) {
  11. if (!"instance".equals(elems[i].getName())) {
  12. list.add(elems[i]);
  13. }
  14. }
  15. return (Element[]) list.toArray(new Element[list.size()]);
  16. }

代码示例来源:origin: apache/felix

  1. /**
  2. * Gets the array of instance configuration described in the metadata.
  3. * @return the instances list or <code>null</code> if no instance configuration.
  4. * @throws ParseException if the metadata cannot be parsed successfully
  5. */
  6. public Dictionary[] getInstances() throws ParseException {
  7. Element[] configs = m_elements[0].getElements("instance");
  8. if (configs == null) {
  9. return null;
  10. }
  11. Dictionary[] dicts = new Dictionary[configs.length];
  12. for (int i = 0; i < configs.length; i++) {
  13. dicts[i] = parseInstance(configs[i]);
  14. }
  15. return dicts;
  16. }

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo

  1. /**
  2. * Parses a complex property.
  3. * This property will be built as a {@link Map}.
  4. * The used {@link Map} implementation is {@link HashMap}.
  5. * @param prop the property to parse
  6. * @return the resulting Map
  7. * @throws ParseException if an internal property is incorrect.
  8. */
  9. private Map parseMap(Element prop) throws ParseException {
  10. // Check if there is 'property' elements
  11. Element[] subProps = prop.getElements("property");
  12. if (subProps != null) {
  13. Map map = new HashMap(); // Create an hashmap to store elements.
  14. for (int i = 0; i < subProps.length; i++) {
  15. parseProperty(subProps[i], map);
  16. }
  17. return map;
  18. } else { // if not inject an empty map
  19. return new HashMap(0);
  20. }
  21. }

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo

  1. /**
  2. * Parses a complex property. This property will be built as a {@link List}.
  3. * The used {@link List} implementation is {@link ArrayList}.
  4. * The order of elements is kept.
  5. * @param prop the property to parse
  6. * @return the resulting List
  7. * @throws ParseException if an internal property is incorrect.
  8. */
  9. private List parseList(Element prop) throws ParseException {
  10. Element[] subProps = prop.getElements("property");
  11. if (subProps != null) {
  12. List list = new ArrayList(subProps.length); // Create a list to store elements.
  13. for (int i = 0; i < subProps.length; i++) {
  14. parseAnonymousProperty(subProps[i], list); // Anonymous properties.
  15. }
  16. return list;
  17. } else {
  18. // If no sub-properties, inject an empty list.
  19. return new ArrayList(0);
  20. }
  21. }

代码示例来源:origin: apache/felix

  1. /**
  2. * Looks for 'field' attribute in the given metadata.
  3. * @param fields discovered fields (accumulator)
  4. * @param metadata metadata to inspect
  5. */
  6. public static void findFields(List<String> fields, Element metadata) {
  7. String field = metadata.getAttribute("field");
  8. if (field != null && !fields.contains(field)) {
  9. fields.add(field);
  10. }
  11. for (Element element : metadata.getElements()) {
  12. findFields(fields, element);
  13. }
  14. }

代码示例来源:origin: apache/felix

  1. /**
  2. * Find all the values of the specified attribute in the given element.
  3. * @param metadata Element to be traversed
  4. * @param attributeName Search attribute name
  5. * @return Set of attribute values (no duplicate).
  6. */
  7. public static Set<String> findAttributes(Element metadata, String attributeName) {
  8. Set<String> referred = new HashSet<String>();
  9. // Search in the given element
  10. if (metadata.containsAttribute(attributeName)) {
  11. referred.add(metadata.getAttribute(attributeName));
  12. }
  13. // Search in children
  14. for (Element elem : metadata.getElements()) {
  15. Set<String> found = findAttributes(elem, attributeName);
  16. referred.addAll(found);
  17. }
  18. // Return all found values
  19. return referred;
  20. }

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo.composite

  1. /**
  2. * Compute required handlers.
  3. * @return the list of required handler.
  4. */
  5. public List<RequiredHandler> getRequiredHandlerList() {
  6. List<RequiredHandler> list = new ArrayList<RequiredHandler>();
  7. Element[] elems = m_componentMetadata.getElements();
  8. for (Element current : elems) {
  9. RequiredHandler req = new RequiredHandler(current.getName(), current.getNameSpace());
  10. if (!list.contains(req)) {
  11. list.add(req);
  12. }
  13. }
  14. // Add architecture if architecture != 'false'
  15. String arch = m_componentMetadata.getAttribute("architecture");
  16. if (arch == null || arch.equalsIgnoreCase("true")) {
  17. RequiredHandler req = new RequiredHandler("architecture", null);
  18. if (! list.contains(req)) { list.add(req); }
  19. }
  20. return list;
  21. }

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo

  1. /**
  2. * Configure method.
  3. * Look for the first 'controller' element.
  4. * @param metadata : metadata
  5. * @param configuration : configuration
  6. * @throws ConfigurationException : the field attribute is missing or does not exist in the class.
  7. * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
  8. */
  9. public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
  10. Element[] controller = metadata.getElements("controller");
  11. m_field = controller[0].getAttribute("field");
  12. getInstanceManager().register(new FieldMetadata(m_field, "boolean"), this);
  13. }

代码示例来源:origin: apache/felix

  1. /**
  2. * Configure method.
  3. * Look for the first 'controller' element.
  4. * @param metadata : metadata
  5. * @param configuration : configuration
  6. * @throws ConfigurationException : the field attribute is missing or does not exist in the class.
  7. * @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
  8. */
  9. public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
  10. Element[] controller = metadata.getElements("controller");
  11. m_field = controller[0].getAttribute("field");
  12. getInstanceManager().register(new FieldMetadata(m_field, "boolean"), this);
  13. }

代码示例来源:origin: apache/felix

  1. private void addCallbacksToDependency(Element dependencyElement, Dependency dep) throws ConfigurationException {
  2. Element[] cbs = dependencyElement.getElements("Callback");
  3. for (int j = 0; cbs != null && j < cbs.length; j++) {
  4. if (!cbs[j].containsAttribute("method") || !cbs[j].containsAttribute("type")) {
  5. throw new ConfigurationException("Requirement Callback : a dependency callback must contain a method " +
  6. "and a type (bind or unbind) attribute");
  7. }
  8. String method = cbs[j].getAttribute("method");
  9. String type = cbs[j].getAttribute("type");
  10. int methodType = DependencyCallback.UNBIND;
  11. if ("bind".equalsIgnoreCase(type)) {
  12. methodType = DependencyCallback.BIND;
  13. } else if ("modified".equalsIgnoreCase(type)) {
  14. methodType = DependencyCallback.MODIFIED;
  15. }
  16. dep.addDependencyCallback(createDependencyHandler(dep, method, methodType));
  17. }
  18. }

代码示例来源:origin: apache/felix

  1. private Element getPropertyElement() {
  2. // Gather all the <property> Elements
  3. Element[] props = m_parent.getElements("property");
  4. Element prop = null;
  5. for (int i = 0; props != null && prop == null && i < props.length; i++) {
  6. // Get the first one with the good name
  7. String name = props[i].getAttribute("name");
  8. if (name != null && name.equals(m_name)) {
  9. prop = props[i];
  10. }
  11. }
  12. // Create the Element if not present
  13. if (prop == null) {
  14. prop = new Element("property", "");
  15. m_parent.addElement(prop);
  16. if (m_name != null) {
  17. prop.addAttribute(new Attribute("name", m_name));
  18. }
  19. }
  20. return prop;
  21. }
  22. }

代码示例来源:origin: org.apache.felix/org.apache.felix.ipojo

  1. private void addCallbacksToDependency(Element dependencyElement, Dependency dep) throws ConfigurationException {
  2. Element[] cbs = dependencyElement.getElements("Callback");
  3. for (int j = 0; cbs != null && j < cbs.length; j++) {
  4. if (!cbs[j].containsAttribute("method") || !cbs[j].containsAttribute("type")) {
  5. throw new ConfigurationException("Requirement Callback : a dependency callback must contain a method " +
  6. "and a type (bind or unbind) attribute");
  7. }
  8. String method = cbs[j].getAttribute("method");
  9. String type = cbs[j].getAttribute("type");
  10. int methodType = DependencyCallback.UNBIND;
  11. if ("bind".equalsIgnoreCase(type)) {
  12. methodType = DependencyCallback.BIND;
  13. } else if ("modified".equalsIgnoreCase(type)) {
  14. methodType = DependencyCallback.MODIFIED;
  15. }
  16. dep.addDependencyCallback(createDependencyHandler(dep, method, methodType));
  17. }
  18. }

代码示例来源:origin: apache/felix

  1. private void renderElement(Element element, StringBuilder builder) {
  2. // If the element is already here, do not re-add the element.
  3. if(!isFiltered(element)) {
  4. // Print the beginning of the element
  5. startElement(element, builder);
  6. // Render all attributes
  7. for (Attribute attribute : element.getAttributes()) {
  8. renderAttribute(attribute, builder);
  9. }
  10. // Render child elements
  11. for (Element child : element.getElements()) {
  12. renderElement(child, builder);
  13. }
  14. // Print the end of the element
  15. endElement(builder);
  16. }
  17. }

相关文章