use of org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration in project felix by apache.
the class DefaultInstanceBuilderTestCase method testDeclarationIsNotAutomaticallyStarted.
public void testDeclarationIsNotAutomaticallyStarted() throws Exception {
InstanceBuilder builder = new DefaultInstanceBuilder(m_bundleContext, "type");
DeclarationHandle handle = builder.build();
DefaultInstanceDeclaration did = (DefaultInstanceDeclaration) handle;
assertFalse(did.isRegistered());
}
use of org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration in project felix by apache.
the class ConfigurationProcessor method instantiateAndDeclareInstances.
private void instantiateAndDeclareInstances(Bundle bundle, String resource, ClassLoader classLoader) {
String classname = getClassNameFromResource(resource);
List<Instance> instances = new ArrayList<Instance>();
try {
Class clazz = classLoader.loadClass(classname);
Object configuration = clazz.newInstance();
// Collect fields
Map<Field, Instance> fields = fields().ofType(Instance.class).in(configuration).map();
for (Map.Entry<Field, Instance> entry : fields.entrySet()) {
Instance instance = entry.getValue();
instance.nameIfUnnamed(entry.getKey().getName()).with("instance.bundle.context").setto(bundle.getBundleContext());
instances.add(instance);
}
// Collect methods with Bundle Context as argument
Map<Method, InvocationResult<Instance>> methods = methods().in(configuration).ofReturnType(Instance.class).withParameter(BundleContext.class).map(bundle.getBundleContext());
// Collect methods without arguments
methods.putAll(methods().in(configuration).ofReturnType(Instance.class).map());
for (Map.Entry<Method, InvocationResult<Instance>> entry : methods.entrySet()) {
Instance instance = entry.getValue().get();
if (instance == null) {
m_logger.log(Log.ERROR, "The Instance declaration creation failed because the method " + entry.getKey().getName() + " of class " + entry.getKey().getDeclaringClass() + " threw an " + "exception", entry.getValue().error());
} else {
instance.nameIfUnnamed(entry.getKey().getName()).with("instance.bundle.context").setto(bundle.getBundleContext());
instances.add(instance);
}
}
} catch (ClassNotFoundException e) {
m_logger.log(Log.ERROR, "Cannot load class " + classname + " despite it was considered as a " + "configuration", e);
return;
} catch (InstantiationException e) {
m_logger.log(Log.ERROR, "Cannot instantiate class " + classname + " despite it was considered as a " + "configuration", e);
return;
} catch (IllegalAccessException e) {
m_logger.log(Log.ERROR, "Cannot instantiate class " + classname + " despite it was considered as a " + "configuration", e);
return;
}
m_logger.log(Log.WARNING, instances.size() + " instances found in class " + classname);
// Build and enqueue declaration
for (Instance instance : instances) {
DefaultInstanceDeclaration declaration = new DefaultInstanceDeclaration(bundle.getBundleContext(), instance.factory(), instance.configuration());
declaration.start();
getComponentsAndInstances(bundle).m_instances.add(declaration);
}
}
use of org.apache.felix.ipojo.extender.internal.declaration.DefaultInstanceDeclaration in project felix by apache.
the class ComponentsBundleProcessor method handleInstanceDeclaration.
/**
* Extracts and builds the declaration attached to an instance.
*
* @param bundle the bundle declaring the instance
* @param instance the instance configuration (parsed from the header)
*/
private void handleInstanceDeclaration(Bundle bundle, Dictionary instance) {
String component = (String) instance.get(COMPONENT_INSTANCE_ATTRIBUTE);
// String v = (String) instance.get(Factory.FACTORY_VERSION_PROPERTY); //TODO CES to GSA, why this is commented ?
DefaultInstanceDeclaration declaration = new DefaultInstanceDeclaration(bundle.getBundleContext(), component, instance);
declaration.start();
getComponentsAndInstances(bundle).m_instances.add(declaration);
}
Aggregations