[jboss-cvs] JBossAS SVN: r97749 - in projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator: rules and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Dec 11 14:05:54 EST 2009


Author: jesper.pedersen
Date: 2009-12-11 14:05:54 -0500 (Fri, 11 Dec 2009)
New Revision: 97749

Added:
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/AOConfigProperties.java
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/package.html
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/ASConfigProperties.java
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/package.html
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/mcf/MCFConfigProperties.java
Modified:
   projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Validator.java
Log:
[JBJCA-201] Add some config-property rules

Modified: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Validator.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Validator.java	2009-12-11 18:04:13 UTC (rev 97748)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/Validator.java	2009-12-11 19:05:54 UTC (rev 97749)
@@ -41,6 +41,7 @@
       "org.jboss.jca.deployers.common.validator.rules.mcf.MCF",
       "org.jboss.jca.deployers.common.validator.rules.mcf.MCFHashCode",
       "org.jboss.jca.deployers.common.validator.rules.mcf.MCFEquals",
+      "org.jboss.jca.deployers.common.validator.rules.mcf.MCFConfigProperties",
       "org.jboss.jca.deployers.common.validator.rules.mc.MC",
       "org.jboss.jca.deployers.common.validator.rules.mc.MCGetMetaData",
       "org.jboss.jca.deployers.common.validator.rules.ra.RANull",
@@ -50,7 +51,9 @@
       "org.jboss.jca.deployers.common.validator.rules.ra.RAConfigProperties",
       "org.jboss.jca.deployers.common.validator.rules.cf.CFNull",
       "org.jboss.jca.deployers.common.validator.rules.cf.CFSerializable",
-      "org.jboss.jca.deployers.common.validator.rules.cf.CFReferenceable"
+      "org.jboss.jca.deployers.common.validator.rules.cf.CFReferenceable",
+      "org.jboss.jca.deployers.common.validator.rules.as.ASConfigProperties",
+      "org.jboss.jca.deployers.common.validator.rules.ao.AOConfigProperties"
    };
 
    /**

Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/AOConfigProperties.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/AOConfigProperties.java	                        (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/AOConfigProperties.java	2009-12-11 19:05:54 UTC (rev 97749)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.common.validator.rules.ao;
+
+import org.jboss.jca.deployers.common.validator.Failure;
+import org.jboss.jca.deployers.common.validator.Key;
+import org.jboss.jca.deployers.common.validator.Rule;
+import org.jboss.jca.deployers.common.validator.Severity;
+import org.jboss.jca.deployers.common.validator.ValidateObject;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
+
+/**
+ * An AdminObject must use the valid set of config-property-type
+ */
+public class AOConfigProperties implements Rule
+{
+   /** Section */
+   private static final String SECTION = "20.7";
+
+   /** Valid types */
+   private static final Set<Class> VALID_TYPES;
+
+   static
+   {
+      VALID_TYPES = new HashSet<Class>(9);
+
+      VALID_TYPES.add(Boolean.class);
+      VALID_TYPES.add(Byte.class);
+      VALID_TYPES.add(Character.class);
+      VALID_TYPES.add(Double.class);
+      VALID_TYPES.add(Float.class);
+      VALID_TYPES.add(Integer.class);
+      VALID_TYPES.add(Long.class);
+      VALID_TYPES.add(Short.class);
+      VALID_TYPES.add(String.class);
+   }
+
+   /**
+    * Constructor
+    */
+   public AOConfigProperties()
+   {
+   }
+
+   /**
+    * Validate
+    * @param vo The validate object
+    * @param rb The resource bundle 
+    * @return The list of failures found; <code>null</code> if none
+    */
+   @SuppressWarnings("unchecked")
+   public List<Failure> validate(ValidateObject vo, ResourceBundle rb)
+   {
+      if (vo != null && 
+          Key.ADMIN_OBJECT == vo.getKey() &&
+          vo.getObject() != null)
+      {
+         if (vo.getConfigProperties() != null && vo.getConfigProperties().size() > 0)
+         {
+            Class clz = vo.getObject().getClass();
+            List<Failure> failures = new ArrayList<Failure>(1);
+
+            for (ConfigPropertyMetaData cpmd : vo.getConfigProperties())
+            {
+               try
+               {
+                  String methodName = "get" + cpmd.getName().substring(0, 1).toUpperCase(Locale.US);
+                  if (cpmd.getName().length() > 1)
+                  {
+                     methodName += cpmd.getName().substring(1);
+                  }
+
+                  Method method = clz.getMethod(methodName, (Class[])null);
+
+                  if (!VALID_TYPES.contains(method.getReturnType()))
+                  {
+                     StringBuilder sb = new StringBuilder("Class: " + vo.getObject().getClass().getName());
+                     sb = sb.append(" Property: " + cpmd.getName());
+                     sb = sb.append(" Type: " + method.getReturnType().getName());
+
+                     Failure failure = new Failure(Severity.WARNING,
+                                                   SECTION,
+                                                   rb.getString("ao.AOConfigProperties"),
+                                                   sb.toString());
+                     failures.add(failure);
+                  }
+               }
+               catch (Throwable t)
+               {
+                  try
+                  {
+                     String methodName = "is" + cpmd.getName().substring(0, 1).toUpperCase(Locale.US);
+                     if (cpmd.getName().length() > 1)
+                     {
+                        methodName += cpmd.getName().substring(1);
+                     }
+                     
+                     Method method = clz.getMethod(methodName, (Class[])null);
+
+                     if (!VALID_TYPES.contains(method.getReturnType()))
+                     {
+                        StringBuilder sb = new StringBuilder("Class: " + vo.getObject().getClass().getName());
+                        sb = sb.append(" Property: " + cpmd.getName());
+                        sb = sb.append(" Type: " + method.getReturnType().getName());
+
+                        Failure failure = new Failure(Severity.WARNING,
+                                                      SECTION,
+                                                      rb.getString("ao.AOConfigProperties"),
+                                                      sb.toString());
+                        failures.add(failure);
+                     }
+                  }
+                  catch (Throwable it)
+                  {
+                     // Ignore
+                  }
+               }
+            }
+
+            if (failures.size() == 0)
+               return null;
+
+            return failures;
+         }
+      }
+
+      return null;
+   }
+}

Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/package.html
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/ao/package.html	2009-12-11 19:05:54 UTC (rev 97749)
@@ -0,0 +1,3 @@
+<body>
+Rules for AdminObjects.
+</body>

Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/ASConfigProperties.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/ASConfigProperties.java	                        (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/ASConfigProperties.java	2009-12-11 19:05:54 UTC (rev 97749)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.common.validator.rules.as;
+
+import org.jboss.jca.deployers.common.validator.Failure;
+import org.jboss.jca.deployers.common.validator.Key;
+import org.jboss.jca.deployers.common.validator.Rule;
+import org.jboss.jca.deployers.common.validator.Severity;
+import org.jboss.jca.deployers.common.validator.ValidateObject;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.resource.spi.ActivationSpec;
+
+import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
+
+/**
+ * An ActivationSpec must use the valid set of config-property-type
+ */
+public class ASConfigProperties implements Rule
+{
+   /** Section */
+   private static final String SECTION = "20.7";
+
+   /** Valid types */
+   private static final Set<Class> VALID_TYPES;
+
+   static
+   {
+      VALID_TYPES = new HashSet<Class>(9);
+
+      VALID_TYPES.add(Boolean.class);
+      VALID_TYPES.add(Byte.class);
+      VALID_TYPES.add(Character.class);
+      VALID_TYPES.add(Double.class);
+      VALID_TYPES.add(Float.class);
+      VALID_TYPES.add(Integer.class);
+      VALID_TYPES.add(Long.class);
+      VALID_TYPES.add(Short.class);
+      VALID_TYPES.add(String.class);
+   }
+
+   /**
+    * Constructor
+    */
+   public ASConfigProperties()
+   {
+   }
+
+   /**
+    * Validate
+    * @param vo The validate object
+    * @param rb The resource bundle 
+    * @return The list of failures found; <code>null</code> if none
+    */
+   @SuppressWarnings("unchecked")
+   public List<Failure> validate(ValidateObject vo, ResourceBundle rb)
+   {
+      if (vo != null && 
+          Key.ACTIVATION_SPEC == vo.getKey() &&
+          vo.getObject() != null &&
+          vo.getObject() instanceof ActivationSpec)
+      {
+         if (vo.getConfigProperties() != null && vo.getConfigProperties().size() > 0)
+         {
+            Class clz = vo.getObject().getClass();
+            List<Failure> failures = new ArrayList<Failure>(1);
+
+            for (ConfigPropertyMetaData cpmd : vo.getConfigProperties())
+            {
+               try
+               {
+                  String methodName = "get" + cpmd.getName().substring(0, 1).toUpperCase(Locale.US);
+                  if (cpmd.getName().length() > 1)
+                  {
+                     methodName += cpmd.getName().substring(1);
+                  }
+
+                  Method method = clz.getMethod(methodName, (Class[])null);
+
+                  if (!VALID_TYPES.contains(method.getReturnType()))
+                  {
+                     StringBuilder sb = new StringBuilder("Class: " + vo.getObject().getClass().getName());
+                     sb = sb.append(" Property: " + cpmd.getName());
+                     sb = sb.append(" Type: " + method.getReturnType().getName());
+
+                     Failure failure = new Failure(Severity.WARNING,
+                                                   SECTION,
+                                                   rb.getString("as.ASConfigProperties"),
+                                                   sb.toString());
+                     failures.add(failure);
+                  }
+               }
+               catch (Throwable t)
+               {
+                  try
+                  {
+                     String methodName = "is" + cpmd.getName().substring(0, 1).toUpperCase(Locale.US);
+                     if (cpmd.getName().length() > 1)
+                     {
+                        methodName += cpmd.getName().substring(1);
+                     }
+                     
+                     Method method = clz.getMethod(methodName, (Class[])null);
+
+                     if (!VALID_TYPES.contains(method.getReturnType()))
+                     {
+                        StringBuilder sb = new StringBuilder("Class: " + vo.getObject().getClass().getName());
+                        sb = sb.append(" Property: " + cpmd.getName());
+                        sb = sb.append(" Type: " + method.getReturnType().getName());
+
+                        Failure failure = new Failure(Severity.WARNING,
+                                                      SECTION,
+                                                      rb.getString("as.ASConfigProperties"),
+                                                      sb.toString());
+                        failures.add(failure);
+                     }
+                  }
+                  catch (Throwable it)
+                  {
+                     // Ignore
+                  }
+               }
+            }
+
+            if (failures.size() == 0)
+               return null;
+
+            return failures;
+         }
+      }
+
+      return null;
+   }
+}

Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/package.html
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/package.html	                        (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/as/package.html	2009-12-11 19:05:54 UTC (rev 97749)
@@ -0,0 +1,3 @@
+<body>
+Rules for ActivationSpecs.
+</body>

Added: projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/mcf/MCFConfigProperties.java
===================================================================
--- projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/mcf/MCFConfigProperties.java	                        (rev 0)
+++ projects/jboss-jca/trunk/deployers/src/main/java/org/jboss/jca/deployers/common/validator/rules/mcf/MCFConfigProperties.java	2009-12-11 19:05:54 UTC (rev 97749)
@@ -0,0 +1,161 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008-2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.jca.deployers.common.validator.rules.mcf;
+
+import org.jboss.jca.deployers.common.validator.Failure;
+import org.jboss.jca.deployers.common.validator.Key;
+import org.jboss.jca.deployers.common.validator.Rule;
+import org.jboss.jca.deployers.common.validator.Severity;
+import org.jboss.jca.deployers.common.validator.ValidateObject;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.Set;
+
+import javax.resource.spi.ManagedConnectionFactory;
+
+import org.jboss.metadata.rar.spec.ConfigPropertyMetaData;
+
+/**
+ * A ManagedConnectionFactory must use the valid set of config-property-type
+ */
+public class MCFConfigProperties implements Rule
+{
+   /** Section */
+   private static final String SECTION = "20.7";
+
+   /** Valid types */
+   private static final Set<Class> VALID_TYPES;
+
+   static
+   {
+      VALID_TYPES = new HashSet<Class>(9);
+
+      VALID_TYPES.add(Boolean.class);
+      VALID_TYPES.add(Byte.class);
+      VALID_TYPES.add(Character.class);
+      VALID_TYPES.add(Double.class);
+      VALID_TYPES.add(Float.class);
+      VALID_TYPES.add(Integer.class);
+      VALID_TYPES.add(Long.class);
+      VALID_TYPES.add(Short.class);
+      VALID_TYPES.add(String.class);
+   }
+
+   /**
+    * Constructor
+    */
+   public MCFConfigProperties()
+   {
+   }
+
+   /**
+    * Validate
+    * @param vo The validate object
+    * @param rb The resource bundle 
+    * @return The list of failures found; <code>null</code> if none
+    */
+   @SuppressWarnings("unchecked")
+   public List<Failure> validate(ValidateObject vo, ResourceBundle rb)
+   {
+      if (vo != null && 
+          Key.MANAGED_CONNECTION_FACTORY == vo.getKey() &&
+          vo.getObject() != null &&
+          vo.getObject() instanceof ManagedConnectionFactory)
+      {
+         if (vo.getConfigProperties() != null && vo.getConfigProperties().size() > 0)
+         {
+            Class clz = vo.getObject().getClass();
+            List<Failure> failures = new ArrayList<Failure>(1);
+
+            for (ConfigPropertyMetaData cpmd : vo.getConfigProperties())
+            {
+               try
+               {
+                  String methodName = "get" + cpmd.getName().substring(0, 1).toUpperCase(Locale.US);
+                  if (cpmd.getName().length() > 1)
+                  {
+                     methodName += cpmd.getName().substring(1);
+                  }
+
+                  Method method = clz.getMethod(methodName, (Class[])null);
+
+                  if (!VALID_TYPES.contains(method.getReturnType()))
+                  {
+                     StringBuilder sb = new StringBuilder("Class: " + vo.getObject().getClass().getName());
+                     sb = sb.append(" Property: " + cpmd.getName());
+                     sb = sb.append(" Type: " + method.getReturnType().getName());
+
+                     Failure failure = new Failure(Severity.WARNING,
+                                                   SECTION,
+                                                   rb.getString("mcf.MCFConfigProperties"),
+                                                   sb.toString());
+                     failures.add(failure);
+                  }
+               }
+               catch (Throwable t)
+               {
+                  try
+                  {
+                     String methodName = "is" + cpmd.getName().substring(0, 1).toUpperCase(Locale.US);
+                     if (cpmd.getName().length() > 1)
+                     {
+                        methodName += cpmd.getName().substring(1);
+                     }
+                     
+                     Method method = clz.getMethod(methodName, (Class[])null);
+
+                     if (!VALID_TYPES.contains(method.getReturnType()))
+                     {
+                        StringBuilder sb = new StringBuilder("Class: " + vo.getObject().getClass().getName());
+                        sb = sb.append(" Property: " + cpmd.getName());
+                        sb = sb.append(" Type: " + method.getReturnType().getName());
+
+                        Failure failure = new Failure(Severity.WARNING,
+                                                      SECTION,
+                                                      rb.getString("mcf.MCFConfigProperties"),
+                                                      sb.toString());
+                        failures.add(failure);
+                     }
+                  }
+                  catch (Throwable it)
+                  {
+                     // Ignore
+                  }
+               }
+            }
+
+            if (failures.size() == 0)
+               return null;
+
+            return failures;
+         }
+      }
+
+      return null;
+   }
+}




More information about the jboss-cvs-commits mailing list