1 22 package org.jboss.resource.deployment; 23 24 import java.beans.IntrospectionException ; 25 import java.util.Collection ; 26 import java.util.Iterator ; 27 import java.util.Properties ; 28 29 import javax.management.ObjectName ; 30 import javax.resource.spi.ActivationSpec ; 31 32 import org.jboss.deployment.DeploymentException; 33 import org.jboss.logging.Logger; 34 import org.jboss.metadata.ActivationConfigPropertyMetaData; 35 import org.jboss.resource.metadata.MessageListenerMetaData; 36 import org.jboss.resource.metadata.RequiredConfigPropertyMetaData; 37 import org.jboss.util.propertyeditor.PropertyEditors; 38 39 45 public class ActivationSpecFactory 46 { 47 48 private static final Logger log = Logger.getLogger(ActivationSpecFactory.class); 49 50 public static ActivationSpec createActivationSpec(ObjectName rarName, 51 String messagingType, Collection activationConfig, 52 MessageListenerMetaData mlmd) 53 throws Exception 54 { 55 boolean trace = log.isTraceEnabled(); 56 57 if (trace) 58 log.trace("Create ActivationSpec rar=" + rarName + " messagingType=" + messagingType + 59 " activationConfig=" + activationConfig + " messageListner=" + mlmd); 60 61 for (Iterator i = mlmd.getRequiredConfigProperties().iterator(); i.hasNext();) 63 { 64 RequiredConfigPropertyMetaData rcpmd = (RequiredConfigPropertyMetaData) i.next(); 65 66 String rcp = rcpmd.getName(); 67 String rcpName = rcp.substring(0, 1).toUpperCase(); 68 if (rcp.length() > 1) 69 rcpName = rcpName.concat(rcp.substring(1)); 70 if (trace) 71 log.trace("Checking required config " + rcpName); 72 73 boolean found = false; 74 for (Iterator j = activationConfig.iterator(); j.hasNext();) 75 { 76 ActivationConfigPropertyMetaData acpmd = (ActivationConfigPropertyMetaData) j.next(); 77 78 String acp = acpmd.getName(); 79 String acpName = acp.substring(0, 1).toUpperCase(); 80 if (acp.length() > 1) 81 acpName = acpName.concat(acp.substring(1)); 82 83 if (trace) 84 log.trace("Checking required config " + rcpName + " against " + acpName + " result=" + rcpName.equals(acpName)); 85 86 if (rcpName.equals(acpName)) 87 { 88 if (trace) 89 log.trace("Found required config " + rcp + " " + acpmd); 90 found = true; 91 break; 92 } 93 } 94 if (found == false) 95 throw new DeploymentException("Required config property " + rcpmd + " for messagingType '" + messagingType + 96 "' not found in activation config " + activationConfig + " ra=" + rarName); 97 } 98 99 String className = mlmd.getActivationSpecType(); 101 if (className == null) 102 throw new DeploymentException("No activation spec type for messagingType '" + messagingType + "' ra=" + rarName); 103 104 if (trace) 106 log.trace("Loading ActivationSpec class=" + className); 107 Class asClass = Thread.currentThread().getContextClassLoader().loadClass(className); 108 if (ActivationSpec .class.isAssignableFrom(asClass) == false) 109 throw new DeploymentException(asClass.getName() + " is not an activation spec class '" + messagingType + "' ra=" + rarName); 110 ActivationSpec result = (ActivationSpec ) asClass.newInstance(); 111 if (trace) 112 log.trace("Instantiated ActivationSpec class=" + result); 113 114 117 Properties beanProps = new Properties (); 118 for (Iterator i = activationConfig.iterator(); i.hasNext();) 119 { 120 ActivationConfigPropertyMetaData acpmd = (ActivationConfigPropertyMetaData) i.next(); 121 String name = acpmd.getName(); 122 String value = acpmd.getValue(); 123 beanProps.setProperty(name, value); 124 } 125 if (trace) 126 log.trace("Configuring ActivationSpec properties=" + beanProps); 127 try 128 { 129 PropertyEditors.mapJavaBeanProperties(result, beanProps); 130 } 131 catch(IntrospectionException e) 132 { 133 String msg = "Error for ActivationSpec class " + asClass.getName() 134 + " as JavaBean"; 135 DeploymentException.rethrowAsDeploymentException(msg, e); 136 } 137 138 try 140 { 141 if (trace) 142 log.trace("Trying to validate ActivationSpec " + result); 143 result.validate(); 144 } 145 catch (UnsupportedOperationException e) 146 { 147 log.debug("Validation is not supported for ActivationSpec: " + className); 148 } 149 150 return result; 151 } 152 } 153 | Popular Tags |