You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2006/10/30 17:36:06 UTC

svn commit: r469182 [6/6] - in /incubator/felix/trunk: ipojo.metadata/ ipojo.metadata/src/main/java/org/apache/felix/ipojo/metadata/ ipojo.plugin/ ipojo.plugin/src/main/java/org/apache/felix/ipojo/manipulation/ ipojo.plugin/src/main/java/org/apache/fel...

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java?view=diff&rev=469182&r1=469181&r2=469182
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java Mon Oct 30 08:36:04 2006
@@ -1,22 +1,25 @@
-/*
- *   Copyright 2006 The Apache Software Foundation
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 package org.apache.felix.ipojo.parser;
 
 import java.util.Dictionary;
+import java.util.Properties;
 
 import org.apache.felix.ipojo.metadata.Attribute;
 import org.apache.felix.ipojo.metadata.Element;
@@ -28,26 +31,52 @@
  */
 public class ManifestMetadataParser {
 
-	/**
-	 * Manifest Headers.
-	 */
-	private Dictionary m_headers;
-
-	/**
-	 * Element list.
-	 */
-	private Element[] m_elements = new Element[0];
+    /**
+     * Manifest Headers.
+     */
+    private Dictionary m_headers;
+
+    /**
+     * Element list.
+     */
+    private Element[] m_elements = new Element[0];
 
     /**
      * @return the component metadata.
      * @throws ParseException when a parsing error occurs
      */
     public Element[] getComponentsMetadata() throws ParseException {
-    	return m_elements[0].getElements("Component");
+        return m_elements[0].getElements("Component");
     }
 
+    /**
+     * @return the instances list.
+     * @throws ParseException : if the metadata cannot be parsed successfully
+     */
+    public Dictionary[] getInstances() throws ParseException {
+        Element[] configs = m_elements[0].getElements("Instance");
+        Dictionary[] dicts = new Dictionary[configs.length];
+        for (int i = 0; i < configs.length; i++) {
+            String comp = configs[i].getAttribute("component"); // get the component targeted by the configuration
+            Dictionary d = new Properties();
+            d.put("component", comp);
+            if (configs[i].getAttribute("name") != null) { d.put("name", configs[i].getAttribute("name")); }
+            for (int j = 0; j < configs[i].getElements("property", "").length; j++) {
+                String propsName = configs[i].getElements("property", "")[j].getAttribute("name", "");
+                String propsValue = configs[i].getElements("property", "")[j].getAttribute("value", "");
+                d.put(propsName, propsValue);
+            }
+            dicts[i] = d;
+        }
+        return dicts;
+    }
+
+    /**
+     * Add an element to the list.
+     * @param elem : the element to add
+     */
     private void addElement(Element elem) {
-    	for (int i = 0; (m_elements != null) && (i < m_elements.length); i++) {
+        for (int i = 0; (m_elements != null) && (i < m_elements.length); i++) {
             if (m_elements[i] == elem) { return; }
         }
 
@@ -58,127 +87,135 @@
             m_elements = newElementsList;
         }
         else { m_elements = new Element[] {elem}; }
-	}
+    }
 
+    /**
+     * Remove an element to the list.
+     * @return an element to remove
+     */
     private Element removeLastElement() {
-		int idx = -1;
-		idx = m_elements.length - 1;
-		Element last = m_elements[idx];
+        int idx = -1;
+        idx = m_elements.length - 1;
+        Element last = m_elements[idx];
         if (idx >= 0) {
             if ((m_elements.length - 1) == 0) {
-            	// It is the last element of the list;
-            	m_elements = new Element[0];
-            	}
+                // It is the last element of the list;
+                m_elements = new Element[0];
+            }
             else {
-            	// Remove the last element of the list :
+                // Remove the last element of the list :
                 Element[] newElementsList = new Element[m_elements.length - 1];
                 System.arraycopy(m_elements, 0, newElementsList, 0, idx);
                 m_elements = newElementsList;
             }
         }
         return last;
-	}
+    }
+
+    /**
+     * Parse the given dictionnary and create the components manager.
+     * @param dict : the given headers of the manifest file
+     * @throws ParseException : if any error occurs
+     */
+    public void parse(Dictionary dict) throws ParseException {
+        m_headers = dict;
+        String componentClassesStr = (String) m_headers.get("iPOJO-Components");
+        //Add the ipojo element inside the element list
+        addElement(new Element("iPOJO", ""));
+        parseElements(componentClassesStr.trim());
+
+    }
+
+    /**
+     * Parse the metadata from the string given in argument.
+     * @param metadata : the metadata to parse
+     * @return Element : the root element resulting of the parsing
+     * @throws ParseException : if any error occurs
+     */
+    public static Element parse(String metadata) throws ParseException  {
+        ManifestMetadataParser parser = new ManifestMetadataParser();
+        parser.parseElements(metadata);
+        if (parser.m_elements.length != 1) { throw new ParseException("Error in parsing, root element not found : " + metadata); }
+        return parser.m_elements[0];
+    }
+
+    /**
+     * Paser the given string.
+     * @param s : the string to parse
+     */
+    private void parseElements(String s) {
+        char[] string = s.toCharArray();
+
+        for (int i = 0; i < string.length; i++) {
+            char c = string[i];
 
-	/**
-	 * Parse the given dictionnary and create the components manager.
-	 * @param dict : the given headers of the manifest file
-	 * @throws ParseException : if any error occurs
-	 */
-	public void parse(Dictionary dict) throws ParseException {
-		m_headers = dict;
-		String componentClassesStr = (String)m_headers.get("iPOJO-Components");
-		//Add the ipojo element inside the element list
-		addElement(new Element("iPOJO", ""));
-		parseElements(componentClassesStr.trim());
-
-	}
-
-	/**
-	 * Parse the metadata from the string given in argument.
-	 * @param metadata : the metadata to parse
-	 * @return Element : the root element resulting of the parsing
-	 * @throws ParseException : if any error occurs
-	 */
-	public static Element parse(String metadata) throws ParseException  {
-		ManifestMetadataParser parser = new ManifestMetadataParser();
-		parser.parseElements(metadata);
-		if (parser.m_elements.length != 1) { throw new ParseException("Error in parsing, root element not found : " + metadata); }
-		return parser.m_elements[0];
-	}
-
-	private void parseElements(String s) {
-		char[] string = s.toCharArray();
-
-		for (int i = 0; i < string.length; i++) {
-			char c = string[i];
-
-			switch(c) {
-
-			case '$' :
-				String attName = "";
-				String attValue = "";
-				String attNs = "";
-				i++;
-				c = string[i];
-				while (c != '=') {
-					if (c == ':') {
-						attNs = attName;
-						attName = "";
-					} else { attName = attName + c; }
-					i = i + 1;
-					c = string[i];
-				}
-				i++; // skip =
-				i++; // skip "
-				c = string[i];
-				while (c != '"') {
-					attValue = attValue + c;
-					i++;
-					c = string[i];
-				}
-				i++; // skip "
-				c = string[i];
-
-				Attribute att = new Attribute(attName, attNs , attValue);
-				m_elements[m_elements.length - 1].addAttribute(att);
-				break;
-
-			case '}' :
-				Element lastElement = removeLastElement();
-				if (m_elements.length != 0) {
-					Element newQueue = m_elements[m_elements.length - 1];
-					newQueue.addElement(lastElement);
-				}
-				else {
-					addElement(lastElement);
-				}
-				break;
-			case ' ' : break; // do nothing;
-			default :
-					String name = "";
-					String ns = "";
-					c = string[i];
-					while (c != ' ') {
-						if (c == ':') {
-							ns = name;
-							name = "";
-							i++;
-							c = string[i];
-						}
-						else {
-							name = name + c;
-							i++;
-							c = string[i];
-						}
-					}
-					// Skip spaces
-					while (string[i] == ' ') { i = i + 1; }
-					i = i + 1; // skip {
-				    Element elem = new Element(name, ns);
-					addElement(elem);
-				break;
-			}
-			}
-		}
+            switch(c) {
+
+                case '$' :
+                    String attName = "";
+                    String attValue = "";
+                    String attNs = "";
+                    i++;
+                    c = string[i];
+                    while (c != '=') {
+                        if (c == ':') {
+                            attNs = attName;
+                            attName = "";
+                        } else { attName = attName + c; }
+                        i = i + 1;
+                        c = string[i];
+                    }
+                    i++; // skip =
+                    i++; // skip "
+                    c = string[i];
+                    while (c != '"') {
+                        attValue = attValue + c;
+                        i++;
+                        c = string[i];
+                    }
+                    i++; // skip "
+                    c = string[i];
+
+                    Attribute att = new Attribute(attName, attNs , attValue);
+                    m_elements[m_elements.length - 1].addAttribute(att);
+                    break;
+
+                case '}' :
+                    Element lastElement = removeLastElement();
+                    if (m_elements.length != 0) {
+                        Element newQueue = m_elements[m_elements.length - 1];
+                        newQueue.addElement(lastElement);
+                    }
+                    else {
+                        addElement(lastElement);
+                    }
+                    break;
+                case ' ' : break; // do nothing;
+                default :
+                    String name = "";
+                String ns = "";
+                c = string[i];
+                while (c != ' ') {
+                    if (c == ':') {
+                        ns = name;
+                        name = "";
+                        i++;
+                        c = string[i];
+                    }
+                    else {
+                        name = name + c;
+                        i++;
+                        c = string[i];
+                    }
+                }
+                // Skip spaces
+                while (string[i] == ' ') { i = i + 1; }
+                i = i + 1; // skip {
+                Element elem = new Element(name, ns);
+                addElement(elem);
+                break;
+            }
+        }
+    }
 
 }

Modified: incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java?view=diff&rev=469182&r1=469181&r2=469182
==============================================================================
--- incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java (original)
+++ incubator/felix/trunk/ipojo/src/main/java/org/apache/felix/ipojo/parser/ParseException.java Mon Oct 30 08:36:04 2006
@@ -1,18 +1,20 @@
-/*
- *   Copyright 2006 The Apache Software Foundation
+/* 
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
  *
- *   Licensed under the Apache License, Version 2.0 (the "License");
- *   you may not use this file except in compliance with the License.
- *   You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *   Unless required by applicable law or agreed to in writing, software
- *   distributed under the License is distributed on an "AS IS" BASIS,
- *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *   See the License for the specific language governing permissions and
- *   limitations under the License.
+ *   http://www.apache.org/licenses/LICENSE-2.0
  *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
  */
 package org.apache.felix.ipojo.parser;