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 2008/03/03 16:46:43 UTC
svn commit: r633138 [2/7] - in /felix/sandbox/clement/ipojo: composite/
composite/src/main/java/org/apache/felix/ipojo/composite/
composite/src/main/java/org/apache/felix/ipojo/composite/architecture/
composite/src/main/java/org/apache/felix/ipojo/comp...
Modified: felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/MethodMetadata.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/MethodMetadata.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/MethodMetadata.java (original)
+++ felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/MethodMetadata.java Mon Mar 3 07:46:27 2008
@@ -63,8 +63,8 @@
return m_method;
}
- public void setDelegation(FieldMetadata dm) {
- m_delegation = dm;
+ public void setDelegation(FieldMetadata field) {
+ m_delegation = field;
}
public FieldMetadata getDelegation() {
@@ -74,18 +74,18 @@
/**
* Equals method.
* This method check if two MethodMetadata are equals or if the current MemethodMetadata is equals with a Method object.
- * @param o : object.
+ * @param object : object.
* @return true if the current object and the given object are equals.
* @see java.lang.Object#equals(java.lang.Object)
*/
- public boolean equals(Object o) {
- if (o instanceof MethodMetadata) {
- Method met = ((MethodMetadata) o).getMethod();
+ public boolean equals(Object object) {
+ if (object instanceof MethodMetadata) {
+ Method met = ((MethodMetadata) object).getMethod();
return equals(met);
}
- if (o instanceof Method) {
- Method met = (Method) o;
+ if (object instanceof Method) {
+ Method met = (Method) object;
if (! met.getName().equals(m_method.getName()) || met.getParameterTypes().length != m_method.getParameterTypes().length) {
return false;
}
@@ -101,6 +101,15 @@
return false;
}
+
+ /**
+ * Hash code method.
+ * @return the parent hash code.
+ * @see java.lang.Object#hashCode()
+ */
+ public int hashCode() {
+ return super.hashCode();
+ }
public int getPolicy() {
return m_policy;
@@ -117,7 +126,7 @@
* Check if the method can throw UnsupportedOperationException.
* @return true if the method has declared the UnsupportedOperationException.
*/
- boolean throwsUnsupportedOperationException() {
+ protected boolean throwsUnsupportedOperationException() {
for (int i = 0; i < m_method.getExceptionTypes().length; i++) {
if (m_method.getExceptionTypes()[i].getName().equals(UnsupportedOperationException.class.getName())) {
return true;
Modified: felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/POJOWriter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/POJOWriter.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/POJOWriter.java (original)
+++ felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/POJOWriter.java Mon Mar 3 07:46:27 2008
@@ -33,6 +33,11 @@
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
public class POJOWriter implements Opcodes {
+
+ //TODO : consider using getOpCode
+ //TODO : fix bug on double-space
+ //TODO : use a logger
+ //TODO : merge this class with another class only static method.
/**
* Create a class.
@@ -168,6 +173,7 @@
writeReturn(Type.getReturnType(desc), mv);
} else { // All policy
if (Type.getReturnType(desc).getSort() != Type.VOID) {
+ //TODO use logger.
System.err.println("All policy cannot be used on method which does not return void");
}
Modified: felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedService.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedService.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedService.java (original)
+++ felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedService.java Mon Mar 3 07:46:27 2008
@@ -30,8 +30,8 @@
import org.apache.felix.ipojo.composite.CompositeManager;
import org.apache.felix.ipojo.composite.instance.InstanceHandler;
import org.apache.felix.ipojo.metadata.Element;
-import org.apache.felix.ipojo.util.AbstractServiceDependency;
-import org.apache.felix.ipojo.util.DependencyLifecycleListener;
+import org.apache.felix.ipojo.util.DependencyModel;
+import org.apache.felix.ipojo.util.DependencyStateListener;
import org.apache.felix.ipojo.util.Logger;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
@@ -41,7 +41,7 @@
* Composite Provided Service.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class ProvidedService implements DependencyLifecycleListener {
+public class ProvidedService implements DependencyStateListener {
/**
* Composite Manager.
@@ -54,16 +54,6 @@
private CompositionMetadata m_composition;
/**
- * generated POJO class.
- */
- private byte[] m_clazz;
-
- /**
- * Metadata of the POJO.
- */
- private Element m_metadata;
-
- /**
* Internal context.
*/
private ServiceContext m_scope;
@@ -116,22 +106,22 @@
m_composition.buildMapping();
m_instanceName = m_composition.getSpecificationMetadata().getName() + "Provider-Gen";
- m_clazz = m_composition.buildPOJO();
- m_metadata = m_composition.buildMetadata(m_instanceName);
+ byte[] clazz = m_composition.buildPOJO();
+ Element metadata = m_composition.buildMetadata(m_instanceName);
// Create the factory
try {
- m_factory = new ComponentFactory(m_context, m_clazz, m_metadata);
+ m_factory = new ComponentFactory(m_context, clazz, metadata);
} catch (ConfigurationException e) {
// Should not happen.
}
m_factory.start();
try {
- Class spec = AbstractServiceDependency.loadSpecification(m_composition.getSpecificationMetadata().getName(), m_context);
+ Class spec = DependencyModel.loadSpecification(m_composition.getSpecificationMetadata().getName(), m_context);
Filter filter = m_context.createFilter("(instance.name=" + m_instanceName + ")");
// Create the exports
- m_exports = new ServiceExporter(spec, filter, false, false, null, AbstractServiceDependency.DYNAMIC_BINDING_POLICY, m_scope, m_context, this, m_manager);
+ m_exports = new ServiceExporter(spec, filter, false, false, null, DependencyModel.DYNAMIC_BINDING_POLICY, m_scope, m_context, this, m_manager);
} catch (InvalidSyntaxException e) {
throw new CompositionException("A provided service filter is invalid : " + e.getMessage());
} catch (ConfigurationException e) {
@@ -166,14 +156,16 @@
* The exporter becomes valid.
* @param exporter : the exporter
*/
- public void validate(AbstractServiceDependency exporter) {
+ public void validate(DependencyModel exporter) {
+ // Nothing to do.
}
/**
* The exporter becomes invalid.
* @param exporter : the exporter
*/
- public void invalidate(AbstractServiceDependency exporter) {
+ public void invalidate(DependencyModel exporter) {
+ // Nothing to do.
}
/**
@@ -182,12 +174,12 @@
* @return an object from an instance of this type or null
*/
private Object getObjectByType(String type) {
- InstanceHandler h = (InstanceHandler) m_manager.getCompositeHandler("org.apache.felix.ipojo.composite.instance.InstanceHandler");
- Object o = h.getObjectFromInstance(type);
- if (o == null) {
+ InstanceHandler handler = (InstanceHandler) m_manager.getCompositeHandler("org.apache.felix.ipojo.composite.instance.InstanceHandler");
+ Object pojo = handler.getObjectFromInstance(type);
+ if (pojo == null) {
m_manager.getFactory().getLogger().log(Logger.ERROR, "An instance object cannot be found for the type : " + type);
}
- return o;
+ return pojo;
}
public String getSpecification() {
@@ -205,25 +197,22 @@
* Register the exposed service.
*/
public void register() {
- Properties p = new Properties();
- p.put("name", m_instanceName);
+ Properties props = new Properties();
+ props.put("name", m_instanceName);
List fields = m_composition.getFieldList();
for (int i = 0; i < fields.size(); i++) {
- FieldMetadata fm = (FieldMetadata) fields.get(i);
- if (fm.isUseful() && !fm.getSpecification().isInterface()) {
- String type = fm.getSpecification().getComponentType();
- Object o = getObjectByType(type);
- p.put(fm.getName(), o);
+ FieldMetadata field = (FieldMetadata) fields.get(i);
+ if (field.isUseful() && !field.getSpecification().isInterface()) {
+ String type = field.getSpecification().getComponentType();
+ Object pojo = getObjectByType(type);
+ props.put(field.getName(), pojo);
}
}
- if (m_instance != null) {
- // We have to reconfigure the instance in order to inject up to date glue component instance.
- m_instance.reconfigure(p);
- } else {
- // Else we have to create the instance
+ if (m_instance == null) {
+ // Else we have to create the instance
try {
- m_instance = m_factory.createComponentInstance(p, m_manager.getServiceContext());
+ m_instance = m_factory.createComponentInstance(props, m_manager.getServiceContext());
} catch (UnacceptableConfiguration e) {
throw new IllegalStateException("Cannot create the service implementation : " + e.getMessage());
} catch (MissingHandlerException e) {
@@ -231,13 +220,16 @@
} catch (ConfigurationException e) {
throw new IllegalStateException("Cannot create the service implementation : " + e.getMessage());
}
+ } else {
+ // We have to reconfigure the instance in order to inject up to date glue component instance.
+ m_instance.reconfigure(props);
}
-
+
m_exports.start();
}
public boolean isRegistered() {
- return m_exports.getState() == AbstractServiceDependency.RESOLVED;
+ return m_exports.getState() == DependencyModel.RESOLVED;
}
}
Modified: felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandler.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandler.java (original)
+++ felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandler.java Mon Mar 3 07:46:27 2008
@@ -30,7 +30,9 @@
import org.apache.felix.ipojo.Factory;
import org.apache.felix.ipojo.HandlerFactory;
import org.apache.felix.ipojo.HandlerManager;
+import org.apache.felix.ipojo.MissingHandlerException;
import org.apache.felix.ipojo.PolicyServiceContext;
+import org.apache.felix.ipojo.UnacceptableConfiguration;
import org.apache.felix.ipojo.architecture.ComponentTypeDescription;
import org.apache.felix.ipojo.architecture.HandlerDescription;
import org.apache.felix.ipojo.composite.CompositeHandler;
@@ -41,8 +43,8 @@
import org.apache.felix.ipojo.metadata.Element;
import org.apache.felix.ipojo.parser.ManifestMetadataParser;
import org.apache.felix.ipojo.parser.ParseException;
-import org.apache.felix.ipojo.util.AbstractServiceDependency;
-import org.apache.felix.ipojo.util.DependencyLifecycleListener;
+import org.apache.felix.ipojo.util.DependencyModel;
+import org.apache.felix.ipojo.util.DependencyStateListener;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
@@ -52,7 +54,7 @@
* Composite Provided Service Handler.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class ProvidedServiceHandler extends CompositeHandler implements DependencyLifecycleListener {
+public class ProvidedServiceHandler extends CompositeHandler implements DependencyStateListener {
/**
* External context.
@@ -81,12 +83,12 @@
/**
* Initialize the component type.
- * @param cd : component type description to populate.
+ * @param desc : component type description to populate.
* @param metadata : component type metadata.
* @throws ConfigurationException : metadata are incorrect.
* @see org.apache.felix.ipojo.Handler#initializeComponentFactory(org.apache.felix.ipojo.architecture.ComponentTypeDescription, org.apache.felix.ipojo.metadata.Element)
*/
- public void initializeComponentFactory(ComponentTypeDescription cd, Element metadata) throws ConfigurationException {
+ public void initializeComponentFactory(ComponentTypeDescription desc, Element metadata) throws ConfigurationException {
Element[] provides = metadata.getElements("provides");
for (int i = 0; i < provides.length; i++) {
String action = provides[i].getAttribute("action");
@@ -94,18 +96,17 @@
throw new ConfigurationException("Invalid composition service providing : no specified action");
} else if (action.equalsIgnoreCase("implement")) {
String spec = provides[i].getAttribute("specification");
- if (spec != null) {
- cd.addProvidedServiceSpecification(spec);
- } else {
+ if (spec == null) {
throw new ConfigurationException("Malformed provides : the specification attribute is mandatory");
+ } else {
+ desc.addProvidedServiceSpecification(spec);
}
} else if (action.equalsIgnoreCase("export")) {
String spec = provides[i].getAttribute("specification");
- if (spec != null) {
- cd.addProvidedServiceSpecification(spec);
- } else {
- // Malformed exports
+ if (spec == null) {
throw new ConfigurationException("Malformed exports - Missing the specification attribute");
+ } else {
+ desc.addProvidedServiceSpecification(spec);
}
} else {
throw new ConfigurationException("Invalid composition service providing : unknown action " + action);
@@ -127,8 +128,8 @@
for (int i = 0; i < provides.length; i++) {
String action = provides[i].getAttribute("action");
if (action.equalsIgnoreCase("implement")) {
- ProvidedService ps = new ProvidedService(this, provides[i], "" + i);
- m_managedServices.add(ps);
+ ProvidedService svc = new ProvidedService(this, provides[i], Integer.toString(i));
+ m_managedServices.add(svc);
} else if (action.equalsIgnoreCase("export")) {
boolean optional = false;
boolean aggregate = false;
@@ -142,9 +143,9 @@
String agg = provides[i].getAttribute("aggregate");
aggregate = agg != null && agg.equalsIgnoreCase("true");
- String f = provides[i].getAttribute("filter");
- if (f != null) {
- filter = "(&" + filter + f + ")";
+ String givenFilter = provides[i].getAttribute("filter");
+ if (givenFilter != null) {
+ filter = "(&" + filter + givenFilter + ")"; //NOPMD
}
Filter fil = null;
@@ -154,12 +155,12 @@
throw new ConfigurationException("An exporter filter is invalid " + filter + " : " + e.getMessage());
}
- Comparator cmp = AbstractServiceDependency.getComparator(provides[i], m_context);
- int policy = AbstractServiceDependency.getPolicy(provides[i]);
- Class spec = AbstractServiceDependency.loadSpecification(specification, m_context);
+ Comparator cmp = DependencyModel.getComparator(provides[i], m_context);
+ int policy = DependencyModel.getPolicy(provides[i]);
+ Class spec = DependencyModel.loadSpecification(specification, m_context);
- ServiceExporter si = new ServiceExporter(spec, fil, aggregate, optional, cmp, policy, getCompositeManager().getServiceContext(), m_context, this, getCompositeManager());
- m_exporters.add(si);
+ ServiceExporter imp = new ServiceExporter(spec, fil, aggregate, optional, cmp, policy, getCompositeManager().getServiceContext(), m_context, this, getCompositeManager());
+ m_exporters.add(imp);
} // Others case cannot happen. The test was already made during the factory initialization.
}
@@ -176,10 +177,10 @@
computeAvailableTypes();
for (int i = 0; i < m_managedServices.size(); i++) {
- ProvidedService ps = (ProvidedService) m_managedServices.get(i);
+ ProvidedService svc = (ProvidedService) m_managedServices.get(i);
try {
- checkServiceSpecification(ps);
- ps.start();
+ checkServiceSpecification(svc);
+ svc.start();
} catch (CompositionException e) {
error("Cannot start the provided service handler", e);
setValidity(false);
@@ -188,8 +189,8 @@
}
for (int i = 0; i < m_exporters.size(); i++) {
- ServiceExporter se = (ServiceExporter) m_exporters.get(i);
- se.start();
+ ServiceExporter exp = (ServiceExporter) m_exporters.get(i);
+ exp.start();
}
isHandlerValid();
@@ -202,13 +203,13 @@
*/
public void stop() {
for (int i = 0; i < m_managedServices.size(); i++) {
- ProvidedService ps = (ProvidedService) m_managedServices.get(i);
- ps.stop();
+ ProvidedService svc = (ProvidedService) m_managedServices.get(i);
+ svc.stop();
}
for (int i = 0; i < m_exporters.size(); i++) {
- ServiceExporter se = (ServiceExporter) m_exporters.get(i);
- se.stop();
+ ServiceExporter exp = (ServiceExporter) m_exporters.get(i);
+ exp.stop();
}
}
@@ -218,8 +219,8 @@
*/
private void isHandlerValid() {
for (int i = 0; i < m_exporters.size(); i++) {
- ServiceExporter se = (ServiceExporter) m_exporters.get(i);
- if (se.getState() != AbstractServiceDependency.RESOLVED) {
+ ServiceExporter exp = (ServiceExporter) m_exporters.get(i);
+ if (exp.getState() != DependencyModel.RESOLVED) {
setValidity(false);
return;
}
@@ -236,8 +237,8 @@
public void stateChanged(int state) {
if (state == ComponentInstance.INVALID) {
for (int i = 0; i < m_managedServices.size(); i++) {
- ProvidedService ps = (ProvidedService) m_managedServices.get(i);
- ps.unregister();
+ ProvidedService svc = (ProvidedService) m_managedServices.get(i);
+ svc.unregister();
}
return;
}
@@ -245,8 +246,8 @@
// If the new state is VALID => register all the services
if (state == ComponentInstance.VALID) {
for (int i = 0; i < m_managedServices.size(); i++) {
- ProvidedService ps = (ProvidedService) m_managedServices.get(i);
- ps.register();
+ ProvidedService svc = (ProvidedService) m_managedServices.get(i);
+ svc.register();
}
return;
}
@@ -257,7 +258,7 @@
*
* @param exporter : the implicated exporter.
*/
- public void invalidate(AbstractServiceDependency exporter) {
+ public void invalidate(DependencyModel exporter) {
// An export is no more valid
if (getValidity()) {
setValidity(false);
@@ -270,7 +271,7 @@
*
* @param exporter : the implicated exporter.
*/
- public void validate(AbstractServiceDependency exporter) {
+ public void validate(DependencyModel exporter) {
// An import becomes valid
if (!getValidity()) {
isHandlerValid();
@@ -290,41 +291,41 @@
*/
private void computeAvailableServices() {
// Get instantiated services :
- ServiceDependencyHandler sh = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
+ ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
- for (int i = 0; sh != null && i < sh.getInstances().size(); i++) {
- SvcInstance svc = (SvcInstance) sh.getInstances().get(i);
+ for (int i = 0; handler != null && i < handler.getInstances().size(); i++) {
+ SvcInstance svc = (SvcInstance) handler.getInstances().get(i);
String itf = svc.getServiceSpecification();
boolean agg = svc.isAggregate();
boolean opt = svc.isOptional();
- SpecificationMetadata sm = new SpecificationMetadata(itf, m_context, agg, opt, this);
- m_services.add(sm);
+ SpecificationMetadata specMeta = new SpecificationMetadata(itf, m_context, agg, opt, this);
+ m_services.add(specMeta);
}
- for (int i = 0; sh != null && i < sh.getRequirements().size(); i++) {
- ServiceImporter si = (ServiceImporter) sh.getRequirements().get(i);
- String itf = si.getSpecification().getName();
- boolean agg = si.isAggregate();
- boolean opt = si.isOptional();
+ for (int i = 0; handler != null && i < handler.getRequirements().size(); i++) {
+ ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
+ String itf = imp.getSpecification().getName();
+ boolean agg = imp.isAggregate();
+ boolean opt = imp.isOptional();
- SpecificationMetadata sm = new SpecificationMetadata(itf, m_context, agg, opt, this);
- m_services.add(sm);
+ SpecificationMetadata specMeta = new SpecificationMetadata(itf, m_context, agg, opt, this);
+ m_services.add(specMeta);
}
}
/**
* Check composite requirement against service specification requirement is available.
- * @param ps : the provided service to check
+ * @param svc : the provided service to check
* @throws CompositionException : occurs if the specification field of the service specification cannot be analyzed correctly.
*/
- private void checkServiceSpecification(ProvidedService ps) throws CompositionException {
+ private void checkServiceSpecification(ProvidedService svc) throws CompositionException {
try {
- Class spec = m_context.getBundle().loadClass(ps.getSpecification());
+ Class spec = m_context.getBundle().loadClass(svc.getSpecification());
Field specField = spec.getField("specification");
- Object o = specField.get(null);
- if (o instanceof String) {
- Element specification = ManifestMetadataParser.parse((String) o);
+ Object object = specField.get(null);
+ if (object instanceof String) {
+ Element specification = ManifestMetadataParser.parse((String) object);
Element[] reqs = specification.getElements("requires");
for (int j = 0; reqs != null && j < reqs.length; j++) {
ServiceImporter imp = getAttachedRequirement(reqs[j]);
@@ -335,23 +336,23 @@
checkRequirement(imp, reqs[j]);
}
} else {
- error("[" + getCompositeManager().getInstanceName() + "] The specification field of the service specification " + ps.getSpecification() + " need to be a String");
- throw new CompositionException("Service Specification checking failed : The specification field of the service specification " + ps.getSpecification() + " need to be a String");
+ error("[" + getCompositeManager().getInstanceName() + "] The specification field of the service specification " + svc.getSpecification() + " need to be a String");
+ throw new CompositionException("Service Specification checking failed : The specification field of the service specification " + svc.getSpecification() + " need to be a String");
}
} catch (NoSuchFieldException e) {
return; // No specification field
} catch (ClassNotFoundException e) {
- error("[" + getCompositeManager().getInstanceName() + "] The service specification " + ps.getSpecification() + " cannot be load");
- throw new CompositionException("The service specification " + ps.getSpecification() + " cannot be load : " + e.getMessage());
+ error("[" + getCompositeManager().getInstanceName() + "] The service specification " + svc.getSpecification() + " cannot be load");
+ throw new CompositionException("The service specification " + svc.getSpecification() + " cannot be load : " + e.getMessage());
} catch (IllegalArgumentException e) {
- error("[" + getCompositeManager().getInstanceName() + "] The field 'specification' of the service specification " + ps.getSpecification() + " is not accessible : " + e.getMessage());
- throw new CompositionException("The field 'specification' of the service specification " + ps.getSpecification() + " is not accessible : " + e.getMessage());
+ error("[" + getCompositeManager().getInstanceName() + "] The field 'specification' of the service specification " + svc.getSpecification() + " is not accessible : " + e.getMessage());
+ throw new CompositionException("The field 'specification' of the service specification " + svc.getSpecification() + " is not accessible : " + e.getMessage());
} catch (IllegalAccessException e) {
- error("[" + getCompositeManager().getInstanceName() + "] The field 'specification' of the service specification " + ps.getSpecification() + " is not accessible : " + e.getMessage());
- throw new CompositionException("The field 'specification' of the service specification " + ps.getSpecification() + " is not accessible : " + e.getMessage());
+ error("[" + getCompositeManager().getInstanceName() + "] The field 'specification' of the service specification " + svc.getSpecification() + " is not accessible : " + e.getMessage());
+ throw new CompositionException("The field 'specification' of the service specification " + svc.getSpecification() + " is not accessible : " + e.getMessage());
} catch (ParseException e) {
- error("[" + getCompositeManager().getInstanceName() + "] The field 'specification' of the service specification " + ps.getSpecification() + " does not contain a valid String : " + e.getMessage());
- throw new CompositionException("The field 'specification' of the service specification " + ps.getSpecification() + " does not contain a valid String : " + e.getMessage());
+ error("[" + getCompositeManager().getInstanceName() + "] The field 'specification' of the service specification " + svc.getSpecification() + " does not contain a valid String : " + e.getMessage());
+ throw new CompositionException("The field 'specification' of the service specification " + svc.getSpecification() + " does not contain a valid String : " + e.getMessage());
}
}
@@ -361,22 +362,22 @@
* @return the ServiceImporter object, null if not found or if the DependencyHandler is not plugged to the instance
*/
private ServiceImporter getAttachedRequirement(Element element) {
- ServiceDependencyHandler sh = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
- if (sh == null) { return null; }
+ ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
+ if (handler == null) { return null; }
- String id = element.getAttribute("id");
- if (id != null) {
+ String identity = element.getAttribute("id");
+ if (identity != null) {
// Look for dependency Id
- for (int i = 0; i < sh.getRequirements().size(); i++) {
- ServiceImporter imp = (ServiceImporter) sh.getRequirements().get(i);
- if (imp.getId().equals(id)) { return imp; }
+ for (int i = 0; i < handler.getRequirements().size(); i++) {
+ ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
+ if (imp.getId().equals(identity)) { return imp; }
}
}
// If not found or no id, look for a dependency with the same specification
String requirement = element.getAttribute("specification");
- for (int i = 0; i < sh.getRequirements().size(); i++) {
- ServiceImporter imp = (ServiceImporter) sh.getRequirements().get(i);
+ for (int i = 0; i < handler.getRequirements().size(); i++) {
+ ServiceImporter imp = (ServiceImporter) handler.getRequirements().get(i);
if (imp.getId().equals(requirement) || imp.getSpecification().getName().equals(requirement)) { return imp; }
}
return null;
@@ -389,44 +390,51 @@
* @throws CompositionException : occurs if the requirement does not match with service-level specification requirement
*/
private void checkRequirement(ServiceImporter imp, Element elem) throws CompositionException {
- String op = elem.getAttribute("optional");
- boolean opt = op != null && op.equalsIgnoreCase("true");
+ String optional = elem.getAttribute("optional");
+ boolean opt = optional != null && optional.equalsIgnoreCase("true");
- String ag = elem.getAttribute("aggregate");
- boolean agg = ag != null && ag.equalsIgnoreCase("true");
+ String aggregate = elem.getAttribute("aggregate");
+ boolean agg = aggregate != null && aggregate.equalsIgnoreCase("true");
if (imp == null) {
// Add the missing requirement
- ServiceDependencyHandler sh = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
- if (sh == null) {
+ ServiceDependencyHandler handler = (ServiceDependencyHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":subservice");
+ if (handler == null) {
// Look for the ServiceDependencyHandler factory
- HandlerManager ci = null;
+ HandlerManager handlerManager = null;
try {
ServiceReference[] refs = m_context.getServiceReferences(Factory.class.getName(), "(&(handler.name=subservice)(handler.namespace=" + HandlerFactory.IPOJO_NAMESPACE + ")(handler.type=composite))");
Factory factory = (Factory) m_context.getService(refs[0]);
- ci = (HandlerManager) factory.createComponentInstance(null, getCompositeManager().getServiceContext());
- } catch (Exception e) {
- e.printStackTrace(); // Should not happen
+ handlerManager = (HandlerManager) factory.createComponentInstance(null, getCompositeManager().getServiceContext());
+ } catch (InvalidSyntaxException e) {
+ // Should not happen
+ } catch (UnacceptableConfiguration e) {
+ // Should not happen
+ } catch (MissingHandlerException e) {
+ // Should not happen
+ } catch (ConfigurationException e) {
+ // Should not happen
}
+
// Add the required handler
try {
- ci.init(getCompositeManager(), new Element("composite", ""), new Properties());
+ handlerManager.init(getCompositeManager(), new Element("composite", ""), new Properties());
} catch (ConfigurationException e) {
error("Internal error : cannot configure the Import Handler : " + e.getMessage());
throw new CompositionException("Internal error : cannot configure the Import Handler : " + e.getMessage());
}
- sh = (ServiceDependencyHandler) ci.getHandler();
- getCompositeManager().addCompositeHandler(ci);
+ handler = (ServiceDependencyHandler) handlerManager.getHandler();
+ getCompositeManager().addCompositeHandler(handlerManager);
}
String spec = elem.getAttribute("specification");
String filter = "(&(objectClass=" + spec + ")(!(instance.name=" + getCompositeManager().getInstanceName() + ")))"; // Cannot import yourself
- String f = elem.getAttribute("filter");
- if (f != null) {
- filter = "(&" + filter + f + ")";
+ String givenFilter = elem.getAttribute("filter");
+ if (givenFilter != null) {
+ filter = "(&" + filter + givenFilter + ")"; //NOPMD
}
- BundleContext bc = new PolicyServiceContext(getCompositeManager().getGlobalContext(), getCompositeManager().getParentServiceContext(), PolicyServiceContext.GLOBAL);
+ BundleContext context = new PolicyServiceContext(getCompositeManager().getGlobalContext(), getCompositeManager().getParentServiceContext(), PolicyServiceContext.GLOBAL);
Filter fil = null;
try {
@@ -442,11 +450,11 @@
throw new CompositionException("A required specification cannot be loaded : " + spec);
}
- ServiceImporter si = new ServiceImporter(specToImport, fil, agg, opt, null, AbstractServiceDependency.DYNAMIC_BINDING_POLICY, bc, null, sh);
+ ServiceImporter importer = new ServiceImporter(specToImport, fil, agg, opt, null, DependencyModel.DYNAMIC_BINDING_POLICY, context, null, handler);
- sh.getRequirements().add(si);
- SpecificationMetadata sm = new SpecificationMetadata(spec, m_context, agg, opt, this);
- m_services.add(sm); // Update the available types
+ handler.getRequirements().add(importer);
+ SpecificationMetadata specMeta = new SpecificationMetadata(spec, m_context, agg, opt, this);
+ m_services.add(specMeta); // Update the available types
return;
}
@@ -473,11 +481,11 @@
* Build available instance types.
*/
private void computeAvailableTypes() {
- InstanceHandler ih = (InstanceHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":instance");
- if (ih == null) {
+ InstanceHandler handler = (InstanceHandler) getHandler(HandlerFactory.IPOJO_NAMESPACE + ":instance");
+ if (handler == null) {
m_types = new ArrayList();
} else {
- m_types = ih.getUsedType();
+ m_types = handler.getUsedType();
}
}
Modified: felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandlerDescription.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandlerDescription.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandlerDescription.java (original)
+++ felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ProvidedServiceHandlerDescription.java Mon Mar 3 07:46:27 2008
@@ -25,7 +25,7 @@
import org.apache.felix.ipojo.composite.CompositeHandler;
import org.apache.felix.ipojo.metadata.Attribute;
import org.apache.felix.ipojo.metadata.Element;
-import org.apache.felix.ipojo.util.AbstractServiceDependency;
+import org.apache.felix.ipojo.util.DependencyModel;
/**
* Provided Service Handler Description for composite.
@@ -37,7 +37,7 @@
/**
* Provided Service Description list.
*/
- private List m_providedServices = new ArrayList();
+ private List m_services = new ArrayList();
/**
* List of exports.
@@ -47,13 +47,13 @@
/**
* Constructor.
*
- * @param h : composite handler.
- * @param ps : The list of Provided Service.
+ * @param handler : composite handler.
+ * @param services : The list of Provided Service.
* @param exporters : list of managed exports
*/
- public ProvidedServiceHandlerDescription(CompositeHandler h, List ps, List exporters) {
- super(h);
- m_providedServices = ps;
+ public ProvidedServiceHandlerDescription(CompositeHandler handler, List services, List exporters) {
+ super(handler);
+ m_services = services;
m_exports = exporters;
}
@@ -64,14 +64,14 @@
*/
public Element getHandlerInfo() {
Element services = super.getHandlerInfo();
- for (int i = 0; i < m_providedServices.size(); i++) {
- ProvidedService ps = (ProvidedService) m_providedServices.get(i);
+ for (int i = 0; i < m_services.size(); i++) {
+ ProvidedService svc = (ProvidedService) m_services.get(i);
Element service = new Element("service", "");
String state = "unregistered";
- if (ps.isRegistered()) {
+ if (svc.isRegistered()) {
state = "registered";
}
- String spec = "[" + ps.getSpecification() + "]";
+ String spec = "[" + svc.getSpecification() + "]";
service.addAttribute(new Attribute("Specification", spec));
service.addAttribute(new Attribute("State", state));
services.addElement(service);
@@ -82,7 +82,7 @@
Element expo = new Element("Exports", "");
expo.addAttribute(new Attribute("Specification", exp.getSpecification().getName()));
expo.addAttribute(new Attribute("Filter", exp.getFilter()));
- if (exp.getState() == AbstractServiceDependency.RESOLVED) {
+ if (exp.getState() == DependencyModel.RESOLVED) {
expo.addAttribute(new Attribute("State", "resolved"));
} else {
expo.addAttribute(new Attribute("State", "unresolved"));
Modified: felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java (original)
+++ felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/ServiceExporter.java Mon Mar 3 07:46:27 2008
@@ -28,8 +28,8 @@
import org.apache.felix.ipojo.ServiceContext;
import org.apache.felix.ipojo.composite.CompositeManager;
-import org.apache.felix.ipojo.util.AbstractServiceDependency;
-import org.apache.felix.ipojo.util.DependencyLifecycleListener;
+import org.apache.felix.ipojo.util.DependencyModel;
+import org.apache.felix.ipojo.util.DependencyStateListener;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Filter;
import org.osgi.framework.ServiceReference;
@@ -39,7 +39,7 @@
* Export an service from the scope to the parent context.
* @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
*/
-public class ServiceExporter extends AbstractServiceDependency {
+public class ServiceExporter extends DependencyModel {
/**
* Destination context.
@@ -66,16 +66,16 @@
* @param cmp : comparator to use in the dependency
* @param policy : binding policy.
* @param from : internal service context
- * @param to : parent bundle context
+ * @param dest : parent bundle context
* @param listener : dependency lifecycle listener to notify when the dependency state change.
- * @param cm : composite manager
+ * @param manager : composite manager
*/
- public ServiceExporter(Class specification, Filter filter, boolean multiple, boolean optional, Comparator cmp, int policy, ServiceContext from, BundleContext to, DependencyLifecycleListener listener, CompositeManager cm) {
+ public ServiceExporter(Class specification, Filter filter, boolean multiple, boolean optional, Comparator cmp, int policy, ServiceContext from, BundleContext dest, DependencyStateListener listener, CompositeManager manager) {
super(specification, multiple, optional, filter, cmp, policy, from, listener);
- m_destination = to;
+ m_destination = dest;
- m_manager = cm;
+ m_manager = manager;
}
@@ -106,9 +106,9 @@
public void stop() {
super.stop();
Set refs = m_registrations.keySet();
- Iterator it = refs.iterator();
- while (it.hasNext()) {
- ServiceReference ref = (ServiceReference) it.next();
+ Iterator iterator = refs.iterator();
+ while (iterator.hasNext()) {
+ ServiceReference ref = (ServiceReference) iterator.next();
ServiceRegistration reg = (ServiceRegistration) m_registrations.get(ref);
reg.unregister();
}
@@ -155,7 +155,7 @@
* On Dependency Reconfiguration notification method.
* @param departs : leaving service references.
* @param arrivals : new injected service references.
- * @see org.apache.felix.ipojo.util.AbstractServiceDependency#onDependencyReconfiguration(org.osgi.framework.ServiceReference[], org.osgi.framework.ServiceReference[])
+ * @see org.apache.felix.ipojo.util.DependencyModel#onDependencyReconfiguration(org.osgi.framework.ServiceReference[], org.osgi.framework.ServiceReference[])
*/
public void onDependencyReconfiguration(ServiceReference[] departs, ServiceReference[] arrivals) {
throw new UnsupportedOperationException("Dynamic dependency reconfiguration is not supported by service exporter");
Modified: felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/SpecificationMetadata.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/SpecificationMetadata.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/SpecificationMetadata.java (original)
+++ felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/service/provides/SpecificationMetadata.java Mon Mar 3 07:46:27 2008
@@ -68,18 +68,18 @@
/**
* Constructor.
* @param name : specification name.
- * @param bc : bundle context.
+ * @param context : bundle context.
* @param isAggregate : is the specification aggregate.
* @param isOptional : is the specification optional.
* @param psd : the handler.
*/
- public SpecificationMetadata(String name, BundleContext bc, boolean isAggregate, boolean isOptional, ProvidedServiceHandler psd) {
+ public SpecificationMetadata(String name, BundleContext context, boolean isAggregate, boolean isOptional, ProvidedServiceHandler psd) {
m_name = name;
m_handler = psd;
// Populate methods :
try {
- Class clazz = bc.getBundle().loadClass(name);
+ Class clazz = context.getBundle().loadClass(name);
Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
MethodMetadata method = new MethodMetadata(methods[i]);
@@ -96,17 +96,17 @@
/**
* Constructor.
- * @param c : class
+ * @param clazz : class
* @param type : component type
* @param psd : the parent handler
*/
- public SpecificationMetadata(Class c, String type, ProvidedServiceHandler psd) {
+ public SpecificationMetadata(Class clazz, String type, ProvidedServiceHandler psd) {
m_handler = psd;
m_isAggregate = false;
m_isOptional = false;
m_componentType = type;
- m_name = c.getName();
- Method[] methods = c.getMethods();
+ m_name = clazz.getName();
+ Method[] methods = clazz.getMethods();
for (int i = 0; i < methods.length; i++) {
MethodMetadata method = new MethodMetadata(methods[i]);
m_methods.add(method);
Modified: felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/util/SourceManager.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/util/SourceManager.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/util/SourceManager.java (original)
+++ felix/sandbox/clement/ipojo/composite/src/main/java/org/apache/felix/ipojo/composite/util/SourceManager.java Mon Mar 3 07:46:27 2008
@@ -27,7 +27,8 @@
import org.apache.felix.ipojo.ContextSource;
import org.apache.felix.ipojo.Extender;
import org.apache.felix.ipojo.composite.CompositeManager;
-import org.apache.felix.ipojo.util.AbstractServiceDependency;
+import org.apache.felix.ipojo.parser.ParseUtils;
+import org.apache.felix.ipojo.util.DependencyModel;
import org.apache.felix.ipojo.util.Tracker;
import org.apache.felix.ipojo.util.TrackerCustomizer;
import org.osgi.framework.BundleContext;
@@ -50,7 +51,7 @@
/**
* Managed dependency.
*/
- private AbstractServiceDependency m_dependency;
+ private DependencyModel m_dependency;
/**
* List of monitored context sources.
@@ -82,18 +83,19 @@
* @param sources : context-source attribute from the dependency metadata
* @param depfilter : original dependency filter
* @param dependency : dependency object
- * @param cm : composite manager
+ * @param manager : composite manager
* @throws ConfigurationException : the sources are incorrect.
*/
- public SourceManager(String sources, String depfilter, AbstractServiceDependency dependency, CompositeManager cm) throws ConfigurationException {
+ public SourceManager(String sources, String depfilter, DependencyModel dependency, CompositeManager manager) throws ConfigurationException {
m_filter = depfilter;
m_properties = getProperties(depfilter);
m_dependency = dependency;
- m_context = cm.getGlobalContext();
- if (cm.getParentServiceContext() != null) {
- parseSources(sources, cm.getGlobalContext(), cm.getParentServiceContext(), cm.getServiceContext());
- } else { // The parent is the global context
- parseSources(sources, cm.getGlobalContext(), cm.getGlobalContext(), cm.getServiceContext());
+ m_context = manager.getGlobalContext();
+ if (manager.getParentServiceContext() == null) {
+ // The parent is the global context
+ parseSources(sources, manager.getGlobalContext(), manager.getGlobalContext(), manager.getServiceContext());
+ } else {
+ parseSources(sources, manager.getGlobalContext(), manager.getParentServiceContext(), manager.getServiceContext());
}
}
@@ -123,10 +125,10 @@
* @return the state of this source manager.
*/
public int getState() {
- if (m_sources.size() > 0) {
- return AbstractServiceDependency.RESOLVED;
+ if (m_sources.isEmpty()) {
+ return DependencyModel.UNRESOLVED;
} else {
- return AbstractServiceDependency.UNRESOLVED;
+ return DependencyModel.RESOLVED;
}
}
@@ -153,7 +155,7 @@
synchronized (this) {
for (int i = 0; i < m_sources.size(); i++) {
Dictionary props = ((ContextSource) m_sources.get(i)).getContext();
- fil = substitute(fil, props);
+ fil = substitute(fil, props); //NOPMD
}
}
if (!fil.equals(m_dependency.getFilter())) {
@@ -169,19 +171,19 @@
*/
public static String substitute(String str, Dictionary values) {
int len = str.length();
- StringBuffer sb = new StringBuffer(len);
+ StringBuffer buffer = new StringBuffer(len);
int prev = 0;
int start = str.indexOf("${");
- int end = str.indexOf("}", start);
+ int end = str.indexOf('}', start);
while (start != -1 && end != -1) {
String key = str.substring(start + 2, end);
Object value = values.get(key);
- if (value != null) {
- sb.append(str.substring(prev, start));
- sb.append(value);
+ if (value == null) {
+ buffer.append(str.substring(prev, end + 1));
} else {
- sb.append(str.substring(prev, end + 1));
+ buffer.append(str.substring(prev, start));
+ buffer.append(value);
}
prev = end + 1;
if (prev >= str.length()) {
@@ -190,13 +192,13 @@
start = str.indexOf("${", prev);
if (start != -1) {
- end = str.indexOf("}", start);
+ end = str.indexOf('}', start);
}
}
- sb.append(str.substring(prev));
+ buffer.append(str.substring(prev));
- return sb.toString();
+ return buffer.toString();
}
/**
@@ -208,7 +210,7 @@
List list = new ArrayList();
int prev = 0;
int start = str.indexOf("${");
- int end = str.indexOf("}", start);
+ int end = str.indexOf('}', start);
while (start != -1 && end != -1) {
String key = str.substring(start + 2, end);
list.add(key);
@@ -219,7 +221,7 @@
start = str.indexOf("${", prev);
if (start != -1) {
- end = str.indexOf("}", start);
+ end = str.indexOf('}', start);
}
}
@@ -246,24 +248,24 @@
* @throws ConfigurationException : the context-source attribute is invalid.
*/
private void parseSources(String sourceAtt, BundleContext global, BundleContext parent, BundleContext local) throws ConfigurationException {
- String[] sources = Extender.split(sourceAtt, ',');
+ String[] sources = ParseUtils.split(sourceAtt, ",");
for (int i = 0; i < sources.length; i++) {
- String[] srcs = Extender.split(sources[i], ':');
+ String[] srcs = ParseUtils.split(sources[i], ":");
if (srcs.length == 1) {
// No prefix use local. //TODO choose default case.
- SourceTracker st = new SourceTracker(srcs[0], local);
- m_trackers.add(st);
+ SourceTracker tracker = new SourceTracker(srcs[0], local);
+ m_trackers.add(tracker);
} else if (srcs.length == 2) {
// According to prefix add the source in the good list.
if (srcs[0].equalsIgnoreCase("parent")) {
- SourceTracker st = new SourceTracker(srcs[1], parent);
- m_trackers.add(st);
+ SourceTracker tracker = new SourceTracker(srcs[1], parent);
+ m_trackers.add(tracker);
} else if (srcs[0].equalsIgnoreCase("local")) {
- SourceTracker st = new SourceTracker(srcs[1], local);
- m_trackers.add(st);
+ SourceTracker tracker = new SourceTracker(srcs[1], local);
+ m_trackers.add(tracker);
} else if (srcs[0].equalsIgnoreCase("global")) {
- SourceTracker st = new SourceTracker(srcs[1], global);
- m_trackers.add(st);
+ SourceTracker tracker = new SourceTracker(srcs[1], global);
+ m_trackers.add(tracker);
} else {
throw new ConfigurationException("Unknowns context scope : " + srcs[0]);
}
@@ -275,20 +277,20 @@
/**
* A context source appears.
- * @param cs : new context source.
+ * @param source : new context source.
*/
- private void addContextSource(ContextSource cs) {
- m_sources.add(cs);
+ private void addContextSource(ContextSource source) {
+ m_sources.add(source);
computeFilter();
- cs.registerContextListener(this, m_properties);
+ source.registerContextListener(this, m_properties);
}
/**
* A context source disappears.
- * @param cs : leaving context source.
+ * @param source : leaving context source.
*/
- private void removeContextSource(ContextSource cs) {
- m_sources.remove(cs);
+ private void removeContextSource(ContextSource source) {
+ m_sources.remove(source);
computeFilter();
}
@@ -302,14 +304,14 @@
/**
* Constructor.
* @param name : name of the required context-source.
- * @param bc : bundle context to use.
+ * @param countext : bundle context to use.
* @throws ConfigurationException : the context-source name is invalid.
*/
- public SourceTracker(String name, BundleContext bc) throws ConfigurationException {
+ public SourceTracker(String name, BundleContext countext) throws ConfigurationException {
String fil = "(&(" + Constants.OBJECTCLASS + "=" + ContextSource.class.getName() + ")(" + SOURCE_NAME + "=" + name + "))";
try {
- Filter filter = bc.createFilter(fil);
- m_tracker = new Tracker(bc, filter, this);
+ Filter filter = countext.createFilter(fil);
+ m_tracker = new Tracker(countext, filter, this);
} catch (InvalidSyntaxException e) {
throw new ConfigurationException("A Context source filter is invalid " + fil + " : " + e.getMessage());
}
Modified: felix/sandbox/clement/ipojo/core/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/pom.xml?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/pom.xml (original)
+++ felix/sandbox/clement/ipojo/core/pom.xml Mon Mar 3 07:46:27 2008
@@ -58,9 +58,9 @@
<extensions>true</extensions>
<configuration>
<instructions>
- <Bundle-Name>iPOJO-unstable</Bundle-Name>
+ <Bundle-Name> iPOJO </Bundle-Name>
<Bundle-Vendor>Clement ESCOFFIER</Bundle-Vendor>
- <Bundle-Description> iPOJO </Bundle-Description>
+ <Bundle-Description> iPOJO Core Framework </Bundle-Description>
<Bundle-Activator>org.apache.felix.ipojo.Extender</Bundle-Activator>
<IPOJO-Extension>component:org.apache.felix.ipojo.ComponentFactory, handler:org.apache.felix.ipojo.HandlerFactory</IPOJO-Extension>
<Import-Package>
@@ -72,8 +72,7 @@
org.apache.felix.ipojo.handlers.architecture,
org.apache.felix.ipojo.handlers.configuration,
org.apache.felix.ipojo.handlers.lifecycle.callback,
- org.apache.felix.ipojo.handlers.lifecycle.controller,
- org.objectweb.asm;-split-package:=first
+ org.apache.felix.ipojo.handlers.lifecycle.controller
</Private-Package>
<Export-Package>
org.apache.felix.ipojo; version="0.7.6",
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/ComponentFactory.java Mon Mar 3 07:46:27 2008
@@ -51,51 +51,51 @@
* Tracker used to track required handler factories.
*/
protected Tracker m_tracker;
-
+
/**
* Class loader to delegate loading.
*/
private FactoryClassloader m_classLoader = null;
-
+
/**
* Component Implementation class.
*/
private byte[] m_clazz = null;
-
+
/**
* Component Implementation Class Name.
*/
- private String m_componentClassName = null;
-
+ private String m_classname = null;
+
/**
* Manipulation Metadata of the internal POJO.
*/
private PojoMetadata m_manipulation = null;
-
+
/**
* Create a instance manager factory. The class is given in parameter. The
* component type is not a composite.
- * @param bc : bundle context
+ * @param context : bundle context
* @param clazz : the component class
- * @param cm : metadata of the component
+ * @param element : metadata of the component
* @throws ConfigurationException occurs when the element describing the factory is malformed.
*/
- public ComponentFactory(BundleContext bc, byte[] clazz, Element cm) throws ConfigurationException {
- this(bc, cm);
+ public ComponentFactory(BundleContext context, byte[] clazz, Element element) throws ConfigurationException {
+ this(context, element);
m_clazz = clazz;
}
-
+
/**
* Create a instance manager factory.
- * @param bc : bundle context
- * @param cm : metadata of the component to create
+ * @param context : bundle context
+ * @param element : metadata of the component to create
* @throws ConfigurationException occurs when the element describing the factory is malformed.
*/
- public ComponentFactory(BundleContext bc, Element cm) throws ConfigurationException {
- super(bc, cm);
- check(cm);
+ public ComponentFactory(BundleContext context, Element element) throws ConfigurationException {
+ super(context, element);
+ check(element); // NOPMD. This invocation is normal.
}
-
+
public ComponentTypeDescription getComponentTypeDescription() {
return new PrimitiveTypeDescription(this);
}
@@ -103,56 +103,55 @@
/**
* Check method : allow a factory to check if given element are correct.
* A component factory metadata are correct if they contain the 'classname' attribute.
- * @param cm : the metadata
+ * @param element : the metadata
* @throws ConfigurationException occurs when the element describing the factory is malformed.
*/
- public void check(Element cm) throws ConfigurationException {
- m_componentClassName = cm.getAttribute("className");
- if (m_componentClassName == null) {
- throw new ConfigurationException("A component needs a class name : " + cm);
- }
- }
-
+ public void check(Element element) throws ConfigurationException {
+ m_classname = element.getAttribute("className");
+ if (m_classname == null) { throw new ConfigurationException("A component needs a class name : " + element); }
+ }
+
public String getClassName() {
- return m_componentClassName;
+ return m_classname;
}
-
+
/**
* Create a primitive instance.
- * @param configuration : instance configuration
+ * @param config : instance configuration
* @param context : service context.
* @param handlers : handler to use
* @return the created instance
* @throws org.apache.felix.ipojo.ConfigurationException : if the configuration process failed.
* @see org.apache.felix.ipojo.IPojoFactory#createInstance(java.util.Dictionary, org.apache.felix.ipojo.IPojoContext, org.apache.felix.ipojo.HandlerManager[])
*/
- public ComponentInstance createInstance(Dictionary configuration, IPojoContext context, HandlerManager[] handlers) throws org.apache.felix.ipojo.ConfigurationException {
+ public ComponentInstance createInstance(Dictionary config, IPojoContext context, HandlerManager[] handlers) throws org.apache.felix.ipojo.ConfigurationException {
InstanceManager instance = new InstanceManager(this, context, handlers);
- instance.configure(m_componentMetadata, configuration);
+ instance.configure(m_componentMetadata, config);
try {
instance.start();
return instance;
} catch (IllegalStateException e) {
// An exception occurs during the start method.
+ m_logger.log(Logger.ERROR, e.getMessage(), e);
throw new ConfigurationException(e.getMessage());
}
-
+
}
/**
* Define a class.
* @param name : qualified name of the class
- * @param b : byte array of the class
+ * @param clazz : byte array of the class
* @param domain : protection domain of the class
* @return the defined class object
*/
- public Class defineClass(String name, byte[] b, ProtectionDomain domain) {
+ public Class defineClass(String name, byte[] clazz, ProtectionDomain domain) {
if (m_classLoader == null) {
m_classLoader = new FactoryClassloader();
}
- return m_classLoader.defineClass(name, b, domain);
+ return m_classLoader.defineClass(name, clazz, domain);
}
-
+
/**
* Return the URL of a resource.
* @param resName : resource name
@@ -170,33 +169,29 @@
* @throws ClassNotFoundException : happen when the class is not found
*/
public Class loadClass(String className) throws ClassNotFoundException {
- if (m_clazz != null && className.equals(m_componentClassName)) {
+ if (m_clazz != null && className.equals(m_classname)) {
// Used the factory classloader to load the component implementation
// class
if (m_classLoader == null) {
m_classLoader = new FactoryClassloader();
}
- return m_classLoader.defineClass(m_componentClassName, m_clazz, null);
+ return m_classLoader.defineClass(m_classname, m_clazz, null);
}
return m_context.getBundle().loadClass(className);
}
-
/**
* Start the factory.
*/
- public synchronized void starting() {
+ public synchronized void starting() {
if (m_requiredHandlers.size() != 0) {
try {
- String filter = "(&(" + Handler.HANDLER_TYPE_PROPERTY + "=" + PrimitiveHandler.HANDLER_TYPE + ")"
- + "(factory.state=1)"
- + ")";
+ String filter = "(&(" + Handler.HANDLER_TYPE_PROPERTY + "=" + PrimitiveHandler.HANDLER_TYPE + ")" + "(factory.state=1)" + ")";
m_tracker = new Tracker(m_context, m_context.createFilter(filter), this);
m_tracker.open();
} catch (InvalidSyntaxException e) {
m_logger.log(Logger.ERROR, "A factory filter is not valid: " + e.getMessage());
stop();
- return;
}
}
}
@@ -205,26 +200,27 @@
* Stop all the instance managers.
*/
public synchronized void stopping() {
+ m_tracker.close();
+ m_tracker = null;
m_classLoader = null;
m_clazz = null;
}
-
/**
* Compute the factory name.
* @return the factory name.
*/
public String getFactoryName() {
- String s = m_componentMetadata.getAttribute("name");
- if (s == null) { // No factory name, try with factory attribute
- s = m_componentMetadata.getAttribute("factory");
- if (s == null || s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) { // Avoid boolean case
- s = m_componentMetadata.getAttribute("className");
+ String name = m_componentMetadata.getAttribute("name");
+ if (name == null) { // No factory name, try with factory attribute
+ name = m_componentMetadata.getAttribute("factory");
+ if (name == null || name.equalsIgnoreCase("true") || name.equalsIgnoreCase("false")) { // Avoid boolean case
+ name = m_componentMetadata.getAttribute("className");
}
}
- return s;
+ return name;
}
-
+
/**
* Compute required handlers.
* @return the required handler list.
@@ -233,30 +229,31 @@
List list = new ArrayList();
Element[] elems = m_componentMetadata.getElements();
for (int i = 0; i < elems.length; i++) {
- Element current = elems[i];
- if (! "manipulation".equals(current.getName())) {
- RequiredHandler hi = new RequiredHandler(current.getName(), current.getNameSpace());
- if (! list.contains(hi)) { list.add(hi); }
+ Element current = elems[i];
+ if (!"manipulation".equals(current.getName())) {
+ RequiredHandler req = new RequiredHandler(current.getName(), current.getNameSpace());
+ if (!list.contains(req)) {
+ list.add(req);
+ }
}
}
-
+
// Add architecture if architecture != 'false'
- RequiredHandler hi = new RequiredHandler("architecture", null);
String arch = m_componentMetadata.getAttribute("architecture");
if (arch == null || arch.equalsIgnoreCase("true")) {
- list.add(hi);
+ list.add(new RequiredHandler("architecture", null));
}
-
+
// Add lifecycle callback if immediate = true
- RequiredHandler hi2 = new RequiredHandler("callback", null);
+ RequiredHandler reqCallback = new RequiredHandler("callback", null);
String imm = m_componentMetadata.getAttribute("immediate");
- if (! list.contains(hi2) && imm != null && imm.equalsIgnoreCase("true")) {
- list.add(hi2);
+ if (!list.contains(reqCallback) && imm != null && imm.equalsIgnoreCase("true")) {
+ list.add(reqCallback);
}
-
+
return list;
}
-
+
/**
* A new handler factory is detected.
* Test if the factory can be used or not.
@@ -266,12 +263,12 @@
*/
public boolean addingService(ServiceReference reference) {
for (int i = 0; i < m_requiredHandlers.size(); i++) {
- RequiredHandler hi = (RequiredHandler) m_requiredHandlers.get(i);
- if (hi.getReference() == null && match(hi, reference)) {
- int oldP = hi.getLevel();
- hi.setReference(reference);
+ RequiredHandler req = (RequiredHandler) m_requiredHandlers.get(i);
+ if (req.getReference() == null && match(req, reference)) {
+ int oldP = req.getLevel();
+ req.setReference(reference);
// If the priority has changed, sort the list.
- if (oldP != hi.getLevel()) {
+ if (oldP != req.getLevel()) {
Collections.sort(m_requiredHandlers);
}
return true;
@@ -279,7 +276,7 @@
}
return false;
}
-
+
/**
* A matching service has been added to the tracker, we can no compute the factory state.
* @param reference : added reference.
@@ -290,7 +287,7 @@
computeFactoryState();
}
}
-
+
/**
* A used factory disappears.
* @param reference : service reference.
@@ -300,15 +297,15 @@
public void removedService(ServiceReference reference, Object service) {
// Look for the implied reference and invalid the handler identifier
for (int i = 0; i < m_requiredHandlers.size(); i++) {
- RequiredHandler hi = (RequiredHandler) m_requiredHandlers.get(i);
- if (reference.equals(hi.getReference())) {
- hi.unRef(); // This method will unget the service.
+ RequiredHandler req = (RequiredHandler) m_requiredHandlers.get(i);
+ if (reference.equals(req.getReference())) {
+ req.unRef(); // This method will unget the service.
computeFactoryState();
return; // The factory can be used only once.
}
}
}
-
+
/**
* A used handler factory is modified.
* @param reference : the service reference
@@ -318,8 +315,7 @@
public void modifiedService(ServiceReference reference, Object service) {
// Noting to do
}
-
-
+
/**
* Returns manipulation metadata of this component type.
* The returned object is computed at the first call and then is cached.
@@ -331,7 +327,7 @@
}
return m_manipulation;
}
-
+
/**
* FactoryClassloader.
*/
@@ -340,22 +336,20 @@
/**
* Map of defined classes [Name, Class Object].
*/
- private Map m_definedClasses = new HashMap();
+ private final Map m_definedClasses = new HashMap();
/**
* The defineClass method.
* @param name : name of the class
- * @param b : the byte array of the class
+ * @param clazz : the byte array of the class
* @param domain : the protection domain
* @return : the defined class.
*/
- public Class defineClass(String name, byte[] b, ProtectionDomain domain) {
- if (m_definedClasses.containsKey(name)) {
- return (Class) m_definedClasses.get(name);
- }
- final Class c = super.defineClass(name, b, 0, b.length, domain);
- m_definedClasses.put(name, c);
- return c;
+ public Class defineClass(String name, byte[] clazz, ProtectionDomain domain) {
+ if (m_definedClasses.containsKey(name)) { return (Class) m_definedClasses.get(name); }
+ Class clas = super.defineClass(name, clazz, 0, clazz.length, domain);
+ m_definedClasses.put(name, clas);
+ return clas;
}
/**
@@ -376,21 +370,21 @@
* @return : the loaded class
* @throws ClassNotFoundException : the class to load is not found
*/
- protected synchronized Class loadClass(final String name, final boolean resolve) throws ClassNotFoundException {
+ protected synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
return m_context.getBundle().loadClass(name);
}
}
-
+
private final class PrimitiveTypeDescription extends ComponentTypeDescription {
/**
* Constructor.
* @param factory : the represented factory.
*/
- private PrimitiveTypeDescription(Factory factory) {
+ public PrimitiveTypeDescription(Factory factory) {
super(factory);
}
-
+
/**
* Compute the properties to publish :
* component.class contains the pojo class name.
@@ -398,13 +392,13 @@
* @see org.apache.felix.ipojo.architecture.ComponentTypeDescription#getPropertiesToPublish()
*/
public Dictionary getPropertiesToPublish() {
- Dictionary dict = super.getPropertiesToPublish();
- if (m_componentClassName != null) {
- dict.put("component.class", m_componentClassName);
+ Dictionary dict = super.getPropertiesToPublish();
+ if (m_classname != null) {
+ dict.put("component.class", m_classname);
}
return dict;
}
-
+
/**
* Add the "implementation-class" attribute to the type description.
* @return the component type description.
@@ -412,7 +406,7 @@
*/
public Element getDescription() {
Element elem = super.getDescription();
- elem.addAttribute(new Attribute("Implementation-Class", m_componentClassName));
+ elem.addAttribute(new Attribute("Implementation-Class", m_classname));
return elem;
}
}
Modified: felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java?rev=633138&r1=633137&r2=633138&view=diff
==============================================================================
--- felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java (original)
+++ felix/sandbox/clement/ipojo/core/src/main/java/org/apache/felix/ipojo/ConfigurationException.java Mon Mar 3 07:46:27 2008
@@ -29,11 +29,6 @@
* Serialization Id.
*/
private static final long serialVersionUID = 1L;
-
- /**
- * Message.
- */
- private String m_message;
/**
* Component Type on which the error occurs.
@@ -46,8 +41,8 @@
* @param typ : component type
*/
ConfigurationException(String mes, String typ) {
+ super(mes);
m_type = typ;
- m_message = mes;
}
/**
@@ -55,7 +50,7 @@
* @param mes : message
*/
public ConfigurationException(String mes) {
- m_message = mes;
+ super(mes);
}
/**
@@ -64,10 +59,10 @@
* @see java.lang.Throwable#getMessage()
*/
public String getMessage() {
- if (m_type != null) {
- return "The configuration is not correct for the type " + m_type + " : " + m_message;
+ if (m_type == null) {
+ return super.getMessage();
} else {
- return m_message;
+ return "The configuration is not correct for the type " + m_type + " : " + super.getMessage();
}
}