Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.ConfigurationException


                dependency.setAggregateType(AggregateDependencyInjectionType.SET);
            } else if (Vector.class.getName().equals(type)) {
                dependency.setAggregateType(AggregateDependencyInjectionType.VECTOR);
            } else if (dependency.isAggregate()) {
                // Something wrong. The dependency has a field that is not suitable for aggregate dependencies
                throw new ConfigurationException("The dependency " + DependencyHandler.getDependencyIdentifier
                        (dependency) + " cannot be an aggregate dependency - reason: the type " + field.getFieldType
                        () + " of the field " + field.getFieldName() + " is not suitable for aggregate " +
                        "dependencies. Compatible types are array, vector, list, set and collection.");
            }
        }
        if (dependency.getConstructorParameterIndex() != -1) {
            String type = manipulation.getConstructors()[0].getMethodArguments()[dependency
                    .getConstructorParameterIndex()];
            if (type.endsWith("[]")) {
                dependency.setAggregateType(AggregateDependencyInjectionType.ARRAY);
            } else if (Collection.class.getName().equals(type|| List.class.getName().equals(type)) {
                dependency.setAggregateType(AggregateDependencyInjectionType.LIST);
            } else if (Set.class.getName().equals(type)) {
                dependency.setAggregateType(AggregateDependencyInjectionType.SET);
            } else if (Vector.class.getName().equals(type)) {
                dependency.setAggregateType(AggregateDependencyInjectionType.VECTOR);
            } else if (dependency.isAggregate()) {
                // Something wrong. The dependency has a field that is not suitable for aggregate dependencies
                throw new ConfigurationException("The dependency " + DependencyHandler.getDependencyIdentifier
                        (dependency) + " cannot be an aggregate dependency - reason: the type " + type
                        + " of the constructor parameter " + dependency.getConstructorParameterIndex() + " is not suitable for aggregate " +
                        "dependencies. Compatible types are array, vector, list, set and collection.");
            }
        }
View Full Code Here


     */
    private static void ensureThatAtLeastOneInjectionIsSpecified(Dependency dependency) throws ConfigurationException {
        if (dependency.getField() == null
                && (dependency.getCallbacks() == null  || dependency.getCallbacks().length == 0)
                && dependency.getConstructorParameterIndex() == -1) {
            throw new ConfigurationException("The dependency " + DependencyHandler.getDependencyIdentifier
                    (dependency) + " is invalid - reason: no injection specified, at least a field, " +
                    "a method or a constructor parameter index must be set");
        }
    }
View Full Code Here

        if (metadata.getAttribute("from") != null) {
            final String message = "The `from` attribute is not usable in " + DependencyHandler
                    .getDependencyIdentifier(dependency) + " - reason: ";
            // Rule 1
            if (dependency.isAggregate()) {
                throw new ConfigurationException(message + "the dependency is " +
                        "aggregate");
            }
            // Rule 2
            String comparator = metadata.getAttribute("comparator");
            if (comparator != null) {
                throw new ConfigurationException(message + "the dependency uses a comparator");
            }
            // Rule 3
            if (dependency.getBindingPolicy() == DependencyModel.DYNAMIC_PRIORITY_BINDING_POLICY) {
                throw new ConfigurationException(message + "the dependency uses the dynamic-priority " +
                        "binding policy");
            }
        }
    }
View Full Code Here

                .getException() != null) {
            // Rule 1:
            String message = "The `nullable`, `default-implementation` and `exception` attributes are not " +
                    "usable in " + DependencyHandler.getDependencyIdentifier(dependency) + " - reason: ";
            if (dependency.isAggregate()) {
                throw  new ConfigurationException(message + "the dependency is aggregate");
            }
            if (! dependency.isOptional()) {
                throw  new ConfigurationException(message + "the dependency is mandatory");
            }

            // At this point, we know that the dependency is scalar and optional, and at least one attribute is set

            // Rule 2:
            message = "Inconsistent use of the `nullable`, `default-implementation` and `exception` attributes are " +
                    "not usable in " + DependencyHandler.getDependencyIdentifier(dependency) + " - reason: ";
            if (metadata.containsAttribute("nullable"&& dependency.getDefaultImplementation() != null) {
                throw new ConfigurationException(message + "`nullable` and `default-implementation` cannot be " +
                        "combined");
            }
            if (metadata.containsAttribute("nullable") && dependency.getException() != null) {
                throw new ConfigurationException(message + "`nullable` and `exception` cannot be combined");
            }
            if (dependency.getDefaultImplementation() != null  && dependency.getException() != null) {
                throw new ConfigurationException(message + "`exception` and `default-implementation` cannot be " +
                        "combined");
            }
        }

        // Rule 3:
        if (dependency.getTimeout() != && ! dependency.isOptional()) {
            throw new ConfigurationException("The `timeout` attribute is not usable in " + DependencyHandler
                    .getDependencyIdentifier(dependency) + " - reason: the dependency is not optional");
        }


View Full Code Here

                    manipulation);
        }

        if (dependency.getSpecification() == null
                && fieldType == null  && callbackType == null  && constructorType == null) {
            throw new ConfigurationException("The deduction of the service specification for " + DependencyHandler
                    .getDependencyIdentifier(dependency) + " has failed - reason: when neither the field, " +
                    "methods and constructor parameter have provided the service specification, " +
                    "the `specification` attribute must be set");

        }
View Full Code Here

                        && ! Map.class.getName().equals(parameters[0])) {
                        if (type == null) {
                            type = parameters[0];
                        } else {
                            if (! type.equals(parameters[0])) {
                                throw new ConfigurationException("The callbacks of " + DependencyHandler
                                        .getDependencyIdentifier(dependency) + " have inconsistent parameters");
                            }
                        }
                    }
                }
View Full Code Here

     * @throws ConfigurationException if the given specification is not loadable or if the dependency has already a
     * specification set that is not the given one.
     */
    private static void setSpecification(Dependency dep, String className) throws ConfigurationException {
        if (dep.getSpecification() != null  && ! dep.getSpecification().getName().equals(className)) {
            throw new ConfigurationException("Inconsistent service specification for " + DependencyHandler
                    .getDependencyIdentifier(dep) + " - reason: mismatch between the current specification (" + dep
                    .getSpecification().getName() + ") and the discovered specification (" + className + ")");
        } else if (dep.getSpecification() == null) {
            // Set the specification
            try {
                dep.setSpecification(dep.getBundleContext().getBundle().loadClass(className));
            } catch (ClassNotFoundException e) {
                throw new ConfigurationException("Cannot set the service specification of " + DependencyHandler
                        .getDependencyIdentifier(dep) + " - reason: the class " + className + " cannot be loaded from" +
                        " the bundle " + dep.getBundleContext().getBundle().getBundleId(), e);
            }
        }
    }
View Full Code Here

          }
        }

        String spec = service.getAttribute("specification");
        if (spec == null) {
            throw new ConfigurationException("Malformed service : the specification attribute is mandatory");
        }
        String filter = "(&(!(factory.name=" + getCompositeManager().getFactory().getComponentDescription().getName() + "))(factory.state=1))"; // Cannot reinstantiate yourself
        String givenFilter = service.getAttribute("filter");
        if (givenFilter != null) {
            filter = "(&" + filter + givenFilter + ")"; //NOPMD
        }

        Filter fil;
        try {
            fil = getCompositeManager().getGlobalContext().createFilter(filter);
        } catch (InvalidSyntaxException e) {
            throw new ConfigurationException("Malformed filter " + filter + " : " + e.getMessage());
        }

        Properties prop = new Properties();
        Element[] props = service.getElements("property");
        for (int k = 0; props != null && k < props.length; k++) {
            try {
                InstanceHandler.parseProperty(props[k], prop);
            } catch (ParseException e) {
                throw new ConfigurationException("An instance configuration is invalid : " + e.getMessage());
            }
        }

        Properties instanceConfiguration = new Properties();
       instanceConfiguration.putAll(prop);
View Full Code Here

        String specification = imp.getAttribute("specification");

        if (specification == null) {
            // Malformed import
            error("Malformed import: the specification attribute is mandatory");
            throw new ConfigurationException("Malformed import : the specification attribute is mandatory");
        } else {
            String opt = imp.getAttribute("optional");
            optional = opt != null && opt.equalsIgnoreCase("true");

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

            String original = "(&(objectClass=" + specification + ")(!(instance.name=" + getCompositeManager().getInstanceName() + ")))"; // Cannot import yourself
            String filter = original;
            String givenFilter = imp.getAttribute("filter");
            if (givenFilter != null) {
                filter = "(&" + filter + givenFilter + ")"; //NOPMD
            }

            String identitity = imp.getAttribute("id");

            String scope = imp.getAttribute("scope");
            BundleContext context = getCompositeManager().getGlobalContext(); // Get the default bundle context.
            if (scope != null) {
                if (scope.equalsIgnoreCase("global")) {
                    context = new PolicyServiceContext(getCompositeManager().getGlobalContext(), getCompositeManager().getParentServiceContext(), PolicyServiceContext.GLOBAL);
                } else if (scope.equalsIgnoreCase("composite")) {
                    context = new PolicyServiceContext(getCompositeManager().getGlobalContext(), getCompositeManager().getParentServiceContext(), PolicyServiceContext.LOCAL);
                } else if (scope.equalsIgnoreCase("composite+global")) {
                    context = new PolicyServiceContext(getCompositeManager().getGlobalContext(), getCompositeManager().getParentServiceContext(), PolicyServiceContext.LOCAL_AND_GLOBAL);
                }
            }

            // Configure instance filter if available
            if (confFilter != null && identitity != null && confFilter.get(identitity) != null) {
                filter = "(&" + original + (String) confFilter.get(identitity) + ")";
            }

            Filter fil = null;
            if (filter != null) {
                try {
                    fil = getCompositeManager().getGlobalContext().createFilter(filter);
                } catch (InvalidSyntaxException e) {
                    throw new ConfigurationException("A required filter " + filter + " is malformed : " + e.getMessage());
                }
            }

            Comparator cmp = DependencyModel.getComparator(imp, getCompositeManager().getGlobalContext());
            Class spec = DependencyModel.loadSpecification(specification, getCompositeManager().getGlobalContext());
View Full Code Here

        }

        for (int i = 0; i < services.length; i++) {
            String action = services[i].getAttribute("action");
            if (action == null) {
                throw new ConfigurationException("The action attribute must be set to 'instantiate' or 'import'");
            } else if ("instantiate".equalsIgnoreCase(action)) {
                createServiceInstance(services[i], conf);
            } else if ("import".equalsIgnoreCase(action)) {
                createServiceImport(services[i], confFilter);
            } else {
                throw new ConfigurationException("Unknown action : " + action);
            }
        }

        m_description = new ServiceInstantiatorDescription(this, m_instances, m_importers);
    }
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.