Author: clement
Date: Tue Jul 10 10:03:54 2007
New Revision: 555009
URL: http://svn.apache.org/viewvc?view=rev&rev=555009
Log:
Commit a small change on architecture (Felix-311).
Now factories expose a description displayed by the arch command.
Modified:
felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
felix/trunk/ipojo/arch/src/main/resources/metadata.xml
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
Modified:
felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
---
felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
(original)
+++
felix/trunk/ipojo/arch/src/main/java/org/apache/felix/ipojo/arch/ArchCommandImpl.java
Tue Jul 10 10:03:54 2007
@@ -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");
}
}
Modified: felix/trunk/ipojo/arch/src/main/resources/metadata.xml
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/arch/src/main/resources/metadata.xml?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
--- felix/trunk/ipojo/arch/src/main/resources/metadata.xml (original)
+++ felix/trunk/ipojo/arch/src/main/resources/metadata.xml Tue Jul 10 10:03:54
2007
@@ -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>
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
Tue Jul 10 10:03:54 2007
@@ -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();
}
/**
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
(original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/Factory.java
Tue Jul 10 10:03:54 2007
@@ -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
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/ComponentDescription.java
Tue Jul 10 10:03:54 2007
@@ -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();
}
/**
@@ -151,6 +142,42 @@
*/
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;
}
}
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/architecture/PropertyDescription.java
Tue Jul 10 10:03:54 2007
@@ -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";
- }
- }
-
}
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/FactoryProxy.java
Tue Jul 10 10:03:54 2007
@@ -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();
}
/**
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/architecture/ArchitectureHandler.java
Tue Jul 10 10:03:54 2007
@@ -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();
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/composite/service/instantiator/SvcInstance.java
Tue Jul 10 10:03:54 2007
@@ -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;
}
}
Modified:
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
URL:
http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java?view=diff&rev=555009&r1=555008&r2=555009
==============================================================================
---
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
(original)
+++
felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/architecture/ArchitectureHandler.java
Tue Jul 10 10:03:54 2007
@@ -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();