Author: jlmonteiro Date: Tue May 10 11:19:47 2011 New Revision: 1101405 URL: http://svn.apache.org/viewvc?rev=1101405&view=rev Log: OPENEJB-1352 Bean Validation support. Porting changes to 3.2.x. Thanks again Romain. Added: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfo.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfoObject.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorFactoryWrapper.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java openejb/branches/openejb-3.2.x/container/openejb-core/src/test/java/org/apache/openejb/bval/ openejb/branches/openejb-3.2.x/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/AnnotationType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/BeanType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ClassType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintDefinitionType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintMappingsType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ElementType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/FieldType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/GetterType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/GroupSequenceType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/GroupsType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ObjectFactory.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/PayloadType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/PropertyType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ValidatedByType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ValidationConfigType.java openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/package-info.java Modified: openejb/branches/openejb-3.2.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java openejb/branches/openejb-3.2.x/container/openejb-core/pom.xml openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ClientInfo.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ConnectorInfo.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WebAppInfo.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java openejb/branches/openejb-3.2.x/pom.xml Modified: openejb/branches/openejb-3.2.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java (original) +++ openejb/branches/openejb-3.2.x/assembly/openejb-tomcat/openejb-tomcat-catalina/src/main/java/org/apache/openejb/tomcat/catalina/TomcatWebAppBuilder.java Tue May 10 11:19:47 2011 @@ -344,6 +344,9 @@ public class TomcatWebAppBuilder impleme // add context to WebDeploymentInfo for (WebAppInfo webAppInfo : contextInfo.appInfo.webApps) { + // Bean Validation + standardContext.getServletContext().setAttribute("javax.faces.validator.beanValidator.ValidatorFactory", openejbContext.lookup(Assembler.VALIDATOR_FACTORY_NAMING_CONTEXT + webAppInfo.moduleId)); + if (("/" + webAppInfo.contextRoot).equals(standardContext.getPath()) || isRootApplication(standardContext)) { CoreWebDeploymentInfo webDeploymentInfo = (CoreWebDeploymentInfo) getContainerSystem().getWebDeploymentInfo(webAppInfo.moduleId); if (webDeploymentInfo != null) { Modified: openejb/branches/openejb-3.2.x/container/openejb-core/pom.xml URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/pom.xml?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/pom.xml (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/pom.xml Tue May 10 11:19:47 2011 @@ -205,6 +205,14 @@ + org.apache.bval + bval-core + + + org.apache.bval + bval-jsr303 + + org.apache.openejb javaee-api 6.0-SNAPSHOT Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/Assembler.java Tue May 10 11:19:47 2011 @@ -28,6 +28,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; @@ -45,6 +46,7 @@ import javax.naming.InitialContext; import javax.naming.NameAlreadyBoundException; import javax.naming.NamingEnumeration; import javax.naming.NamingException; +import javax.validation.ValidatorFactory; import javax.persistence.EntityManagerFactory; import javax.resource.spi.BootstrapContext; import javax.resource.spi.ConnectionManager; @@ -115,7 +117,10 @@ public class Assembler extends Assembler public static final String JAVA_OPENEJB_NAMING_CONTEXT = "openejb/"; - public static final String PERSISTENCE_UNIT_NAMING_CONTEXT = "openejb/PersistenceUnit/"; + public static final String PERSISTENCE_UNIT_NAMING_CONTEXT = JAVA_OPENEJB_NAMING_CONTEXT + "PersistenceUnit/"; + + public static final String VALIDATOR_FACTORY_NAMING_CONTEXT = JAVA_OPENEJB_NAMING_CONTEXT + "ValidatorFactory/"; + public static final String VALIDATOR_NAMING_CONTEXT = JAVA_OPENEJB_NAMING_CONTEXT + "Validator/"; private static final String OPENEJB_URL_PKG_PREFIX = "org.apache.openejb.core.ivm.naming"; @@ -132,6 +137,7 @@ public class Assembler extends Assembler protected OpenEjbConfigurationFactory configFactory; private final Map deployedApplications = new HashMap(); private final List deploymentListeners = new ArrayList(); + private final Set uniqueIds = new HashSet(); public org.apache.openejb.spi.ContainerSystem getContainerSystem() { @@ -482,6 +488,43 @@ public class Assembler extends Assembler classLoader = ClassLoaderUtil.createClassLoader(appInfo.jarPath, new URL []{generatedJar.toURI().toURL()}, classLoader); } + Context containerSystemContext = containerSystem.getJNDIContext(); + + // Bean Validation + // ValidatorFactory needs to be put in the map sent to the entity manager factory + // so it has to be constructed before + Map validatorFactories = new HashMap(); + //geronimo will handle the bean validator by itself + if (!SystemInstance.get().hasProperty("openejb.geronimo")){ + for (ClientInfo clientInfo : appInfo.clients) { + validatorFactories.put(clientInfo.uniqueId, ValidatorBuilder.buildFactory(classLoader, clientInfo.validationInfo)); + } + for (ConnectorInfo connectorInfo : appInfo.connectors) { + validatorFactories.put(connectorInfo.uniqueId, ValidatorBuilder.buildFactory(classLoader, connectorInfo.validationInfo)); + } + for (EjbJarInfo ejbJarInfo : appInfo.ejbJars) { + validatorFactories.put(ejbJarInfo.uniqueId, ValidatorBuilder.buildFactory(classLoader, ejbJarInfo.validationInfo)); + } + for (WebAppInfo webAppInfo : appInfo.webApps) { + validatorFactories.put(webAppInfo.uniqueId, ValidatorBuilder.buildFactory(classLoader, webAppInfo.validationInfo)); + } + uniqueIds.addAll(validatorFactories.keySet()); + + // validators bindings + for (Map.Entry validatorFactory : validatorFactories.entrySet()) { + String id = validatorFactory.getKey(); + ValidatorFactory factory = validatorFactory.getValue(); + try { + containerSystemContext.bind(VALIDATOR_FACTORY_NAMING_CONTEXT + id, factory); + containerSystemContext.bind(VALIDATOR_NAMING_CONTEXT + id, factory.usingContext().getValidator()); + } catch (NameAlreadyBoundException e) { + throw new OpenEJBException("ValidatorFactory already exists for module " + id); + } catch (Exception e) { + throw new OpenEJBException(e); + } + } + } + // JPA - Persistence Units MUST be processed first since they will add ClassFileTransformers // to the class loader which must be added before any classes are loaded PersistenceBuilder persistenceBuilder = new PersistenceBuilder(persistenceClassLoaderHandler); @@ -616,7 +659,7 @@ public class Assembler extends Assembler List injections = injectionBuilder.buildInjections(clientInfo.jndiEnc); // build the enc - JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc, injections, "Bean", clientInfo.moduleId, classLoader); + JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(clientInfo.jndiEnc, injections, "Bean", clientInfo.moduleId, clientInfo.uniqueId, classLoader); // if there is at least a remote client classes // or if there is no local client classes // then, we can set the client flag @@ -907,6 +950,17 @@ public class Assembler extends Assembler } } + for (String id : uniqueIds) { + try { + globalContext.unbind(VALIDATOR_FACTORY_NAMING_CONTEXT + id); + globalContext.unbind(VALIDATOR_NAMING_CONTEXT + id); + } catch (NamingException e) { + undeployException.getCauses().add(new Exception("validator: " + id + ": " + e.getMessage(), e)); + } + } + uniqueIds.clear(); + + try { if (globalContext instanceof IvmContext) { IvmContext ivmContext = (IvmContext) globalContext; Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ClientInfo.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ClientInfo.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ClientInfo.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ClientInfo.java Tue May 10 11:19:47 2011 @@ -21,7 +21,7 @@ import java.util.ArrayList; import java.util.Set; import java.util.TreeSet; -public class ClientInfo extends InfoObject { +public class ClientInfo extends ValidationInfoObject { public String codebase; public String description; Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ConnectorInfo.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ConnectorInfo.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ConnectorInfo.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ConnectorInfo.java Tue May 10 11:19:47 2011 @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.Set; import java.util.TreeSet; -public class ConnectorInfo extends InfoObject { +public class ConnectorInfo extends ValidationInfoObject { public String codebase; public String description; Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarBuilder.java Tue May 10 11:19:47 2011 @@ -48,7 +48,7 @@ public class EjbJarBuilder { for (EnterpriseBeanInfo ejbInfo : ejbJar.enterpriseBeans) { try { - EnterpriseBeanBuilder deploymentBuilder = new EnterpriseBeanBuilder(classLoader, ejbInfo, ejbJar.moduleId, new ArrayList()); + EnterpriseBeanBuilder deploymentBuilder = new EnterpriseBeanBuilder(classLoader, ejbInfo, ejbJar.moduleId, ejbJar.uniqueId, new ArrayList()); CoreDeploymentInfo deployment = (CoreDeploymentInfo) deploymentBuilder.build(); interceptorBindingBuilder.build(deployment, ejbInfo); Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EjbJarInfo.java Tue May 10 11:19:47 2011 @@ -22,7 +22,7 @@ import java.util.Properties; import java.util.Set; import java.util.TreeSet; -public class EjbJarInfo extends InfoObject { +public class EjbJarInfo extends ValidationInfoObject { public final Properties properties = new Properties(); public String moduleId; Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/EnterpriseBeanBuilder.java Tue May 10 11:19:47 2011 @@ -46,14 +46,16 @@ class EnterpriseBeanBuilder { protected static final Messages messages = new Messages("org.apache.openejb.util.resources"); private final EnterpriseBeanInfo bean; private final String moduleId; + private final String uniqueId; private final List defaultInterceptors; private final BeanType ejbType; private final ClassLoader cl; private List warnings = new ArrayList(); - public EnterpriseBeanBuilder(ClassLoader cl, EnterpriseBeanInfo bean, String moduleId, List defaultInterceptors) { + public EnterpriseBeanBuilder(ClassLoader cl, EnterpriseBeanInfo bean, String moduleId, String uniqueId, List defaultInterceptors) { this.bean = bean; this.moduleId = moduleId; + this.uniqueId = uniqueId; this.defaultInterceptors = defaultInterceptors; if (bean.type == EnterpriseBeanInfo.STATEFUL) { @@ -122,7 +124,7 @@ class EnterpriseBeanBuilder { List injections = injectionBuilder.buildInjections(bean.jndiEnc); // build the enc - JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(bean.jndiEnc, injections, transactionType, moduleId, cl); + JndiEncBuilder jndiEncBuilder = new JndiEncBuilder(bean.jndiEnc, injections, transactionType, moduleId, uniqueId, cl); Context root = jndiEncBuilder.build(); DeploymentContext deploymentContext = new DeploymentContext(bean.ejbDeploymentId, cl, root); @@ -198,7 +200,7 @@ class EnterpriseBeanBuilder { try { ContainerSystem containerSystem = SystemInstance.get().getComponent(ContainerSystem.class); - Object o = containerSystem.getJNDIContext().lookup("openejb/PersistenceUnit/" + info.unitId); + Object o = containerSystem.getJNDIContext().lookup(PersistenceBuilder.getOpenEJBJndiName(info.unitId)); extendedEntityManagerFactories.put((EntityManagerFactory) o, info.properties); } catch (NamingException e) { throw new OpenEJBException("PersistenceUnit '" + info.unitId + "' not found for EXTENDED ref '" + info.referenceName + "'"); Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/JndiEncBuilder.java Tue May 10 11:19:47 2011 @@ -53,6 +53,8 @@ import javax.naming.NamingException; import javax.persistence.EntityManagerFactory; import javax.transaction.TransactionManager; import javax.transaction.UserTransaction; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; import javax.xml.ws.Service; import javax.xml.ws.WebServiceContext; import java.net.MalformedURLException; @@ -78,17 +80,18 @@ public class JndiEncBuilder { private final boolean beanManagedTransactions; private final JndiEncInfo jndiEnc; private final URI moduleUri; + private final String uniqueId; private final List injections; private final ClassLoader classLoader; private boolean useCrossClassLoaderRef = true; private boolean client = false; - public JndiEncBuilder(JndiEncInfo jndiEnc, List injections, String moduleId, ClassLoader classLoader) throws OpenEJBException { - this(jndiEnc, injections, null, moduleId, classLoader); + public JndiEncBuilder(JndiEncInfo jndiEnc, List injections, String moduleId, String uniqueId, ClassLoader classLoader) throws OpenEJBException { + this(jndiEnc, injections, null, moduleId, uniqueId, classLoader); } - public JndiEncBuilder(JndiEncInfo jndiEnc, List injections, String transactionType, String moduleId, ClassLoader classLoader) throws OpenEJBException { + public JndiEncBuilder(JndiEncInfo jndiEnc, List injections, String transactionType, String moduleId, String uniqueId, ClassLoader classLoader) throws OpenEJBException { this.jndiEnc = jndiEnc; this.injections = injections; beanManagedTransactions = transactionType != null && transactionType.equalsIgnoreCase("Bean"); @@ -98,6 +101,7 @@ public class JndiEncBuilder { } catch (URISyntaxException e) { throw new OpenEJBException(e); } + this.uniqueId = uniqueId; this.classLoader = classLoader; } @@ -136,6 +140,14 @@ public class JndiEncBuilder { bindings.put("java:comp/ORB", new SystemComponentReference(ORB.class)); bindings.put("java:comp/HandleDelegate", new SystemComponentReference(HandleDelegate.class)); + // bind bean validation objects + String moduleId = null; + if (moduleUri != null) { + moduleId = moduleUri.toString(); + } + bindings.put("java:comp/ValidatorFactory", new IntraVmJndiReference(Assembler.VALIDATOR_FACTORY_NAMING_CONTEXT + uniqueId)); + bindings.put("java:comp/Validator", new IntraVmJndiReference(Assembler.VALIDATOR_NAMING_CONTEXT + uniqueId)); + // get JtaEntityManagerRegistry JtaEntityManagerRegistry jtaEntityManagerRegistry = SystemInstance.get().getComponent(JtaEntityManagerRegistry.class); @@ -237,6 +249,12 @@ public class JndiEncBuilder { } else { reference = new URLReference(referenceInfo.resourceID); } + } else if (ValidatorFactory.class.getName().equals(referenceInfo.referenceType)) { + String jndiName = Assembler.VALIDATOR_FACTORY_NAMING_CONTEXT + uniqueId; + reference = new IntraVmJndiReference(jndiName); + } else if (Validator.class.getName().equals(referenceInfo.referenceType)) { + String jndiName = Assembler.VALIDATOR_NAMING_CONTEXT + uniqueId; + reference = new IntraVmJndiReference(jndiName); } else if (referenceInfo.location != null) { reference = buildReferenceLocation(referenceInfo.location); } else if (referenceInfo.resourceID != null) { @@ -256,16 +274,14 @@ public class JndiEncBuilder { if (EJBContext.class.isAssignableFrom(type)) { String jndiName = "java:comp/EJBContext"; linkRef = new LinkRef(jndiName); - bindings.put(normalize(referenceInfo.resourceEnvRefName), linkRef); - continue; } else if (WebServiceContext.class.equals(type)) { String jndiName = "java:comp/WebServiceContext"; linkRef = new LinkRef(jndiName); - bindings.put(normalize(referenceInfo.resourceEnvRefName), linkRef); - continue; } else if (TimerService.class.equals(type)) { String jndiName = "java:comp/TimerService"; linkRef = new LinkRef(jndiName); + } + if (linkRef != null) { bindings.put(normalize(referenceInfo.resourceEnvRefName), linkRef); continue; } @@ -296,7 +312,7 @@ public class JndiEncBuilder { continue; } - String jndiName = "openejb/PersistenceUnit/" + referenceInfo.unitId; + String jndiName = PersistenceBuilder.getOpenEJBJndiName(referenceInfo.unitId); Reference reference = new IntraVmJndiReference(jndiName); bindings.put(normalize(referenceInfo.referenceName), reference); } @@ -311,7 +327,8 @@ public class JndiEncBuilder { Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext(); EntityManagerFactory factory; try { - factory = (EntityManagerFactory) context.lookup("openejb/PersistenceUnit/" + contextInfo.unitId); + String jndiName = PersistenceBuilder.getOpenEJBJndiName(contextInfo.unitId); + factory = (EntityManagerFactory) context.lookup(jndiName); } catch (NamingException e) { throw new OpenEJBException("PersistenceUnit '" + contextInfo.unitId + "' not found for EXTENDED ref '" + contextInfo.referenceName + "'"); } Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/PersistenceBuilder.java Tue May 10 11:19:47 2011 @@ -18,6 +18,7 @@ package org.apache.openejb.assembler.cla import java.util.HashMap; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import javax.naming.Context; @@ -110,6 +111,8 @@ public class PersistenceBuilder { // Exclude Unlisted Classes unitInfo.setExcludeUnlistedClasses(info.excludeUnlistedClasses); + Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext(); + // JTA Datasource String jtaDataSourceId = info.jtaDataSource; if (jtaDataSourceEnv != null) jtaDataSourceId = jtaDataSourceEnv; @@ -120,7 +123,6 @@ public class PersistenceBuilder { if (!jtaDataSourceId.startsWith("java:openejb/Resource/") && !jtaDataSourceId.startsWith("openejb/Resource/")) jtaDataSourceId = "openejb/Resource/"+jtaDataSourceId; - Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext(); DataSource jtaDataSource = (DataSource) context.lookup(jtaDataSourceId); unitInfo.setJtaDataSource(jtaDataSource); } catch (NamingException e) { @@ -172,7 +174,6 @@ public class PersistenceBuilder { try { if (!nonJtaDataSourceId.startsWith("java:openejb/Resource/")) nonJtaDataSourceId = "java:openejb/Resource/"+nonJtaDataSourceId; - Context context = SystemInstance.get().getComponent(ContainerSystem.class).getJNDIContext(); DataSource nonJtaDataSource = (DataSource) context.lookup(nonJtaDataSourceId); unitInfo.setNonJtaDataSource(nonJtaDataSource); } catch (NamingException e) { @@ -196,8 +197,10 @@ public class PersistenceBuilder { Class clazz = classLoader.loadClass(persistenceProviderClassName); PersistenceProvider persistenceProvider = (PersistenceProvider) clazz.newInstance(); - // Create entity manager factory - EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo, new HashMap()); + // Create entity manager factories with the validator factory + Map properties = new HashMap(); + properties.put("javax.persistence.validator.ValidatorFactory", new ValidatorFactoryWrapper()); + EntityManagerFactory emf = persistenceProvider.createContainerEntityManagerFactory(unitInfo, properties); return emf; } finally { final long time = TimeUnit.MILLISECONDS.convert(System.nanoTime() - start, TimeUnit.NANOSECONDS); @@ -209,4 +212,8 @@ public class PersistenceBuilder { } } } + + public static String getOpenEJBJndiName(String unit) { + return Assembler.PERSISTENCE_UNIT_NAMING_CONTEXT + unit; +} } Added: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfo.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfo.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfo.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfo.java Tue May 10 11:19:47 2011 @@ -0,0 +1,17 @@ +package org.apache.openejb.assembler.classic; + +import java.util.ArrayList; +import java.util.List; +import java.util.Properties; + +/** + * @author Romain Manni-Bucau + */ +public class ValidationInfo extends InfoObject { + public String providerClassName; + public String messageInterpolatorClass; + public String traversableResolverClass; + public String constraintFactoryClass; + public final Properties propertyTypes = new Properties(); + public final List constraintMappings = new ArrayList(); +} Added: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfoObject.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfoObject.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfoObject.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidationInfoObject.java Tue May 10 11:19:47 2011 @@ -0,0 +1,9 @@ +package org.apache.openejb.assembler.classic; + +/** + * @author Romain Manni-Bucau + */ +public class ValidationInfoObject extends InfoObject { + public ValidationInfo validationInfo; + public String uniqueId; +} Added: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorBuilder.java Tue May 10 11:19:47 2011 @@ -0,0 +1,159 @@ +package org.apache.openejb.assembler.classic; + +import org.apache.openejb.config.sys.JaxbOpenejb; +import org.apache.openejb.jee.bval.PropertyType; +import org.apache.openejb.jee.bval.ValidationConfigType; +import org.apache.openejb.util.LogCategory; +import org.apache.openejb.util.Logger; + +import javax.validation.Configuration; +import javax.validation.ConstraintValidatorFactory; +import javax.validation.MessageInterpolator; +import javax.validation.TraversableResolver; +import javax.validation.Validation; +import javax.validation.ValidationException; +import javax.validation.ValidatorFactory; +import javax.validation.spi.ValidationProvider; +import javax.xml.bind.JAXBElement; +import java.io.InputStream; +import java.net.URL; +import java.util.Map; + +public final class ValidatorBuilder { + public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_STARTUP, ValidatorBuilder.class); + + private ValidatorBuilder() { + // no-op + } + + public static ValidatorFactory buildFactory(ClassLoader classLoader, ValidationInfo info) { + return buildFactory(info, classLoader); + } + + public static ValidationConfigType readConfig(URL url) { + if (url == null) { + return null; + } + + ValidationConfigType validationConfigType; + try { + validationConfigType = JaxbOpenejb.unmarshal(ValidationConfigType.class, url.openStream()); + } catch (Throwable t) { + logger.warning("Unable to create module ValidatorFactory instance. Using default factory", t); + return null; + } + + return validationConfigType; + } + + public static ValidationInfo getInfo(ValidationConfigType config) { + ValidationInfo info = new ValidationInfo(); + if (config != null) { + info.providerClassName = config.getDefaultProvider(); + info.constraintFactoryClass = config.getConstraintValidatorFactory(); + info.traversableResolverClass = config.getTraversableResolver(); + info.messageInterpolatorClass = config.getMessageInterpolator(); + for (PropertyType p : config.getProperty()) { + info.propertyTypes.put(p.getName(), p.getValue()); + } + for (JAXBElement element : config.getConstraintMapping()) { + info.constraintMappings.add(element.getValue()); + } + } + return info; + } + + public static ValidatorFactory buildFactory(ValidationInfo config, ClassLoader classLoader) { + ValidatorFactory factory = null; + ClassLoader oldContextLoader = Thread.currentThread().getContextClassLoader(); + try { + Thread.currentThread().setContextClassLoader(classLoader); + if (config == null) { + factory = Validation.buildDefaultValidatorFactory(); + } else { + Configuration configuration = getConfig(config); + factory = configuration.buildValidatorFactory(); + configuration.ignoreXmlConfiguration(); + } + } finally { + Thread.currentThread().setContextClassLoader(oldContextLoader); + } + return factory; + } + + private static Configuration getConfig(ValidationInfo info) { + Configuration target = null; + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + + String providerClassName = info.providerClassName; + if (providerClassName != null) { + try { + @SuppressWarnings("unchecked") + Class clazz = (Class) classLoader.loadClass(providerClassName); + target = Validation.byProvider(clazz).configure(); + logger.info("Using " + providerClassName + " as validation provider."); + } catch (ClassNotFoundException e) { + logger.warning("Unable to load provider class "+providerClassName, e); + } + } + if (target == null) { + target = Validation.byDefaultProvider().configure(); + } + + String messageInterpolatorClass = info.messageInterpolatorClass; + if (messageInterpolatorClass != null) { + try { + @SuppressWarnings("unchecked") + Class clazz = (Class) classLoader.loadClass(messageInterpolatorClass); + target.messageInterpolator(clazz.newInstance()); + } catch (Exception e) { + logger.warning("Unable to set "+messageInterpolatorClass+ " as message interpolator.", e); + } + logger.info("Using " + messageInterpolatorClass + " as message interpolator."); + } + String traversableResolverClass = info.traversableResolverClass; + if (traversableResolverClass != null) { + try { + @SuppressWarnings("unchecked") + Class clazz = (Class) classLoader.loadClass(traversableResolverClass); + target.traversableResolver(clazz.newInstance()); + } catch (Exception e) { + logger.warning("Unable to set "+traversableResolverClass+ " as traversable resolver.", e); + } + logger.info("Using " + traversableResolverClass + " as traversable resolver."); + } + String constraintFactoryClass = info.constraintFactoryClass; + if (constraintFactoryClass != null) { + try { + @SuppressWarnings("unchecked") + Class clazz = (Class) classLoader.loadClass(constraintFactoryClass); + target.constraintValidatorFactory(clazz.newInstance()); + } catch (Exception e) { + logger.warning("Unable to set "+constraintFactoryClass+ " as constraint factory.", e); + } + logger.info("Using " + constraintFactoryClass + " as constraint factory."); + } + for (Map.Entry entry : info.propertyTypes.entrySet()) { + PropertyType property = new PropertyType(); + property.setName((String) entry.getKey()); + property.setValue((String) entry.getValue()); + + if (logger.isDebugEnabled()) { + logger.debug("Found property '" + property.getName() + "' with value '" + property.getValue()); + } + target.addProperty(property.getName(), property.getValue()); + } + for (String mappingFileName : info.constraintMappings) { + if (logger.isDebugEnabled()) { + logger.debug("Opening input stream for " + mappingFileName); + } + InputStream in = classLoader.getResourceAsStream(mappingFileName); + if (in == null) { + throw new ValidationException("Unable to open input stream for mapping file " + mappingFileName); + } + target.addMapping(in); + } + + return target; + } +} Added: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorFactoryWrapper.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorFactoryWrapper.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorFactoryWrapper.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/ValidatorFactoryWrapper.java Tue May 10 11:19:47 2011 @@ -0,0 +1,59 @@ +package org.apache.openejb.assembler.classic; + +import org.apache.openejb.util.LogCategory; +import org.apache.openejb.util.Logger; + +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.validation.ConstraintValidatorFactory; +import javax.validation.MessageInterpolator; +import javax.validation.TraversableResolver; +import javax.validation.Validator; +import javax.validation.ValidatorContext; +import javax.validation.ValidatorFactory; + +/** + * @author Romain Manni-Bucau + */ +public class ValidatorFactoryWrapper implements ValidatorFactory { + public static final Logger logger = Logger.getInstance(LogCategory.OPENEJB, ValidatorFactoryWrapper.class); + + private ValidatorFactory factory() { + try { + return (ValidatorFactory) new InitialContext().lookup("java:comp/ValidatorFactory"); + } catch (NamingException e) { + logger.warning("validator factory not found for current module "); + return null; + } + } + + @Override + public Validator getValidator() { + return factory().getValidator(); + } + + @Override + public ValidatorContext usingContext() { + return factory().usingContext(); + } + + @Override + public MessageInterpolator getMessageInterpolator() { + return factory().getMessageInterpolator(); + } + + @Override + public TraversableResolver getTraversableResolver() { + return factory().getTraversableResolver(); + } + + @Override + public ConstraintValidatorFactory getConstraintValidatorFactory() { + return factory().getConstraintValidatorFactory(); + } + + @Override + public T unwrap(Class tClass) { + return factory().unwrap(tClass); + } +} Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WebAppInfo.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WebAppInfo.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WebAppInfo.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WebAppInfo.java Tue May 10 11:19:47 2011 @@ -22,7 +22,7 @@ import java.util.TreeSet; import java.util.List; import java.util.ArrayList; -public class WebAppInfo extends InfoObject { +public class WebAppInfo extends ValidationInfoObject { public String codebase; public String description; public String displayName; Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AnnotationDeployer.java Tue May 10 11:19:47 2011 @@ -142,6 +142,8 @@ import javax.persistence.PersistenceCont import javax.persistence.PersistenceContexts; import javax.persistence.PersistenceUnit; import javax.persistence.PersistenceUnits; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; import javax.xml.ws.Service; import javax.xml.ws.WebServiceProvider; import javax.xml.ws.WebServiceRef; Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/AutoConfig.java Tue May 10 11:19:47 2011 @@ -64,6 +64,8 @@ import static org.apache.openejb.util.Jo import javax.jms.Queue; import javax.jms.Topic; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; import java.io.File; import java.io.IOException; @@ -97,6 +99,9 @@ public class AutoConfig implements Dynam // User transaction is automatically handled ignoredReferenceTypes.add("javax.transaction.UserTransaction"); ignoredReferenceTypes.add("javax.ejb.TimerService"); + // Bean Validation is automatically handled + ignoredReferenceTypes.add(Validator.class.getName()); + ignoredReferenceTypes.add(ValidatorFactory.class.getName()); } private final ConfigurationFactory configFactory; Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ClientModule.java Tue May 10 11:19:47 2011 @@ -30,7 +30,7 @@ import java.io.File; /** * @version $Rev$ $Date$ */ -public class ClientModule implements DeploymentModule { +public class ClientModule extends Module implements DeploymentModule { private final ValidationContext validation; private ApplicationClient applicationClient; private String jarLocation; @@ -40,7 +40,6 @@ public class ClientModule implements Dep private AtomicReference finder; private final Set localClients = new HashSet(); private final Set remoteClients = new HashSet(); - private final Map altDDs = new HashMap(); private final String moduleId; private final Set watchedResources = new TreeSet(); @@ -91,10 +90,6 @@ public class ClientModule implements Dep return moduleId; } - public Map getAltDDs() { - return altDDs; - } - public ApplicationClient getApplicationClient() { return applicationClient; } Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ConnectorModule.java Tue May 10 11:19:47 2011 @@ -30,9 +30,8 @@ import java.net.URL; /** * @version $Rev$ $Date$ */ -public class ConnectorModule implements DeploymentModule { +public class ConnectorModule extends Module implements DeploymentModule { private final ValidationContext validation; - private final Map altDDs = new HashMap(); private Connector connector; private ClassLoader classLoader; @@ -77,10 +76,6 @@ public class ConnectorModule implements return moduleId; } - public Map getAltDDs() { - return altDDs; - } - public Connector getConnector() { return connector; } Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/EjbModule.java Tue May 10 11:19:47 2011 @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.Atomi * Class is intentionally not an interface as that would encourage "smart" implementations * @version $Revision$ $Date$ */ -public class EjbModule implements WsModule { +public class EjbModule extends Module implements WsModule { private final ValidationContext validation; @@ -45,7 +45,6 @@ public class EjbModule implements WsModu private Webservices webservices; private String moduleId; private final AtomicReference finder = new AtomicReference(); - private final Map altDDs = new HashMap(); private final Set watchedResources = new TreeSet(); private ClientModule clientModule; @@ -120,10 +119,6 @@ public class EjbModule implements WsModu return validation; } - public Map getAltDDs() { - return altDDs; - } - public ClassLoader getClassLoader() { return classLoader; } Added: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/Module.java Tue May 10 11:19:47 2011 @@ -0,0 +1,35 @@ +package org.apache.openejb.config; + +import org.apache.openejb.jee.bval.ValidationConfigType; + +import java.util.HashMap; +import java.util.Map; + +public class Module { + private static int currentId = 1; // unique id to be able to bind something for each module in the jndi tree + + private ValidationConfigType validationConfig; + private final Map altDDs = new HashMap(); + + private String uniqueId; + + public Module() { + uniqueId = Integer.toString(currentId++); + } + + public ValidationConfigType getValidationConfig() { + return validationConfig; + } + + public void setValidationConfig(ValidationConfigType v) { + validationConfig = v; + } + + public Map getAltDDs() { + return altDDs; + } + + public String getUniqueId() { + return uniqueId; + } +} Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/ReadDescriptors.java Tue May 10 11:19:47 2011 @@ -16,7 +16,6 @@ */ package org.apache.openejb.config; -import static org.apache.openejb.util.URLs.toFilePath; import org.apache.openejb.OpenEJBException; import org.apache.openejb.core.webservices.WsdlResolver; import org.apache.openejb.jee.ApplicationClient; @@ -25,6 +24,8 @@ import org.apache.openejb.jee.EjbJar; import org.apache.openejb.jee.FacesConfig; import org.apache.openejb.jee.HandlerChains; import org.apache.openejb.jee.JavaWsdlMapping; +import org.apache.openejb.assembler.classic.ValidatorBuilder; +import org.apache.openejb.config.rules.ValidationBase; import org.apache.openejb.jee.JaxbJavaee; import org.apache.openejb.jee.TldTaglib; import org.apache.openejb.jee.WebApp; @@ -57,6 +58,7 @@ import java.io.FileOutputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; +import java.util.ArrayList; import java.net.URL; import java.util.List; @@ -73,19 +75,23 @@ public class ReadDescriptors implements readOpenejbJar(ejbModule); } + readValidationConfigType(ejbModule); readCmpOrm(ejbModule); } for (ClientModule clientModule : appModule.getClientModules()) { readAppClient(clientModule, appModule); + readValidationConfigType(clientModule); } for (ConnectorModule connectorModule : appModule.getResourceModules()) { readConnector(connectorModule, appModule); + readValidationConfigType(connectorModule); } for (WebModule webModule : appModule.getWebModules()) { readWebApp(webModule, appModule); + readValidationConfigType(webModule); } List persistenceUrls = (List) appModule.getAltDDs().get("persistence.xml"); @@ -118,6 +124,16 @@ public class ReadDescriptors implements } + private void readValidationConfigType(Module module) { + if (module.getValidationConfig() != null) { + return; + } + URL url = (URL) module.getAltDDs().get("validation.xml"); + if (url != null) { + module.setValidationConfig(ValidatorBuilder.readConfig(url)); + } + } + private void readOpenejbJar(EjbModule ejbModule) throws OpenEJBException { Source source = getSource(ejbModule.getAltDDs().get("openejb-jar.xml")); Modified: openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java?rev=1101405&r1=1101404&r2=1101405&view=diff ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java (original) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/main/java/org/apache/openejb/config/WebModule.java Tue May 10 11:19:47 2011 @@ -34,9 +34,8 @@ import org.apache.xbean.finder.ClassFind /** * @version $Rev$ $Date$ */ -public class WebModule implements WsModule { +public class WebModule extends Module implements WsModule { private final ValidationContext validation; - private final Map altDDs = new HashMap(); private WebApp webApp; private Webservices webservices; @@ -102,10 +101,6 @@ public class WebModule implements WsModu return moduleId; } - public Map getAltDDs() { - return altDDs; - } - public WebApp getWebApp() { return webApp; } Added: openejb/branches/openejb-3.2.x/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-core/src/test/java/org/apache/openejb/bval/BeanValidationTest.java Tue May 10 11:19:47 2011 @@ -0,0 +1,144 @@ +package org.apache.openejb.bval; + +import org.apache.openejb.jee.EmptyType; +import org.apache.openejb.jee.StatelessBean; +import org.apache.openejb.jee.jpa.unit.Persistence; +import org.apache.openejb.jee.jpa.unit.PersistenceUnit; +import org.apache.openejb.junit.ApplicationComposer; +import org.apache.openejb.junit.Configuration; +import org.apache.openejb.junit.Module; +import org.junit.Test; +import org.junit.runner.RunWith; + +import javax.annotation.Resource; +import javax.ejb.EJB; +import javax.ejb.EJBException; +import javax.ejb.LocalBean; +import javax.ejb.Stateless; +import javax.ejb.TransactionAttribute; +import javax.ejb.TransactionAttributeType; +import javax.naming.InitialContext; +import javax.persistence.Entity; +import javax.persistence.EntityManager; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.PersistenceContext; +import javax.validation.ConstraintViolationException; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.rmi.RemoteException; +import java.util.Properties; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; +import static junit.framework.Assert.assertTrue; +import static junit.framework.Assert.fail; + +/** + * @author Romain Manni-Bucau + */ +@RunWith(ApplicationComposer.class) +public class BeanValidationTest { + @EJB private PersistManager persistManager; + @Resource private Validator validator; + @Resource private ValidatorFactory validatorFactory; + + @Configuration public Properties config() { + final Properties p = new Properties(); + p.put("bvalDatabase", "new://Resource?type=DataSource"); + p.put("bvalDatabase.JdbcDriver", "org.hsqldb.jdbcDriver"); + p.put("bvalDatabase.JdbcUrl", "jdbc:hsqldb:mem:bval"); + return p; + } + + @Module public StatelessBean app() throws Exception { + final StatelessBean bean = new StatelessBean(PersistManager.class); + bean.setLocalBean(new EmptyType()); + return bean; + } + + @Module public Persistence persistence() { + PersistenceUnit unit = new PersistenceUnit("foo-unit"); + unit.addClass(EntityToValidate.class); + unit.setProperty("openjpa.jdbc.SynchronizeMappings", "buildSchema(ForeignKeys=true)"); + unit.getProperties().setProperty("openjpa.RuntimeUnenhancedClasses", "supported"); + unit.setExcludeUnlistedClasses(true); + + Persistence persistence = new Persistence(unit); + persistence.setVersion("2.0"); + return persistence; + } + + @LocalBean + @Stateless + public static class PersistManager { + @PersistenceContext private EntityManager em; + + public void persistValid() { + EntityToValidate entity = new EntityToValidate(); + entity.setName("name"); + em.persist(entity); + } + + public void persistNotValid() { + em.persist(new EntityToValidate()); + } + } + + @Entity + public static class EntityToValidate { + @Id @GeneratedValue private long id; + @NotNull @Size(min = 1, max = 5) private String name; + + public long getId() { + return id; + } + + public void setId(long i) { + id = i; + } + + public String getName() { + return name; + } + + public void setName(String n) { + name = n; + } + } + + @Test public void valid() { + persistManager.persistValid(); + } + + @Test public void notValid() { + try { + persistManager.persistNotValid(); + fail(); + } catch (Exception wrappingException) { + assertTrue(wrappingException.getCause() instanceof ConstraintViolationException); + ConstraintViolationException constraintViolationException = (ConstraintViolationException) wrappingException.getCause(); + assertEquals(1, constraintViolationException.getConstraintViolations().size()); + } + } + + @Test public void lookupValidatorFactory() throws Exception { + ValidatorFactory validatorFactory = (ValidatorFactory) new InitialContext().lookup("java:comp/ValidatorFactory"); + assertNotNull(validatorFactory); + } + + @Test public void lookupValidator() throws Exception { + Validator validator = (Validator) new InitialContext().lookup("java:comp/Validator"); + assertNotNull(validator); + } + + @Test public void injectionValidatorFactory() { + assertNotNull(validatorFactory); + } + + @Test public void injectionValidator() { + assertNotNull(validator); + } +} Added: openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/AnnotationType.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/AnnotationType.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/AnnotationType.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/AnnotationType.java Tue May 10 11:19:47 2011 @@ -0,0 +1,66 @@ +package org.apache.openejb.jee.bval; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for annotationType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="annotationType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="element" type="{http://jboss.org/xml/ns/javax/validation/mapping}elementType" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "annotationType", propOrder = { + "element" +}) +public class AnnotationType { + + protected List element; + + /** + * Gets the value of the element property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the element property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getElement().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link ElementType } + * + * + */ + public List getElement() { + if (element == null) { + element = new ArrayList(); + } + return this.element; + } + +} Added: openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/BeanType.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/BeanType.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/BeanType.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/BeanType.java Tue May 10 11:19:47 2011 @@ -0,0 +1,185 @@ +package org.apache.openejb.jee.bval; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + + +/** + *

Java class for beanType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="beanType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="class" type="{http://jboss.org/xml/ns/javax/validation/mapping}classType" minOccurs="0"/>
+ *         <element name="field" type="{http://jboss.org/xml/ns/javax/validation/mapping}fieldType" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element name="getter" type="{http://jboss.org/xml/ns/javax/validation/mapping}getterType" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="class" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       <attribute name="ignore-annotations" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "beanType", propOrder = { + "classType", + "field", + "getter" +}) +public class BeanType { + + @XmlElement(name = "class") + protected ClassType classType; + protected List field; + protected List getter; + @XmlAttribute(name = "class", required = true) + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + protected String clazz; + @XmlAttribute(name = "ignore-annotations") + protected Boolean ignoreAnnotations; + + /** + * Gets the value of the classType property. + * + * @return + * possible object is + * {@link ClassType } + * + */ + public ClassType getClassType() { + return classType; + } + + /** + * Sets the value of the classType property. + * + * @param value + * allowed object is + * {@link ClassType } + * + */ + public void setClassType(ClassType value) { + this.classType = value; + } + + /** + * Gets the value of the field property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the field property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getField().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link FieldType } + * + * + */ + public List getField() { + if (field == null) { + field = new ArrayList(); + } + return this.field; + } + + /** + * Gets the value of the getter property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the getter property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getGetter().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link GetterType } + * + * + */ + public List getGetter() { + if (getter == null) { + getter = new ArrayList(); + } + return this.getter; + } + + /** + * Gets the value of the clazz property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getClazz() { + return clazz; + } + + /** + * Sets the value of the clazz property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setClazz(String value) { + this.clazz = value; + } + + /** + * Gets the value of the ignoreAnnotations property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isIgnoreAnnotations() { + return ignoreAnnotations; + } + + /** + * Sets the value of the ignoreAnnotations property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setIgnoreAnnotations(Boolean value) { + this.ignoreAnnotations = value; + } + +} Added: openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ClassType.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ClassType.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ClassType.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ClassType.java Tue May 10 11:19:47 2011 @@ -0,0 +1,123 @@ +package org.apache.openejb.jee.bval; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; + + +/** + *

Java class for classType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="classType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="group-sequence" type="{http://jboss.org/xml/ns/javax/validation/mapping}groupSequenceType" minOccurs="0"/>
+ *         <element name="constraint" type="{http://jboss.org/xml/ns/javax/validation/mapping}constraintType" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *       <attribute name="ignore-annotations" type="{http://www.w3.org/2001/XMLSchema}boolean" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "classType", propOrder = { + "groupSequence", + "constraint" +}) +public class ClassType { + + @XmlElement(name = "group-sequence") + protected GroupSequenceType groupSequence; + protected List constraint; + @XmlAttribute(name = "ignore-annotations") + protected Boolean ignoreAnnotations; + + /** + * Gets the value of the groupSequence property. + * + * @return + * possible object is + * {@link GroupSequenceType } + * + */ + public GroupSequenceType getGroupSequence() { + return groupSequence; + } + + /** + * Sets the value of the groupSequence property. + * + * @param value + * allowed object is + * {@link GroupSequenceType } + * + */ + public void setGroupSequence(GroupSequenceType value) { + this.groupSequence = value; + } + + /** + * Gets the value of the constraint property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the constraint property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getConstraint().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link ConstraintType } + * + * + */ + public List getConstraint() { + if (constraint == null) { + constraint = new ArrayList(); + } + return this.constraint; + } + + /** + * Gets the value of the ignoreAnnotations property. + * + * @return + * possible object is + * {@link Boolean } + * + */ + public Boolean isIgnoreAnnotations() { + return ignoreAnnotations; + } + + /** + * Sets the value of the ignoreAnnotations property. + * + * @param value + * allowed object is + * {@link Boolean } + * + */ + public void setIgnoreAnnotations(Boolean value) { + this.ignoreAnnotations = value; + } + +} Added: openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintDefinitionType.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintDefinitionType.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintDefinitionType.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintDefinitionType.java Tue May 10 11:19:47 2011 @@ -0,0 +1,92 @@ +package org.apache.openejb.jee.bval; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + + +/** + *

Java class for constraint-definitionType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="constraint-definitionType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="validated-by" type="{http://jboss.org/xml/ns/javax/validation/mapping}validated-byType"/>
+ *       </sequence>
+ *       <attribute name="annotation" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "constraint-definitionType", propOrder = { + "validatedBy" +}) +public class ConstraintDefinitionType { + + @XmlElement(name = "validated-by", required = true) + protected ValidatedByType validatedBy; + @XmlAttribute(required = true) + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + protected String annotation; + + /** + * Gets the value of the validatedBy property. + * + * @return + * possible object is + * {@link ValidatedByType } + * + */ + public ValidatedByType getValidatedBy() { + return validatedBy; + } + + /** + * Sets the value of the validatedBy property. + * + * @param value + * allowed object is + * {@link ValidatedByType } + * + */ + public void setValidatedBy(ValidatedByType value) { + this.validatedBy = value; + } + + /** + * Gets the value of the annotation property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getAnnotation() { + return annotation; + } + + /** + * Sets the value of the annotation property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setAnnotation(String value) { + this.annotation = value; + } + +} Added: openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintMappingsType.java URL: http://svn.apache.org/viewvc/openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintMappingsType.java?rev=1101405&view=auto ============================================================================== --- openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintMappingsType.java (added) +++ openejb/branches/openejb-3.2.x/container/openejb-jee/src/main/java/org/apache/openejb/jee/bval/ConstraintMappingsType.java Tue May 10 11:19:47 2011 @@ -0,0 +1,131 @@ +package org.apache.openejb.jee.bval; + +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlType; +import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; +import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; + + +/** + *

Java class for constraint-mappingsType complex type. + * + *

The following schema fragment specifies the expected content contained within this class. + * + *

+ * <complexType name="constraint-mappingsType">
+ *   <complexContent>
+ *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       <sequence>
+ *         <element name="default-package" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
+ *         <element name="bean" type="{http://jboss.org/xml/ns/javax/validation/mapping}beanType" maxOccurs="unbounded" minOccurs="0"/>
+ *         <element name="constraint-definition" type="{http://jboss.org/xml/ns/javax/validation/mapping}constraint-definitionType" maxOccurs="unbounded" minOccurs="0"/>
+ *       </sequence>
+ *     </restriction>
+ *   </complexContent>
+ * </complexType>
+ * 
+ * + * + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "constraint-mappingsType", propOrder = { + "defaultPackage", + "bean", + "constraintDefinition" +}) +public class ConstraintMappingsType { + @XmlElement(name = "default-package") + @XmlJavaTypeAdapter(CollapsedStringAdapter.class) + protected String defaultPackage; + protected List bean; + @XmlElement(name = "constraint-definition") + protected List constraintDefinition; + + /** + * Gets the value of the defaultPackage property. + * + * @return + * possible object is + * {@link String } + * + */ + public String getDefaultPackage() { + return defaultPackage; + } + + /** + * Sets the value of the defaultPackage property. + * + * @param value + * allowed object is + * {@link String } + * + */ + public void setDefaultPackage(String value) { + this.defaultPackage = value; + } + + /** + * Gets the value of the bean property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the bean property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getBean().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link BeanType } + * + * + */ + public List getBean() { + if (bean == null) { + bean = new ArrayList(); + } + return this.bean; + } + + /** + * Gets the value of the constraintDefinition property. + * + *

+ * This accessor method returns a reference to the live list, + * not a snapshot. Therefore any modification you make to the + * returned list will be present inside the JAXB object. + * This is why there is not a set method for the constraintDefinition property. + * + *

+ * For example, to add a new item, do as follows: + *

+     *    getConstraintDefinition().add(newItem);
+     * 
+ * + * + *

+ * Objects of the following type(s) are allowed in the list + * {@link ConstraintDefinitionType } + * + * + */ + public List getConstraintDefinition() { + if (constraintDefinition == null) { + constraintDefinition = new ArrayList(); + } + return this.constraintDefinition; + } + +} +