use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.
the class InjectionProcessor method construct.
private void construct() throws OpenEJBException {
if (instance != null) {
throw new IllegalStateException("Instance already constructed");
}
Class<? extends T> clazz = beanClass;
final ObjectRecipe objectRecipe;
if (suppliedInstance != null) {
clazz = (Class<? extends T>) suppliedInstance.getClass();
objectRecipe = PassthroughFactory.recipe(suppliedInstance);
} else {
objectRecipe = new ObjectRecipe(clazz);
}
objectRecipe.allow(Option.FIELD_INJECTION);
objectRecipe.allow(Option.PRIVATE_PROPERTIES);
objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
objectRecipe.allow(Option.NAMED_PARAMETERS);
fillInjectionProperties(objectRecipe);
bindings.clear();
for (final Entry<String, Object> entry : properties.entrySet()) {
objectRecipe.setProperty(entry.getKey(), entry.getValue());
}
final Object object;
try {
object = objectRecipe.create(clazz.getClassLoader());
} catch (final Exception e) {
throw new OpenEJBException("Error while creating bean " + clazz.getName(), e);
}
final Map unsetProperties = objectRecipe.getUnsetProperties();
if (unsetProperties.size() > 0) {
for (final Object property : unsetProperties.keySet()) {
logger.warning("Injection: No such property '" + property + "' in class " + clazz.getName());
}
}
instance = clazz.cast(object);
}
use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.
the class CdiResourceInjectionService method injectJavaEEResources.
@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();
}
use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.
the class MdbContainer method createActivationSpec.
private ActivationSpec createActivationSpec(final BeanContext beanContext) throws OpenEJBException {
try {
// initialize the object recipe
final ObjectRecipe objectRecipe = new ObjectRecipe(activationSpecClass);
objectRecipe.allow(Option.IGNORE_MISSING_PROPERTIES);
objectRecipe.disallow(Option.FIELD_INJECTION);
final Map<String, String> activationProperties = beanContext.getActivationProperties();
for (final Map.Entry<String, String> entry : activationProperties.entrySet()) {
objectRecipe.setMethodProperty(entry.getKey(), entry.getValue());
}
objectRecipe.setMethodProperty("beanClass", beanContext.getBeanClass());
// create the activationSpec
final ActivationSpec activationSpec = (ActivationSpec) objectRecipe.create(activationSpecClass.getClassLoader());
// verify all properties except "destination" and "destinationType" were consumed
final Set<String> unusedProperties = new TreeSet<String>(objectRecipe.getUnsetProperties().keySet());
unusedProperties.remove("destination");
unusedProperties.remove("destinationType");
unusedProperties.remove("destinationLookup");
unusedProperties.remove("connectionFactoryLookup");
unusedProperties.remove("beanClass");
unusedProperties.remove("MdbActiveOnStartup");
unusedProperties.remove("MdbJMXControl");
unusedProperties.remove("DeliveryActive");
if (!unusedProperties.isEmpty()) {
final String text = "No setter found for the activation spec properties: " + unusedProperties;
if (failOnUnknownActivationSpec) {
throw new IllegalArgumentException(text);
} else {
logger.warning(text);
}
}
// validate the activation spec
try {
activationSpec.validate();
} catch (final UnsupportedOperationException uoe) {
logger.info("ActivationSpec does not support validate. Implementation of validate is optional");
}
// also try validating using Bean Validation if there is a Validator available in the context.
try {
final Validator validator = (Validator) beanContext.getJndiContext().lookup("comp/Validator");
final Set generalSet = validator.validate(activationSpec);
if (!generalSet.isEmpty()) {
throw new ConstraintViolationException("Constraint violation for ActivationSpec " + activationSpecClass.getName(), generalSet);
}
} catch (final NamingException e) {
logger.debug("No Validator bound to JNDI context");
}
// set the resource adapter into the activation spec
activationSpec.setResourceAdapter(resourceAdapter);
return activationSpec;
} catch (final Exception e) {
throw new OpenEJBException("Unable to create activation spec", e);
}
}
use of org.apache.xbean.recipe.ObjectRecipe in project tomee by apache.
the class Assembler method createProxyFactory.
public void createProxyFactory(final ProxyFactoryInfo serviceInfo) throws OpenEJBException {
final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);
final Object service = serviceRecipe.create();
logUnusedProperties(serviceRecipe, serviceInfo);
final Class interfce = serviceInterfaces.get(serviceInfo.service);
checkImplementation(interfce, service.getClass(), serviceInfo.service, serviceInfo.id);
ProxyManager.registerFactory(serviceInfo.id, (ProxyFactory) service);
ProxyManager.setDefaultFactory(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.intraVmServer = 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 createTransactionManager.
public void createTransactionManager(final TransactionServiceInfo serviceInfo) throws OpenEJBException {
Object service = SystemInstance.get().getComponent(TransactionManager.class);
if (service == null) {
final ObjectRecipe serviceRecipe = createRecipe(Collections.<ServiceInfo>emptyList(), serviceInfo);
service = serviceRecipe.create();
logUnusedProperties(serviceRecipe, serviceInfo);
} else {
logger.info("Reusing provided TransactionManager " + service);
}
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);
this.containerSystem.getJNDIContext().bind("comp/UserTransaction", new CoreUserTransaction((TransactionManager) service));
this.containerSystem.getJNDIContext().bind("comp/TransactionManager", 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.transactionManager = (TransactionManager) service;
// Update the config tree
config.facilities.transactionService = serviceInfo;
// todo find a better place for this
// TransactionSynchronizationRegistry
final TransactionSynchronizationRegistry synchronizationRegistry;
if (transactionManager instanceof TransactionSynchronizationRegistry) {
synchronizationRegistry = (TransactionSynchronizationRegistry) transactionManager;
} else {
// todo this should be built
synchronizationRegistry = new SimpleTransactionSynchronizationRegistry(transactionManager);
}
Assembler.getContext().put(TransactionSynchronizationRegistry.class.getName(), synchronizationRegistry);
SystemInstance.get().setComponent(TransactionSynchronizationRegistry.class, synchronizationRegistry);
try {
this.containerSystem.getJNDIContext().bind("comp/TransactionSynchronizationRegistry", new TransactionSynchronizationRegistryWrapper());
} catch (final NamingException e) {
throw new OpenEJBException("Cannot bind java:comp/TransactionSynchronizationRegistry", e);
}
// JtaEntityManagerRegistry
// todo this should be built
final JtaEntityManagerRegistry jtaEntityManagerRegistry = new JtaEntityManagerRegistry(synchronizationRegistry);
Assembler.getContext().put(JtaEntityManagerRegistry.class.getName(), jtaEntityManagerRegistry);
SystemInstance.get().setComponent(JtaEntityManagerRegistry.class, jtaEntityManagerRegistry);
logger.getChildLogger("service").debug("createService.success", serviceInfo.service, serviceInfo.id, serviceInfo.className);
}
Aggregations