org.apache.felix.ipojo.metadata.Element类的使用及代码示例

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

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

Element介绍

[英]An element represents an XML Element. It contains a name, a namepace, Attribute objects and sub-elements. This class is used to parse iPOJO metadata.
[中]元素表示XML元素。它包含名称、名称空间、属性对象和子元素。此类用于解析iPOJO元数据。

代码示例

代码示例来源: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.api

  1. /**
  2. * Adds an array property.
  3. * @param name the property name
  4. * @param values the property value
  5. * @return the current instantiated sub-service
  6. */
  7. public InstantiatedService addProperty(String name, String[] values) {
  8. Element elem = new Element("property", "");
  9. elem.addAttribute(new Attribute("name", name));
  10. elem.addAttribute(new Attribute("type", "array"));
  11. m_conf.add(elem);
  12. for (int i = 0; i < values.length; i++) {
  13. Object obj = values[i];
  14. Element e = new Element("property", "");
  15. elem.addElement(e);
  16. e.addAttribute(new Attribute("value", obj.toString()));
  17. }
  18. return this;
  19. }

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

  1. /**
  2. * To String method.
  3. * @return the String form of this element.
  4. * @see java.lang.Object#toString()
  5. */
  6. public String toString() {
  7. return toString(0);
  8. }

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

  1. private String initExtension() {
  2. if (m_componentMetadata.getNameSpace() == null) {
  3. return m_componentMetadata.getName();
  4. }
  5. return m_componentMetadata.getNameSpace() + ":" + m_componentMetadata.getName();
  6. }

代码示例来源: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: apache/felix

  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. * Creates a field metadata.
  3. * This constructor is used when creating the {@link PojoMetadata}
  4. * object.
  5. * @param metadata the field manipulation element from Manipulation
  6. * Metadata.
  7. */
  8. FieldMetadata(Element metadata) {
  9. m_name = metadata.getAttribute("name");
  10. m_type = metadata.getAttribute("type");
  11. }

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

  1. /**
  2. * Adds a string property.
  3. * @param name the property name
  4. * @param value the property value
  5. * @return the current instantiated sub-service
  6. */
  7. public InstantiatedService addProperty(String name, String value) {
  8. Element elem = new Element("property", "");
  9. m_conf.add(elem);
  10. elem.addAttribute(new Attribute("name", name));
  11. elem.addAttribute(new Attribute("value", value));
  12. return this;
  13. }

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

  1. if (publisher.containsAttribute(NAME_ATTRIBUTE)) {
  2. m_name = publisher.getAttribute(NAME_ATTRIBUTE);
  3. } else {
  4. throw new ConfigurationException(
  5. if (publisher.containsAttribute(FIELD_ATTRIBUTE)) {
  6. m_field = publisher.getAttribute(FIELD_ATTRIBUTE);
  7. } else {
  8. throw new ConfigurationException(
  9. if (publisher.containsAttribute(TOPICS_ATTRIBUTE)) {
  10. setTopics(publisher.getAttribute(TOPICS_ATTRIBUTE));
  11. } else {
  12. m_topics = null;
  13. if (publisher.containsAttribute(SYNCHRONOUS_ATTRIBUTE)) {
  14. m_synchronous = "true".equalsIgnoreCase(publisher
  15. .getAttribute(SYNCHRONOUS_ATTRIBUTE));
  16. } else {
  17. m_synchronous = DEFAULT_SYNCHRONOUS_VALUE;
  18. if (publisher.containsAttribute(DATA_KEY_ATTRIBUTE)) {
  19. m_dataKey = publisher.getAttribute(DATA_KEY_ATTRIBUTE);
  20. } else if (publisher.containsAttribute("data_key")) {
  21. m_dataKey = publisher.getAttribute("data_key");
  22. } else if (publisher.containsAttribute("dataKey")) {
  23. m_dataKey = publisher.getAttribute("dataKey");

代码示例来源: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. if (componentMetadata != null && componentMetadata.containsAttribute("name") && instanceMetadata != null) {
  2. instanceMetadata.addAttribute(new Attribute("component", componentMetadata.getAttribute("name")));

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

  1. private void computeServiceReferenceDescription(ServiceReference ref, Element use) {
  2. use.addAttribute(new Attribute(Constants.SERVICE_ID, ref.getProperty(Constants.SERVICE_ID).toString()));
  3. String instance = (String) ref.getProperty(Factory.INSTANCE_NAME_PROPERTY);
  4. if (instance != null) {
  5. use.addAttribute(new Attribute(Factory.INSTANCE_NAME_PROPERTY, instance));
  6. }
  7. }

代码示例来源:origin: org.wisdom-framework/wisdom-ipojo-module

  1. /**
  2. * @return the Component element.
  3. */
  4. public static Element getComponentElement() {
  5. return new Element(COMPONENT, "");
  6. }
  7. }

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

  1. /**
  2. * Gets the instance description.
  3. * Overridden to add created objects.
  4. * @return the instance description
  5. */
  6. public Element getDescription() {
  7. Element elem = super.getDescription();
  8. elem.addElement(getInternalServices());
  9. InstanceDescription[] descs = getContainedInstances();
  10. if (descs.length > 0) {
  11. Element inst = new Element("ContainedInstances", "");
  12. for (int i = 0; i < descs.length; i++) {
  13. inst.addElement(descs[i].getDescription());
  14. }
  15. elem.addElement(inst);
  16. }
  17. return elem;
  18. }

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

  1. /**
  2. * End of the annotation.
  3. * Create a "controller" element
  4. * @see org.objectweb.asm.AnnotationVisitor#visitEnd()
  5. */
  6. public void visitEnd() {
  7. provides.addElement(controller);
  8. }
  9. }

代码示例来源: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. }

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

  1. if (metadata.containsAttribute("nullable") || dependency.getDefaultImplementation() != null || dependency
  2. .getException() != null) {
  3. if (metadata.containsAttribute("nullable") && dependency.getDefaultImplementation() != null) {
  4. throw new ConfigurationException(message + "`nullable` and `default-implementation` cannot be " +
  5. "combined");
  6. if (metadata.containsAttribute("nullable") && dependency.getException() != null) {
  7. throw new ConfigurationException(message + "`nullable` and `exception` cannot be combined");

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

  1. private boolean isInstance(Element element) {
  2. return "instance".equals(element.getName());
  3. }
  4. }

代码示例来源: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. }

相关文章