Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.ConfigurationException


        if ("INSTANCE".equalsIgnoreCase(type)) {
            context = getInstanceBundleContext();
        } else if (type == null || "COMPONENT".equalsIgnoreCase(type)) {
            context = getComponentBundleContext();
        } else {
            throw new ConfigurationException("Not supported bundle context source : " + type);
        }
        return context;
    }
View Full Code Here


                } else {
                    // Customized policy
                    try {
                        custom = getInstanceManager().getContext().getBundle().loadClass(strategy);
                        if (!CreationStrategy.class.isAssignableFrom(custom)) {
                            throw new ConfigurationException("The custom creation policy class " + custom.getName() + " does not implement " + CreationStrategy.class.getName());
                        }
                    } catch (ClassNotFoundException e) {
                        throw new ConfigurationException("The custom creation policy class " + strategy + " cannot be loaded ", e);

                    }

                }
            }


            // Then create the provided service
            ProvidedService svc = new ProvidedService(this, serviceSpecifications, factory, custom, configuration);

            // Post-Registration callback
            String post = providedService.getAttribute("post-registration");
            if (post != null) {
                Callback cb = new Callback(post, new Class[]{ServiceReference.class}, false, getInstanceManager());
                svc.setPostRegistrationCallback(cb);
            }

            post = providedService.getAttribute("post-unregistration");
            if (post != null) {
                // TODO Can we really send the service reference here ?
                Callback cb = new Callback(post, new Class[]{ServiceReference.class}, false, getInstanceManager());
                svc.setPostUnregistrationCallback(cb);
            }

            Element[] props = providedService.getElements("Property");
            if (props != null) {
                //Property[] properties = new Property[props.length];
                Property[] properties = new Property[props.length];
                for (int j = 0; j < props.length; j++) {
                    String name = props[j].getAttribute("name");
                    String value = props[j].getAttribute("value");
                    String type = props[j].getAttribute("type");
                    String field = props[j].getAttribute("field");

                    Property prop = new Property(name, field, null, value, type, getInstanceManager(), this);
                    properties[j] = prop;

                    // Check if the instance configuration has a value for this property
                    Object object = configuration.get(prop.getName());
                    if (object != null) {
                        prop.setValue(object);
                    }

                    if (field != null) {
                        getInstanceManager().register(new FieldMetadata(field, type), this);
                        // Cannot register the property as the interception is necessary
                        // to deal with registration update.
                    }
                }

                // Attach to properties to the provided service
                svc.setProperties(properties);
            }

            Element[] controllers = providedService.getElements("Controller");
            if (controllers != null) {
                for (Element controller : controllers) {
                    String field = controller.getAttribute("field");
                    if (field == null) {
                        throw new ConfigurationException("The field attribute of a controller is mandatory");
                    }

                    String v = controller.getAttribute("value");
                    boolean value = !(v != null && v.equalsIgnoreCase("false"));
                    String s = controller.getAttribute("specification");
                    if (s == null) {
                        s = "ALL";
                    }
                    svc.setController(field, value, s);

                    getInstanceManager().register(new FieldMetadata(field, "boolean"), this);
                }
            }

            if (checkProvidedService(svc)) {
                m_providedServices.add(svc);
            } else {
                StringBuilder itfs = new StringBuilder();
                for (String serviceSpecification : serviceSpecifications) {
                    itfs.append(' ');
                    itfs.append(serviceSpecification);
                }
                throw new ConfigurationException("The provided service" + itfs + " is not valid");
            }

            // Initialize the description.
            m_description = new ProvidedServiceHandlerDescription(this, getProvidedServices());
View Full Code Here

                            dep.setServiceLevelDependency();
                        }
                        isDependencyCorrect(dep, deps[j]);
                    }
                } else {
                    throw new ConfigurationException("Service Providing: The specification field of the service specification " + svc.getServiceSpecifications()[i] + " needs to be a String");
                }
            } catch (NoSuchFieldException e) {
                return true; // No specification field
            } catch (ClassNotFoundException e) {
                throw new ConfigurationException("Service Providing: The service specification " + svc.getServiceSpecifications()[i] + " cannot be loaded", e);
            } catch (IllegalArgumentException e) {
                throw new ConfigurationException("Service Providing: The field 'specification' of the service specification " + svc.getServiceSpecifications()[i] + " is not accessible", e);
            } catch (IllegalAccessException e) {
                throw new ConfigurationException("Service Providing: The field 'specification' of the service specification " + svc.getServiceSpecifications()[i] + " is not accessible", e);
            } catch (ParseException e) {
                throw new ConfigurationException("Service Providing: The field 'specification' of the service specification " + svc.getServiceSpecifications()[i] + " does not contain a valid String", e);
            }
        }

        return true;
    }
View Full Code Here

        String aggregate = elem.getAttribute("aggregate");
        boolean agg = aggregate != null && aggregate.equalsIgnoreCase("true");

        if (dep == null && !opt) {
            throw new ConfigurationException("Service Providing: The requirement " + elem.getAttribute("specification") + " is not present in the implementation and is declared as a mandatory service-level requirement");
        }

        if (dep != null && dep.isAggregate() && !agg) {
            throw new ConfigurationException("Service Providing: The requirement " + elem.getAttribute("specification") + " is aggregate in the implementation and is declared as a simple service-level requirement");
        }

        String filter = elem.getAttribute("filter");
        if (dep != null && filter != null) {
            String filter2 = dep.getFilter();
            if (filter2 == null || !filter2.equalsIgnoreCase(filter)) {
                throw new ConfigurationException("Service Providing: The specification requirement " + elem.getAttribute("specification") + " has not the same filter as declared in the service-level requirement");
            }
        }
    }
View Full Code Here

            try {
                computeInterfacesAndSuperClasses(serviceSpecification, parent, desc.getBundleContext().getBundle(), interfaces, parentClasses);
                getLogger().log(Logger.INFO, "Collected interfaces from " + metadata.getAttribute("classname") + " : " + interfaces);
                getLogger().log(Logger.INFO, "Collected super classes from " + metadata.getAttribute("classname") + " : " + parentClasses);
            } catch (ClassNotFoundException e) {
                throw new ConfigurationException("An interface or parent class cannot be loaded", e);
            }

            String serviceSpecificationStr = provide.getAttribute("specifications");
            if (serviceSpecificationStr == null) {
                serviceSpecificationStr = provide.getAttribute("interface");
                if (serviceSpecificationStr != null) {
                    warn("The 'interface' attribute is deprecated, use the 'specifications' attribute instead of 'interface'");
                }
            }

            if (serviceSpecificationStr != null) {
                List<String> itfs = ParseUtils.parseArraysAsList(serviceSpecificationStr);
                for (String itf : itfs)
                    if (!interfaces.contains(itf)
                            && !parentClasses.contains(itf)
                            && !desc.getFactory().getClassName().equals(itf)) {
                        desc.getFactory().getLogger().log(Logger.ERROR, "The specification " + itf + " is not implemented by " + metadata.getAttribute("classname"));
                    }
                interfaces.clear();
                interfaces.addAll(itfs);
            }

            if (interfaces.isEmpty()) {
                warn("No service interface found in the class hierarchy, use the implementation class");
                interfaces.add(desc.getFactory().getClassName());
            }

            StringBuffer specs = null;
            Set<String> set = new HashSet<String>(interfaces);
            set.remove(Pojo.class.getName()); // Remove POJO.
            for (String spec : set) {
                desc.addProvidedServiceSpecification(spec);
                if (specs == null) {
                    specs = new StringBuffer("{");
                    specs.append(spec);
                } else {
                    specs.append(',');
                    specs.append(spec);
                }
            }

            specs.append('}');
            provide.addAttribute(new Attribute("specifications", specs.toString())); // Add interface attribute to avoid checking in the configure method

            Element[] props = provide.getElements("property");
            for (int j = 0; props != null && j < props.length; j++) {
                String name = props[j].getAttribute("name");
                String value = props[j].getAttribute("value");
                String type = props[j].getAttribute("type");
                String 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) {
                        throw new ConfigurationException("The property " + name + " has neither type nor field.");
                    }
                    FieldMetadata fieldMeta = manipulation.getField(field);
                    if (fieldMeta == null) {
                        throw new ConfigurationException("A declared property was not found in the implementation class : " + field);
                    }
                    type = fieldMeta.getFieldType();
                    props[j].addAttribute(new Attribute("type", type));
                }
View Full Code Here

        Element[] hooksMetadata = metadata.getElements("callback");
        for (int i = 0; hooksMetadata != null && i < hooksMetadata.length; i++) {
            String method = hooksMetadata[i].getAttribute("method");
            if (method == null) {
                throw new ConfigurationException("Lifecycle callback : A callback needs to contain a method attribute");
            }
           
            MethodMetadata met = meta.getMethod(method, new String[0]);
           
            int transition = -1;
            String trans = hooksMetadata[i].getAttribute("transition");
            if (trans == null) {
                throw new ConfigurationException("Lifecycle callback : the transition attribute is missing");
            } else {
                if (trans.equalsIgnoreCase("validate")) {
                    transition = LifecycleCallback.VALIDATE;
                } else if (trans.equalsIgnoreCase("invalidate")) {
                    transition = LifecycleCallback.INVALIDATE;
                } else {
                    throw new ConfigurationException("Lifecycle callback : Unknown or malformed transition : " + trans);
                }
            }
           
            LifecycleCallback callback = null;
            if (met == null) {
View Full Code Here

        String field = null;
        Element[] controller = metadata.getElements("controller");
        // Use only the first controller
        field = controller[0].getAttribute("field");
        if (field == null) {
            throw new ConfigurationException("Lifecycle controller : the controller element needs to contain a field attribute");
        }

        PojoMetadata method = getFactory().getPojoMetadata();
        FieldMetadata fieldMetadata = method.getField(field);
        if (fieldMetadata == null) {
            throw new ConfigurationException("Lifecycle controller : The field " + field + " does not exist in the implementation class");
        }

        if (!fieldMetadata.getFieldType().equalsIgnoreCase("boolean")) {
            throw new ConfigurationException("Lifecycle controller : The field " + field + " must be a boolean (" + fieldMetadata.getFieldType() + " found)");
        }
    }
View Full Code Here

            } else {
                try {
                    Class cla = context.getBundle().loadClass(comp);
                    cmp = (Comparator) cla.newInstance();
                } catch (ClassNotFoundException e) {
                    throw new ConfigurationException("Cannot load a customized comparator", e);
                } catch (IllegalAccessException e) {
                    throw new ConfigurationException("Cannot create a customized comparator", e);
                } catch (InstantiationException e) {
                    throw new ConfigurationException("Cannot create a customized comparator", e);
                }
            }
        }
        return cmp;
    }
View Full Code Here

    public static Class loadSpecification(String specification, BundleContext context) throws ConfigurationException {
        Class spec;
        try {
            spec = context.getBundle().loadClass(specification);
        } catch (ClassNotFoundException e) {
            throw new ConfigurationException("A required specification cannot be loaded : " + specification, e);
        }
        return spec;
    }
View Full Code Here

        } else if (policy.equalsIgnoreCase("dynamic-priority")) {
            return DependencyModel.DYNAMIC_PRIORITY_BINDING_POLICY;
        } else if (policy.equalsIgnoreCase("static")) {
            return DependencyModel.STATIC_BINDING_POLICY;
        } else {
            throw new ConfigurationException("Binding policy unknown : " + policy);
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.ipojo.ConfigurationException

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.