Package org.apache.xbean.recipe

Examples of org.apache.xbean.recipe.ObjectRecipe$Property


                    throw e;
                }
                clientSubject = loginContext.getSubject();
            }
            ContextManager.setCallers(clientSubject, clientSubject);
            ObjectRecipe objectRecipe = new ObjectRecipe(mainClassName);
            objectRecipe.allow(Option.FIELD_INJECTION);
            objectRecipe.allow(Option.PRIVATE_PROPERTIES);
            objectRecipe.allow(Option.STATIC_PROPERTIES);
            Class mainClass = classLoader.loadClass(mainClassName);
            List<Injection> injections = new ArrayList<Injection>();
            while (mainClass != null && mainClass != Object.class) {
                List<Injection> perClass = holder.getInjections(mainClass.getName());
                if (perClass != null) {
                    injections.addAll(perClass);
                }
                mainClass = mainClass.getSuperclass();
            }
            if (injections != null) {
                List<NamingException> problems = new ArrayList<NamingException>();
                for (Injection injection : injections) {
                    try {
                        String jndiName = injection.getJndiName();
                        //our componentContext is attached to jndi at "java:comp" so we remove that when looking stuff up in it
                        Object object = componentContext.lookup("env/" + jndiName);
                        if (object instanceof String) {
                            String string = (String) object;
                            // Pass it in raw so it could be potentially converted to
                            // another data type by an xbean-reflect property editor
                            objectRecipe.setProperty(injection.getTargetName(), string);
                        } else {
                            objectRecipe.setProperty(injection.getTargetName(), new StaticRecipe(object));
                        }
                    } catch (NamingException e) {
                        problems.add(e);
                    }
                }
                if (!problems.isEmpty()) {
                    throw new Exception("Some objects to be injected were not found in jndi: " + problems);
                }
            }
            Class clazz = objectRecipe.setStaticProperties(classLoader);
            if (holder.getPostConstruct() != null) {
                Holder.apply(null, clazz, holder.getPostConstruct());
            }

            if (clientSubject == null) {
View Full Code Here


                loginContext = ContextManager.login(realmName, callbackHandler);
                clientSubject = loginContext.getSubject();
            }
            ContextManager.setCallers(clientSubject, clientSubject);
            Class mainClass = classLoader.loadClass(mainClassName);
            ObjectRecipe objectRecipe = new ObjectRecipe(mainClass);
            objectRecipe.allow(Option.FIELD_INJECTION);
            objectRecipe.allow(Option.PRIVATE_PROPERTIES);
            objectRecipe.allow(Option.STATIC_PROPERTIES);
            List<Injection> injections = new ArrayList<Injection>();
            while (mainClass != null && mainClass != Object.class) {
                List<Injection> perClass = holder.getInjections(mainClass.getName());
                if (perClass != null) {
                    injections.addAll(perClass);
                }
                mainClass = mainClass.getSuperclass();
            }
            if (injections != null) {
                List<NamingException> problems = new ArrayList<NamingException>();
                for (Injection injection : injections) {
                    try {
                        String jndiName = injection.getJndiName();
                        //our componentContext is attached to jndi at "java:comp" so we remove that when looking stuff up in it
                        Object object = componentContext.lookup("env/" + jndiName);
                        if (object instanceof String) {
                            String string = (String) object;
                            // Pass it in raw so it could be potentially converted to
                            // another data type by an xbean-reflect property editor
                            objectRecipe.setProperty(injection.getTargetName(), string);
                        } else {
                            objectRecipe.setProperty(injection.getTargetName(), new StaticRecipe(object));
                        }
                    } catch (NamingException e) {
                        problems.add(e);
                    }
                }
                if (!problems.isEmpty()) {
                    throw new Exception("Some objects to be injected were not found in jndi: " + problems);
                }
            }
            Class clazz = objectRecipe.setStaticProperties();
            if (holder.getPostConstruct() != null) {
                Holder.apply(null, clazz, holder.getPostConstruct());
            }

            if (clientSubject == null) {
View Full Code Here

                Integer index = attributeIndex.get(argumentName);
                GBeanAttribute attribute = attributes[index];
                cstrTypes[i] = attribute.getType();
            }
        }
        ObjectRecipe objectRecipe = new ObjectRecipe(type, cstrNames.toArray(new String[0]), cstrTypes);
        objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);

        // set the initial attribute values
        Map<String, Object> dataAttributes = gbeanData.getAttributes();
        for (GAttributeInfo attributeInfo : beanInfo.getAttributes()) {
            Integer integer = attributeIndex.get(attributeInfo.getName());
            GBeanAttribute attribute = attributes[integer];
            String attributeName = attribute.getName();
            if (attribute.isPersistent() || attribute.isDynamic()) {
                Object attributeValue = dataAttributes.get(attributeName);
                if (null != attributeValue) {
                    attribute.setPersistentValue(attributeValue);
                }
                if (attribute.isPersistent() && null != attributeValue && !attribute.isDynamic()) {
                    objectRecipe.setProperty(attributeName, attribute.getPersistentValue());
                }
            } else if (attribute.isSpecial() && (attribute.isWritable() || cstrNames.contains(attributeName))) {
                objectRecipe.setProperty(attributeName, attribute.getPersistentValue());
            }
        }
       
        return objectRecipe;
    }
View Full Code Here

                loginContext = ContextManager.login(realmName, callbackHandler);
                clientSubject = loginContext.getSubject();
            }
            ContextManager.setCallers(clientSubject, clientSubject);
            Class mainClass = classLoader.loadClass(mainClassName);
            ObjectRecipe objectRecipe = new ObjectRecipe(mainClass);
            objectRecipe.allow(Option.FIELD_INJECTION);
            objectRecipe.allow(Option.PRIVATE_PROPERTIES);
            objectRecipe.allow(Option.STATIC_PROPERTIES);
            List<Injection> injections = new ArrayList<Injection>();
            while (mainClass != null && mainClass != Object.class) {
                List<Injection> perClass = holder.getInjections(mainClass.getName());
                if (perClass != null) {
                    injections.addAll(perClass);
                }
                mainClass = mainClass.getSuperclass();
            }
            if (injections != null) {
                List<NamingException> problems = new ArrayList<NamingException>();
                for (Injection injection : injections) {
                    String jndiName = injection.getJndiName();
                    try {
                        Object object = componentContext.lookup(jndiName);
                        objectRecipe.setProperty(injection.getTargetName(), object);
                    } catch (NamingException e) {
                        log.info("Injection problem for jndiName: " + jndiName, e);
                        problems.add(e);
                    }
                }
                if (!problems.isEmpty()) {
                    //TODO fix the problems with trying to lookup resource refs from the client.
//                    throw new Exception("Some objects to be injected were not found in jndi: " + problems);
                    log.error("Some objects to be injected were not found in jndi: " + problems);
                }
            }
            Class clazz = objectRecipe.setStaticProperties();
            if (holder.getPostConstruct() != null) {
                Holder.apply(null, clazz, holder.getPostConstruct());
            }

            if (clientSubject == null) {
View Full Code Here

                Integer index = attributeIndex.get(argumentName);
                GBeanAttribute attribute = attributes[index];
                cstrTypes[i] = attribute.getType();
            }
        }
        ObjectRecipe objectRecipe = new ObjectRecipe(type, cstrNames.toArray(new String[0]), cstrTypes);
        objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);

        // set the initial attribute values
        Map<String, Object> dataAttributes = gbeanData.getAttributes();
        for (GAttributeInfo attributeInfo : beanInfo.getAttributes()) {
            Integer integer = attributeIndex.get(attributeInfo.getName());
            GBeanAttribute attribute = attributes[integer];
            String attributeName = attribute.getName();
            if (attribute.isPersistent() || attribute.isDynamic()) {
                Object attributeValue = dataAttributes.get(attributeName);
                if (null != attributeValue) {
                    attribute.setPersistentValue(attributeValue);
                }
                if (attribute.isPersistent() && null != attributeValue && !attribute.isDynamic()) {
                    objectRecipe.setProperty(attributeName, attribute.getPersistentValue());
                }
            } else if (attribute.isSpecial() && (attribute.isWritable() || cstrNames.contains(attributeName))) {
                objectRecipe.setProperty(attributeName, attribute.getPersistentValue());
            }
        }

        return objectRecipe;
    }
View Full Code Here

                && (postConstruct == null || postConstruct.isEmpty())
                && (preDestroy == null || preDestroy.isEmpty());
    }

    public Object newInstance(String className, ClassLoader classLoader, Context context) throws IllegalAccessException, InstantiationException {
        ObjectRecipe objectRecipe = new ObjectRecipe(className);
        objectRecipe.allow(Option.FIELD_INJECTION);
        objectRecipe.allow(Option.PRIVATE_PROPERTIES);
        Class<?> clazz;
        try {
            clazz = classLoader.loadClass(className);
        } catch (ClassNotFoundException e) {
            throw (InstantiationException)new InstantiationException("Can't load class " + className + " in classloader: " + classLoader).initCause(e);
        }
        List<NamingException> problems = new ArrayList<NamingException>();
        while (clazz != Object.class) {
            addInjections(clazz.getName(), context, objectRecipe, problems);
            clazz = clazz.getSuperclass();
        }
        if (!problems.isEmpty()) {
            throw new InstantiationException("Some objects to be injected were not found in jndi: " + problems);
        }
        Object result;
        try {
            result = objectRecipe.create(classLoader);
        } catch (ConstructionException e) {
            throw (InstantiationException)new InstantiationException("Could not construct object").initCause(e);
        }
        // TODO we likely don't want to create a new one each time -- investigate the destroy() method
        OWBInjector beanInjector = new OWBInjector();
View Full Code Here

        for (Map.Entry<QName, String> entry: otherAttributes.entrySet()) {
            String name = entry.getKey().getLocalPart();
            properties.put(name, entry.getValue());
        }
        ObjectRecipe recipe = new ObjectRecipe(className, properties);
        recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
        Engine engine = (Engine) recipe.create(cl);
//        Class<? extends Engine> engineClass = cl.loadClass(className).asSubclass(Engine.class);
//        Engine engine = engineClass.newInstance();
//        engine.setName(name);
//        engine.setDefaultHost(defaultHost);
//        engine.setJvmRoute(jvmRoute);
View Full Code Here

        Map<String, Object> properties = new HashMap<String, Object>();
        for (Map.Entry<QName, String> entry: otherAttributes.entrySet()) {
            String name = entry.getKey().getLocalPart();
            properties.put(name, entry.getValue());
        }
        ObjectRecipe recipe = new ObjectRecipe(className, properties);
        recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
        Server instance = (Server) recipe.create(cl);
        instance.setPort(port);
        instance.setShutdown(shutdown);

        for (ListenerType listenerType : getListener()) {
            LifecycleListener listener = listenerType.getLifecycleListener(cl);
View Full Code Here

        properties.put("name", getName());
        for (Map.Entry<QName, String> entry: otherAttributes.entrySet()) {
            String name = entry.getKey().getLocalPart();
            properties.put(name, entry.getValue());
        }
        ObjectRecipe recipe = new ObjectRecipe(className, properties);
        recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
        Service service = (Service) recipe.create(cl);
        for (ExecutorType executorType: getExecutor()) {
            Executor executor = executorType.getExecutor(cl, kernel);
            service.addExecutor(executor);
            TomcatServerGBean.executors.put(executor.getName(), executor);
        }
View Full Code Here

        // other properties
        if (dataSourceDescription.getProperties() != null) {
            properties.putAll(dataSourceDescription.getProperties());
        }
                                                   
        ObjectRecipe recipe = new ObjectRecipe(clazz, properties);
        recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
           
        Object instance = recipe.create();
           
        Map<String, Object> unset = recipe.getUnsetProperties();
        if (unset != null && !unset.isEmpty()) {
            log.warn("Some DataSource properties were not set {}", unset);
        }
           
        return instance;
View Full Code Here

TOP

Related Classes of org.apache.xbean.recipe.ObjectRecipe$Property

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.