geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r1005848 - in /geronimo/components/txmanager/trunk: ./ geronimo-connector/ geronimo-connector/src/main/java/org/apache/geronimo/connector/
Date Fri, 08 Oct 2010 14:44:55 GMT
Author: rickmcguire
Date: Fri Oct  8 14:44:55 2010
New Revision: 1005848

URL: http://svn.apache.org/viewvc?rev=1005848&view=rev
Log:
GERONIMO-5230 Add Bean Validation Support to the connector 1.6 implementation. 

Changes to the connector component to support validation. 


Added:
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/AdminObjectWrapper.java
  (with props)
Modified:
    geronimo/components/txmanager/trunk/geronimo-connector/pom.xml
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ActivationSpecWrapper.java
    geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java
    geronimo/components/txmanager/trunk/pom.xml

Modified: geronimo/components/txmanager/trunk/geronimo-connector/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/pom.xml?rev=1005848&r1=1005847&r2=1005848&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/pom.xml (original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/pom.xml Fri Oct  8 14:44:55 2010
@@ -60,6 +60,11 @@
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-j2ee-connector_1.6_spec</artifactId>
         </dependency>
+            
+        <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-validation_1.0_spec</artifactId>
+        </dependency>
 
         <dependency>
             <groupId>junit</groupId>

Modified: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ActivationSpecWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ActivationSpecWrapper.java?rev=1005848&r1=1005847&r2=1005848&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ActivationSpecWrapper.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ActivationSpecWrapper.java
Fri Oct  8 14:44:55 2010
@@ -17,10 +17,17 @@
 
 package org.apache.geronimo.connector;
 
+import java.util.Set; 
+
 import javax.resource.ResourceException;
 import javax.resource.spi.ActivationSpec;
 import javax.resource.spi.ResourceAdapter;
+import javax.resource.spi.InvalidPropertyException; 
 import javax.resource.spi.endpoint.MessageEndpointFactory;
+import javax.validation.ConstraintViolation; 
+import javax.validation.ConstraintViolationException; 
+import javax.validation.Validator; 
+import javax.validation.ValidatorFactory; 
 
 /**
  * Wrapper for ActivationSpec instances.
@@ -35,6 +42,9 @@ public class ActivationSpecWrapper {
 
     private final ResourceAdapterWrapper resourceAdapterWrapper;
     private final String containerId;
+    private final ValidatorFactory validatorFactory; 
+    // indicates we've validated the spec on the first usage. 
+    private boolean validated = false; 
 
     /**
      * Default constructor required when a class is used as a GBean Endpoint.
@@ -43,6 +53,8 @@ public class ActivationSpecWrapper {
         activationSpec = null;
         containerId = null;
         resourceAdapterWrapper = null;
+        validatorFactory = null; 
+        validated = false; 
     }
 
     /**
@@ -55,19 +67,24 @@ public class ActivationSpecWrapper {
     public ActivationSpecWrapper(final String activationSpecClass,
                                  final String containerId,
                                  final ResourceAdapterWrapper resourceAdapterWrapper,
-                                 final ClassLoader cl) throws IllegalAccessException, InstantiationException,
ClassNotFoundException {
+                                 final ClassLoader cl, 
+                                 final ValidatorFactory validatorFactory) throws IllegalAccessException,
InstantiationException, ClassNotFoundException {
         Class clazz = cl.loadClass(activationSpecClass);
         this.activationSpec = (ActivationSpec) clazz.newInstance();
         this.containerId = containerId;
         this.resourceAdapterWrapper = resourceAdapterWrapper;
+        this.validatorFactory = validatorFactory; 
+        this.validated = false; 
     }
 
     /**
      */
-    public ActivationSpecWrapper(ActivationSpec activationSpec, ResourceAdapterWrapper resourceAdapterWrapper)
 {
+    public ActivationSpecWrapper(ActivationSpec activationSpec, ResourceAdapterWrapper resourceAdapterWrapper,
ValidatorFactory validatorFactory)  {
         this.activationSpec = activationSpec;
         this.resourceAdapterWrapper = resourceAdapterWrapper;
         this.containerId = null;
+        this.validatorFactory = validatorFactory; 
+        this.validated = false; 
     }
 
     /**
@@ -90,6 +107,8 @@ public class ActivationSpecWrapper {
 
     //GBeanLifecycle implementation
     public void activate(final MessageEndpointFactory messageEndpointFactory) throws ResourceException
{
+        checkConstraints(activationSpec);
+        
         ResourceAdapter resourceAdapter = activationSpec.getResourceAdapter();
         if (resourceAdapter == null) {
             resourceAdapterWrapper.registerResourceAdapterAssociation(activationSpec);
@@ -108,5 +127,33 @@ public class ActivationSpecWrapper {
             throw new IllegalStateException("ActivationSpec was never registered with ResourceAdapter");
         }
     }
-
+    
+    /**
+     * Validate an ActivationSpec instance on the first usage. 
+     * 
+     * @param spec   The spec instance to validate.
+     */
+    private void checkConstraints(ActivationSpec spec) throws InvalidPropertyException {
+        if (!validated) {
+            // There are two potential validations, self validation via the 
+            // validate() method and container-driven validation using bean validation. 
+            try {
+                spec.validate();
+            } catch (UnsupportedOperationException uoe) {
+                // ignore if not implemented. 
+            }
+
+            // if we have a validator factory at this point, then validate 
+            // the resource adaptor instance 
+            if (validatorFactory != null) {
+                Validator validator = validatorFactory.getValidator(); 
+
+                Set generalSet = validator.validate(spec);
+                if (!generalSet.isEmpty()) {
+                    throw new ConstraintViolationException("Constraint violation for ActitvationSpec",
generalSet); 
+                }
+            }
+            validated = true; 
+        }
+    }
 }

Added: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/AdminObjectWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/AdminObjectWrapper.java?rev=1005848&view=auto
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/AdminObjectWrapper.java
(added)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/AdminObjectWrapper.java
Fri Oct  8 14:44:55 2010
@@ -0,0 +1,115 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.geronimo.connector;
+
+import java.util.Set; 
+
+import javax.resource.spi.ResourceAdapterAssociation;
+import javax.validation.ConstraintViolation; 
+import javax.validation.ConstraintViolationException; 
+import javax.validation.Validator; 
+import javax.validation.ValidatorFactory; 
+
+
+/**
+ * Wrapper around AdminObject that manages the AdminObject lifecycle. 
+ *
+ * @version $Rev$ $Date$
+ */
+public class AdminObjectWrapper {
+
+    private final String adminObjectInterface;
+    private final String adminObjectClass;
+    protected ResourceAdapterWrapper resourceAdapterWrapper;
+    
+    protected Object adminObject;
+    private final ValidatorFactory validatorFactory; 
+
+    /**
+     * Normal managed constructor.
+     *
+     * @param adminObjectInterface Interface the proxy will implement.
+     * @param adminObjectClass Class of admin object to be wrapped.
+     * @throws IllegalAccessException
+     * @throws InstantiationException
+     */
+    public AdminObjectWrapper(final String adminObjectInterface,
+                              final String adminObjectClass,
+                              final ResourceAdapterWrapper resourceAdapterWrapper,
+                              final ClassLoader cl,
+                              final ValidatorFactory validatorFactory) throws IllegalAccessException,
InstantiationException, ClassNotFoundException {
+        this.adminObjectInterface = adminObjectInterface;
+        this.adminObjectClass = adminObjectClass;
+        this.resourceAdapterWrapper = resourceAdapterWrapper;
+        this.validatorFactory = validatorFactory; 
+        Class clazz = cl.loadClass(adminObjectClass);
+        adminObject = clazz.newInstance();
+    }
+
+    public String getAdminObjectInterface() {
+        return adminObjectInterface;
+    }
+
+    /**
+     * Returns class of wrapped AdminObject.
+     * @return class of wrapped AdminObject
+     */
+    public String getAdminObjectClass() {
+        return adminObjectClass;
+    }
+
+
+    /**
+     * Starts the AdminObject.  This will validate the instance and register the object instance
          
+     * with its ResourceAdapter
+     *
+     * @throws Exception if the target failed to start; this will cause a transition to the
failed state
+     */
+    public void doStart() throws Exception {
+        // if we have a validator factory at this point, then validate 
+        // the resource adaptor instance 
+        if (validatorFactory != null) {
+            Validator validator = validatorFactory.getValidator(); 
+            
+            Set generalSet = validator.validate(adminObject);
+            if (!generalSet.isEmpty()) {
+                throw new ConstraintViolationException("Constraint violation for AdminObject
" + adminObjectClass, generalSet); 
+            }
+        }
+        if (adminObject instanceof ResourceAdapterAssociation) {
+            if (resourceAdapterWrapper == null) {
+                throw new IllegalStateException("Admin object expects to be registered with
a ResourceAdapter, but there is no ResourceAdapter");
+            }
+            resourceAdapterWrapper.registerResourceAdapterAssociation((ResourceAdapterAssociation)
adminObject);
+        }
+    }
+
+    /**
+     * Stops the target.  This is a NOP for AdminObjects
+     *
+     * @throws Exception if the target failed to stop; this will cause a transition to the
failed state
+     */
+    public void doStop() throws Exception {
+    }
+
+    /**
+     * Fails the target.  This is a nop for an AdminObject. 
+     */
+    public void doFail() {
+    }
+}

Propchange: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/AdminObjectWrapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/AdminObjectWrapper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/AdminObjectWrapper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java?rev=1005848&r1=1005847&r2=1005848&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java
(original)
+++ geronimo/components/txmanager/trunk/geronimo-connector/src/main/java/org/apache/geronimo/connector/ResourceAdapterWrapper.java
Fri Oct  8 14:44:55 2010
@@ -18,6 +18,7 @@
 package org.apache.geronimo.connector;
 
 import java.util.Map;
+import java.util.Set;
 
 import javax.resource.ResourceException;
 import javax.resource.spi.ActivationSpec;
@@ -28,6 +29,10 @@ import javax.resource.spi.ResourceAdapte
 import javax.resource.spi.endpoint.MessageEndpointFactory;
 import javax.transaction.SystemException;
 import javax.transaction.xa.XAResource;
+import javax.validation.ConstraintViolation; 
+import javax.validation.ConstraintViolationException; 
+import javax.validation.Validator; 
+import javax.validation.ValidatorFactory; 
 
 import org.apache.geronimo.transaction.manager.NamedXAResource;
 import org.apache.geronimo.transaction.manager.NamedXAResourceFactory;
@@ -53,6 +58,8 @@ public class ResourceAdapterWrapper impl
     private final Map<String,String> messageListenerToActivationSpecMap;
 
     private final RecoverableTransactionManager transactionManager;
+    
+    private final ValidatorFactory validatorFactory; 
 
 
     /**
@@ -65,6 +72,7 @@ public class ResourceAdapterWrapper impl
         this.resourceAdapter = null;
         this.messageListenerToActivationSpecMap = null;
         this.transactionManager = null;
+        this.validatorFactory = null; 
     }
 
     public ResourceAdapterWrapper(String name,
@@ -72,7 +80,8 @@ public class ResourceAdapterWrapper impl
             Map<String, String> messageListenerToActivationSpecMap,
             BootstrapContext bootstrapContext,
             RecoverableTransactionManager transactionManager,
-            ClassLoader cl) throws InstantiationException, IllegalAccessException, ClassNotFoundException
{
+            ClassLoader cl, 
+            ValidatorFactory validatorFactory) throws InstantiationException, IllegalAccessException,
ClassNotFoundException {
         this.name = name;
         this.resourceAdapterClass = resourceAdapterClass;
         this.bootstrapContext = bootstrapContext;
@@ -80,15 +89,17 @@ public class ResourceAdapterWrapper impl
         resourceAdapter = (ResourceAdapter) clazz.newInstance();
         this.messageListenerToActivationSpecMap = messageListenerToActivationSpecMap;
         this.transactionManager = transactionManager;
+        this.validatorFactory = validatorFactory; 
     }
     
-    public ResourceAdapterWrapper(String name, ResourceAdapter resourceAdapter, Map<String,
String> messageListenerToActivationSpecMap, BootstrapContext bootstrapContext, RecoverableTransactionManager
transactionManager) {
+    public ResourceAdapterWrapper(String name, ResourceAdapter resourceAdapter, Map<String,
String> messageListenerToActivationSpecMap, BootstrapContext bootstrapContext, RecoverableTransactionManager
transactionManager, ValidatorFactory validatorFactory) {
         this.name = name;
         this.resourceAdapterClass = resourceAdapter.getClass().getName();
         this.bootstrapContext = bootstrapContext;
         this.resourceAdapter = resourceAdapter;
         this.messageListenerToActivationSpecMap = messageListenerToActivationSpecMap;
         this.transactionManager = transactionManager;
+        this.validatorFactory = validatorFactory; 
     }
 
     public String getName() {
@@ -141,6 +152,16 @@ public class ResourceAdapterWrapper impl
     }
 
     public void doStart() throws Exception {
+        // if we have a validator factory at this point, then validate 
+        // the resource adaptor instance 
+        if (validatorFactory != null) {
+            Validator validator = validatorFactory.getValidator(); 
+            
+            Set generalSet = validator.validate(resourceAdapter);
+            if (!generalSet.isEmpty()) {
+                throw new ConstraintViolationException("Constraint violation for ResourceAdapter
" + resourceAdapterClass, generalSet); 
+            }
+        }
         resourceAdapter.start(bootstrapContext);
     }
 

Modified: geronimo/components/txmanager/trunk/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/components/txmanager/trunk/pom.xml?rev=1005848&r1=1005847&r2=1005848&view=diff
==============================================================================
--- geronimo/components/txmanager/trunk/pom.xml (original)
+++ geronimo/components/txmanager/trunk/pom.xml Fri Oct  8 14:44:55 2010
@@ -89,6 +89,12 @@
                 <artifactId>geronimo-j2ee-connector_1.6_spec</artifactId>
                 <version>1.0</version>
             </dependency>
+                
+            <dependency>
+                <groupId>org.apache.geronimo.specs</groupId>
+                <artifactId>geronimo-validation_1.0_spec</artifactId>
+                <version>1.1</version>
+            </dependency>
 
             <dependency>
                 <groupId>org.objectweb.howl</groupId>



Mime
View raw message