geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r487415 - in /geronimo/server/trunk/modules: geronimo-axis-builder/src/main/java/org/apache/geronimo/axis/builder/ geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ geronimo-naming-builder/src/main/java/org/...
Date Fri, 15 Dec 2006 01:04:16 GMT
Author: djencks
Date: Thu Dec 14 17:04:15 2006
New Revision: 487415

URL: http://svn.apache.org/viewvc?view=rev&rev=487415
Log:
GERONIMO-2657 intermediate checkin, new method in AbstractNamingBuilder and deal with spec
refs in PersistenceUnitRefBuilder

Modified:
    geronimo/server/trunk/modules/geronimo-axis-builder/src/main/java/org/apache/geronimo/axis/builder/AxisServiceRefBuilder.java
    geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
    geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
    geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
    geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
    geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
    geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java

Modified: geronimo/server/trunk/modules/geronimo-axis-builder/src/main/java/org/apache/geronimo/axis/builder/AxisServiceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-axis-builder/src/main/java/org/apache/geronimo/axis/builder/AxisServiceRefBuilder.java?view=diff&rev=487415&r1=487414&r2=487415
==============================================================================
--- geronimo/server/trunk/modules/geronimo-axis-builder/src/main/java/org/apache/geronimo/axis/builder/AxisServiceRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-axis-builder/src/main/java/org/apache/geronimo/axis/builder/AxisServiceRefBuilder.java
Thu Dec 14 17:04:15 2006
@@ -69,13 +69,12 @@
     }
     
     public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException
{
-        XmlObject[] serviceRefsUntyped = convert(specDD.selectChildren(serviceRefQNameSet),
J2EE_CONVERTER, ServiceRefType.type);
+        List<ServiceRefType> serviceRefsUntyped = convert(specDD.selectChildren(serviceRefQNameSet),
J2EE_CONVERTER, ServiceRefType.class, ServiceRefType.type);
         XmlObject[] gerServiceRefsUntyped = plan == null? NO_REFS: plan.selectChildren(GER_SERVICE_REF_QNAME_SET);
         Map serviceRefMap = mapServiceRefs(gerServiceRefsUntyped);
         ClassLoader cl = module.getEarContext().getClassLoader();
 
-        for (int i = 0; i < serviceRefsUntyped.length; i++) {
-            ServiceRefType serviceRef = (ServiceRefType) serviceRefsUntyped[i];
+        for (ServiceRefType serviceRef: serviceRefsUntyped) {
             String name = getStringValue(serviceRef.getServiceRefName());
             GerServiceRefType serviceRefType = (GerServiceRefType) serviceRefMap.get(name);
 //            Map credentialsNameMap = (Map) serviceRefCredentialsNameMap.get(name);

Modified: geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java?view=diff&rev=487415&r1=487414&r2=487415
==============================================================================
--- geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/AdminObjectRefBuilder.java
Thu Dec 14 17:04:15 2006
@@ -20,6 +20,7 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.List;
 
 import javax.naming.Reference;
 import javax.xml.namespace.QName;
@@ -72,7 +73,7 @@
     }
 
     public void initContext(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module) throws DeploymentException {
-        XmlObject[] specDestinations = convert(specDD.selectChildren(messageDestinationQNameSet),
J2EE_CONVERTER, MessageDestinationType.type);
+        List<MessageDestinationType> specDestinations = convert(specDD.selectChildren(messageDestinationQNameSet),
J2EE_CONVERTER, MessageDestinationType.class, MessageDestinationType.type);
         XmlObject[] gerDestinations = plan.selectChildren(GER_MESSAGE_DESTINATION_QNAME_SET);
             Map nameMap = new HashMap();
             for (int i = 0; i < gerDestinations.length; i++) {
@@ -80,8 +81,7 @@
                 String name = destination.getMessageDestinationName().trim();
                 nameMap.put(name, destination);
                 boolean found = false;
-                for (int j = 0; j < specDestinations.length; j++) {
-                    MessageDestinationType specDestination = (MessageDestinationType) specDestinations[j];
+                for (MessageDestinationType specDestination: specDestinations) {
                     if (specDestination.getMessageDestinationName().getStringValue().trim().equals(name))
{
                         found = true;
                         break;
@@ -96,12 +96,11 @@
 
 
     public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException
{
-        XmlObject[] resourceEnvRefsUntyped = convert(specDD.selectChildren(adminOjbectRefQNameSet),
J2EE_CONVERTER, ResourceEnvRefType.type);
+        List<ResourceEnvRefType> resourceEnvRefsUntyped = convert(specDD.selectChildren(adminOjbectRefQNameSet),
J2EE_CONVERTER, ResourceEnvRefType.class, ResourceEnvRefType.type);
         ClassLoader cl = module.getEarContext().getClassLoader();
         XmlObject[] gerResourceEnvRefsUntyped = plan == null? NO_REFS: plan.selectChildren(GER_ADMIN_OBJECT_REF_QNAME_SET);
         Map refMap = mapResourceEnvRefs(gerResourceEnvRefsUntyped);
-        for (int i = 0; i < resourceEnvRefsUntyped.length; i++) {
-            ResourceEnvRefType resourceEnvRef = (ResourceEnvRefType) resourceEnvRefsUntyped[i];
+        for (ResourceEnvRefType resourceEnvRef: resourceEnvRefsUntyped) {
             String name = resourceEnvRef.getResourceEnvRefName().getStringValue().trim();
             String type = resourceEnvRef.getResourceEnvRefType().getStringValue().trim();
             Class iface;
@@ -121,10 +120,9 @@
         }
 
         //message-destination-refs
-        XmlObject[] messageDestinationRefsUntyped = convert(specDD.selectChildren(messageDestinationRefQNameSet),
J2EE_CONVERTER, MessageDestinationRefType.type);
+        List<MessageDestinationRefType> messageDestinationRefsUntyped = convert(specDD.selectChildren(messageDestinationRefQNameSet),
J2EE_CONVERTER, MessageDestinationRefType.class, MessageDestinationRefType.type);
 
-        for (int i = 0; i < messageDestinationRefsUntyped.length; i++) {
-            MessageDestinationRefType messageDestinationRef = (MessageDestinationRefType)
messageDestinationRefsUntyped[i];
+        for (MessageDestinationRefType messageDestinationRef: messageDestinationRefsUntyped)
{
             String name = getStringValue(messageDestinationRef.getMessageDestinationRefName());
             String linkName = getStringValue(messageDestinationRef.getMessageDestinationLink());
             String type = getStringValue(messageDestinationRef.getMessageDestinationType());

Modified: geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java?view=diff&rev=487415&r1=487414&r2=487415
==============================================================================
--- geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-connector-builder/src/main/java/org/apache/geronimo/connector/deployment/ResourceRefBuilder.java
Thu Dec 14 17:04:15 2006
@@ -24,6 +24,7 @@
 import java.util.Map;
 import java.util.Set;
 import java.util.HashSet;
+import java.util.List;
 
 import javax.naming.Reference;
 import javax.xml.namespace.QName;
@@ -72,13 +73,12 @@
     }
 
     public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException
{
-        XmlObject[] resourceRefsUntyped = convert(specDD.selectChildren(resourceRefQNameSet),
J2EE_CONVERTER, ResourceRefType.type);
+        List<ResourceRefType> resourceRefsUntyped = convert(specDD.selectChildren(resourceRefQNameSet),
J2EE_CONVERTER, ResourceRefType.class, ResourceRefType.type);
         XmlObject[] gerResourceRefsUntyped = plan == null? NO_REFS: plan.selectChildren(GER_RESOURCE_REF_QNAME_SET);
         Map refMap = mapResourceRefs(gerResourceRefsUntyped);
         ClassLoader cl = module.getEarContext().getClassLoader();
 
-        for (int i = 0; i < resourceRefsUntyped.length; i++) {
-            ResourceRefType resourceRef = (ResourceRefType) resourceRefsUntyped[i];
+        for (ResourceRefType resourceRef: resourceRefsUntyped) {
             String name = resourceRef.getResRefName().getStringValue().trim();
             String type = resourceRef.getResType().getStringValue().trim();
             GerResourceRefType gerResourceRef = (GerResourceRefType) refMap.get(name);
@@ -148,12 +148,11 @@
     }
 
     public void setResourceEnvironment(ResourceEnvironmentBuilder builder, XmlObject[] resourceRefs,
GerResourceRefType[] gerResourceRefs) throws DeploymentException {
-        resourceRefs = convert(resourceRefs, J2EE_CONVERTER, ResourceRefType.type);
+        List<ResourceRefType> resourceRefList = convert(resourceRefs, J2EE_CONVERTER,
ResourceRefType.class, ResourceRefType.type);
         Map refMap = mapResourceRefs(gerResourceRefs);
         Set unshareableResources = new HashSet();
         Set applicationManagedSecurityResources = new HashSet();
-        for (int i = 0; i < resourceRefs.length; i++) {
-            ResourceRefType resourceRefType = (ResourceRefType) resourceRefs[i];
+        for (ResourceRefType resourceRefType: resourceRefList) {
 
             String type = resourceRefType.getResType().getStringValue().trim();
 

Modified: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java?view=diff&rev=487415&r1=487414&r2=487415
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/AbstractNamingBuilder.java
Thu Dec 14 17:04:15 2006
@@ -23,6 +23,8 @@
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
 
 import javax.xml.namespace.QName;
 
@@ -124,8 +126,16 @@
         return QNameSet.forSets(null, Collections.EMPTY_SET, Collections.EMPTY_SET, qnames);
     }
 
+    /**
+     * @deprecated
+     * @param xmlObjects
+     * @param converter
+     * @param type
+     * @return
+     * @throws DeploymentException
+     */
     protected static XmlObject[] convert(XmlObject[] xmlObjects, NamespaceElementConverter
converter, SchemaType type) throws DeploymentException {
-        //bizarre ArrayStoreException if xmlObjects is loaded by the wrong classloader
+               //bizarre ArrayStoreException if xmlObjects is loaded by the wrong classloader
         XmlObject[] converted = new XmlObject[xmlObjects.length];
         for (int i = 0; i < xmlObjects.length; i++) {
             XmlObject xmlObject = xmlObjects[i].copy();
@@ -142,6 +152,26 @@
             }
         }
         return converted;
+
+    }
+
+    protected static <T extends XmlObject> List<T> convert(XmlObject[] xmlObjects,
NamespaceElementConverter converter, Class<T> c, SchemaType type) throws DeploymentException
{
+        //there's probably a better way to say T extends XmlObject and get the type from
that
+        List<T> result = new ArrayList<T>(xmlObjects.length);
+        for (XmlObject xmlObject : xmlObjects) {
+            xmlObject = xmlObject.copy();
+            if (xmlObject.schemaType() != type) {
+                converter.convertElement(xmlObject);
+                xmlObject = xmlObject.changeType(type);
+            }
+            try {
+                XmlBeansUtil.validateDD(xmlObject);
+            } catch (XmlException e) {
+                throw new DeploymentException("Could not validate xmlObject of type " + type,
e);
+            }
+            result.add((T) xmlObject);
+        }
+        return result;
     }
 
     protected static String getStringValue(org.apache.geronimo.xbeans.j2ee.String string)
{

Modified: geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java?view=diff&rev=487415&r1=487414&r2=487415
==============================================================================
--- geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-naming-builder/src/main/java/org/apache/geronimo/naming/deployment/EnvironmentEntryBuilder.java
Thu Dec 14 17:04:15 2006
@@ -18,6 +18,7 @@
 package org.apache.geronimo.naming.deployment;
 
 import java.util.Map;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
@@ -52,9 +53,8 @@
     }
 
     public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException
{
-        XmlObject[] envEntriesUntyped = convert(specDD.selectChildren(envEntryQNameSet),
J2EE_CONVERTER, EnvEntryType.type);
-        for (int i = 0; i < envEntriesUntyped.length; i++) {
-            EnvEntryType envEntry = (EnvEntryType) envEntriesUntyped[i];
+        List<EnvEntryType> envEntriesUntyped = convert(specDD.selectChildren(envEntryQNameSet),
J2EE_CONVERTER, EnvEntryType.class, EnvEntryType.type);
+        for (EnvEntryType envEntry: envEntriesUntyped) {
             String name = envEntry.getEnvEntryName().getStringValue().trim();
             String type = envEntry.getEnvEntryType().getStringValue().trim();
             String text = envEntry.getEnvEntryValue().getStringValue().trim();

Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java?view=diff&rev=487415&r1=487414&r2=487415
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceContextRefBuilder.java
Thu Dec 14 17:04:15 2006
@@ -21,6 +21,7 @@
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
@@ -57,16 +58,12 @@
     }
 
     protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan) throws DeploymentException
{
-        return getPersistenceContextRefs(plan).length > 0;
+        return plan != null && plan.selectChildren(PersistenceContextRefBuilder.PERSISTENCE_CONTEXT_REF_QNAME_SET).length
> 0;
     }
 
     public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException
{
-        XmlObject[] persistenceContextRefsUntyped = getPersistenceContextRefs(plan);
-        for (int i = 0; i < persistenceContextRefsUntyped.length; i++) {
-            GerPersistenceContextRefType persistenceContextRef = (GerPersistenceContextRefType)
persistenceContextRefsUntyped[i];
-            if (persistenceContextRef == null) {
-                throw new DeploymentException("Could not read persistenceContextRef number
" + i + " as the correct xml type");
-            }
+        List<GerPersistenceContextRefType> persistenceContextRefsUntyped = convert(plan.selectChildren(PersistenceContextRefBuilder.PERSISTENCE_CONTEXT_REF_QNAME_SET),
NAMING_CONVERTER, GerPersistenceContextRefType.class, GerPersistenceContextRefType.type);
+        for (GerPersistenceContextRefType persistenceContextRef: persistenceContextRefsUntyped)
{
             String persistenceContextRefName = persistenceContextRef.getPersistenceContextRefName();
             boolean transactionScoped = !persistenceContextRef.getPersistenceContextType().equals(GerPersistenceContextTypeType.EXTENDED);
             GerPropertyType[] propertyTypes = persistenceContextRef.getPropertyArray();
@@ -110,10 +107,6 @@
 
     public QNameSet getPlanQNameSet() {
         return PERSISTENCE_CONTEXT_REF_QNAME_SET;
-    }
-
-    private XmlObject[] getPersistenceContextRefs(XmlObject plan) throws DeploymentException
{
-        return plan == null? NO_REFS: convert(plan.selectChildren(PersistenceContextRefBuilder.PERSISTENCE_CONTEXT_REF_QNAME_SET),
NAMING_CONVERTER, GerPersistenceContextRefType.type);
     }
 
     public static final GBeanInfo GBEAN_INFO;

Modified: geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java?view=diff&rev=487415&r1=487414&r2=487415
==============================================================================
--- geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
(original)
+++ geronimo/server/trunk/modules/geronimo-persistence-jpa10-builder/src/main/java/org/apache/geronimo/persistence/builder/PersistenceUnitRefBuilder.java
Thu Dec 14 17:04:15 2006
@@ -19,6 +19,8 @@
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
+import java.util.HashMap;
+import java.util.List;
 
 import javax.xml.namespace.QName;
 
@@ -38,6 +40,7 @@
 import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceUnitRefDocument;
 import org.apache.geronimo.xbeans.geronimo.naming.GerPersistenceUnitRefType;
 import org.apache.geronimo.xbeans.geronimo.naming.GerPatternType;
+import org.apache.geronimo.xbeans.javaee.PersistenceUnitRefType;
 import org.apache.xmlbeans.QNameSet;
 import org.apache.xmlbeans.XmlObject;
 
@@ -45,41 +48,64 @@
  * @version $Rev$ $Date$
  */
 public class PersistenceUnitRefBuilder extends AbstractNamingBuilder {
-    private static final QName ENTITY_MANAGER_FACTORY_REF_QNAME = GerPersistenceUnitRefDocument.type.getDocumentElementName();
-    private static final QNameSet ENTITY_MANAGER_FACTORY_REF_QNAME_SET = QNameSet.singleton(PersistenceUnitRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME);
+    private static final QName PERSISTENCE_UNIT_REF_QNAME = new QName(JEE_NAMESPACE, "persistence-unit-ref");
+    private static final QNameSet PERSISTENCE_UNIT_REF_QNAME_SET = QNameSet.singleton(PERSISTENCE_UNIT_REF_QNAME);
+    private static final QName GER_PERSISTENCE_UNIT_REF_QNAME = GerPersistenceUnitRefDocument.type.getDocumentElementName();
+    private static final QNameSet GER_PERSISTENCE_UNIT_REF_QNAME_SET = QNameSet.singleton(GER_PERSISTENCE_UNIT_REF_QNAME);
+    private static final Set PERSISTENCE_UNIT_INTERFACE_TYPES = Collections.singleton("org.apache.geronimo.persistence.PersistenceUnitGBean");
+    private final AbstractNameQuery defaultPersistenceUnitAbstractNameQuery;
 
 
-    public PersistenceUnitRefBuilder(Environment defaultEnvironment) {
+    public PersistenceUnitRefBuilder(Environment defaultEnvironment, AbstractNameQuery defaultPersistenceUnitAbstractNameQuery)
{
         super(defaultEnvironment);
+        this.defaultPersistenceUnitAbstractNameQuery = defaultPersistenceUnitAbstractNameQuery;
     }
 
     protected boolean willMergeEnvironment(XmlObject specDD, XmlObject plan) throws DeploymentException
{
-        return getPersistenceUnitRefs(plan).length > 0;
+        if (specDD != null && specDD.selectChildren(PersistenceUnitRefBuilder.PERSISTENCE_UNIT_REF_QNAME_SET).length
> 0) {
+            return true;
+        }
+        return plan != null && plan.selectChildren(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME_SET).length
> 0;
     }
 
     public void initContext(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module) throws DeploymentException {
     }
 
     public void buildNaming(XmlObject specDD, XmlObject plan, Configuration localConfiguration,
Configuration remoteConfiguration, Module module, Map componentContext) throws DeploymentException
{
-        XmlObject[] PersistenceUnitRefsUntyped = getPersistenceUnitRefs(plan);
-        for (int i = 0; i < PersistenceUnitRefsUntyped.length; i++) {
-            GerPersistenceUnitRefType PersistenceUnitRef = (GerPersistenceUnitRefType) PersistenceUnitRefsUntyped[i];
-            if (PersistenceUnitRef == null) {
-                throw new DeploymentException("Could not read PersistenceUnitRef number "
+ i + " as the correct xml type");
-            }
-            String PersistenceUnitRefName = PersistenceUnitRef.getPersistenceUnitRefName();
+        List<PersistenceUnitRefType> specPersistenceUnitRefsUntyped = convert(specDD.selectChildren(PersistenceUnitRefBuilder.PERSISTENCE_UNIT_REF_QNAME_SET),
NAMING_CONVERTER, PersistenceUnitRefType.class, PersistenceUnitRefType.type);
+        Map<String, GerPersistenceUnitRefType> gerPersistenceUnitRefsUntyped = getGerPersistenceUnitRefs(plan);
+        for (PersistenceUnitRefType PersistenceUnitRef: specPersistenceUnitRefsUntyped) {
+            String persistenceUnitRefName = PersistenceUnitRef.getPersistenceUnitRefName().getStringValue().trim();
 
-            Set interfaceTypes = Collections.singleton("org.apache.geronimo.persistence.PersistenceUnitGBean");
             AbstractNameQuery persistenceUnitNameQuery;
-            if (PersistenceUnitRef.isSetPersistenceUnitName()) {
-                String persistenceUnitName = PersistenceUnitRef.getPersistenceUnitName();
-                persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.singletonMap("name",
persistenceUnitName), interfaceTypes);
+            GerPersistenceUnitRefType gerPersistenceUnitRef = gerPersistenceUnitRefsUntyped.get(persistenceUnitRefName);
+            if (gerPersistenceUnitRef != null) {
+                persistenceUnitNameQuery = findPersistenceUnit(gerPersistenceUnitRef);
+            } else if (PersistenceUnitRef.isSetPersistenceUnitName()) {
+                String persistenceUnitName = PersistenceUnitRef.getPersistenceUnitName().getStringValue().trim();
+                persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.singletonMap("name",
persistenceUnitName), PERSISTENCE_UNIT_INTERFACE_TYPES);
             } else {
-                GerPatternType gbeanLocator = PersistenceUnitRef.getPattern();
+                persistenceUnitNameQuery = defaultPersistenceUnitAbstractNameQuery;
+            }
 
-                persistenceUnitNameQuery = buildAbstractNameQuery(gbeanLocator, null, null,
interfaceTypes);
+            try {
+                localConfiguration.findGBeanData(persistenceUnitNameQuery);
+            } catch (GBeanNotFoundException e) {
+                throw new DeploymentException("Could not resolve reference at deploy time
for query " + persistenceUnitNameQuery, e);
             }
 
+            PersistenceUnitReference reference = new PersistenceUnitReference(localConfiguration.getId(),
persistenceUnitNameQuery);
+
+            ((Map)componentContext.get(JNDI_KEY)).put(ENV + persistenceUnitRefName, reference);
+
+        }
+
+
+        for (GerPersistenceUnitRefType gerPersistenceUnitRef: gerPersistenceUnitRefsUntyped.values())
{
+            String PersistenceUnitRefName = gerPersistenceUnitRef.getPersistenceUnitRefName();
+
+            AbstractNameQuery persistenceUnitNameQuery = findPersistenceUnit(gerPersistenceUnitRef);
+
             try {
                 localConfiguration.findGBeanData(persistenceUnitNameQuery);
             } catch (GBeanNotFoundException e) {
@@ -93,17 +119,37 @@
         }
     }
 
+    private AbstractNameQuery findPersistenceUnit(GerPersistenceUnitRefType gerPersistenceUnitRef)
{
+        AbstractNameQuery persistenceUnitNameQuery;
+        if (gerPersistenceUnitRef.isSetPersistenceUnitName()) {
+            String persistenceUnitName = gerPersistenceUnitRef.getPersistenceUnitName();
+            persistenceUnitNameQuery = new AbstractNameQuery(null, Collections.singletonMap("name",
persistenceUnitName), PERSISTENCE_UNIT_INTERFACE_TYPES);
+        } else {
+            GerPatternType gbeanLocator = gerPersistenceUnitRef.getPattern();
+
+            persistenceUnitNameQuery = buildAbstractNameQuery(gbeanLocator, null, null, PERSISTENCE_UNIT_INTERFACE_TYPES);
+        }
+        return persistenceUnitNameQuery;
+    }
+
     public QNameSet getSpecQNameSet() {
-        SchemaConversionUtils.registerNamespaceConversions(Collections.singletonMap(PersistenceUnitRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME.getLocalPart(),
new NamespaceElementConverter(PersistenceUnitRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME.getNamespaceURI())));
-        return QNameSet.EMPTY;
+        SchemaConversionUtils.registerNamespaceConversions(Collections.singletonMap(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME.getLocalPart(),
new NamespaceElementConverter(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME.getNamespaceURI())));
+        return PERSISTENCE_UNIT_REF_QNAME_SET;
     }
 
     public QNameSet getPlanQNameSet() {
-        return PersistenceUnitRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME_SET;
+        return GER_PERSISTENCE_UNIT_REF_QNAME_SET;
     }
 
-    private XmlObject[] getPersistenceUnitRefs(XmlObject plan) throws DeploymentException
{
-        return plan == null? NO_REFS: convert(plan.selectChildren(PersistenceUnitRefBuilder.ENTITY_MANAGER_FACTORY_REF_QNAME_SET),
NAMING_CONVERTER, GerPersistenceUnitRefType.type);
+    private Map<String, GerPersistenceUnitRefType> getGerPersistenceUnitRefs(XmlObject
plan) throws DeploymentException {
+        Map<String, GerPersistenceUnitRefType> map = new HashMap<String, GerPersistenceUnitRefType>();
+        if (plan != null) {
+            List<GerPersistenceUnitRefType> refs = convert(plan.selectChildren(PersistenceUnitRefBuilder.GER_PERSISTENCE_UNIT_REF_QNAME_SET),
NAMING_CONVERTER, GerPersistenceUnitRefType.class, GerPersistenceUnitRefType.type);
+            for (GerPersistenceUnitRefType ref: refs) {
+                map.put(ref.getPersistenceUnitRefName().trim(), ref);
+            }
+        }
+        return map;
     }
 
     public static final GBeanInfo GBEAN_INFO;
@@ -111,8 +157,9 @@
     static {
         GBeanInfoBuilder infoBuilder = GBeanInfoBuilder.createStatic(PersistenceUnitRefBuilder.class,
NameFactory.MODULE_BUILDER);
         infoBuilder.addAttribute("defaultEnvironment", Environment.class, true, true);
+        infoBuilder.addAttribute("defaultPersistenceUnitAbstractNameQuery", AbstractNameQuery.class,
true, true);
 
-        infoBuilder.setConstructor(new String[] {"defaultEnvironment"});
+        infoBuilder.setConstructor(new String[] {"defaultEnvironment", "defaultPersistenceUnitAbstractNameQuery"});
         GBEAN_INFO = infoBuilder.getBeanInfo();
     }
 



Mime
View raw message