You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cl...@apache.org on 2007/09/25 15:27:54 UTC
svn commit: r579239 [7/8] - in /felix/trunk/ipojo: annotations/ ant/ arch/
arch/src/main/java/org/apache/felix/ipojo/arch/ arch/src/main/resources/
core/ core/src/main/java/org/apache/felix/ipojo/
core/src/main/java/org/apache/felix/ipojo/architecture/...
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandler.java Tue Sep 25 06:27:49 2007
@@ -23,9 +23,9 @@
import java.util.Dictionary;
import java.util.List;
-import org.apache.felix.ipojo.Handler;
-import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.PolicyServiceContext;
+import org.apache.felix.ipojo.PrimitiveHandler;
import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.handlers.dependency.nullable.NullableObjectWriter;
import org.apache.felix.ipojo.metadata.Element;
@@ -36,19 +36,13 @@
import org.osgi.framework.ServiceReference;
/**
- * The dependency handler manages a list of dependencies.
- *
+ * The dependency handler manages a list of service dependencies.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class DependencyHandler extends Handler {
+public class DependencyHandler extends PrimitiveHandler {
/**
- * The instance manager using this handler.
- */
- private InstanceManager m_manager;
-
- /**
- * List of depednencies of the component.
+ * List of dependencies of the component.
*/
private Dependency[] m_dependencies = new Dependency[0];
@@ -59,10 +53,9 @@
/**
* State of the handler.
+ * Lifecycle controller.
*/
- private int m_state;
-
- // ===================== Fields getters & setters =====================
+ private boolean m_state;
/**
* Add a dependency.
@@ -71,9 +64,7 @@
*/
private void addDependency(Dependency dep) {
for (int i = 0; (m_dependencies != null) && (i < m_dependencies.length); i++) {
- if (m_dependencies[i] == dep) {
- return;
- }
+ if (m_dependencies[i] == dep) { return; }
}
if (m_dependencies.length > 0) {
Dependency[] newDep = new Dependency[m_dependencies.length + 1];
@@ -92,9 +83,7 @@
*/
private void addNullableClass(Class clazz) {
for (int i = 0; (m_nullableClasses != null) && (i < m_nullableClasses.length); i++) {
- if (m_nullableClasses[i] == clazz) {
- return;
- }
+ if (m_nullableClasses[i] == clazz) { return; }
}
if (m_nullableClasses.length > 0) {
Class[] newClass = new Class[m_nullableClasses.length + 1];
@@ -115,38 +104,26 @@
}
/**
- * Get the instance manager.
- * @return the instance manager
- */
- protected InstanceManager getInstanceManager() {
- return m_manager;
- }
-
- // ===================== Handler implementation =====================
-
- /**
* Check the validity of the dependencies.
*/
protected void checkContext() {
- synchronized (this) {
+ synchronized (m_dependencies) {
// Store the initial state
- int initialState = m_state;
+ boolean initialState = m_state;
// Check the component dependencies
if (validateComponentDependencies()) {
// The dependencies are valid
- if (initialState == InstanceManager.INVALID) {
+ if (!initialState) {
// There is a state change
- m_state = InstanceManager.VALID;
- m_manager.checkInstanceState();
+ m_state = true;
}
// Else do nothing, the component state stay VALID
} else {
// The dependencies are not valid
- if (initialState == InstanceManager.VALID) {
+ if (initialState) {
// There is a state change
- m_state = InstanceManager.INVALID;
- m_manager.checkInstanceState();
+ m_state = false;
}
// Else do nothing, the component state stay UNRESOLVED
}
@@ -157,25 +134,25 @@
/**
* Check if the dependency given is valid in the sense that metadata are
* consistent.
- *
* @param dep : the dependency to check
* @param manipulation : the component-type manipulation metadata
* @return true if the dependency is valid
+ * @throws ConfigurationException : the checked dependency is not correct
*/
- private boolean checkDependency(Dependency dep, ManipulationMetadata manipulation) {
+ private boolean checkDependency(Dependency dep, ManipulationMetadata manipulation) throws ConfigurationException {
// Check the internal type of dependency
String field = dep.getField();
DependencyCallback[] callbacks = dep.getCallbacks();
-
+
for (int i = 0; i < callbacks.length; i++) {
MethodMetadata[] mets = manipulation.getMethods(callbacks[i].getMethodName());
if (mets.length == 0) {
- getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "A dependency callback " + callbacks[i].getMethodName() + " does not exist in the implementation");
- return false;
+ getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "A requirement callback " + callbacks[i].getMethodName() + " does not exist in the implementation");
+ throw new ConfigurationException("Requirement Callback : A requirement callback " + callbacks[i].getMethodName() + " does not exist in the implementation", getInstanceManager().getFactory().getName());
}
if (mets[0].getMethodArguments().length > 1) {
- getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "A dependency callback " + callbacks[i].getMethodName() + " must have 0 or 1 argument");
- return false;
+ getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "A requirement callback " + callbacks[i].getMethodName() + " must have 0 or 1 argument");
+ throw new ConfigurationException("Requirement Callback : A requirement callback " + callbacks[i].getMethodName() + " must have 0 or 1 argument", getInstanceManager().getFactory().getName());
}
if (mets[0].getMethodArguments().length == 0) {
callbacks[i].setArgument("EMPTY");
@@ -186,68 +163,67 @@
dep.setSpecification(mets[0].getMethodArguments()[0]);
}
if (!dep.getSpecification().equals(mets[0].getMethodArguments()[0])) {
- m_manager.getFactory().getLogger().log(Logger.WARNING, "[DependencyHandler on " + m_manager.getClassName() + "] The field type [" + mets[0].getMethodArguments()[0] + "] and the needed service interface ["
- + dep.getSpecification() + "] are not the same");
+ log(Logger.WARNING, "[DependencyHandler on " + getInstanceManager().getInstanceName() + "] The field type [" + mets[0].getMethodArguments()[0] + "] and the needed service interface [" + dep.getSpecification()
+ + "] are not the same");
dep.setSpecification(mets[0].getMethodArguments()[0]);
}
}
- }
+ }
}
-
+
if (field != null) {
FieldMetadata fm = manipulation.getField(field);
if (fm == null) {
- getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "A dependency field " + field + " does not exist in the implementation class");
- return false;
+ getInstanceManager().getFactory().getLogger().log(Logger.ERROR, "A requirement field " + field + " does not exist in the implementation class");
+ throw new ConfigurationException("Requirement Callback : A requirement field " + field + " does not exist in the implementation class", getInstanceManager().getFactory().getName());
}
- String type = fm.getFieldType();
+ String type = fm.getFieldType();
if (type.endsWith("[]")) {
// Set the dependency to multiple
dep.setAggregate();
type = type.substring(0, type.length() - 2);
}
- if (dep.getSpecification() == null) { dep.setSpecification(type); }
+ if (dep.getSpecification() == null) {
+ dep.setSpecification(type);
+ }
if (!dep.getSpecification().equals(type)) {
- m_manager.getFactory().getLogger().log(Logger.WARNING, "[DependencyHandler on " + m_manager.getClassName() + "] The field type [" + type + "] and the needed service interface ["
- + dep.getSpecification() + "] are not the same");
+ log(Logger.WARNING, "[DependencyHandler on " + getInstanceManager().getInstanceName() + "] The field type [" + type + "] and the needed service interface [" + dep.getSpecification() + "] are not the same");
dep.setSpecification(type);
}
}
-
+
//Check that all required info are set
return dep.getSpecification() != null;
}
/**
* Configure the handler.
- * @param im : the instance manager
* @param componentMetadata : the component type metadata
* @param configuration : the instance configuration
+ * @throws ConfigurationException : one dependency metadata is not correct.
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
- public void configure(InstanceManager im, Element componentMetadata, Dictionary configuration) {
- m_manager = im;
+ public void configure(Element componentMetadata, Dictionary configuration) throws ConfigurationException {
m_dependencies = new Dependency[0];
m_nullableClasses = new Class[0];
-
+
ManipulationMetadata manipulation = new ManipulationMetadata(componentMetadata);
List fl = new ArrayList();
// Create the dependency according to the component metadata
- Element[] deps = componentMetadata.getElements("Requires");
-
+ Element[] deps = componentMetadata.getElements("Requires");
+
// DEPRECATED BLOCK :
if (deps.length == 0) {
deps = componentMetadata.getElements("Dependency");
if (deps.length != 0) {
- im.getFactory().getLogger().log(Logger.WARNING, "Dependency is deprecated, please use 'requires' instead of 'dependency'");
+ log(Logger.WARNING, "Dependency is deprecated, please use 'requires' instead of 'dependency'");
}
}
// END OF DEPRECATED BLOCK
-
for (int i = 0; i < deps.length; i++) {
// Create the dependency metadata
String field = null;
@@ -263,19 +239,19 @@
filter = deps[i].getAttribute("filter");
}
boolean optional = false;
- if (deps[i].containsAttribute("optional") && deps[i].getAttribute("optional").equals("true")) {
+ if (deps[i].containsAttribute("optional") && "true".equals(deps[i].getAttribute("optional"))) {
optional = true;
}
boolean aggregate = false;
- if (deps[i].containsAttribute("aggregate") && deps[i].getAttribute("aggregate").equals("true")) {
+ if (deps[i].containsAttribute("aggregate") && "true".equals(deps[i].getAttribute("aggregate"))) {
aggregate = true;
}
-
+
String id = null;
if (deps[i].containsAttribute("id")) {
id = deps[i].getAttribute("id");
}
-
+
int scopePolicy = -1;
if (deps[i].containsAttribute("scope")) {
if (deps[i].getAttribute("scope").equalsIgnoreCase("global")) {
@@ -284,17 +260,20 @@
scopePolicy = PolicyServiceContext.LOCAL;
} else if (deps[i].getAttribute("scope").equalsIgnoreCase("composite+global")) {
scopePolicy = PolicyServiceContext.LOCAL_AND_GLOBAL;
- }
+ }
}
Dependency dep = new Dependency(this, field, serviceSpecification, filter, optional, aggregate, id, scopePolicy);
-
+
// Look for dependency callback :
for (int j = 0; j < (deps[i].getElements("Callback", "")).length; j++) {
+ if (!(deps[i].getElements("Callback", "")[j].containsAttribute("method") && deps[i].getElements("Callback", "")[j].containsAttribute("type"))) {
+ throw new ConfigurationException("Requirement Callback : a dependency callback must contain a method and a type attribute", getInstanceManager().getFactory().getName());
+ }
String method = deps[i].getElements("Callback", "")[j].getAttribute("method");
String type = deps[i].getElements("Callback", "")[j].getAttribute("type");
int methodType = 0;
- if (type.equals("bind")) {
+ if ("bind".equalsIgnoreCase(type)) {
methodType = DependencyCallback.BIND;
} else {
methodType = DependencyCallback.UNBIND;
@@ -303,7 +282,7 @@
DependencyCallback dc = new DependencyCallback(dep, method, methodType);
dep.addDependencyCallback(dc);
}
-
+
// Check the dependency :
if (checkDependency(dep, manipulation)) {
addDependency(dep);
@@ -311,14 +290,13 @@
fl.add(manipulation.getField(dep.getField()));
}
} else {
- m_manager.getFactory().getLogger().log(Logger.ERROR,
- "[DependencyHandler on " + m_manager.getClassName() + "] The dependency on " + dep.getField() + " is not valid");
+ log(Logger.ERROR, "[DependencyHandler on " + getInstanceManager().getInstanceName() + "] The dependency on " + dep.getField() + " is not valid");
}
}
if (deps.length > 0) {
- m_manager.register(this, (FieldMetadata[]) fl.toArray(new FieldMetadata[0]), manipulation.getMethods());
+ getInstanceManager().register(this, (FieldMetadata[]) fl.toArray(new FieldMetadata[0]), manipulation.getMethods());
}
}
@@ -328,8 +306,7 @@
* @param dep : the dependency
*/
private void createNullableClass(Dependency dep) {
- m_manager.getFactory().getLogger().log(Logger.INFO,
- "[DependencyHandler on " + m_manager.getClassName() + "] Try to load the nullable class for " + dep.getSpecification());
+ log(Logger.INFO, "[DependencyHandler on " + getInstanceManager().getInstanceName() + "] Try to load the nullable class for " + dep.getSpecification());
// String[] segment =
// dep.getMetadata().getServiceSpecification().split("[.]");
@@ -337,23 +314,22 @@
// - 1] + "Nullable";
String className = dep.getSpecification() + "Nullable";
String resource = dep.getSpecification().replace('.', '/') + ".class";
- URL url = m_manager.getContext().getBundle().getResource(resource);
+ URL url = getInstanceManager().getContext().getBundle().getResource(resource);
try {
byte[] b = NullableObjectWriter.dump(url, dep.getSpecification());
Class c = null;
try {
- c = m_manager.getFactory().defineClass(className, b, null);
+ c = getInstanceManager().getFactory().defineClass(className, b, null);
} catch (Exception e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "Cannot define the nullable class : " + e.getMessage());
+ log(Logger.ERROR, "Cannot define the nullable class : " + e.getMessage());
+ e.printStackTrace();
return;
}
addNullableClass(c);
- m_manager.getFactory().getLogger().log(Logger.INFO,
- "[DependencyHandler on " + m_manager.getClassName() + "] Nullable class created for " + dep.getSpecification());
+ log(Logger.INFO, "[DependencyHandler on " + getInstanceManager().getInstanceName() + "] Nullable class created for " + dep.getSpecification());
} catch (Exception e2) {
- m_manager.getFactory().getLogger().log(Logger.ERROR,
- "[DependencyHandler on " + m_manager.getClassName() + "] Cannot load the nullable class for " + dep.getSpecification(), e2);
+ log(Logger.ERROR, "[DependencyHandler on " + getInstanceManager().getInstanceName() + "] Cannot load the nullable class for " + dep.getSpecification(), e2);
}
}
@@ -367,9 +343,7 @@
protected Class getNullableClass(String name) {
for (int i = 0; i < m_nullableClasses.length; i++) {
Class c = m_nullableClasses[i];
- if (c.getName().equals(name)) {
- return c;
- }
+ if (c.getName().equals(name)) { return c; }
}
return null;
}
@@ -392,7 +366,7 @@
// Else return the value
return value;
}
-
+
/**
* Method Entry callback.
* @param methodId : method Id.
@@ -404,7 +378,7 @@
dep.entry(methodId);
}
}
-
+
/**
* Method Exit callback.
* @param methodId : method id.
@@ -417,25 +391,12 @@
dep.exit(methodId);
}
}
-
-
-
- /**
- * Check the handler validity.
- * @return true if all mandatory dependencies are resolved.
- * @see org.apache.felix.ipojo.Handler#isValid()
- */
- public boolean isValid() {
- return m_state == InstanceManager.VALID;
- }
/**
* Handler start method.
* @see org.apache.felix.ipojo.Handler#start()
*/
public void start() {
- m_manager.getFactory().getLogger().log(Logger.INFO, "[DependencyHandler on " + m_manager.getClassName() + "] Start the dependency handler");
-
// Start the dependencies, for optional dependencies create Nullable
// class
for (int i = 0; i < m_dependencies.length; i++) {
@@ -446,20 +407,10 @@
dep.start();
}
// Check the state
- m_state = m_manager.getState();
checkContext();
}
/**
- * Handler stateChanged method.
- * @param state : new instance state
- * @see org.apache.felix.ipojo.Handler#stateChanged(int)
- */
- public void stateChanged(int state) {
- m_state = state;
- }
-
- /**
* Handler stop method.
* @see org.apache.felix.ipojo.Handler#stop()
*/
@@ -474,9 +425,9 @@
* Handler createInstance method.
* This method is overided to allow delayed callback invocation.
* @param instance : the created object
- * @see org.apache.felix.ipojo.Handler#createInstance(java.lang.Object)
+ * @see org.apache.felix.ipojo.Handler#objectCreated(java.lang.Object)
*/
- public void createInstance(Object instance) {
+ public void objectCreated(Object instance) {
for (int i = 0; i < m_dependencies.length; i++) {
m_dependencies[i].callBindMethod(instance);
}
@@ -490,10 +441,8 @@
boolean valide = true;
for (int i = 0; i < m_dependencies.length; i++) {
Dependency dep = m_dependencies[i];
- valide = valide & dep.isSatisfied();
- if (!valide) {
- return false;
- }
+ valide = valide & dep.getState() == Dependency.RESOLVED;
+ if (!valide) { return false; }
}
return valide;
}
@@ -504,7 +453,7 @@
* @see org.apache.felix.ipojo.Handler#getDescription()
*/
public HandlerDescription getDescription() {
- DependencyHandlerDescription dhd = new DependencyHandlerDescription(isValid());
+ DependencyHandlerDescription dhd = new DependencyHandlerDescription(this);
for (int j = 0; j < getDependencies().length; j++) {
Dependency dep = getDependencies()[j];
// Create & add the dependency description
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/dependency/DependencyHandlerDescription.java Tue Sep 25 06:27:49 2007
@@ -21,10 +21,10 @@
import java.util.Iterator;
import java.util.List;
+import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.metadata.Attribute;
import org.apache.felix.ipojo.metadata.Element;
-import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
/**
@@ -41,11 +41,10 @@
/**
* Constructor.
- *
- * @param isValid : the validity of the dependency handler.
+ * @param h : Handler.
*/
- public DependencyHandlerDescription(boolean isValid) {
- super(DependencyHandler.class.getName(), isValid);
+ public DependencyHandlerDescription(Handler h) {
+ super(h);
}
/**
@@ -91,7 +90,7 @@
Element dep = new Element("Requires", "");
dep.addAttribute(new Attribute("Specification", m_dependencies[i].getInterface()));
- if (!m_dependencies[i].getFilter().equals("")) {
+ if (!"".equals(m_dependencies[i].getFilter())) {
dep.addAttribute(new Attribute("Filter", m_dependencies[i].getFilter()));
}
@@ -113,10 +112,10 @@
while (it.hasNext()) {
Element use = new Element("Uses", "");
ServiceReference ref = (ServiceReference) it.next();
- use.addAttribute(new Attribute("service.id", ref.getProperty(Constants.SERVICE_ID).toString()));
- String pid = (String) ref.getProperty(Constants.SERVICE_PID);
- if (pid != null) {
- use.addAttribute(new Attribute("service.pid", pid));
+ use.addAttribute(new Attribute("instance.name", ref.getProperty("instance.name").toString()));
+ String in = (String) ref.getProperty("instance.name");
+ if (in != null) {
+ use.addAttribute(new Attribute("instance.name", in));
}
dep.addElement(use);
}
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallback.java Tue Sep 25 06:27:49 2007
@@ -41,7 +41,7 @@
protected static final int INVALIDATE = 0;
/**
- * Transition on wich calling the callback.
+ * Transition on which calling the callback.
*/
private int m_transition;
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/callback/LifecycleCallbackHandler.java Tue Sep 25 06:27:49 2007
@@ -22,8 +22,9 @@
import java.util.Dictionary;
import org.apache.felix.ipojo.ComponentInstance;
-import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.PrimitiveHandler;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.ManipulationMetadata;
import org.apache.felix.ipojo.parser.MethodMetadata;
@@ -34,7 +35,7 @@
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class LifecycleCallbackHandler extends Handler {
+public class LifecycleCallbackHandler extends PrimitiveHandler {
/**
* The list of the callback of the component.
@@ -45,12 +46,6 @@
* State of the instance manager (unresolved at the beginning).
*/
private int m_state = InstanceManager.INVALID;
-
- /**
- * The instance manager.
- */
- private InstanceManager m_manager;
-
/**
* Does a POJO object be created at starting.
*/
@@ -81,13 +76,12 @@
/**
* Configure the handler.
- * @param cm : the instance manager
* @param metadata : the component type metadata
* @param configuration : the instance configuration
+ * @throws ConfigurationException : one callback metadata is not correct (either the transition or the method are not correct).
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
- public void configure(InstanceManager cm, Element metadata, Dictionary configuration) {
- m_manager = cm;
+ public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
m_callbacks = new LifecycleCallback[0];
if (metadata.containsAttribute("immediate") && metadata.getAttribute("immediate").equalsIgnoreCase("true")) {
@@ -98,6 +92,9 @@
Element[] hooksMetadata = metadata.getElements("callback");
for (int i = 0; i < hooksMetadata.length; i++) {
+ if (! hooksMetadata[i].containsAttribute("method")) {
+ throw new ConfigurationException("Lifecycle callback : A callback needs to contains a method attribute", getInstanceManager().getFactory().getName());
+ }
String methodName = hooksMetadata[i].getAttribute("method");
MethodMetadata met = mm.getMethod(methodName, new String[0]);
@@ -114,7 +111,7 @@
//DEPRECATED BLOCK
if (hooksMetadata[i].containsAttribute("initial")) {
- cm.getFactory().getLogger().log(Logger.WARNING, "initial & final are deprecated, please use 'transition=validate|invalidate' instead.");
+ log(Logger.WARNING, "initial & final are deprecated, please use 'transition=validate|invalidate' instead.");
if (hooksMetadata[i].containsAttribute("final")) {
if (hooksMetadata[i].getAttribute("initial").equalsIgnoreCase("valid") && hooksMetadata[i].getAttribute("final").equalsIgnoreCase("invalid")) {
transition = LifecycleCallback.INVALIDATE;
@@ -126,8 +123,8 @@
//END OF DEPRECATED BLOCK
if (transition == -1) {
- cm.getFactory().getLogger().log(Logger.ERROR, "Unknown or malformed transition");
- return;
+ log(Logger.ERROR, "Unknown or malformed transition");
+ throw new ConfigurationException("Lifecycle callback : Unknown or malformed transition", getInstanceManager().getFactory().getName());
}
LifecycleCallback hk = null;
@@ -138,9 +135,6 @@
}
addCallback(hk);
}
- if (m_callbacks.length > 0 || m_immediate) {
- m_manager.register(this);
- }
}
/**
@@ -159,14 +153,6 @@
}
/**
- * Get the instance manager.
- * @return the instance manager
- */
- protected InstanceManager getInstanceManager() {
- return m_manager;
- }
-
- /**
* When the state change call the associated callback.
*
* @param state : the new instance state.
@@ -182,8 +168,8 @@
}
// Manage immediate component
- if (m_immediate && transition == LifecycleCallback.VALIDATE && m_manager.getPojoObjects().length == 0) {
- m_manager.createPojoObject();
+ if (m_immediate && transition == LifecycleCallback.VALIDATE && getInstanceManager().getPojoObjects().length == 0) {
+ getInstanceManager().getPojoObject();
}
for (int i = 0; i < m_callbacks.length; i++) {
@@ -191,15 +177,15 @@
try {
m_callbacks[i].call();
} catch (NoSuchMethodException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR,
- "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
+ log(Logger.ERROR,
+ "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not found", e);
} catch (IllegalAccessException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR,
- "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
+ log(Logger.ERROR,
+ "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " is not accessible", e);
} catch (InvocationTargetException e) {
- m_manager.getFactory().getLogger().log(
+ log(
Logger.ERROR,
- "[" + m_manager.getClassName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : "
+ "[" + getInstanceManager().getInstanceName() + "] The callback method " + m_callbacks[i].getMethod() + " has throws an exception : "
+ e.getMessage());
}
}
@@ -207,5 +193,4 @@
// Update to internal state
m_state = state;
}
-
}
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/lifecycle/controller/ControllerHandler.java Tue Sep 25 06:27:49 2007
@@ -20,8 +20,10 @@
import java.util.Dictionary;
-import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.ComponentInstance;
+import org.apache.felix.ipojo.ConfigurationException;
import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.PrimitiveHandler;
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.FieldMetadata;
import org.apache.felix.ipojo.parser.ManipulationMetadata;
@@ -32,12 +34,7 @@
* This handler allow a POJO to vote for the instance state. By setting a boolean field to true or false, the handler state changed.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class ControllerHandler extends Handler {
-
- /**
- * Instance Manager.
- */
- private InstanceManager m_manager;
+public class ControllerHandler extends PrimitiveHandler {
/**
* Actual handler (i.e. field value) state
@@ -47,13 +44,12 @@
/**
* Configure method.
* Look for the first 'controller' element.
- * @param im : instance manager
* @param metadata : metadata
* @param configuration : configuration
+ * @throws ConfigurationException : the field attribute is missing or does not exist in the class.
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
- public void configure(InstanceManager im, Element metadata, Dictionary configuration) {
- m_manager = im;
+ public void configure(Element metadata, Dictionary configuration) throws ConfigurationException {
String field = null;
Element[] lc = metadata.getElements("controller");
if (lc.length > 0) {
@@ -61,8 +57,8 @@
if (lc[0].containsAttribute("field")) {
field = lc[0].getAttribute("field");
} else {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "A lifecycle controler needs to contain a field attribute");
- return;
+ log(Logger.ERROR, "A lifecycle controler needs to contain a field attribute");
+ throw new ConfigurationException("Lifecycle controller : the controller element needs to have a field attribute", getInstanceManager().getFactory().getName());
}
} else {
return;
@@ -71,16 +67,16 @@
ManipulationMetadata mm = new ManipulationMetadata(metadata);
FieldMetadata fm = mm.getField(field);
if (fm == null) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "The field " + field + " does not exist in the class");
- return;
+ log(Logger.ERROR, "The field " + field + " does not exist in the class");
+ throw new ConfigurationException("Lifecycle controller : The field " + field + " does not exist in the class", getInstanceManager().getFactory().getName());
}
if (!fm.getFieldType().equalsIgnoreCase("boolean")) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "The field " + field + " must be a boolean (" + fm.getFieldType() + " found)");
- return;
+ log(Logger.ERROR, "The field " + field + " must be a boolean (" + fm.getFieldType() + " found)");
+ throw new ConfigurationException("Lifecycle controller : The field " + field + " must be a boolean (" + fm.getFieldType() + " found)", getInstanceManager().getFactory().getName());
}
- im.register(this, new FieldMetadata[] {fm}, null);
+ getInstanceManager().register(this, new FieldMetadata[] {fm}, null);
}
/**
@@ -100,15 +96,6 @@
public void stop() { }
/**
- * Return the field value.
- * @return the field value (i.e. the handler state)
- * @see org.apache.felix.ipojo.Handler#isValid()
- */
- public boolean isValid() {
- return m_state;
- }
-
- /**
* GetterCallback.
* Return the stored value.
* @param field : field name.
@@ -130,10 +117,14 @@
boolean nv = ((Boolean) o).booleanValue();
if (nv != m_state) {
m_state = nv;
- m_manager.checkInstanceState();
+ if (m_state) {
+ ((InstanceManager) getInstance()).setState(ComponentInstance.VALID);
+ } else {
+ ((InstanceManager) getInstance()).setState(ComponentInstance.INVALID);
+ }
}
} else {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "Boolean expected");
+ log(Logger.ERROR, "Boolean expected");
}
}
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/Property.java Tue Sep 25 06:27:49 2007
@@ -178,35 +178,35 @@
}
// Simple :
- if (m_type.equals("string") || m_type.equals("String")) {
+ if ("string".equals(m_type) || "String".equals(m_type)) {
m_value = new String(value);
return;
}
- if (m_type.equals("boolean")) {
+ if ("boolean".equals(m_type)) {
m_value = new Boolean(value);
return;
}
- if (m_type.equals("byte")) {
+ if ("byte".equals(m_type)) {
m_value = new Byte(value);
return;
}
- if (m_type.equals("short")) {
+ if ("short".equals(m_type)) {
m_value = new Short(value);
return;
}
- if (m_type.equals("int")) {
+ if ("int".equals(m_type)) {
m_value = new Integer(value);
return;
}
- if (m_type.equals("long")) {
+ if ("long".equals(m_type)) {
m_value = new Long(value);
return;
}
- if (m_type.equals("float")) {
+ if ("float".equals(m_type)) {
m_value = new Float(value);
return;
}
- if (m_type.equals("double")) {
+ if ("double".equals(m_type)) {
m_value = new Double(value);
return;
}
@@ -243,11 +243,11 @@
* @param values : the new value
*/
private void setArrayValue(String internalType, String[] values) {
- if (internalType.equals("string") || internalType.equals("String")) {
+ if ("string".equals(internalType) || "String".equals(internalType)) {
m_value = values;
return;
}
- if (internalType.equals("boolean")) {
+ if ("boolean".equals(internalType)) {
boolean[] bool = new boolean[values.length];
for (int i = 0; i < values.length; i++) {
bool[i] = new Boolean(values[i]).booleanValue();
@@ -255,7 +255,7 @@
m_value = bool;
return;
}
- if (internalType.equals("byte")) {
+ if ("byte".equals(internalType)) {
byte[] byt = new byte[values.length];
for (int i = 0; i < values.length; i++) {
byt[i] = new Byte(values[i]).byteValue();
@@ -263,7 +263,7 @@
m_value = byt;
return;
}
- if (internalType.equals("short")) {
+ if ("short".equals(internalType)) {
short[] shor = new short[values.length];
for (int i = 0; i < values.length; i++) {
shor[i] = new Short(values[i]).shortValue();
@@ -271,7 +271,7 @@
m_value = shor;
return;
}
- if (internalType.equals("int")) {
+ if ("int".equals(internalType)) {
int[] in = new int[values.length];
for (int i = 0; i < values.length; i++) {
in[i] = new Integer(values[i]).intValue();
@@ -279,7 +279,7 @@
m_value = in;
return;
}
- if (internalType.equals("long")) {
+ if ("long".equals(internalType)) {
long[] ll = new long[values.length];
for (int i = 0; i < values.length; i++) {
ll[i] = new Long(values[i]).longValue();
@@ -287,7 +287,7 @@
m_value = ll;
return;
}
- if (internalType.equals("float")) {
+ if ("float".equals(internalType)) {
float[] fl = new float[values.length];
for (int i = 0; i < values.length; i++) {
fl[i] = new Float(values[i]).floatValue();
@@ -295,7 +295,7 @@
m_value = fl;
return;
}
- if (internalType.equals("double")) {
+ if ("double".equals(internalType)) {
double[] dl = new double[values.length];
for (int i = 0; i < values.length; i++) {
dl[i] = new Double(values[i]).doubleValue();
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedService.java Tue Sep 25 06:27:49 2007
@@ -95,14 +95,13 @@
m_serviceSpecification = specification;
m_factoryPolicy = factoryPolicy;
- // Add service pid and factory pid
- addProperty(new Property(this, org.osgi.framework.Constants.SERVICE_PID, handler.getInstanceManager().getInstanceName()));
- addProperty(new Property(this, "factory.pid", handler.getInstanceManager().getFactory().getName()));
+ // Add instance name & factory name
+ addProperty(new Property(this, "instance.name", handler.getInstanceManager().getInstanceName()));
+ addProperty(new Property(this, "factory.name", handler.getInstanceManager().getFactory().getName()));
}
/**
* Add properties to the provided service.
- *
* @param props : the properties to attached to the service registration
*/
protected void setProperties(Property[] props) {
@@ -219,8 +218,8 @@
/**
* Register the service. The service object must be able to serve this
- * service. To avoid cycle in Check Context, the registred service is set to
- * registred before the real registration.
+ * service. To avoid cycle in Check Context, the registered service is set to
+ * registered before the real registration.
*/
protected synchronized void registerService() {
if (m_serviceRegistration == null) {
@@ -240,11 +239,7 @@
*/
protected synchronized void unregisterService() {
if (m_serviceRegistration != null) {
- try {
- m_serviceRegistration.unregister();
- } catch (Exception e) {
- return;
- }
+ m_serviceRegistration.unregister();
m_serviceRegistration = null;
}
}
@@ -310,7 +305,6 @@
/**
* Add properties to the list.
- *
* @param props : properties to add
*/
protected void addProperties(Dictionary props) {
@@ -325,7 +319,6 @@
/**
* Remove properties from the list.
- *
* @param props : properties to remove
*/
protected void deleteProperties(Dictionary props) {
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandler.java Tue Sep 25 06:27:49 2007
@@ -22,8 +22,10 @@
import java.util.Dictionary;
import java.util.Properties;
-import org.apache.felix.ipojo.Handler;
+import org.apache.felix.ipojo.ConfigurationException;
+import org.apache.felix.ipojo.IPojoConfiguration;
import org.apache.felix.ipojo.InstanceManager;
+import org.apache.felix.ipojo.PrimitiveHandler;
import org.apache.felix.ipojo.architecture.ComponentDescription;
import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.architecture.PropertyDescription;
@@ -36,14 +38,13 @@
import org.apache.felix.ipojo.parser.ParseException;
import org.apache.felix.ipojo.parser.ParseUtils;
import org.apache.felix.ipojo.util.Logger;
-import org.osgi.framework.Constants;
/**
- * Composite PRovided Service Handler.
- * This handler maange the service providing for a composition.
+ * Composite Provided Service Handler.
+ * This handler manage the service providing for a composition.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class ProvidedServiceHandler extends Handler {
+public class ProvidedServiceHandler extends PrimitiveHandler {
/**
* The list of the provided service.
@@ -51,11 +52,6 @@
private ProvidedService[] m_providedServices = new ProvidedService[0];
/**
- * The instance manager.
- */
- private InstanceManager m_manager;
-
- /**
* Add a provided service to the list .
*
* @param ps : the provided service to add
@@ -63,9 +59,7 @@
private void addProvidedService(ProvidedService ps) {
// Verify that the provided service is not already in the array.
for (int i = 0; (m_providedServices != null) && (i < m_providedServices.length); i++) {
- if (m_providedServices[i] == ps) {
- return;
- }
+ if (m_providedServices[i] == ps) { return; }
}
if (m_providedServices.length > 0) {
@@ -79,14 +73,6 @@
}
/**
- * Get the instance manager.
- * @return the instance manager.
- */
- public InstanceManager getInstanceManager() {
- return m_manager;
- }
-
- /**
* Get the array of provided service.
* @return the list of the provided service.
*/
@@ -96,18 +82,14 @@
/**
* Configure the handler.
- * @param im : the instance manager
* @param componentMetadata : the component type metadata
* @param configuration : the instance configuration
+ * @throws ConfigurationException : the metadata are not correct.
* @see org.apache.felix.ipojo.Handler#configure(org.apache.felix.ipojo.InstanceManager, org.apache.felix.ipojo.metadata.Element, java.util.Dictionary)
*/
- public void configure(InstanceManager im, Element componentMetadata, Dictionary configuration) {
- // Fix the instance manager & clean the provided service list
- m_manager = im;
-
- ManipulationMetadata manipulation = new ManipulationMetadata(componentMetadata);
+ public void configure(Element componentMetadata, Dictionary configuration) throws ConfigurationException {
- ComponentDescription cd = im.getComponentDescription();
+ ManipulationMetadata manipulation = new ManipulationMetadata(componentMetadata);
m_providedServices = new ProvidedService[0];
// Create the dependency according to the component metadata
@@ -124,14 +106,13 @@
serviceSpecification = manipulation.getInterfaces();
}
if (serviceSpecification.length == 0) {
- m_manager.getFactory().getLogger().log(Logger.ERROR,
- "Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)");
- return;
+ log(Logger.ERROR, "Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)");
+ throw new ConfigurationException("Provides : Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)", getInstanceManager().getFactory().getName());
}
// Get the factory policy
int factory = ProvidedService.SINGLETON_FACTORY;
- if (providedServices[i].containsAttribute("factory") && providedServices[i].getAttribute("factory").equals("service")) {
+ if (providedServices[i].containsAttribute("factory") && "service".equals(providedServices[i].getAttribute("factory"))) {
factory = ProvidedService.SERVICE_FACTORY;
}
@@ -175,24 +156,13 @@
if (checkProvidedService(ps, manipulation)) {
addProvidedService(ps);
- // Change ComponentInfo
- for (int k = 0; k < ps.getServiceSpecification().length; k++) {
- cd.addProvidedServiceSpecification(ps.getServiceSpecification()[k]);
- }
- for (int k = 0; k < ps.getProperties().length; k++) {
- if (!ps.getProperties()[k].getName().equals(Constants.SERVICE_PID) && !ps.getProperties()[k].getName().equals("factory.pid")) {
- cd.addProperty(new PropertyDescription(ps.getProperties()[k].getName(), ps.getProperties()[k].getType(), ps.getProperties()[k]
- .getInitialValue()));
- }
- }
} else {
String itfs = "";
for (int j = 0; j < serviceSpecification.length; j++) {
itfs = itfs + " " + serviceSpecification[j];
}
- m_manager.getFactory().getLogger().log(Logger.ERROR,
- "[" + m_manager.getClassName() + "] The provided service" + itfs + " is not valid, it will be removed");
- ps = null;
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The provided service" + itfs + " is not valid");
+ return;
}
}
@@ -221,8 +191,7 @@
}
}
}
-
- m_manager.register(this, fields, null);
+ getInstanceManager().register(this, fields, null);
}
}
@@ -233,25 +202,23 @@
* @param ps : the provided service to check.
* @param manipulation : component-type manipulation metadata.
* @return true if the provided service is correct
+ * @throws ConfigurationException : the checked provided service is not correct.
*/
- private boolean checkProvidedService(ProvidedService ps, ManipulationMetadata manipulation) {
+ private boolean checkProvidedService(ProvidedService ps, ManipulationMetadata manipulation) throws ConfigurationException {
for (int i = 0; i < ps.getServiceSpecification().length; i++) {
// Check the implementation of the specification
- if (! manipulation.isInterfaceImplemented(ps.getServiceSpecification()[i])) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The service specification " + ps.getServiceSpecification()[i]
- + " is not implemented by the component class");
- return false;
+ if (!manipulation.isInterfaceImplemented(ps.getServiceSpecification()[i])) {
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The service specification " + ps.getServiceSpecification()[i] + " is not implemented by the component class");
+ throw new ConfigurationException("Provides : The service specification " + ps.getServiceSpecification()[i] + " is not implemented by the component class", getInstanceManager().getFactory().getName());
+
}
-
+
// Check service level dependencies
try {
- Class spec = m_manager.getFactory().loadClass(ps.getServiceSpecification()[i]);
- Field specField = spec.getField("specification");
+ Class spec = getInstanceManager().getFactory().loadClass(ps.getServiceSpecification()[i]);
+ Field specField = spec.getField("specification");
Object o = specField.get(null);
- if (!(o instanceof String)) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The specification field of the service specification " + ps.getServiceSpecification()[i] + " need to be a String");
- return false;
- } else {
+ if (o instanceof String) {
Element specification = ManifestMetadataParser.parse((String) o);
Element[] deps = specification.getElements("requires");
for (int j = 0; j < deps.length; j++) {
@@ -260,25 +227,27 @@
// Fix service-level dependency flag
d.setServiceLevelDependency();
}
- if (!isDependencyCorrect(d, deps[j])) {
- return false;
- }
+ isDependencyCorrect(d, deps[j]);
}
+ } else {
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The specification field of the service specification " + ps.getServiceSpecification()[i] + " need to be a String");
+ throw new ConfigurationException("Provides : The specification field of the service specification " + ps.getServiceSpecification()[i] + " need to be a String", getInstanceManager().getFactory().getName());
}
} catch (NoSuchFieldException e) {
- return true; // No specification field
+ return true; // No specification field
} catch (ClassNotFoundException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The service specification " + ps.getServiceSpecification()[i] + " cannot be load");
- return false;
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The service specification " + ps.getServiceSpecification()[i] + " cannot be load");
+ throw new ConfigurationException("Provides : The service specification " + ps.getServiceSpecification()[i] + " cannot be load", getInstanceManager().getFactory().getName());
} catch (IllegalArgumentException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " is not accessible : " + e.getMessage());
- return false;
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " is not accessible : " + e.getMessage());
+ throw new ConfigurationException("Provides : The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " is not accessible : " + e.getMessage(), getInstanceManager().getFactory().getName());
} catch (IllegalAccessException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " is not accessible : " + e.getMessage());
- return false;
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " is not accessible : " + e.getMessage());
+ throw new ConfigurationException("Provides : The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " is not accessible : " + e.getMessage(), getInstanceManager().getFactory().getName());
} catch (ParseException e) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " does not contain a valid String : " + e.getMessage());
- return false;
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " does not contain a valid String : " + e.getMessage());
+ throw new ConfigurationException("Provides : The field 'specification' of the service specification " + ps.getServiceSpecification()[i] + " does not contain a valid String : " + e.getMessage(), getInstanceManager().getFactory()
+ .getName());
}
}
@@ -291,29 +260,23 @@
* @return the Dependency object, null if not found or if the DependencyHandler is not plugged to the instance
*/
private Dependency getAttachedDependency(Element element) {
- DependencyHandler dh = (DependencyHandler) m_manager.getHandler(DependencyHandler.class.getName());
- if (dh == null) {
- return null;
- }
-
+ DependencyHandler dh = (DependencyHandler) getHandler(IPojoConfiguration.IPOJO_NAMESPACE + ":requires");
+ if (dh == null) { return null; }
+
if (element.containsAttribute("id")) {
// Look for dependency Id
String id = element.getAttribute("id");
for (int i = 0; i < dh.getDependencies().length; i++) {
- if (dh.getDependencies()[i].getId().equals(id)) {
- return dh.getDependencies()[i];
- }
+ if (dh.getDependencies()[i].getId().equals(id)) { return dh.getDependencies()[i]; }
}
}
-
+
// If not found or no id, look for a dependency with the same specification
String requirement = element.getAttribute("specification");
for (int i = 0; i < dh.getDependencies().length; i++) {
- if (dh.getDependencies()[i].getSpecification().equals(requirement)) {
- return dh.getDependencies()[i];
- }
+ if (dh.getDependencies()[i].getSpecification().equals(requirement)) { return dh.getDependencies()[i]; }
}
-
+
return null;
}
@@ -321,40 +284,39 @@
* Check the correctness of the implementation dependency against the service level dependency.
* @param dep : dependency to check
* @param elem : service-level dependency metadata
- * @return true if the dependency is correct, false otherwise
+ * @throws ConfigurationException : the service level dependency and the implementation dependency does not match.
*/
- private boolean isDependencyCorrect(Dependency dep, Element elem) {
+ private void isDependencyCorrect(Dependency dep, Element elem) throws ConfigurationException {
boolean opt = false;
if (elem.containsAttribute("optional") && elem.getAttribute("optional").equalsIgnoreCase("true")) {
opt = true;
}
-
+
boolean agg = false;
if (elem.containsAttribute("aggregate") && elem.getAttribute("aggregate").equalsIgnoreCase("true")) {
agg = true;
}
if (dep == null && !opt) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The requirement " + elem.getAttribute("specification") + " is not present in the implementation and is declared as a mandatory service-level requirement");
- return false;
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The requirement " + elem.getAttribute("specification") + " is not present in the implementation and is declared as a mandatory service-level requirement");
+ throw new ConfigurationException("Provides : The requirement " + elem.getAttribute("specification") + " is not present in the implementation and is declared as a mandatory service-level requirement", getInstanceManager().getFactory()
+ .getName());
}
-
-
+
if (dep != null && dep.isAggregate() && !agg) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The requirement " + elem.getAttribute("specification") + " is aggregate in the implementation and is declared as a simple service-level requirement");
- return false;
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The requirement " + elem.getAttribute("specification") + " is aggregate in the implementation and is declared as a simple service-level requirement");
+ throw new ConfigurationException("Provides : The requirement " + elem.getAttribute("specification") + " is aggregate in the implementation and is declared as a simple service-level requirement", getInstanceManager().getFactory()
+ .getName());
}
-
+
if (dep != null && elem.containsAttribute("filter")) {
String filter = elem.getAttribute("filter");
String filter2 = dep.getFilter();
if (filter2 == null || !filter2.equalsIgnoreCase(filter)) {
- m_manager.getFactory().getLogger().log(Logger.ERROR, "[" + m_manager.getClassName() + "] The specification requirement " + elem.getAttribute("specification") + " as not the same filter as declared in the service-level requirement");
- return false;
+ log(Logger.ERROR, "[" + getInstanceManager().getInstanceName() + "] The specification requirement " + elem.getAttribute("specification") + " as not the same filter as declared in the service-level requirement");
+ throw new ConfigurationException("Provides : The specification requirement " + elem.getAttribute("specification") + " as not the same filter as declared in the service-level requirement", getInstanceManager().getFactory().getName());
}
}
-
- return true;
}
/**
@@ -373,11 +335,11 @@
public void start() {
}
- /**
- * Setter Callback Method.
- * Check if the modified field is a property to update the value.
- * @param fieldName : field name
- * @param value : new value
+ /**
+ * Setter Callback Method.
+ * Check if the modified field is a property to update the value.
+ * @param fieldName : field name
+ * @param value : new value
* @see org.apache.felix.ipojo.Handler#setterCallback(java.lang.String,
* java.lang.Object)
*/
@@ -480,7 +442,7 @@
* @see org.apache.felix.ipojo.Handler#getDescription()
*/
public HandlerDescription getDescription() {
- ProvidedServiceHandlerDescription pshd = new ProvidedServiceHandlerDescription(this.isValid());
+ ProvidedServiceHandlerDescription pshd = new ProvidedServiceHandlerDescription(this);
for (int j = 0; j < getProvidedService().length; j++) {
ProvidedService ps = getProvidedService()[j];
@@ -521,6 +483,77 @@
}
if (update) {
ps.update();
+ }
+ }
+ }
+
+ /**
+ * Initialize the component type.
+ * @param cd : component type description to populate.
+ * @param metadata : component type metadata.
+ * @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentDescription, org.apache.felix.ipojo.metadata.Element)
+ */
+ public void initializeComponentFactory(ComponentDescription cd, Element metadata) {
+ // Change ComponentInfo
+ Element[] provides = metadata.getElements("provides");
+ ManipulationMetadata mm = new ManipulationMetadata(metadata);
+
+ for (int i = 0; i < provides.length; i++) {
+ String[] serviceSpecification = new String[0];
+ if (provides[i].containsAttribute("interface")) {
+ String serviceSpecificationStr = provides[i].getAttribute("interface");
+ serviceSpecification = ParseUtils.parseArrays(serviceSpecificationStr);
+ } else {
+ serviceSpecification = mm.getInterfaces();
+ }
+ if (serviceSpecification.length == 0) {
+ log(Logger.ERROR, "Cannot instantiate a provided service : no specifications found (no interfaces implemented by the pojo)");
+ return;
+ }
+
+ for (int j = 0; j < serviceSpecification.length; j++) {
+ cd.addProvidedServiceSpecification(serviceSpecification[j]);
+ }
+
+ Element[] props = provides[i].getElements("property");
+ for (int j = 0; j < props.length; j++) {
+ String name = null;
+ if (props[j].containsAttribute("name")) {
+ name = props[j].getAttribute("name");
+ }
+ String value = null;
+ if (props[j].containsAttribute("value")) {
+ value = props[j].getAttribute("value");
+ }
+ String type = null;
+ if (props[j].containsAttribute("type")) {
+ type = props[j].getAttribute("type");
+ }
+ String field = null;
+ if (props[j].containsAttribute("field")) {
+ field = props[j].getAttribute("field");
+ }
+
+ // Get property name :
+ if (field != null && name == null) {
+ name = field;
+ }
+
+ // Check type if not already set
+ if (type == null) {
+ if (field == null) {
+ System.err.println("The property " + name + " has neither type neither field.");
+ return;
+ }
+ FieldMetadata fm = mm.getField(field);
+ if (fm == null) {
+ System.err.println("A declared property was not found in the class : " + field);
+ return;
+ }
+ type = fm.getFieldType();
+ }
+
+ cd.addProperty(new PropertyDescription(name, type, value));
}
}
}
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/handlers/providedservice/ProvidedServiceHandlerDescription.java Tue Sep 25 06:27:49 2007
@@ -20,6 +20,7 @@
import java.util.Iterator;
+import org.apache.felix.ipojo.Handler;
import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.metadata.Attribute;
import org.apache.felix.ipojo.metadata.Element;
@@ -39,11 +40,10 @@
/**
* Constructor.
- *
- * @param isValid : the validity of the provided service handler.
+ * @param h : handler.
*/
- public ProvidedServiceHandlerDescription(boolean isValid) {
- super(ProvidedServiceHandler.class.getName(), isValid);
+ public ProvidedServiceHandlerDescription(Handler h) {
+ super(h);
}
/**
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManifestMetadataParser.java Tue Sep 25 06:27:49 2007
@@ -49,7 +49,8 @@
public Element[] getComponentsMetadata() throws ParseException {
Element[] components = m_elements[0].getElements("Component");
Element[] composites = m_elements[0].getElements("Composite");
- Element[] all = new Element[components.length + composites.length];
+ Element[] handlers = m_elements[0].getElements("Handler");
+ Element[] all = new Element[components.length + composites.length + handlers.length];
int l = 0;
for (int i = 0; i < components.length; i++) {
all[l] = components[i];
@@ -57,6 +58,10 @@
}
for (int i = 0; i < composites.length; i++) {
all[l] = composites[i];
+ l++;
+ }
+ for (int i = 0; i < handlers.length; i++) {
+ all[l] = handlers[i];
l++;
}
return all;
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManipulationMetadata.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManipulationMetadata.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManipulationMetadata.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/parser/ManipulationMetadata.java Tue Sep 25 06:27:49 2007
@@ -22,7 +22,7 @@
/**
* Manipulation Metadata allows getting information about the implementation class
- * whithout doing reflection.
+ * without doing reflection.
*
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
@@ -52,16 +52,19 @@
*/
public ManipulationMetadata(Element metadata) {
Element manip = metadata.getElements("manipulation", "")[0];
- for (int i = 0; i < manip.getElements().length; i++) {
- if (manip.getElements()[i].getName().equals("field")) {
- FieldMetadata fm = new FieldMetadata(manip.getElements()[i]);
- addField(fm);
- } else if (manip.getElements()[i].getName().equals("method")) {
- MethodMetadata fm = new MethodMetadata(manip.getElements()[i]);
- addMethod(fm);
- } else if (manip.getElements()[i].getName().equals("interface")) {
- addInterface(manip.getElements()[i].getAttribute("name"));
- }
+ Element[] fields = manip.getElements("field");
+ for (int i = 0; i < fields.length; i++) {
+ FieldMetadata fm = new FieldMetadata(fields[i]);
+ addField(fm);
+ }
+ Element[] methods = manip.getElements("method");
+ for (int i = 0; i < methods.length; i++) {
+ MethodMetadata fm = new MethodMetadata(methods[i]);
+ addMethod(fm);
+ }
+ Element[] itfs = manip.getElements("interface");
+ for (int i = 0; i < itfs.length; i++) {
+ addInterface(itfs[i].getAttribute("name"));
}
}
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Callback.java Tue Sep 25 06:27:49 2007
@@ -293,7 +293,7 @@
* @param arg : the parameters
* @return the result of the invocation, null for void method, the last result for multi-object instance
* @throws NoSuchMethodException : the callback method is not found
- * @throws IllegalAccessException : the callbback method cannot be called
+ * @throws IllegalAccessException : the callback method cannot be called
* @throws InvocationTargetException : an error occurs inside the called
* method
*/
Modified: felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java
URL: http://svn.apache.org/viewvc/felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java?rev=579239&r1=579238&r2=579239&view=diff
==============================================================================
--- felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java (original)
+++ felix/trunk/ipojo/core/src/main/java/org/apache/felix/ipojo/util/Logger.java Tue Sep 25 06:27:49 2007
@@ -75,7 +75,6 @@
m_name = name;
m_level = level;
m_context = bc;
-
}
/**
@@ -86,9 +85,7 @@
*/
public void log(int level, String msg) {
if (m_level >= level) {
- synchronized (this) {
- dispatch(level, msg, null);
- }
+ dispatch(level, msg, null);
}
}
@@ -101,9 +98,7 @@
*/
public void log(int level, String msg, Throwable ex) {
if (m_level >= level) {
- synchronized (this) {
- dispatch(level, msg, ex);
- }
+ dispatch(level, msg, ex);
}
}