org.apache.xbean.recipe.ObjectRecipe Java Examples

The following examples show how to use org.apache.xbean.recipe.ObjectRecipe. 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: Meecrowave.java    From openwebbeans-meecrowave with Apache License 2.0 6 votes vote down vote up
/**
 * Syntax uses:
 * <code>
 *     valves.myValve1._className = org.apache.meecrowave.tomcat.LoggingAccessLogPattern
 *     valves.myValve1._order = 0
 *
 *     valves.myValve1._className = SSOVa
 *     valves.myValve1._order = 1
 *     valves.myValve1.showReportInfo = false
 * </code>
 *
 * @return the list of valve from the properties.
 */
private List<Valve> buildValves() {
    final List<Valve> valves = new ArrayList<>();
    configuration.getProperties().stringPropertyNames().stream()
                            .filter(key -> key.startsWith("valves.") && key.endsWith("._className"))
                            .sorted(comparing(key -> Integer.parseInt(configuration.getProperties()
                                    .getProperty(key.replaceFirst("\\._className$", "._order"), "0"))))
                            .map(key -> key.split("\\."))
                            .filter(parts -> parts.length == 3)
                            .forEach(key -> {
        final String prefix = key[0] + '.' + key[1] + '.';
        final ObjectRecipe recipe = newRecipe(configuration.getProperties().getProperty(prefix + key[2]));
        configuration.getProperties().stringPropertyNames().stream()
                .filter(it -> it.startsWith(prefix) && !it.endsWith("._order") && !it.endsWith("._className"))
                .forEach(propKey -> {
                    final String value = configuration.getProperties().getProperty(propKey);
                    recipe.setProperty(propKey.substring(prefix.length()), value);
                });
        valves.add(Valve.class.cast(recipe.create(Thread.currentThread().getContextClassLoader())));
    });
    return valves;
}
 
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: WSS4JInterceptorFactoryBase.java    From tomee with Apache License 2.0 6 votes vote down vote up
protected Map<String, Object> getAndDestroyMap() {
    final Map<String, Object> map = new HashMap<String, Object>();
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
        map.put(entry.getKey().toString(), entry.getValue());
    }

    // avoid warnings
    final Recipe recipe = ExecutionContext.getContext().getStack().getLast();
    if (ObjectRecipe.class.isInstance(recipe)) {
        final ObjectRecipe or = ObjectRecipe.class.cast(recipe);
        if (or.getUnsetProperties() != null) {
            or.getUnsetProperties().clear();
        }
    }

    return map;
}
 
Example #4
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 #5
Source File: ClassLoaderUtil.java    From tomee with Apache License 2.0 6 votes vote down vote up
private static ClassLoaderConfigurer createConfigurer(final String key, final String impl) {
    try {
        final ObjectRecipe recipe = new ObjectRecipe(impl);
        for (final Map.Entry<Object, Object> entry : SystemInstance.get().getProperties().entrySet()) {
            final String entryKey = entry.getKey().toString();
            if (entryKey.startsWith(key)) {
                final String newKey = entryKey.substring(key.length());
                if (!"clazz".equals(newKey)) {
                    recipe.setProperty(newKey, entry.getValue());
                }
            }
        }

        final Object instance = recipe.create();
        if (instance instanceof ClassLoaderConfigurer) {
            return (ClassLoaderConfigurer) instance;
        } else {
            logger.error(impl + " is not a classlaoder configurer, using default behavior");
        }
    } catch (final Exception e) {
        logger.error("Can't create classloader configurer " + impl + ", using default behavior");
    }
    return null;
}
 
Example #6
Source File: ActiveMQ5Factory.java    From tomee with Apache License 2.0 5 votes vote down vote up
private BrokerPlugin[] createPlugins(final Map<String, String> params) {
    final String plugins = params.remove("amq.plugins");
    if (plugins == null) {
        return null;
    }

    final Collection<BrokerPlugin> instances = new LinkedList<>();
    for (final String p : plugins.split(" *, *")) {
        if (p.isEmpty()) {
            continue;
        }

        final String prefix = p + ".";
        final ObjectRecipe recipe = new ObjectRecipe(params.remove(prefix + "class"));
        final Iterator<Map.Entry<String, String>> iterator = params.entrySet().iterator();
        while (iterator.hasNext()) {
            final Map.Entry<String, String> entry = iterator.next();
            final String key = entry.getKey();
            if (key.startsWith(prefix)) {
                recipe.setProperty(key.substring(prefix.length()), entry.getValue());
                iterator.remove();
            }
        }
        instances.add(BrokerPlugin.class.cast(recipe.create()));
    }
    return instances.toArray(new BrokerPlugin[instances.size()]);
}
 
Example #7
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 #8
Source File: ListConfigurator.java    From tomee with Apache License 2.0 5 votes vote down vote up
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<>();
    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;
}
 
Example #9
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 #10
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 #11
Source File: ServiceInfos.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static void setProperties(final Collection<ServiceInfo> services, final ServiceInfo info, final ObjectRecipe serviceRecipe) {
    for (final Map.Entry<Object, Object> entry : info.properties.entrySet()) { // manage links
        final String key = entry.getKey().toString();
        final Object value = entry.getValue();
        if (value instanceof String) {
            String valueStr = value.toString();
            if (valueStr.startsWith("collection:")) { // for now only supports Service cause that's where it is useful but feel free to enrich it
                valueStr = valueStr.substring("collection:".length());
                final String[] elt = valueStr.split(" *, *");
                final List<Object> val = new ArrayList<>(elt.length);
                for (final String e : elt) {
                    if (!e.trim().isEmpty()) {
                        val.add(e.startsWith("@") ? lookup(e) : resolve(services, e.startsWith("$") ? e.substring(1) : e));
                    }
                }
                serviceRecipe.setProperty(key, val);
            } else if (valueStr.startsWith("$")) {
                serviceRecipe.setProperty(key, resolve(services, valueStr.substring(1)));
            } else if (valueStr.startsWith("@")) {
                serviceRecipe.setProperty(key, lookup(value));
            } else {
                serviceRecipe.setProperty(key, value);
            }
        } else {
            serviceRecipe.setProperty(key, entry.getValue());
        }
    }
}
 
Example #12
Source File: ServiceInfos.java    From tomee with Apache License 2.0 5 votes vote down vote up
private static Object build(final Collection<ServiceInfo> services, final ServiceInfo info) throws OpenEJBException {
    if (info == null) {
        return null;
    }

    final ObjectRecipe serviceRecipe = Assembler.prepareRecipe(info);
    return build(services, info, serviceRecipe);
}
 
Example #13
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 #14
Source File: Assembler.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void createSecurityService(final SecurityServiceInfo serviceInfo) throws OpenEJBException {

        Object service = SystemInstance.get().getComponent(SecurityService.class);
        if (service == null) {
            final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);
            service = serviceRecipe.create();
            logUnusedProperties(serviceRecipe, serviceInfo);
        }

        final Class interfce = serviceInterfaces.get(serviceInfo.service);
        checkImplementation(interfce, service.getClass(), serviceInfo.service, serviceInfo.id);

        try {
            this.containerSystem.getJNDIContext().bind(JAVA_OPENEJB_NAMING_CONTEXT + serviceInfo.service, service);
        } catch (final NamingException e) {
            throw new OpenEJBException("Cannot bind " + serviceInfo.service + " with id " + serviceInfo.id, e);
        }

        setSystemInstanceComponent(interfce, service);

        getContext().put(interfce.getName(), service);

        props.put(interfce.getName(), service);
        props.put(serviceInfo.service, service);
        props.put(serviceInfo.id, service);

        this.securityService = (SecurityService) service;

        // Update the config tree
        config.facilities.securityService = serviceInfo;

        logger.getChildLogger("service").debug("createService.success", serviceInfo.service, serviceInfo.id, serviceInfo.className);
    }
 
Example #15
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 #16
Source File: Meecrowave.java    From openwebbeans-meecrowave with Apache License 2.0 5 votes vote down vote up
private List<SSLHostConfig> buildSslHostConfig() {
    final List<SSLHostConfig> sslHostConfigs = new ArrayList<>();
    // Configures default SSLHostConfig
    final ObjectRecipe defaultSslHostConfig = newRecipe(SSLHostConfig.class.getName());
    for (final String key : configuration.getProperties().stringPropertyNames()) {
        if (key.startsWith("connector.sslhostconfig.") && key.split("\\.").length == 3) {
            final String substring = key.substring("connector.sslhostconfig.".length());
            defaultSslHostConfig.setProperty(substring, configuration.getProperties().getProperty(key));
        }
    }
    if (!defaultSslHostConfig.getProperties().isEmpty()) {
        sslHostConfigs.add(SSLHostConfig.class.cast(defaultSslHostConfig.create()));
    }
    // Allows to add N Multiple SSLHostConfig elements not including the default one.
    final Collection<Integer> itemNumbers = configuration.getProperties().stringPropertyNames()
                            .stream()
                            .filter(key -> (key.startsWith("connector.sslhostconfig.") && key.split("\\.").length == 4))
                            .map(key -> Integer.parseInt(key.split("\\.")[2]))
                            .collect(toSet());
    itemNumbers.stream().sorted().forEach(itemNumber -> {
        final ObjectRecipe recipe = newRecipe(SSLHostConfig.class.getName());
        final String prefix = "connector.sslhostconfig." + itemNumber + '.';
        configuration.getProperties().stringPropertyNames().stream()
                                .filter(k -> k.startsWith(prefix))
                                .forEach(key -> {
                                    final String keyName = key.split("\\.")[3];
                                    recipe.setProperty(keyName, configuration.getProperties().getProperty(key));
                                });
        if (!recipe.getProperties().isEmpty()) {
            final SSLHostConfig sslHostConfig = SSLHostConfig.class.cast(recipe.create());
            sslHostConfigs.add(sslHostConfig);
            new LogFacade(Meecrowave.class.getName())
                    .info("Created SSLHostConfig #" + itemNumber + " (" + sslHostConfig.getHostName() + ")");
        }
    });
    return sslHostConfigs;
}
 
Example #17
Source File: DataSourceFactory.java    From tomee with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("SuspiciousMethodCalls")
public static ObjectRecipe forgetRecipe(final Object rawObject, final ObjectRecipe defaultValue) {
    final Object object = realInstance(rawObject);
    final DataSourceCreator creator = creatorByDataSource.get(object);
    ObjectRecipe recipe = null;
    if (creator != null) {
        recipe = creator.clearRecipe(object);
    }
    if (recipe == null) {
        return defaultValue;
    }
    return recipe;
}
 
Example #18
Source File: PoolDataSourceCreator.java    From tomee with Apache License 2.0 5 votes vote down vote up
protected <T> T build(final Class<T> clazz, final Properties properties) {
    final ObjectRecipe serviceRecipe = new ObjectRecipe(clazz);
    recipeOptions(serviceRecipe);
    serviceRecipe.setAllProperties(properties);
    final T value = (T) serviceRecipe.create();
    if (trackRecipeFor(value)) { // avoid to keep config objects
        recipes.put(value, serviceRecipe);
    }
    return value;
}
 
Example #19
Source File: PoolDataSourceCreator.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public ObjectRecipe clearRecipe(final Object object) {
    if (object instanceof ManagedDataSource) {
        return recipes.remove(((ManagedDataSource) object).getDelegate());
    } else {
        return recipes.remove(object);
    }
}
 
Example #20
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 #21
Source File: PoolDataSourceCreator.java    From tomee with Apache License 2.0 5 votes vote down vote up
protected <T> T build(final Class<T> clazz, final Object instance, final Properties properties) {
    final ObjectRecipe recipe = PassthroughFactory.recipe(instance);
    recipeOptions(recipe);
    recipe.setAllProperties(properties);
    final T value = (T) recipe.create();
    recipes.put(value, recipe);
    return value;
}
 
Example #22
Source File: Assembler.java    From tomee with Apache License 2.0 4 votes vote down vote up
public static void logUnusedProperties(final ObjectRecipe serviceRecipe, final ServiceInfo info) {
    final Map<String, Object> unsetProperties = serviceRecipe.getUnsetProperties();
    logUnusedProperties(unsetProperties, info);
}
 
Example #23
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 #24
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 #25
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 #26
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);
}
 
Example #27
Source File: Assembler.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void createService(final ServiceInfo serviceInfo) throws OpenEJBException {
    final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);
    serviceRecipe.setProperty("properties", new UnsetPropertiesRecipe());

    final Object service = serviceRecipe.create();
    SystemInstance.get().addObserver(service);

    logUnusedProperties(serviceRecipe, serviceInfo);

    final Class<?> serviceClass = service.getClass();

    getContext().put(serviceClass.getName(), service);

    props.put(serviceClass.getName(), service);
    props.put(serviceInfo.service, service);
    props.put(serviceInfo.id, service);

    config.facilities.services.add(serviceInfo);

    logger.getChildLogger("service").debug("createService.success", serviceInfo.service, serviceInfo.id, serviceInfo.className);
}
 
Example #28
Source File: Assembler.java    From tomee with Apache License 2.0 4 votes vote down vote up
public void createContainer(final ContainerInfo serviceInfo) throws OpenEJBException {

        final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);

        serviceRecipe.setProperty("id", serviceInfo.id);
        serviceRecipe.setProperty("transactionManager", props.get(TransactionManager.class.getName()));
        serviceRecipe.setProperty("securityService", props.get(SecurityService.class.getName()));
        serviceRecipe.setProperty("properties", new UnsetPropertiesRecipe());

        // MDB container has a resource adapter string name that
        // must be replaced with the real resource adapter instance
        replaceResourceAdapterProperty(serviceRecipe);

        final Object service = serviceRecipe.create();

        serviceRecipe.getUnsetProperties().remove("id"); // we forced it
        serviceRecipe.getUnsetProperties().remove("securityService"); // we forced it
        logUnusedProperties(serviceRecipe, serviceInfo);

        final Class interfce = serviceInterfaces.get(serviceInfo.service);
        checkImplementation(interfce, service.getClass(), serviceInfo.service, serviceInfo.id);

        bindService(serviceInfo, service);

        setSystemInstanceComponent(interfce, service);

        props.put(interfce.getName(), service);
        props.put(serviceInfo.service, service);
        props.put(serviceInfo.id, service);

        containerSystem.addContainer(serviceInfo.id, (Container) service);

        // Update the config tree
        config.containerSystem.containers.add(serviceInfo);

        logger.getChildLogger("service").debug("createService.success", serviceInfo.service, serviceInfo.id, serviceInfo.className);

        if (Container.class.isInstance(service) && LocalMBeanServer.isJMXActive()) {
            final ObjectName objectName = ObjectNameBuilder.uniqueName("containers", serviceInfo.id, service);
            try {
                LocalMBeanServer.get().registerMBean(new DynamicMBeanWrapper(new JMXContainer(serviceInfo, (Container) service)), objectName);
                containerObjectNames.add(objectName);
            } catch (final Exception | NoClassDefFoundError e) {
                // no-op
            }
        }
    }
 
Example #29
Source File: ObjectFactoryImpl.java    From component-runtime with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectFactoryInstance createInstance(final String type) {
    final ObjectRecipe recipe = new ObjectRecipe(type);
    recipe.setRegistry(registry);
    return new ObjectFactoryInstanceImpl(recipe);
}
 
Example #30
Source File: SimpleDataSourceCreator.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public ObjectRecipe clearRecipe(final Object object) {
    return null;
}