Java Code Examples for org.apache.xbean.recipe.ObjectRecipe#setProperty()
The following examples show how to use
org.apache.xbean.recipe.ObjectRecipe#setProperty() .
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: ClassLoaderUtil.java From tomee with Apache License 2.0 | 6 votes |
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 2
Source File: Meecrowave.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
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 3
Source File: FlushableDataSourceHandler.java From tomee with Apache License 2.0 | 5 votes |
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 4
Source File: ActiveMQ5Factory.java From tomee with Apache License 2.0 | 5 votes |
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 5
Source File: ServiceInfos.java From tomee with Apache License 2.0 | 5 votes |
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 6
Source File: ListConfigurator.java From tomee with Apache License 2.0 | 5 votes |
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 7
Source File: Client.java From tomee with Apache License 2.0 | 4 votes |
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 8
Source File: Assembler.java From tomee with Apache License 2.0 | 4 votes |
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 9
Source File: Assembler.java From tomee with Apache License 2.0 | 4 votes |
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 10
Source File: Assembler.java From tomee with Apache License 2.0 | 3 votes |
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); }