Package org.apache.felix.ipojo.configuration

Examples of org.apache.felix.ipojo.configuration.Instance


            // 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());
                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());
                    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);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.configuration.Instance

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.