tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickmcgu...@apache.org
Subject svn commit: r675161 - in /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb: config/CmpJpaConversion.java core/cmp/CmpUtil.java
Date Wed, 09 Jul 2008 13:21:18 GMT
Author: rickmcguire
Date: Wed Jul  9 06:21:18 2008
New Revision: 675161

URL: http://svn.apache.org/viewvc?rev=675161&view=rev
Log:
OPENEJB-853 CmpUtil.getCmpImplClassName can throw StringIndexOutOfBoundsException


Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpUtil.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java?rev=675161&r1=675160&r2=675161&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/config/CmpJpaConversion.java
Wed Jul  9 06:21:18 2008
@@ -398,6 +398,15 @@
         return r;
     }
 
+    /**
+     * Generate the CMP mapping data for an individual 
+     * EntityBean.  
+     * 
+     * @param ejbModule The module containing the bean.
+     * @param entityMappings
+     *                  The accumulated set of entity mappings.
+     * @param bean      The been we're generating the mapping for.
+     */
     private void processEntityBean(EjbModule ejbModule, EntityMappings entityMappings, EntityBean
bean) {
         // try to add a new persistence-context-ref for cmp
         if (!addPersistenceContextRef(bean)) {
@@ -421,14 +430,15 @@
         // need to be spot on.
         EntityMappings userMappings = getUserEntityMappings(ejbModule);
 
-        // Look for any existing mapped superclass mappings
+        // Look for any existing mapped superclass mappings.  We check the entire inheritance

+        // chain of the bean looking for any that have user defined mappings. 
         for (Class clazz = ejbClass; clazz != null; clazz = clazz.getSuperclass()){
 
             MappedSuperclass mappedSuperclass = removeMappedSuperclass(userMappings, clazz.getName());
 
             // We're going to assume that if they bothered to map a superclass
             // that the mapping is correct.  Copy it from their mappings to ours
-            if (mappedSuperclass != null){
+            if (mappedSuperclass != null) {
                 entityMappings.getMappedSuperclass().add(mappedSuperclass);
             }
         }
@@ -568,6 +578,19 @@
         return entity;
     }
 
+    /**
+     * Check the user-defined entity mappings for a superclass 
+     * mapping for a given named class. If the user mappings exist, 
+     * remove them from the user list and return them 
+     * for inclusion in our generated mappings. 
+     * 
+     * @param userMappings
+     *                  The current user mapping set.
+     * @param className The name of the class of interest.
+     * 
+     * @return Returns the superclass mapping for the named class, or 
+     *         null if the class is not in the mapping set.
+     */
     private MappedSuperclass removeMappedSuperclass(EntityMappings userMappings, String className)
{
         MappedSuperclass mappedSuperclass;
 
@@ -782,6 +805,17 @@
         return fields;
     }
 
+    
+    /**
+     * Add a persistence context reference for the CMP 
+     * persistence contexts to this EntityBean definition. 
+     * 
+     * @param bean   The bean we're updating.
+     * 
+     * @return Returns true if the context was added.  Returns false if 
+     *         the bean already is associated with the CMP persistence
+     *         context.
+     */
     private boolean addPersistenceContextRef(EntityBean bean) {
         // if a ref is already defined, skip this bean
         if (bean.getPersistenceContextRefMap().containsKey(JpaCmpEngine.CMP_PERSISTENCE_CONTEXT_REF_NAME))
return false;

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpUtil.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpUtil.java?rev=675161&r1=675160&r2=675161&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpUtil.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/cmp/CmpUtil.java
Wed Jul  9 06:21:18 2008
@@ -18,13 +18,16 @@
 
 public class CmpUtil {
     public static String getCmpImplClassName(String abstractSchemaName, String ejbClass)
{
-        String cmpImplClass = ejbClass.substring(0, ejbClass.lastIndexOf('.'));
-        if (cmpImplClass.length() > 0) {
-            cmpImplClass = "openejb." + cmpImplClass;
-        } else {
-            cmpImplClass = "openejb";
+        // locate the end of the package portion 
+        int packageEnd = ejbClass.lastIndexOf('.'); 
+        String cmpImplClass;
+        // we have a package, pull that out and add "openejb." in front of the package 
+        if (packageEnd != -1) {
+            return "openejb." + ejbClass.substring(0, packageEnd + 1) + abstractSchemaName;
+        }
+        else {
+            // no package, construct this from just "openejb." and the schema name 
+            return "openejb." + abstractSchemaName; 
         }
-        cmpImplClass += "." + abstractSchemaName;
-        return cmpImplClass;
     }
 }



Mime
View raw message