Commit a small change on architecture (Felix-311).
Now factories expose a description displayed by the arch command.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@555009 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java b/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
index 75c2c07..4456cc8 100644
--- a/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
+++ b/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
@@ -21,9 +21,10 @@
import java.io.PrintStream;
import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.architecture.Architecture;
import org.apache.felix.ipojo.architecture.InstanceDescription;
-import org.ungoverned.osgi.service.shell.Command;
+import org.apache.felix.shell.Command;
/**
* Implementation of the arch command printing the actual architecture.
@@ -36,11 +37,16 @@
* List of arch service.
*/
private Architecture[] m_archs;
+
+ /**
+ * Factory services.
+ */
+ private Factory[] m_factories;
/**
* Get the command name.
* @return the command name (arch)
- * @see org.ungoverned.osgi.service.shell.Command#getName()
+ * @see org.apache.felix.shell.Command#getName()
*/
public String getName() {
return "arch";
@@ -49,16 +55,16 @@
/**
* Get help message.
* @return the command usage.
- * @see org.ungoverned.osgi.service.shell.Command#getUsage()
+ * @see org.apache.felix.shell.Command#getUsage()
*/
public String getUsage() {
- return "arch [instance name]";
+ return "arch [-factories] [-instances] [-factory factory_name] [-instance instance_name]";
}
/**
* Get a small description.
* @return get a description.
- * @see org.ungoverned.osgi.service.shell.Command#getShortDescription()
+ * @see org.apache.felix.shell.Command#getShortDescription()
*/
public String getShortDescription() {
return "Architecture command : display the architecture";
@@ -69,35 +75,98 @@
* @param line : command line
* @param out : the default output stream
* @param err : the error output stream
- * @see org.ungoverned.osgi.service.shell.Command#execute(java.lang.String, java.io.PrintStream, java.io.PrintStream)
+ * @see org.apache.felix.shell.Command#execute(java.lang.String, java.io.PrintStream, java.io.PrintStream)
*/
public void execute(String line, PrintStream out, PrintStream err) {
synchronized (this) {
- if (line.substring("arch".length()).trim().length() == 0) {
- for (int i = 0; i < m_archs.length; i++) {
- InstanceDescription instance = m_archs[i].getInstanceDescription();
- if (instance.getState() == ComponentInstance.VALID) {
- out.println("Instance " + instance.getName() + " -> valid");
- }
- if (instance.getState() == ComponentInstance.INVALID) {
- out.println("Instance " + instance.getName() + " -> invalid");
- }
- if (instance.getState() == ComponentInstance.STOPPED) {
- out.println("Instance " + instance.getName() + " -> stopped");
- }
- }
- } else {
- String line2 = line.substring("arch".length()).trim();
- for (int i = 0; i < m_archs.length; i++) {
- InstanceDescription instance = m_archs[i].getInstanceDescription();
- if (instance.getName().equalsIgnoreCase(line2)) {
- out.println(instance.getDescription());
- return;
- }
- }
- err.println("Instance " + line2 + " not found");
+ String line2 = line.substring("arch".length()).trim();
+
+ if (line2.equalsIgnoreCase("-instances") || line2.length() == 0) {
+ printInstances(out);
+ return;
}
+
+ if (line2.equalsIgnoreCase("-factories")) {
+ printFactories(out);
+ return;
+ }
+
+ if (line2.startsWith("-factory")) {
+ String name = line2.substring("-factory".length()).trim();
+ printFactory(name, out, err);
+ return;
+ }
+
+ if (line2.startsWith("-instance")) {
+ String name = line2.substring("-instance".length()).trim();
+ printInstance(name, out, err);
+ return;
+ }
+
+ err.println(getUsage());
}
}
+
+ /**
+ * Print instance list.
+ * @param out : default print stream
+ */
+ private void printInstances(PrintStream out) {
+ for (int i = 0; i < m_archs.length; i++) {
+ InstanceDescription instance = m_archs[i].getInstanceDescription();
+ if (instance.getState() == ComponentInstance.VALID) {
+ out.println("Instance " + instance.getName() + " -> valid");
+ }
+ if (instance.getState() == ComponentInstance.INVALID) {
+ out.println("Instance " + instance.getName() + " -> invalid");
+ }
+ if (instance.getState() == ComponentInstance.STOPPED) {
+ out.println("Instance " + instance.getName() + " -> stopped");
+ }
+ }
+ }
+
+ /**
+ * Print instance description.
+ * @param name : instance name
+ * @param out : default print stream
+ * @param err : error print stream (if the instance is not found)
+ */
+ private void printInstance(String name, PrintStream out, PrintStream err) {
+ for (int i = 0; i < m_archs.length; i++) {
+ InstanceDescription instance = m_archs[i].getInstanceDescription();
+ if (instance.getName().equalsIgnoreCase(name)) {
+ out.println(instance.getDescription());
+ return;
+ }
+ }
+ err.println("Instance " + name + " not found");
+ }
+
+ /**
+ * Print Factory information.
+ * @param out : output stream
+ */
+ private void printFactories(PrintStream out) {
+ for (int i = 0; i < m_factories.length; i++) {
+ out.println("Factory " + m_factories[i].getName());
+ }
+ }
+
+ /**
+ * Print factory description.
+ * @param name : factory name
+ * @param out : default print stream
+ * @param err : error print stream (if the factory is not found)
+ */
+ private void printFactory(String name, PrintStream out, PrintStream err) {
+ for (int i = 0; i < m_factories.length; i++) {
+ if (m_factories[i].getName().equalsIgnoreCase(name)) {
+ out.println(m_factories[i].getDescription());
+ return;
+ }
+ }
+ err.println("Factory " + name + " not found");
+ }
}
diff --git a/ipojo/arch/src/main/resources/metadata.xml b/ipojo/arch/src/main/resources/metadata.xml
index 335418a..7934090 100644
--- a/ipojo/arch/src/main/resources/metadata.xml
+++ b/ipojo/arch/src/main/resources/metadata.xml
@@ -3,6 +3,7 @@
<Component className="org.apache.felix.ipojo.arch.ArchCommandImpl">
<Provides/>
<Requires field="m_archs" optional="true"/>
+ <Requires field="m_factories" optional="true"/>
</Component>
<instance component="org.apache.felix.ipojo.arch.ArchCommandImpl" name="ArchCommand"/>
</iPOJO>
\ No newline at end of file
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
index bb7f2a3..1f42b9a 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
@@ -412,10 +412,10 @@
* Get the component type description attached to this factory.
*
* @return : the component type description
- * @see org.apache.felix.ipojo.Factory#getComponentDescription()
+ * @see org.apache.felix.ipojo.Factory#getDescription()
*/
- public ComponentDescription getComponentDescription() {
- return m_componentDesc;
+ public Element getDescription() {
+ return m_componentDesc.getDescription();
}
/**
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
index 3354ac4..3df44b4 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
@@ -20,7 +20,7 @@
import java.util.Dictionary;
-import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.metadata.Element;
/**
* Component Type Factory Service. This service is exposed by a instance manager
@@ -56,7 +56,7 @@
*
* @return the component type information.
*/
- ComponentDescription getComponentDescription();
+ Element getDescription();
/**
* Check if the given configuration is acceptable as a configuration of a
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
index c6c629d..a519d0b 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
@@ -18,6 +18,9 @@
*/
package org.apache.felix.ipojo.architecture;
+import org.apache.felix.ipojo.metadata.Attribute;
+import org.apache.felix.ipojo.metadata.Element;
+
/**
* Component Type information.
*
@@ -71,19 +74,7 @@
* @see java.lang.Object#toString()
*/
public String toString() {
- String res = "";
- if (m_className == null) {
- res += "Component Type : " + m_name + " (Composition) \n";
- } else {
- res += "Component Type : " + m_name + " (" + m_className + ") \n";
- }
- for (int i = 0; i < m_providedServiceSpecification.length; i++) {
- res += "\tProvides : " + m_providedServiceSpecification[i] + "\n";
- }
- for (int i = 0; i < m_properties.length; i++) {
- res += "\tProperty : " + m_properties[i] + "\n";
- }
- return res;
+ return getDescription().toString();
}
/**
@@ -152,5 +143,41 @@
public String getName() {
return m_name;
}
+
+ /**
+ * Get the component type description.
+ * @return : the description
+ */
+ public Element getDescription() {
+ Element desc = new Element("Factory", "");
+
+ desc.addAttribute(new Attribute("name", m_name));
+
+ if (m_className != null) {
+ desc.addAttribute(new Attribute("Implementation-Class", m_className));
+ } else {
+ desc.addAttribute(new Attribute("Composite", "true"));
+ }
+
+ for (int i = 0; i < m_providedServiceSpecification.length; i++) {
+ Element prov = new Element("provides", "");
+ prov.addAttribute(new Attribute("specification", m_providedServiceSpecification[i]));
+ desc.addElement(prov);
+ }
+
+ for (int i = 0; i < m_properties.length; i++) {
+ Element prop = new Element("property", "");
+ prop.addAttribute(new Attribute("name", m_properties[i].getName()));
+ prop.addAttribute(new Attribute("type", m_properties[i].getType()));
+ if (m_properties[i].getValue() != null) {
+ prop.addAttribute(new Attribute("value", m_properties[i].getValue()));
+ } else {
+ prop.addAttribute(new Attribute("value", "REQUIRED"));
+ }
+ desc.addElement(prop);
+ }
+
+ return desc;
+ }
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
index 711c057..f3f63f4 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
@@ -77,17 +77,4 @@
return m_value;
}
- /**
- * Get a displayed form of the current property.
- * @return : a String representing this property.
- * @see java.lang.Object#toString()
- */
- public String toString() {
- if (m_value != null) {
- return getName() + " - " + getType() + " - " + getValue();
- } else {
- return getName() + " - " + getType() + " - REQUIRED";
- }
- }
-
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
index 0a70961..6919306 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
@@ -24,7 +24,7 @@
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.ServiceContext;
import org.apache.felix.ipojo.UnacceptableConfiguration;
-import org.apache.felix.ipojo.architecture.ComponentDescription;
+import org.apache.felix.ipojo.metadata.Element;
/**
* Bridge representing a Factory inside a composition.
@@ -86,10 +86,10 @@
* configuration properties ...
*
* @return the component type information.
- * @see org.apache.felix.ipojo.Factory#getComponentDescription()
+ * @see org.apache.felix.ipojo.Factory#getDescription()
*/
- public ComponentDescription getComponentDescription() {
- return m_delegate.getComponentDescription();
+ public Element getDescription() {
+ return m_delegate.getDescription();
}
/**
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
index 069df27..d52bfdc 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
@@ -110,7 +110,7 @@
/**
* Get the instance description.
* @return the instance description
- * @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
+ * @see org.apache.felix.ipojo.architecture.Architecture#getDescription()
*/
public InstanceDescription getInstanceDescription() {
return m_manager.getInstanceDescription();
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
index 9956520..a69dab6 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
@@ -29,7 +29,7 @@
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.ServiceContext;
import org.apache.felix.ipojo.UnacceptableConfiguration;
-import org.apache.felix.ipojo.architecture.PropertyDescription;
+import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceEvent;
@@ -274,8 +274,9 @@
*/
private boolean match(Factory fact) {
// Check if the factory can provide the spec
- for (int i = 0; i < fact.getComponentDescription().getprovidedServiceSpecification().length; i++) {
- if (fact.getComponentDescription().getprovidedServiceSpecification()[i].equals(m_specification)) {
+ Element[] provides = fact.getDescription().getElements("provides");
+ for (int i = 0; i < provides.length; i++) {
+ if (provides[i].getAttribute("specification").equals(m_specification)) {
// Check that the factory needs every properties contained in
// the configuration
@@ -310,9 +311,9 @@
* @return true if the factory support this property
*/
private boolean containsProperty(String name, Factory factory) {
- PropertyDescription[] props = factory.getComponentDescription().getProperties();
+ Element[] props = factory.getDescription().getElements("property");
for (int i = 0; i < props.length; i++) {
- if (props[i].getName().equalsIgnoreCase(name)) {
+ if (props[i].getAttribute("name").equalsIgnoreCase(name)) {
return true;
}
}
diff --git a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
index 1c0a906..a6234db 100644
--- a/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
+++ b/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
@@ -111,7 +111,7 @@
/**
* Get the instance description.
* @return the instance description
- * @see org.apache.felix.ipojo.architecture.Architecture#getComponentDescription()
+ * @see org.apache.felix.ipojo.architecture.Architecture#getDescription()
*/
public InstanceDescription getInstanceDescription() {
return m_manager.getInstanceDescription();