Package org.apache.felix.ipojo

Examples of org.apache.felix.ipojo.ConfigurationException


        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 {
                // Non array, complex type.
                try {
                    return context.getBundle().loadClass(type);
                } catch (ClassNotFoundException e) {
                    throw new ConfigurationException("Class not found exception in setValue on " + type + " : " + e.getMessage());
                } catch (SecurityException e) {
                    throw new ConfigurationException("Security execption in setValue on " + type + " : " + e.getMessage());
                } catch (IllegalArgumentException e) {
                    throw new ConfigurationException("Argument issue when calling the constructor of the type " + type);
                }
            }
        }
    }
View Full Code Here

        try {
            Class clazz = context.getBundle().loadClass(internalType);
            Object[] object = (Object[]) Array.newInstance(clazz, 0);
            return object.getClass();
        } catch (ClassNotFoundException e) {
            throw new ConfigurationException("Class not found exception in setValue on " + internalType);
        } catch (SecurityException e) {
            throw new ConfigurationException("Security Exception in setValue on " + internalType);
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException("Argument issue when calling the constructor of the type " + internalType);
        }
    }
View Full Code Here

                    valueOf.setAccessible(true);
                }
                 // Invoke the static method
                return valueOf.invoke(null, new String[] {strValue});
            } catch (InvocationTargetException e) {
                throw new ConfigurationException("Cannot create an enumerated value for " + type
                        + " with " + strValue + " : " + e.getTargetException());
            } catch (Exception e) {
                throw new ConfigurationException("Cannot create an enumerated value for " + type
                        + " with " + strValue + " : " + e.getMessage());
            }
        }

        // Else it is a neither a primitive type neither a String -> create
        // the object by calling a constructor with a string in argument.
        try {
            Constructor cst = type.getConstructor(new Class[] { String.class });
            return cst.newInstance(new Object[] { strValue });
        } catch (SecurityException e) {
            throw new ConfigurationException("Security exception during the creation of " + type + " : " + e.getMessage());
        } catch (NoSuchMethodException e) {
            throw new ConfigurationException("Constructor not found exception during the creation of " + type + " : " + e.getMessage());
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException("Argument issue when calling the constructor of the type " + type);
        } catch (InstantiationException e) {
            throw new ConfigurationException("Instantiation problem  " + type);
        } catch (IllegalAccessException e) {
            throw new ConfigurationException("Illegal Access " + type);
        } catch (InvocationTargetException e) {
            throw new ConfigurationException("Invocation problem during the creation of " + type + " : " + e.getTargetException().getMessage());
        }

    }
View Full Code Here

            for (int i = 0; i < values.length; i++) {
                object[i] = cst.newInstance(new Object[] { values[i].trim() });
            }
            return object;
        } catch (NoSuchMethodException e) {
            throw new ConfigurationException("Constructor not found exception in setValue on " + interntype.getName());
        } catch (IllegalArgumentException e) {
            throw new ConfigurationException("Argument issue when calling the constructor of the type " + interntype.getName());
        } catch (InstantiationException e) {
            throw new ConfigurationException("Instantiation problem  " + interntype.getName());
        } catch (IllegalAccessException e) {
            throw new ConfigurationException("Illegal Access Exception in  " + interntype.getName());
        } catch (InvocationTargetException e) {
            throw new ConfigurationException("Invocation problem " + interntype.getName() + " : " + e.getTargetException().getMessage());
        }
    }
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 fieldName = configurables[i].getAttribute("field");
            String methodName = configurables[i].getAttribute("method");
            String paramIndex = configurables[i].getAttribute("constructor-parameter");

            if (fieldName == null && methodName == null  && paramIndex == null) {
                throw new ConfigurationException("Malformed property : The property needs to contain" +
                        " at least a field, a method or a constructor-parameter");
            }

            String name = configurables[i].getAttribute("name");
            if (name == null) {
                if (fieldName == null  && methodName != null) {
                    name = methodName;
                } else if (fieldName == null  && paramIndex != null) {
                    name = paramIndex;
                } else {
                    name = fieldName;
                }
                configurables[i].addAttribute(new Attribute("name", name)); // Add the type to avoid configure checking
            }

            String value = configurables[i].getAttribute("value");

            // Detect the type of the property
            PojoMetadata manipulation = getFactory().getPojoMetadata();
            String type = null;
            if (methodName != null) {
                MethodMetadata[] method = manipulation.getMethods(methodName);
                if (method.length == 0) {
                    type = configurables[i].getAttribute("type");
                    if (type == null) {
                        throw new ConfigurationException("Malformed property : The type of the property cannot be discovered, add a 'type' attribute");
                    }
                } else {
                    if (method[0].getMethodArguments().length != 1) {
                        throw new ConfigurationException("Malformed property :  The method " + methodName + " does not have one argument");
                    }
                    type = method[0].getMethodArguments()[0];
                    configurables[i].addAttribute(new Attribute("type", type)); // Add the type to avoid configure checking
                }
            } else if (fieldName != null) {
                FieldMetadata field = manipulation.getField(fieldName);
                if (field == null) { throw new ConfigurationException("Malformed property : The field " + fieldName + " does not exist in the implementation class"); }
                type = field.getFieldType();
                configurables[i].addAttribute(new Attribute("type", type)); // Add the type to avoid configure checking
            } else if (paramIndex != null) {
                int index = Integer.parseInt(paramIndex);
                type = configurables[i].getAttribute("type");
                MethodMetadata[] cts = manipulation.getConstructors();
                // If we don't have a type, try to get the first constructor and get the type of the parameter
                // we the index 'index'.
                if (type == null && cts.length > && cts[0].getMethodArguments().length > index) {
                    type = cts[0].getMethodArguments()[index];
                } else if (type == null) { // Applied only if type was not determined.
                    throw new ConfigurationException("Cannot determine the type of the property " + index +
                            ", please use the type attribute");
                }
                configurables[i].addAttribute(new Attribute("type", type));
            }
View Full Code Here

        // updated method
        String upd = confs[0].getAttribute("updated");
        if (upd != null) {
            MethodMetadata method = getPojoMetadata().getMethod(upd);
            if (method == null) {
                throw new ConfigurationException("The updated method is not found in the class "
                        + getInstanceManager().getClassName());
            } else if (method.getMethodArguments().length == 0) {
                m_updated = new Callback(upd, new Class[0], false, getInstanceManager());
            } else if (method.getMethodArguments().length == 1
                    && method.getMethodArguments()[0].equals(Dictionary.class.getName())) {
                m_updated = new Callback(upd, new Class[] {Dictionary.class}, false, getInstanceManager());
            } else {
                throw new ConfigurationException("The updated method is found in the class "
                        + getInstanceManager().getClassName() + " must have either no argument or a Dictionary");
            }
        }

        for (int i = 0; configurables != null && i < configurables.length; i++) {
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.getMessage());

                    }

                }
            }


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

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

            post = providedServices[i].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 = providedServices[i].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 = providedServices[i].getElements("Controller");
            if (controllers != null) {
                for (int k = 0; k < controllers.length; k++) {
                    String field = controllers[k].getAttribute("field");
                    if (field == null) {
                        throw new ConfigurationException("The field attribute of a controller is mandatory");
                    }

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

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

            if (checkProvidedService(svc)) {
                addProvidedService(svc);
            } else {
                StringBuffer itfs = new StringBuffer();
                for (int j = 0; j < serviceSpecifications.length; j++) {
                    itfs.append(' ');
                    itfs.append(serviceSpecifications[j]);
                }
                throw new ConfigurationException("The provided service" + itfs + " is not valid");
            }

            // Initialize the description.
            m_description = new ProvidedServiceHandlerDescription(this, m_providedServices);
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 load");
            } catch (IllegalArgumentException e) {
                throw new ConfigurationException("Service Providing: The field 'specification' of the service specification " + svc.getServiceSpecifications()[i] + " is not accessible : " + e.getMessage());
            } catch (IllegalAccessException e) {
                throw new ConfigurationException("Service Providing: The field 'specification' of the service specification " + svc.getServiceSpecifications()[i] + " is not accessible : " + e.getMessage());
            } 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.getMessage());
            }
        }

        return true;
    }
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.