Java Code Examples for org.apache.xbean.recipe.ObjectRecipe#allow()

The following examples show how to use org.apache.xbean.recipe.ObjectRecipe#allow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ServiceInfos.java    From tomee with Apache License 2.0 6 votes vote down vote up
public static Object build(final Collection<ServiceInfo> services, final ServiceInfo info, final ObjectRecipe serviceRecipe) {
    if ("org.apache.openejb.config.sys.MapFactory".equals(info.className)) {
        return info.properties;
    }

    if (!info.properties.containsKey("properties")) {
        info.properties.put("properties", new UnsetPropertiesRecipe());
    }

    // we can't ask for having a setter for existing code
    serviceRecipe.allow(Option.FIELD_INJECTION);
    serviceRecipe.allow(Option.PRIVATE_PROPERTIES);

    setProperties(services, info, serviceRecipe);

    final Object service = serviceRecipe.create();

    SystemInstance.get().addObserver(service); // TODO: remove it? in all case the observer should remove itself when done
    Assembler.logUnusedProperties(serviceRecipe, info);

    return service;
}
 
Example 2
Source File: CdiResourceInjectionService.java    From tomee with Apache License 2.0 6 votes vote down vote up
@Override
public void injectJavaEEResources(final Object managedBeanInstance) {
    if (managedBeanInstance == null) {
        return;
    }

    final Class<?> managedBeanInstanceClass = managedBeanInstance.getClass();
    if (ejbPlugin.isSessionBean(managedBeanInstanceClass)) { // already done
        return;
    }

    final ObjectRecipe receipe = PassthroughFactory.recipe(managedBeanInstance);
    receipe.allow(Option.FIELD_INJECTION);
    receipe.allow(Option.PRIVATE_PROPERTIES);
    receipe.allow(Option.IGNORE_MISSING_PROPERTIES);
    receipe.allow(Option.NAMED_PARAMETERS);

    fillInjectionProperties(receipe, managedBeanInstance);

    receipe.create();
}
 
Example 3
Source File: ReflectionService.java    From component-runtime with Apache License 2.0 5 votes vote down vote up
private ObjectRecipe newRecipe(final Class clazz) {
    final ObjectRecipe recipe = new ObjectRecipe(clazz);
    recipe.setRegistry(propertyEditorRegistry);
    recipe.allow(org.apache.xbean.recipe.Option.FIELD_INJECTION);
    recipe.allow(org.apache.xbean.recipe.Option.PRIVATE_PROPERTIES);
    recipe.allow(org.apache.xbean.recipe.Option.CASE_INSENSITIVE_PROPERTIES);
    recipe.allow(org.apache.xbean.recipe.Option.IGNORE_MISSING_PROPERTIES);
    return recipe;
}
 
Example 4
Source File: FlushableDataSourceHandler.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void createANewDelegate() {
    final CommonDataSource old = delegate.get();
    try {
        final ObjectRecipe recipe = new ObjectRecipe(DataSourceFactory.class.getName(), "create", FACTORY_ARGS);
        recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
        recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
        recipe.allow(Option.NAMED_PARAMETERS);
        recipe.allow(Option.PRIVATE_PROPERTIES);
        recipe.setAllProperties(config.properties);

        recipe.setProperty("resettableHandler", resettableHandler);
        recipe.setProperty("flushableHandler", this);

        updateDataSource(CommonDataSource.class.cast(recipe.create()));
    } catch (final Exception e) {
        LOGGER.error("Can't recreate the datasource, keeping old one", e);
        return;
    }

    if (DataSourceFactory.knows(old)) {
        try {
            DataSourceFactory.destroy(old);
        } catch (final Throwable t) {
            //Ignore
        }
    }
}
 
Example 5
Source File: Assembler.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static ObjectRecipe prepareRecipe(final ServiceInfo info) {
    final String[] constructorArgs = info.constructorArgs.toArray(new String[info.constructorArgs.size()]);
    final ObjectRecipe serviceRecipe = new ObjectRecipe(info.className, info.factoryMethod, constructorArgs, null);
    serviceRecipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
    serviceRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
    serviceRecipe.allow(Option.PRIVATE_PROPERTIES);
    return serviceRecipe;
}
 
Example 6
Source File: ConfigurationFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
private ObjectRecipe newObjectRecipe(final String template) {
    final ObjectRecipe recipe = new ObjectRecipe(template);
    recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
    recipe.allow(Option.PRIVATE_PROPERTIES);
    recipe.allow(Option.FIELD_INJECTION);
    recipe.allow(Option.NAMED_PARAMETERS);
    recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
    return recipe;
}
 
Example 7
Source File: ObjectRecipeHelper.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static Object createMeFromSystemProps(final String prefix, final String suffix, final Class<?> clazz) {
    final Properties props = SystemInstance.get().getProperties();
    final Map<String, Object> usedOnes = new HashMap<>();

    for (final Map.Entry<Object, Object> entry : props.entrySet()) {
        final String key = entry.getKey().toString();
        if (prefix != null && !key.startsWith(prefix)) {
            continue;
        }
        if (suffix != null && !key.endsWith(suffix)) {
            continue;
        }

        String newKey = key;
        if (prefix != null) {
            newKey = newKey.substring(prefix.length());
        }
        if (suffix != null) {
            newKey = newKey.substring(0, newKey.length() - suffix.length());
        }
        usedOnes.put(newKey, entry.getValue());
    }

    final ObjectRecipe recipe = new ObjectRecipe(clazz);
    recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
    recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
    recipe.allow(Option.PRIVATE_PROPERTIES);
    recipe.allow(Option.FIELD_INJECTION);
    recipe.allow(Option.NAMED_PARAMETERS);
    recipe.setAllProperties(usedOnes);
    return recipe.create();
}
 
Example 8
Source File: StatefulContainerFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
private void buildCache() throws Exception {
    if (properties == null) {
        throw new IllegalArgumentException("No cache defined for StatefulContainer " + id);
    }

    // get the cache property
    Object cache = getProperty("Cache");
    if (cache == null) {
        throw new IllegalArgumentException("No cache defined for StatefulContainer " + id);
    }

    // if property contains a live cache instance, just use it
    if (cache instanceof Cache) {
        this.cache = (Cache<Object, Instance>) cache;
        return;
    }

    // build the object recipe
    final ObjectRecipe serviceRecipe = new ObjectRecipe((String) cache);
    serviceRecipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
    serviceRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
    serviceRecipe.allow(Option.NAMED_PARAMETERS);
    serviceRecipe.setAllProperties(properties);

    // invoke recipe
    /* the cache should be created with container loader to avoid memory leaks
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    if (classLoader == null) getClass().getClassLoader();
    */
    ClassLoader classLoader = StatefulContainerFactory.class.getClassLoader();
    if (!((String) cache).startsWith("org.apache.tomee")) { // user impl?
        classLoader = Thread.currentThread().getContextClassLoader();
    }
    cache = serviceRecipe.create(classLoader);

    // assign value
    this.cache = (Cache<Object, Instance>) cache;
}
 
Example 9
Source File: Meecrowave.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
private static ObjectRecipe newRecipe(final String clazz) {
    final ObjectRecipe recipe = new ObjectRecipe(clazz);
    recipe.allow(Option.FIELD_INJECTION);
    recipe.allow(Option.PRIVATE_PROPERTIES);
    return recipe;
}
 
Example 10
Source File: Configuration.java    From openwebbeans-meecrowave with Apache License 2.0 4 votes vote down vote up
private static ObjectRecipe newRecipe(final String clazz) {
    final ObjectRecipe recipe = new ObjectRecipe(clazz);
    recipe.allow(Option.FIELD_INJECTION);
    recipe.allow(Option.PRIVATE_PROPERTIES);
    return recipe;
}
 
Example 11
Source File: Client.java    From tomee with Apache License 2.0 4 votes vote down vote up
public static void main(final String[] args) throws Exception {
    if (args.length != 1) {
        System.err.println("Pass the base url as parameter");
        return;
    }

    final ConsoleReader reader = new ConsoleReader(System.in, new OutputStreamWriter(System.out));
    reader.addCompletor(new FileNameCompletor());
    reader.addCompletor(new SimpleCompletor(CommandManager.keys().toArray(new String[CommandManager.size()])));

    String line;
    while ((line = reader.readLine(PROMPT)) != null) {
        if (EXIT_CMD.equals(line)) {
            break;
        }

        Class<?> cmdClass = null;
        for (Map.Entry<String, Class<?>> cmd : CommandManager.getCommands().entrySet()) {
            if (line.startsWith(cmd.getKey())) {
                cmdClass = cmd.getValue();
                break;
            }
        }

        if (cmdClass != null) {
            final ObjectRecipe recipe = new ObjectRecipe(cmdClass);
            recipe.setProperty("url", args[0]);
            recipe.setProperty("command", line);
            recipe.setProperty("commands", CommandManager.getCommands());

            recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
            recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
            recipe.allow(Option.NAMED_PARAMETERS);

            try {
                final AbstractCommand cmdInstance = (AbstractCommand) recipe.create();
                cmdInstance.execute(line);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            System.err.println("sorry i don't understand '" + line + "'");
        }
    }
}
 
Example 12
Source File: PoolDataSourceCreator.java    From tomee with Apache License 2.0 4 votes vote down vote up
private void recipeOptions(final ObjectRecipe recipe) { // important to not set "properties" attribute because pools often use it for sthg else
    recipe.allow(Option.CASE_INSENSITIVE_PROPERTIES);
    recipe.allow(Option.IGNORE_MISSING_PROPERTIES);
}