Search in sources :

Example 6 with ObjectRecipe

use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.

the class PassthroughFactory method recipe.

public static ObjectRecipe recipe(final Object instance) {
    final ObjectRecipe recipe = new ObjectRecipe(PassthroughFactory.Create.class);
    recipe.setFactoryMethod("create");
    final String param = "instance" + recipe.hashCode();
    recipe.setConstructorArgNames(new String[] { param });
    recipe.setProperty(param, instance);
    return recipe;
}
Also used : ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe)

Example 7 with ObjectRecipe

use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.

the class ListConfigurator method getList.

public static <T> List<T> getList(final Properties properties, final String key, final ClassLoader classloader, final Class<T> filter) {
    if (properties == null) {
        return null;
    }
    final String features = properties.getProperty(key);
    if (features == null) {
        return null;
    }
    final List<T> list = new ArrayList<T>();
    final String[] split = features.trim().split(",");
    for (final String feature : split) {
        if (feature == null || feature.trim().isEmpty()) {
            continue;
        }
        final String prefix = key + "." + feature + ".";
        final ObjectRecipe recipe = new ObjectRecipe(feature);
        for (final Map.Entry<Object, Object> entry : properties.entrySet()) {
            final String current = entry.getKey().toString();
            if (current.startsWith(prefix)) {
                final String property = current.substring(prefix.length());
                recipe.setProperty(property, entry.getValue());
            }
        }
        final Object instance = recipe.create(classloader);
        if (!filter.isInstance(instance)) {
            throw new OpenEJBRuntimeException(feature + " is not an abstract feature");
        }
        list.add(filter.cast(instance));
    }
    if (list.isEmpty()) {
        return null;
    }
    return list;
}
Also used : OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) ArrayList(java.util.ArrayList) Map(java.util.Map)

Example 8 with ObjectRecipe

use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.

the class Assembler method createRecipe.

private ObjectRecipe createRecipe(final Collection<ServiceInfo> services, final ServiceInfo info) {
    final Logger serviceLogger = logger.getChildLogger("service");
    if (info instanceof ResourceInfo) {
        final List<String> aliasesList = ((ResourceInfo) info).aliases;
        if (!aliasesList.isEmpty()) {
            final String aliases = Join.join(", ", aliasesList);
            serviceLogger.info("createServiceWithAliases", info.service, info.id, aliases);
        } else {
            serviceLogger.info("createService", info.service, info.id);
        }
    } else {
        serviceLogger.info("createService", info.service, info.id);
    }
    final ObjectRecipe serviceRecipe = prepareRecipe(info);
    // we don't want this one to go in recipe
    final Object value = info.properties.remove("SkipImplicitAttributes");
    final Properties allProperties = PropertyPlaceHolderHelper.simpleHolds(info.properties);
    allProperties.remove("SkipPropertiesFallback");
    if (services == null) {
        // small optim for internal resources
        serviceRecipe.setAllProperties(allProperties);
    } else {
        info.properties = allProperties;
        ServiceInfos.setProperties(services, info, serviceRecipe);
    }
    if (value != null) {
        info.properties.put("SkipImplicitAttributes", value);
    }
    if (serviceLogger.isDebugEnabled()) {
        for (final Map.Entry<String, Object> entry : serviceRecipe.getProperties().entrySet()) {
            serviceLogger.debug("createService.props", entry.getKey(), entry.getValue());
        }
    }
    return serviceRecipe;
}
Also used : ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe) Logger(org.apache.openejb.util.Logger) SuperProperties(org.apache.openejb.util.SuperProperties) Properties(java.util.Properties) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap)

Example 9 with ObjectRecipe

use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.

the class Assembler method createConnectionManager.

public void createConnectionManager(final ConnectionManagerInfo serviceInfo) throws OpenEJBException {
    final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);
    final Object object = props.get("TransactionManager");
    serviceRecipe.setProperty("transactionManager", object);
    final Object service = serviceRecipe.create();
    logUnusedProperties(serviceRecipe, serviceInfo);
    final Class interfce = serviceInterfaces.get(serviceInfo.service);
    checkImplementation(interfce, service.getClass(), serviceInfo.service, serviceInfo.id);
    bindService(serviceInfo, service);
    setSystemInstanceComponent(interfce, service);
    getContext().put(interfce.getName(), service);
    props.put(interfce.getName(), service);
    props.put(serviceInfo.service, service);
    props.put(serviceInfo.id, service);
    // Update the config tree
    config.facilities.connectionManagers.add(serviceInfo);
    logger.getChildLogger("service").debug("createService.success", serviceInfo.service, serviceInfo.id, serviceInfo.className);
}
Also used : ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe)

Example 10 with ObjectRecipe

use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.

the class Assembler method prepareRecipe.

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;
}
Also used : ObjectRecipe(org.apache.xbean.recipe.ObjectRecipe)

Aggregations

ObjectRecipe (org.apache.xbean.recipe.ObjectRecipe)35 Map (java.util.Map)14 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 Properties (java.util.Properties)8 NamingException (javax.naming.NamingException)7 OpenEJBException (org.apache.openejb.OpenEJBException)7 InvocationTargetException (java.lang.reflect.InvocationTargetException)5 SuperProperties (org.apache.openejb.util.SuperProperties)4 MalformedURLException (java.net.MalformedURLException)3 URISyntaxException (java.net.URISyntaxException)3 TreeMap (java.util.TreeMap)3 TimeoutException (java.util.concurrent.TimeoutException)3 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)3 InvalidObjectException (java.io.InvalidObjectException)2 ObjectStreamException (java.io.ObjectStreamException)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 DefinitionException (javax.enterprise.inject.spi.DefinitionException)2 DeploymentException (javax.enterprise.inject.spi.DeploymentException)2