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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations