for (Map.Entry<String, String> entry : activationProperties.entrySet()) {
objectRecipe.setMethodProperty(entry.getKey(), entry.getValue());
}
// create the activationSpec
ActivationSpec activationSpec = (ActivationSpec) objectRecipe.create(activationSpecClass.getClassLoader());
// verify all properties except "destination" and "destinationType" were consumed
Set<String> unusedProperties = new TreeSet<String>(objectRecipe.getUnsetProperties().keySet());
unusedProperties.remove("destination");
unusedProperties.remove("destinationType");
if (!unusedProperties.isEmpty()) {
throw new IllegalArgumentException("No setter found for the activation spec properties: " + unusedProperties);
}
// validate the activation spec
try {
activationSpec.validate();
} catch (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 {
Validator validator = (Validator)beanContext.getJndiContext().lookup("comp/Validator");
Set generalSet = validator.validate(activationSpec);
if (!generalSet.isEmpty()) {
throw new ConstraintViolationException("Constraint violation for ActivationSpec " + activationSpecClass.getName(), generalSet);
}
} catch (NamingException e) {
logger.debug("No Validator bound to JNDI context");
}
// set the resource adapter into the activation spec
activationSpec.setResourceAdapter(resourceAdapter);
return activationSpec;
} catch (Exception e) {
throw new OpenEJBException("Unable to create activation spec", e);
}