public static javax.resource.spi.ActivationSpec | createActivationSpec(javax.management.ObjectName rarName, java.lang.String messagingType, java.util.Collection activationConfig, org.jboss.resource.metadata.MessageListenerMetaData mlmd)
boolean trace = log.isTraceEnabled();
if (trace)
log.trace("Create ActivationSpec rar=" + rarName + " messagingType=" + messagingType +
" activationConfig=" + activationConfig + " messageListner=" + mlmd);
// Check we have all the required properties
for (Iterator i = mlmd.getRequiredConfigProperties().iterator(); i.hasNext();)
{
RequiredConfigPropertyMetaData rcpmd = (RequiredConfigPropertyMetaData) i.next();
String rcp = rcpmd.getName();
String rcpName = rcp.substring(0, 1).toUpperCase();
if (rcp.length() > 1)
rcpName = rcpName.concat(rcp.substring(1));
if (trace)
log.trace("Checking required config " + rcpName);
boolean found = false;
for (Iterator j = activationConfig.iterator(); j.hasNext();)
{
ActivationConfigPropertyMetaData acpmd = (ActivationConfigPropertyMetaData) j.next();
String acp = acpmd.getName();
String acpName = acp.substring(0, 1).toUpperCase();
if (acp.length() > 1)
acpName = acpName.concat(acp.substring(1));
if (trace)
log.trace("Checking required config " + rcpName + " against " + acpName + " result=" + rcpName.equals(acpName));
if (rcpName.equals(acpName))
{
if (trace)
log.trace("Found required config " + rcp + " " + acpmd);
found = true;
break;
}
}
if (found == false)
throw new DeploymentException("Required config property " + rcpmd + " for messagingType '" + messagingType +
"' not found in activation config " + activationConfig + " ra=" + rarName);
}
// Determine the activation spec class
String className = mlmd.getActivationSpecType();
if (className == null)
throw new DeploymentException("No activation spec type for messagingType '" + messagingType + "' ra=" + rarName);
// Load the class
if (trace)
log.trace("Loading ActivationSpec class=" + className);
Class asClass = Thread.currentThread().getContextClassLoader().loadClass(className);
if (ActivationSpec.class.isAssignableFrom(asClass) == false)
throw new DeploymentException(asClass.getName() + " is not an activation spec class '" + messagingType + "' ra=" + rarName);
ActivationSpec result = (ActivationSpec) asClass.newInstance();
if (trace)
log.trace("Instantiated ActivationSpec class=" + result);
/* Apply the properties to the ActivationSpec java bean using the util
PropertyEditors.mapJavaBeanProperties method.
*/
Properties beanProps = new Properties();
for (Iterator i = activationConfig.iterator(); i.hasNext();)
{
ActivationConfigPropertyMetaData acpmd = (ActivationConfigPropertyMetaData) i.next();
String name = acpmd.getName();
String value = acpmd.getValue();
beanProps.setProperty(name, value);
}
if (trace)
log.trace("Configuring ActivationSpec properties=" + beanProps);
try
{
PropertyEditors.mapJavaBeanProperties(result, beanProps);
}
catch(IntrospectionException e)
{
String msg = "Error for ActivationSpec class " + asClass.getName()
+ " as JavaBean";
DeploymentException.rethrowAsDeploymentException(msg, e);
}
// Validate the activation spec
try
{
if (trace)
log.trace("Trying to validate ActivationSpec " + result);
result.validate();
}
catch (UnsupportedOperationException e)
{
log.debug("Validation is not supported for ActivationSpec: " + className);
}
return result;
|