You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by ta...@apache.org on 2016/03/19 21:21:03 UTC

[1/2] deltaspike git commit: DELTASPIKE-1095 Move persistence/orm.xml mapping + parsing from DATA impl to JPA api/spi

Repository: deltaspike
Updated Branches:
  refs/heads/master f30b389ab -> 6480a0e54


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptor.java
new file mode 100644
index 0000000..3315b77
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptor.java
@@ -0,0 +1,66 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.util.List;
+
+public class EntityMappingsDescriptor
+{
+    private List<MappedSuperclassDescriptor> mappedSuperclassDescriptors;
+    private List<EntityDescriptor> entityDescriptors;
+    private String packageName;
+
+    public EntityMappingsDescriptor(List<MappedSuperclassDescriptor> mappedSuperclassDescriptors,
+            List<EntityDescriptor> entityDescriptors, String packageName)
+    {
+        this.mappedSuperclassDescriptors = mappedSuperclassDescriptors;
+        this.entityDescriptors = entityDescriptors;
+        this.packageName = packageName;
+    }
+    
+    public List<MappedSuperclassDescriptor> getMappedSuperclassDescriptors()
+    {
+        return mappedSuperclassDescriptors;
+    }
+
+    public void setMappedSuperclassDescriptors(List<MappedSuperclassDescriptor> mappedSuperclassDescriptors)
+    {
+        this.mappedSuperclassDescriptors = mappedSuperclassDescriptors;
+    }
+
+    public List<EntityDescriptor> getEntityDescriptors()
+    {
+        return entityDescriptors;
+    }
+
+    public void setEntityDescriptors(List<EntityDescriptor> entityDescriptors)
+    {
+        this.entityDescriptors = entityDescriptors;
+    }
+
+    public String getPackageName()
+    {
+        return packageName;
+    }
+
+    public void setPackageName(String packageName)
+    {
+        this.packageName = packageName;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptorParser.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptorParser.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptorParser.java
new file mode 100644
index 0000000..90c5ef7
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityMappingsDescriptorParser.java
@@ -0,0 +1,235 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.List;
+import javax.enterprise.inject.Typed;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+@Typed
+public class EntityMappingsDescriptorParser extends DescriptorReader
+{
+    public static final String DEFAULT_ORM_PATH = "META-INF/orm.xml";
+
+    public EntityMappingsDescriptor readAll(String baseUrl, String resource) throws IOException
+    {
+        Document document = read(baseUrl, resource).getDocument();
+        return readFromDocument(document);
+    }
+
+    public EntityMappingsDescriptor readDefaultOrm(String baseUrl) throws IOException
+    {
+        try
+        {
+            Descriptor desc = read(baseUrl, DEFAULT_ORM_PATH);
+            return readFromDocument(desc.getDocument());
+        }
+        catch (Exception e)
+        {
+            return new EntityMappingsDescriptor(Collections.<MappedSuperclassDescriptor>emptyList(),
+                    Collections.<EntityDescriptor>emptyList(), null);
+        }
+    }
+
+    protected EntityMappingsDescriptor readFromDocument(Document doc)
+    {
+        String packageName =
+            parsePackageName(doc);
+        List<MappedSuperclassDescriptor> mappedSuperclassDescriptors =
+            parseMappedSuperclassDescriptors(doc, packageName);
+        List<EntityDescriptor> entityDescriptors =
+            parseEntityDescriptors(doc, packageName);
+        
+        return new EntityMappingsDescriptor(mappedSuperclassDescriptors, entityDescriptors, packageName);
+    }
+
+    protected String extractNodeAttribute(Element element, String childName, String attribute)
+    {
+        NodeList list = element.getElementsByTagName(childName);
+        if (list.getLength() == 0)
+        {
+            return null;
+        }
+        return extractAttribute(list.item(0), attribute);
+    }
+
+    protected String extractAttribute(Node item, String name)
+    {
+        Node node = item.getAttributes().getNamedItem(name);
+        if (node != null)
+        {
+            return node.getTextContent();
+        }
+        return null;
+    }
+    
+    protected String[] extractNodeAttributes(Element element, String childName, String attribute)
+    {
+        NodeList list = element.getElementsByTagName(childName);
+        if (list.getLength() == 0)
+        {
+            return null;
+        }
+        return extractAttributes(list, attribute);
+    }
+    
+    protected String[] extractAttributes(NodeList list, String name)
+    {
+        String[] values = null;
+        
+        for (int i = 0; i < list.getLength(); i++)
+        {
+            Node node = list.item(i).getAttributes().getNamedItem(name);
+            if (node != null)
+            {
+                if (values == null)
+                {
+                    values = new String[list.getLength()];
+                }
+                
+                values[i] = node.getTextContent();
+            }
+        }
+
+        return values;
+    }
+
+    protected String extractNodeContent(Element element, String name)
+    {
+        NodeList list = element.getElementsByTagName(name);
+        if (list.getLength() == 0)
+        {
+            return null;
+        }
+        return list.item(0).getTextContent();
+    }
+
+    protected String parsePackageName(Document doc)
+    {
+        return extractNodeContent(doc.getDocumentElement(), "package");
+    }
+    
+    protected List<MappedSuperclassDescriptor> parseMappedSuperclassDescriptors(Document doc, String packageName)
+    {
+        List<MappedSuperclassDescriptor> result = new LinkedList<MappedSuperclassDescriptor>();
+
+        NodeList mappings = doc.getElementsByTagName("mapped-superclass");
+        for (int i = 0; i < mappings.getLength(); i++)
+        {
+            Node node = mappings.item(i);
+            
+            MappedSuperclassDescriptor entityDescriptor = new MappedSuperclassDescriptor();
+            parseCommonEntityDescriptorAttributes(packageName, entityDescriptor, node);
+            
+            result.add(entityDescriptor);
+        }
+        
+        return result;
+    }
+    
+    protected List<EntityDescriptor> parseEntityDescriptors(Document doc, String packageName)
+    {
+        List<EntityDescriptor> result = new LinkedList<EntityDescriptor>();
+
+        NodeList mappings = doc.getElementsByTagName("entity");
+        for (int i = 0; i < mappings.getLength(); i++)
+        {
+            Node node = mappings.item(i);
+            
+            EntityDescriptor entityDescriptor = new EntityDescriptor();
+            parseCommonEntityDescriptorAttributes(packageName, entityDescriptor, node);
+            entityDescriptor.setTableName(extractNodeAttribute((Element) node, "table", "name"));
+
+            result.add(entityDescriptor);
+        }
+        
+        return result;
+    } 
+    
+    protected void parseCommonEntityDescriptorAttributes(String packageName,
+            AbstractEntityDescriptor entityDescriptor, Node node)
+    {
+        entityDescriptor.setName(extractAttribute(node, "name"));
+        entityDescriptor.setVersion(extractNodeAttribute((Element) node, "version", "name"));
+
+        String[] id = extractNodeAttributes((Element) node, "id", "name");
+        if (id != null)
+        {
+            entityDescriptor.setId(id);
+        }
+        else
+        {
+            String embeddedId = extractNodeAttribute((Element) node, "embedded-id", "name");
+            if (embeddedId != null)
+            {
+                entityDescriptor.setId(new String[] { embeddedId });
+            }
+        }
+
+        String className = extractAttribute(node, "class");
+        if (className != null)
+        {
+            try
+            {
+                entityDescriptor.setEntityClass(Class.forName(buildClassName(className, packageName)));
+            }
+            catch (ClassNotFoundException e)
+            {
+                throw new IllegalArgumentException("Can't get class " + buildClassName(className, packageName), e);
+            }
+        }
+
+        String idClass = extractNodeAttribute((Element) node, "id-class", "class");
+        if (idClass != null)
+        {
+            try
+            {
+                entityDescriptor.setIdClass(
+                        (Class<? extends Serializable>) Class.forName(buildClassName(idClass, packageName)));
+            }
+            catch (ClassNotFoundException e)
+            {
+                throw new IllegalArgumentException("Can't get class " + buildClassName(className, packageName), e);
+            }
+        }
+    }
+    
+    protected String buildClassName(String clazzName, String packageName)
+    {
+        if (clazzName == null && packageName == null)
+        {
+            return null;
+        }
+        return (packageName != null && !isClassNameQualified(clazzName)) ? packageName + "." + clazzName : clazzName;
+    }
+
+    protected boolean isClassNameQualified(String name)
+    {
+        return name.contains(".");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/MappedSuperclassDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/MappedSuperclassDescriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/MappedSuperclassDescriptor.java
new file mode 100644
index 0000000..2935ae3
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/MappedSuperclassDescriptor.java
@@ -0,0 +1,48 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.io.Serializable;
+
+public class MappedSuperclassDescriptor extends AbstractEntityDescriptor
+{
+    public MappedSuperclassDescriptor()
+    {
+    }
+
+    public MappedSuperclassDescriptor(String[] id, String version, String name, Class<?> entityClass,
+            Class<? extends Serializable> idClass, AbstractEntityDescriptor parent)
+    {
+        super(id, version, name, entityClass, idClass, parent);
+    }
+
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("EntityDescriptor ")
+                .append("[entityClass=").append(getEntityClass().getName())
+                .append(", name=").append(getName())
+                .append(", idClass=").append(getIdClass().getName())
+                .append(", id=").append(getId())
+                .append(", superClass=").append(getParent())
+                .append("]");
+        return builder.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptor.java
new file mode 100644
index 0000000..948a0e6
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptor.java
@@ -0,0 +1,80 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.util.List;
+import java.util.Map;
+
+public class PersistenceUnitDescriptor
+{
+    private String name;
+    /*
+    private String transactionType;
+    private boolean excludeUnlistedClasses;
+    */
+    private List<EntityDescriptor> entityDescriptors;
+    private Map<String, String> properties;
+
+    public PersistenceUnitDescriptor(String name, List<EntityDescriptor> entityDescriptors,
+            Map<String, String> properties)
+    {
+        this.name = name;
+        this.entityDescriptors = entityDescriptors;
+        this.properties = properties;
+    }
+    
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public List<EntityDescriptor> getEntityDescriptors()
+    {
+        return entityDescriptors;
+    }
+
+    public void setEntityDescriptors(List<EntityDescriptor> entityDescriptors)
+    {
+        this.entityDescriptors = entityDescriptors;
+    }
+
+    public Map<String, String> getProperties()
+    {
+        return properties;
+    }
+
+    public void setProperties(Map<String, String> properties)
+    {
+        this.properties = properties;
+    }
+    
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("PersistenceUnit [name=").append(name)
+                .append(", entityDescriptors=").append(entityDescriptors).append("]");
+        return builder.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParser.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParser.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParser.java
new file mode 100644
index 0000000..44dfcd0
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParser.java
@@ -0,0 +1,136 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import javax.enterprise.inject.Typed;
+
+@Typed
+public class PersistenceUnitDescriptorParser extends DescriptorReader
+{
+    public static final String RESOURCE_PATH = "META-INF/persistence.xml";
+
+    private final EntityMappingsDescriptorParser entityMappingsDescriptorParser
+        = new EntityMappingsDescriptorParser();
+    
+    public List<PersistenceUnitDescriptor> readAll() throws IOException
+    {
+        List<PersistenceUnitDescriptor> result = new LinkedList<PersistenceUnitDescriptor>();
+        List<Descriptor> persistenceXmls = readAllFromClassPath(RESOURCE_PATH);
+        for (Descriptor desc : persistenceXmls)
+        {
+            result.addAll(lookupUnits(desc));
+        }
+        return Collections.unmodifiableList(result);
+    }
+
+    protected List<PersistenceUnitDescriptor> lookupUnits(Descriptor descriptor)
+    {
+        List<PersistenceUnitDescriptor> result = new LinkedList<PersistenceUnitDescriptor>();
+        NodeList list = descriptor.getDocument().getDocumentElement().getElementsByTagName("persistence-unit");
+        for (int i = 0; i < list.getLength(); i++)
+        {
+            Node node = list.item(i);
+
+            String unitName = extractUnitName(node);
+            String baseUrl = extractBaseUrl(descriptor.getUrl(), RESOURCE_PATH);
+            List<EntityDescriptor> entities = extractMappings((Element) node, baseUrl, unitName);
+            Map<String, String> properties = extractProperties((Element) node);
+
+            result.add(new PersistenceUnitDescriptor(unitName, entities, properties));
+        }
+        return result;
+    }
+
+    protected List<EntityDescriptor> extractMappings(Element element, String baseUrl, String unitName)
+    {
+        try
+        {
+            List<EntityDescriptor> entities = new LinkedList<EntityDescriptor>();
+            List<MappedSuperclassDescriptor> superClasses = new LinkedList<MappedSuperclassDescriptor>();
+            NodeList list = element.getElementsByTagName("mapping-file");
+            readMappingFiles(baseUrl, unitName, entities, superClasses, list);
+            EntityMappingsDescriptor mappings = entityMappingsDescriptorParser.readDefaultOrm(baseUrl);
+            entities.addAll(mappings.getEntityDescriptors());
+            superClasses.addAll(mappings.getMappedSuperclassDescriptors());
+            AbstractEntityHierarchyBuilder.buildHierarchy(entities, superClasses);
+            return entities;
+        }
+        catch (Exception e)
+        {
+            throw new RuntimeException("Failed initializing mapping files", e);
+        }
+    }
+
+    protected void readMappingFiles(String baseUrl, String unitName,
+                                  List<EntityDescriptor> entities, List<MappedSuperclassDescriptor> superClasses,
+                                  NodeList list)
+    {
+        for (int i = 0; i < list.getLength(); i++)
+        {
+            String resource = list.item(i).getTextContent();
+            try
+            {
+                EntityMappingsDescriptor mappings = entityMappingsDescriptorParser.readAll(baseUrl, resource);
+                entities.addAll(mappings.getEntityDescriptors());
+                superClasses.addAll(mappings.getMappedSuperclassDescriptors());
+            }
+            catch (Exception e)
+            {
+                throw new RuntimeException("[PersistenceUnit: " + unitName + "] " +
+                        "Unable to resolve named mapping-file [" + resource + "]");
+            }
+        }
+    }
+
+    protected String extractUnitName(Node node)
+    {
+        return node.getAttributes().getNamedItem("name").getTextContent();
+    }
+
+    protected Map<String, String> extractProperties(Element element)
+    {
+        Map<String, String> propertiesMap = new HashMap<String, String>();
+
+        Node propertiesNode = element.getElementsByTagName("properties").item(0);
+        if (propertiesNode != null)
+        {
+            NodeList propertyNodes = propertiesNode.getChildNodes();
+            for (int i = 0; i < propertyNodes.getLength(); i++)
+            {
+                if ("property".equals(propertyNodes.item(i).getNodeName()))
+                {
+                    Element propertyNode = (Element) propertyNodes.item(i);
+                    propertiesMap.put(propertyNode.getAttribute("name"), propertyNode.getAttribute("value"));
+                }
+            }
+        }
+
+        return Collections.unmodifiableMap(propertiesMap);
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProvider.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProvider.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProvider.java
new file mode 100644
index 0000000..8f3d431
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProvider.java
@@ -0,0 +1,191 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.io.IOException;
+import java.util.Collections;
+import java.util.List;
+import javax.enterprise.inject.Typed;
+import org.apache.deltaspike.core.util.StringUtils;
+
+@Typed
+public final class PersistenceUnitDescriptorProvider
+{
+    private static final PersistenceUnitDescriptorProvider INSTANCE = new PersistenceUnitDescriptorProvider();
+
+    private final PersistenceUnitDescriptorParser persistenceUnitDescriptorParser
+        = new PersistenceUnitDescriptorParser();
+    
+    private List<PersistenceUnitDescriptor> persistenceUnitDescriptors = Collections.emptyList();
+
+    private PersistenceUnitDescriptorProvider()
+    {
+    }
+
+    public static PersistenceUnitDescriptorProvider getInstance()
+    {
+        return INSTANCE;
+    }
+
+    public void init()
+    {
+        try
+        {
+            persistenceUnitDescriptors = persistenceUnitDescriptorParser.readAll();
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException("Failed to parse persitence.xml's", e);
+        }
+    }
+
+    public PersistenceUnitDescriptor get(String name)
+    {        
+        for (PersistenceUnitDescriptor unit : persistenceUnitDescriptors)
+        {
+            if (name.equalsIgnoreCase(unit.getName()))
+            {
+                return unit;
+            }
+        }
+        return null;
+    }
+
+    public boolean isEntity(Class<?> entityClass)
+    {        
+        return find(entityClass) != null;
+    }
+
+    public String[] primaryKeyFields(Class<?> entityClass)
+    {        
+        EntityDescriptor entity = find(entityClass);
+        if (entity != null)
+        {
+            if (entity.getId() != null)
+            {
+                return entity.getId();
+            }
+            
+            AbstractEntityDescriptor parent = entity.getParent();
+            while (parent != null)
+            {
+                if (parent.getId() != null)
+                {
+                    return parent.getId();
+                }
+                
+                parent = parent.getParent();
+            }
+        }
+        return null;
+    }
+
+    public String versionField(Class<?> entityClass)
+    {        
+        EntityDescriptor entity = find(entityClass);
+        if (entity != null)
+        {            
+            if (!StringUtils.isEmpty(entity.getVersion()))
+            {
+                return entity.getVersion();
+            }
+            
+            AbstractEntityDescriptor parent = entity.getParent();
+            while (parent != null)
+            {
+                if (!StringUtils.isEmpty(parent.getVersion()))
+                {
+                    return parent.getVersion();
+                }
+                
+                parent = parent.getParent();
+            }
+        }
+        return null;
+    }
+
+    public Class<?> primaryKeyIdClass(Class<?> entityClass)
+    {        
+        EntityDescriptor entity = find(entityClass);
+        if (entity != null)
+        {
+            if (entity.getIdClass() != null)
+            {
+                return entity.getIdClass();
+            }
+            
+            AbstractEntityDescriptor parent = entity.getParent();
+            while (parent != null)
+            {
+                if (parent.getIdClass() != null)
+                {
+                    return parent.getIdClass();
+                }
+                
+                parent = parent.getParent();
+            }
+        }
+        return null;
+    }
+
+    public String entityName(Class<?> entityClass)
+    {        
+        EntityDescriptor entity = find(entityClass);
+        if (entity != null)
+        {
+            return entity.getName();
+        }
+        return null;
+    }
+    
+    public String entityTableName(Class<?> entityClass)
+    {        
+        EntityDescriptor entity = find(entityClass);
+        if (entity != null)
+        {
+            return entity.getTableName();
+        }
+        return null;
+    }
+
+    public EntityDescriptor find(Class<?> entityClass)
+    {
+        for (PersistenceUnitDescriptor unit : persistenceUnitDescriptors)
+        {
+            EntityDescriptor entity = find(entityClass, unit);
+            if (entity != null)
+            {
+                return entity;
+            }
+        }
+        return null;
+    }
+    
+    protected EntityDescriptor find(Class<?> entityClass, PersistenceUnitDescriptor descriptor)
+    {
+        for (EntityDescriptor entity : descriptor.getEntityDescriptors())
+        {
+            if (entity.getEntityClass().equals(entityClass))
+            {
+                return entity;
+            }
+        }
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/EntityMappingsDescriptorParserTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/EntityMappingsDescriptorParserTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/EntityMappingsDescriptorParserTest.java
new file mode 100644
index 0000000..6afd9ee
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/EntityMappingsDescriptorParserTest.java
@@ -0,0 +1,114 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+import java.io.IOException;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.EntityMappingsDescriptor;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.EntityMappingsDescriptorParser;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class EntityMappingsDescriptorParserTest
+{
+    private EntityMappingsDescriptorParser entityMappingsDescriptorParser;
+    private EntityMappingsDescriptor descriptor;
+
+    @Before
+    public void before() throws IOException
+    {
+        entityMappingsDescriptorParser
+            = new EntityMappingsDescriptorParser();
+        descriptor
+            = entityMappingsDescriptorParser.readAll(getClass().getResource("/").getPath(), "META-INF/test-orm.xml");
+    }
+    
+    @Test
+    public void testPackageName() throws IOException
+    {
+        Assert.assertEquals("org.apache.deltaspike.test.jpa.spi.descriptor.xml",
+                descriptor.getPackageName());
+    }
+    
+    @Test
+    public void testEntityDescriptors() throws IOException
+    {
+        Assert.assertNotNull(descriptor.getEntityDescriptors());
+        Assert.assertEquals(3, descriptor.getEntityDescriptors().size());
+    }
+    
+    @Test
+    public void testMappedSuperclassDescriptors() throws IOException
+    {
+        Assert.assertNotNull(descriptor.getMappedSuperclassDescriptors());
+        Assert.assertEquals(2, descriptor.getMappedSuperclassDescriptors().size());
+    }
+    
+    @Test
+    public void testEntityClass() throws IOException
+    {
+        Assert.assertEquals(MappedOne.class,
+                descriptor.getEntityDescriptors().get(0).getEntityClass());
+        Assert.assertEquals(MappedTwo.class,
+                descriptor.getEntityDescriptors().get(1).getEntityClass());
+        Assert.assertEquals(MappedThree.class,
+                descriptor.getEntityDescriptors().get(2).getEntityClass());
+    }
+    
+    @Test
+    public void testId() throws IOException
+    {
+        Assert.assertEquals("id",
+                descriptor.getEntityDescriptors().get(0).getId()[0]);
+        Assert.assertEquals("teeSetId",
+                descriptor.getEntityDescriptors().get(1).getId()[0]);
+        Assert.assertEquals("holeId",
+                descriptor.getEntityDescriptors().get(1).getId()[1]);
+        Assert.assertEquals(null,
+                descriptor.getEntityDescriptors().get(2).getId());
+    }
+    
+    @Test
+    public void testVersion() throws IOException
+    {
+        Assert.assertEquals("version",
+                descriptor.getEntityDescriptors().get(0).getVersion());
+        Assert.assertEquals(null,
+                descriptor.getEntityDescriptors().get(1).getVersion());
+        Assert.assertEquals(null,
+                descriptor.getEntityDescriptors().get(2).getVersion());
+        
+        Assert.assertEquals(null, descriptor.getMappedSuperclassDescriptors().get(0).getVersion());
+        Assert.assertEquals("version", descriptor.getMappedSuperclassDescriptors().get(1).getVersion());
+    }
+    
+    @Test
+    public void testName() throws IOException
+    {
+        Assert.assertEquals("Mapped_One",
+                descriptor.getEntityDescriptors().get(0).getName());
+    }
+    
+    @Test
+    public void testTableName() throws IOException
+    {
+        Assert.assertEquals("mapped_three_table",
+                descriptor.getEntityDescriptors().get(2).getTableName());
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedId.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedId.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedId.java
new file mode 100644
index 0000000..a4ddd50
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedId.java
@@ -0,0 +1,36 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+public class MappedId
+{
+
+    private Long id;
+
+    public Long getId()
+    {
+        return id;
+    }
+
+    public void setId(Long id)
+    {
+        this.id = id;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedOne.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedOne.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedOne.java
new file mode 100644
index 0000000..3f0a61a
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedOne.java
@@ -0,0 +1,56 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+public class MappedOne
+{
+
+    private Long id;
+    private String name;
+
+    public MappedOne()
+    {
+    }
+
+    public MappedOne(String name)
+    {
+        this.name = name;
+    }
+
+    public Long getId()
+    {
+        return id;
+    }
+
+    public void setId(Long id)
+    {
+        this.id = id;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedSuperclass.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedSuperclass.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedSuperclass.java
new file mode 100644
index 0000000..59bdc00
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedSuperclass.java
@@ -0,0 +1,36 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+public class MappedSuperclass extends MappedId
+{
+
+    private Long counter;
+
+    public Long getCounter()
+    {
+        return counter;
+    }
+
+    public void setCounter(Long id)
+    {
+        this.counter = id;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedThree.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedThree.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedThree.java
new file mode 100644
index 0000000..9abe4dd
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedThree.java
@@ -0,0 +1,36 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+public class MappedThree extends MappedSuperclass
+{
+
+    private String name;
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedTwo.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedTwo.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedTwo.java
new file mode 100644
index 0000000..6c069e5
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/MappedTwo.java
@@ -0,0 +1,59 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+public class MappedTwo
+{
+
+    private Long teeSetId;
+    private Long holeId;
+
+    private String name;
+
+    public Long getTeeSetId()
+    {
+        return teeSetId;
+    }
+
+    public void setTeeSetId(Long teeSetId)
+    {
+        this.teeSetId = teeSetId;
+    }
+
+    public Long getHoleId()
+    {
+        return holeId;
+    }
+
+    public void setHoleId(Long holeId)
+    {
+        this.holeId = holeId;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParserTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParserTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParserTest.java
new file mode 100644
index 0000000..7d8c227
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorParserTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+import java.io.IOException;
+import java.util.List;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptor;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptorParser;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PersistenceUnitDescriptorParserTest
+{
+    private PersistenceUnitDescriptorParser persistenceUnitDescriptorParser;
+    private List<PersistenceUnitDescriptor> descriptors;
+
+    @Before
+    public void before() throws IOException
+    {
+        persistenceUnitDescriptorParser
+            = new PersistenceUnitDescriptorParser();
+        descriptors
+            = persistenceUnitDescriptorParser.readAll();
+    }
+    
+    @Test
+    public void testPackageName() throws IOException
+    {
+        Assert.assertEquals("test", descriptors.get(0).getName());
+        Assert.assertEquals("test2", descriptors.get(1).getName());
+    }
+    
+    @Test
+    public void testProperties() throws IOException
+    {
+        Assert.assertNotNull(descriptors.get(0).getProperties());
+        Assert.assertEquals(1, descriptors.get(0).getProperties().size());
+        
+        Assert.assertNotNull(descriptors.get(1).getProperties());
+        Assert.assertEquals(3, descriptors.get(1).getProperties().size());
+        
+        Assert.assertNotNull(descriptors.get(2).getProperties());
+        Assert.assertEquals(0, descriptors.get(2).getProperties().size());
+    }
+    
+    @Test
+    public void testEntityDescriptors() throws IOException
+    {
+        Assert.assertNotNull(descriptors.get(0).getEntityDescriptors());
+        Assert.assertEquals(3, descriptors.get(0).getEntityDescriptors().size());
+        Assert.assertEquals(MappedOne.class,
+            descriptors.get(0).getEntityDescriptors().get(0).getEntityClass());
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProviderTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProviderTest.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProviderTest.java
new file mode 100644
index 0000000..5f863ce
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/PersistenceUnitDescriptorProviderTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+import java.io.IOException;
+import junit.framework.Assert;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptorProvider;
+import org.junit.Before;
+import org.junit.Test;
+
+public class PersistenceUnitDescriptorProviderTest
+{
+    @Before
+    public void before() throws IOException
+    {
+        PersistenceUnitDescriptorProvider.getInstance().init();
+    }
+    
+    @Test
+    public void bla()
+    {
+        String[] ids =
+            PersistenceUnitDescriptorProvider.getInstance().primaryKeyFields(MappedThree.class);
+        Assert.assertNotNull(ids);
+        Assert.assertEquals(1, ids.length);
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/TeeId.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/TeeId.java b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/TeeId.java
new file mode 100644
index 0000000..ecd5dea
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/java/org/apache/deltaspike/test/jpa/spi/descriptor/xml/TeeId.java
@@ -0,0 +1,103 @@
+/*
+ * 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.deltaspike.test.jpa.spi.descriptor.xml;
+
+import java.io.Serializable;
+
+import javax.persistence.Column;
+import javax.persistence.Embeddable;
+
+@Embeddable
+@SuppressWarnings("serial")
+public class TeeId implements Serializable
+{
+
+    @Column(nullable = false)
+    private Long teeSetId;
+
+    @Column(nullable = false)
+    private Long holeId;
+
+    public TeeId()
+    {
+    }
+
+    public TeeId(long teeSetId, long holeId)
+    {
+        this.teeSetId = teeSetId;
+        this.holeId = holeId;
+    }
+
+    @Override
+    public int hashCode()
+    {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (int) (holeId ^ (holeId >>> 32));
+        result = prime * result + (int) (teeSetId ^ (teeSetId >>> 32));
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (this == obj)
+        {
+            return true;
+        }
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        TeeId other = (TeeId) obj;
+        if (holeId != other.holeId)
+        {
+            return false;
+        }
+        if (teeSetId != other.teeSetId)
+        {
+            return false;
+        }
+        return true;
+    }
+
+    public long getTeeSetId()
+    {
+        return teeSetId;
+    }
+
+    public void setTeeSetId(long teeSetId)
+    {
+        this.teeSetId = teeSetId;
+    }
+
+    public long getHoleId()
+    {
+        return holeId;
+    }
+
+    public void setHoleId(long holeId)
+    {
+        this.holeId = holeId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/resources/META-INF/persistence.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/resources/META-INF/persistence.xml b/deltaspike/modules/jpa/impl/src/test/resources/META-INF/persistence.xml
new file mode 100644
index 0000000..d938f26
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/resources/META-INF/persistence.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
+    <persistence-unit name="test"> 
+        <jta-data-source>java:test/test</jta-data-source>
+        <mapping-file>META-INF/test-orm.xml</mapping-file>
+        <properties>
+            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+        </properties>
+    </persistence-unit>
+    <persistence-unit name="test2"> 
+        <properties>
+            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
+            <property name="anyOtherProperty" value="test"/>
+            <property name="anyOtherProperty2" value="test"/>
+        </properties>
+    </persistence-unit>
+    <persistence-unit name="test3"> 
+
+    </persistence-unit>
+</persistence>

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/impl/src/test/resources/META-INF/test-orm.xml
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/impl/src/test/resources/META-INF/test-orm.xml b/deltaspike/modules/jpa/impl/src/test/resources/META-INF/test-orm.xml
new file mode 100644
index 0000000..2fe2055
--- /dev/null
+++ b/deltaspike/modules/jpa/impl/src/test/resources/META-INF/test-orm.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
+        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm http://java.sun.com/xml/ns/persistence/orm_2_0.xsd" version="2.0">
+
+    <package>org.apache.deltaspike.test.jpa.spi.descriptor.xml</package>
+    
+    <mapped-superclass class="MappedSuperclass">
+    </mapped-superclass>
+    <mapped-superclass class="MappedId">
+        <attributes>
+            <id name="id">
+                <generated-value />
+            </id>
+            <version name="version" />
+        </attributes>
+    </mapped-superclass>
+    
+    <entity class="MappedOne" name="Mapped_One">
+        <attributes>
+            <id name="id">
+                <generated-value />
+            </id>
+            <version name="version" />
+        </attributes>
+    </entity>
+    <entity class="org.apache.deltaspike.test.jpa.spi.descriptor.xml.MappedTwo" name="Mapped_Two">
+        <id-class class="org.apache.deltaspike.test.jpa.spi.descriptor.xml.TeeId"/>
+        <attributes>
+            <id name="teeSetId"/>
+            <id name="holeId"/>
+        </attributes>
+    </entity>
+    <entity class="MappedThree">
+        <table name="mapped_three_table" />
+    </entity>
+    
+
+
+</entity-mappings>
\ No newline at end of file


[2/2] deltaspike git commit: DELTASPIKE-1095 Move persistence/orm.xml mapping + parsing from DATA impl to JPA api/spi

Posted by ta...@apache.org.
DELTASPIKE-1095 Move  persistence/orm.xml mapping + parsing from DATA impl to JPA api/spi

Project: http://git-wip-us.apache.org/repos/asf/deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/deltaspike/commit/6480a0e5
Tree: http://git-wip-us.apache.org/repos/asf/deltaspike/tree/6480a0e5
Diff: http://git-wip-us.apache.org/repos/asf/deltaspike/diff/6480a0e5

Branch: refs/heads/master
Commit: 6480a0e5466567f487f36d73de697c6310f69149
Parents: f30b389
Author: Thomas Andraschko <ta...@apache.org>
Authored: Sat Mar 19 21:20:52 2016 +0100
Committer: Thomas Andraschko <ta...@apache.org>
Committed: Sat Mar 19 21:20:52 2016 +0100

----------------------------------------------------------------------
 .../core/util/AggregatedClassLoader.java        |  95 ++++++++
 .../data/impl/RepositoryExtension.java          |   4 +-
 .../meta/extractor/TypeMetadataExtractor.java   |   8 +-
 .../data/impl/meta/unit/Descriptor.java         |  47 ----
 .../meta/unit/DescriptorHierarchyBuilder.java   |  88 -------
 .../data/impl/meta/unit/DescriptorReader.java   | 115 ---------
 .../data/impl/meta/unit/EntityDescriptor.java   |  81 -------
 .../impl/meta/unit/EntityDescriptorReader.java  | 223 ------------------
 .../meta/unit/MappedSuperclassDescriptor.java   |  67 ------
 .../data/impl/meta/unit/PersistenceUnit.java    |  72 ------
 .../impl/meta/unit/PersistenceUnitReader.java   | 130 ----------
 .../data/impl/meta/unit/PersistenceUnits.java   | 150 ------------
 .../meta/unit/PersistentClassDescriptor.java    | 140 -----------
 .../data/impl/meta/verifier/EntityVerifier.java |   6 +-
 .../deltaspike/data/impl/util/EntityUtils.java  |  21 +-
 .../impl/util/cl/AggregatedClassLoader.java     |  93 --------
 .../unit/DescriptorHierarchyBuilderTest.java    |  26 +-
 .../impl/meta/unit/PersistenceUnitsTest.java    |  44 ++--
 .../xml/AbstractEntityDescriptor.java           | 108 +++++++++
 .../xml/AbstractEntityHierarchyBuilder.java     |  81 +++++++
 .../jpa/spi/descriptor/xml/Descriptor.java      |  46 ++++
 .../spi/descriptor/xml/DescriptorReader.java    | 114 +++++++++
 .../spi/descriptor/xml/EntityDescriptor.java    |  63 +++++
 .../xml/EntityMappingsDescriptor.java           |  66 ++++++
 .../xml/EntityMappingsDescriptorParser.java     | 235 +++++++++++++++++++
 .../xml/MappedSuperclassDescriptor.java         |  48 ++++
 .../xml/PersistenceUnitDescriptor.java          |  80 +++++++
 .../xml/PersistenceUnitDescriptorParser.java    | 136 +++++++++++
 .../xml/PersistenceUnitDescriptorProvider.java  | 191 +++++++++++++++
 .../xml/EntityMappingsDescriptorParserTest.java | 114 +++++++++
 .../test/jpa/spi/descriptor/xml/MappedId.java   |  36 +++
 .../test/jpa/spi/descriptor/xml/MappedOne.java  |  56 +++++
 .../spi/descriptor/xml/MappedSuperclass.java    |  36 +++
 .../jpa/spi/descriptor/xml/MappedThree.java     |  36 +++
 .../test/jpa/spi/descriptor/xml/MappedTwo.java  |  59 +++++
 .../PersistenceUnitDescriptorParserTest.java    |  71 ++++++
 .../PersistenceUnitDescriptorProviderTest.java  |  43 ++++
 .../test/jpa/spi/descriptor/xml/TeeId.java      | 103 ++++++++
 .../src/test/resources/META-INF/persistence.xml |  38 +++
 .../src/test/resources/META-INF/test-orm.xml    |  58 +++++
 40 files changed, 1978 insertions(+), 1250 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AggregatedClassLoader.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AggregatedClassLoader.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AggregatedClassLoader.java
new file mode 100644
index 0000000..84f9106
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/AggregatedClassLoader.java
@@ -0,0 +1,95 @@
+/*
+ * 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.deltaspike.core.util;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+public class AggregatedClassLoader extends ClassLoader
+{
+
+    private final List<ClassLoader> classLoaders;
+
+    public AggregatedClassLoader(List<ClassLoader> classLoaders)
+    {
+        super();
+        this.classLoaders = classLoaders;
+    }
+
+    public static AggregatedClassLoader newInstance()
+    {
+        return new AggregatedClassLoader(Arrays.asList(
+                AggregatedClassLoader.class.getClassLoader(),
+                Thread.currentThread().getContextClassLoader(),
+                ClassLoader.getSystemClassLoader()));
+    }
+
+    @Override
+    public URL getResource(String name)
+    {
+        for (ClassLoader loader : classLoaders)
+        {
+            URL url = loader.getResource(name);
+            if (url != null)
+            {
+                return url;
+            }
+        }
+        return super.getResource(name);
+    }
+
+    @Override
+    public Enumeration<URL> getResources(String name) throws IOException
+    {
+        final Set<URL> result = new LinkedHashSet<URL>();
+        
+        for (ClassLoader loader : classLoaders)
+        {
+            Enumeration<URL> urls = loader.getResources(name);
+            while (urls.hasMoreElements())
+            {
+                result.add(urls.nextElement());
+            }
+        }
+        
+        return new Enumeration<URL>()
+        {
+            private final Iterator<URL> iterator = result.iterator();
+
+            @Override
+            public URL nextElement()
+            {
+                return iterator.next();
+            }
+
+            @Override
+            public boolean hasMoreElements()
+            {
+                return iterator.hasNext();
+            }
+        };
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
index f33545d..28714a7 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/RepositoryExtension.java
@@ -39,7 +39,7 @@ import org.apache.deltaspike.data.api.AbstractEntityRepository;
 import org.apache.deltaspike.data.api.AbstractFullEntityRepository;
 import org.apache.deltaspike.data.api.Repository;
 import org.apache.deltaspike.data.impl.meta.RepositoryComponents;
-import org.apache.deltaspike.data.impl.meta.unit.PersistenceUnits;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptorProvider;
 
 /**
  * The main extension class for Repositories, based on PartialBeans. Handles following events:<br/>
@@ -77,7 +77,7 @@ public class RepositoryExtension implements Extension, Deactivatable
         {
             return;
         }
-        PersistenceUnits.instance().init();
+        PersistenceUnitDescriptorProvider.getInstance().init();
     }
 
     @SuppressWarnings("unchecked")

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java
index f02a621..043ab88 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/extractor/TypeMetadataExtractor.java
@@ -71,11 +71,17 @@ public class TypeMetadataExtractor implements MetadataExtractor
         {
             return null;
         }
+        
         ParameterizedType parametrizedType = (ParameterizedType) type;
         Type[] genericTypes = parametrizedType.getActualTypeArguments();
+        
         RepositoryEntity result = null;
-        for (Type genericType : genericTypes)
+        
+        // don't use a foreach here, we must be sure that the we first get the entity type
+        for (int i = 0; i < genericTypes.length; i++)
         {
+            Type genericType = genericTypes[i];
+            
             if (genericType instanceof Class && EntityUtils.isEntityClass((Class<?>) genericType))
             {
                 result = new RepositoryEntity((Class<?>) genericType);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/Descriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/Descriptor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/Descriptor.java
deleted file mode 100644
index 8350f36..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/Descriptor.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.net.URL;
-
-import org.w3c.dom.Document;
-
-class Descriptor
-{
-
-    private final Document document;
-    private final URL url;
-
-    public Descriptor(Document document, URL url)
-    {
-        this.document = document;
-        this.url = url;
-    }
-
-    public Document getDocument()
-    {
-        return document;
-    }
-
-    public URL getUrl()
-    {
-        return url;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilder.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilder.java
deleted file mode 100644
index e57099c..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilder.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.util.List;
-
-public final class DescriptorHierarchyBuilder
-{
-
-    private final List<EntityDescriptor> entities;
-    private final List<MappedSuperclassDescriptor> superClasses;
-
-    private DescriptorHierarchyBuilder(List<EntityDescriptor> entities,
-            List<MappedSuperclassDescriptor> superClasses)
-    {
-        this.entities = entities;
-        this.superClasses = superClasses;
-    }
-
-    public static DescriptorHierarchyBuilder newInstance(List<EntityDescriptor> entities,
-            List<MappedSuperclassDescriptor> superClasses)
-    {
-        return new DescriptorHierarchyBuilder(entities, superClasses);
-    }
-
-    public void buildHierarchy()
-    {
-        for (EntityDescriptor descriptor : entities)
-        {
-            buildHierarchy(descriptor);
-        }
-    }
-
-    private void buildHierarchy(PersistentClassDescriptor descriptor)
-    {
-        Class<?> superClass = descriptor.getEntityClass().getSuperclass();
-        while (superClass != null)
-        {
-            PersistentClassDescriptor superDescriptor = findPersistentClassDescriptor(superClass);
-            if (superDescriptor != null)
-            {
-                if (descriptor.getParent() == null)
-                {
-                    buildHierarchy(superDescriptor);
-                }
-                descriptor.setParent(superDescriptor);
-                return;
-            }
-            superClass = superClass.getSuperclass();
-        }
-    }
-
-    private PersistentClassDescriptor findPersistentClassDescriptor(Class<?> superClass)
-    {
-        for (MappedSuperclassDescriptor descriptor : superClasses)
-        {
-            if (descriptor.getEntityClass().equals(superClass))
-            {
-                return descriptor;
-            }
-        }
-        for (EntityDescriptor descriptor : entities)
-        {
-            if (descriptor.getEntityClass().equals(superClass))
-            {
-                return descriptor;
-            }
-        }
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorReader.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorReader.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorReader.java
deleted file mode 100644
index 300b904..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorReader.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import org.apache.deltaspike.data.impl.util.cl.AggregatedClassLoader;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-abstract class DescriptorReader
-{
-    private static final Logger log = Logger.getLogger(DescriptorReader.class.getName());
-
-    private final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-
-    List<Descriptor> readAllFromClassPath(String resource) throws IOException
-    {
-        List<Descriptor> result = new LinkedList<Descriptor>();
-        Enumeration<URL> urls = classLoader().getResources(resource);
-        while (urls.hasMoreElements())
-        {
-            URL u = urls.nextElement();
-            try
-            {
-                result.add(readFromUrl(u));
-            }
-            catch (Exception e)
-            {
-                log.log(Level.WARNING, "Could not load " + resource + " from " + u, e);
-            }
-        }
-        return Collections.unmodifiableList(result);
-    }
-
-    Descriptor readFromClassPath(String resource) throws IOException
-    {
-        return readFromUrl(classLoader().getResource(resource));
-    }
-
-    Descriptor readFromUrl(URL url) throws IOException
-    {
-        InputStream stream = url.openStream();
-        try
-        {
-            DocumentBuilder builder = factory.newDocumentBuilder();
-            return new Descriptor(builder.parse(new InputSource(stream)), url);
-        }
-        catch (SAXException e)
-        {
-            throw new RuntimeException("Failed reading XML document", e);
-        }
-        catch (ParserConfigurationException e)
-        {
-            throw new RuntimeException("Failed reading XML document", e);
-        }
-        finally
-        {
-            stream.close();
-        }
-    }
-
-    Descriptor read(String baseUrl, String resource) throws IOException
-    {
-        try
-        {
-            URL url = new URL(baseUrl + resource);
-            return readFromUrl(url);
-        }
-        catch (Exception e)
-        {
-            return readFromClassPath(resource);
-        }
-    }
-
-    String extractBaseUrl(URL fileUrl, String resource)
-    {
-        String file = fileUrl.toString();
-        return file.substring(0, file.length() - resource.length());
-    }
-
-    ClassLoader classLoader()
-    {
-        return AggregatedClassLoader.newInstance();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/EntityDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/EntityDescriptor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/EntityDescriptor.java
deleted file mode 100644
index 6469baa..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/EntityDescriptor.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.io.Serializable;
-
-import static org.apache.deltaspike.core.util.StringUtils.isEmpty;
-
-class EntityDescriptor extends PersistentClassDescriptor
-{
-
-    protected final String tableName;
-
-    EntityDescriptor(String name, String packageName, String className, String idClass, String id,
-                     String version, String tableName)
-    {
-        super(name, packageName, className, idClass, id, version);
-        this.tableName = tableName;
-    }
-
-    public boolean is(Class<?> entityClass)
-    {
-        return this.entityClass.equals(entityClass);
-    }
-
-    @Override
-    public Class<? extends Serializable> getIdClass()
-    {
-        if (idClass == null && getParent() != null)
-        {
-            return getParent().getIdClass();
-        }
-        return super.getIdClass();
-    }
-
-    @Override
-    public String getId()
-    {
-        if (isEmpty(id) && getParent() != null)
-        {
-            return getParent().getId();
-        }
-        return super.getId();
-    }
-
-    public String getTableName()
-    {
-        return tableName;
-    }
-
-    @Override
-    public String toString()
-    {
-        StringBuilder builder = new StringBuilder();
-        builder.append("EntityDescriptor ")
-                .append("[entityClass=").append(className(entityClass))
-                .append(", name=").append(name)
-                .append(", idClass=").append(className(idClass))
-                .append(", id=").append(id)
-                .append(", superClass=").append(getParent())
-                .append(", tableName=").append(tableName)
-                .append("]");
-        return builder.toString();
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/EntityDescriptorReader.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/EntityDescriptorReader.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/EntityDescriptorReader.java
deleted file mode 100644
index 0b85e70..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/EntityDescriptorReader.java
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class EntityDescriptorReader extends DescriptorReader
-{
-
-    public MappingFile readAll(String baseUrl, String resource) throws IOException
-    {
-        return readFromDocument(read(baseUrl, resource).getDocument());
-    }
-
-    public MappingFile readDefaultOrm(String baseUrl) throws IOException
-    {
-        try
-        {
-            Descriptor desc = read(baseUrl, PersistenceUnit.DEFAULT_ORM_PATH);
-            return readFromDocument(desc.getDocument());
-        }
-        catch (Exception e)
-        {
-            return new MappingFile(Collections.<EntityDescriptor>emptyList(),
-                    Collections.<MappedSuperclassDescriptor>emptyList());
-        }
-    }
-
-    public MappingFile readFromDocument(Document doc)
-    {
-        EntityBuilder<EntityDescriptor> entityDescriptorBuilder = new EntityBuilder<EntityDescriptor>()
-        {
-            @Override
-            protected EntityDescriptor instance(String name, String packageName, String className,
-                                      String idClass, String id, String version, String tableName)
-            {
-                return new EntityDescriptor(name, packageName, className, idClass, id, version, tableName);
-            }
-
-            @Override
-            protected String tagName()
-            {
-                return "entity";
-            }
-        };
-        
-        MappedSuperClassBuilder<MappedSuperclassDescriptor> superClassBuilder = 
-            new MappedSuperClassBuilder<MappedSuperclassDescriptor>()
-            {
-                @Override
-                protected MappedSuperclassDescriptor instance(String name, String packageName, String className,
-                                                    String idClass, String id, String version)
-                {
-                    return new MappedSuperclassDescriptor(name, packageName, className, idClass, id, version);
-                }
-
-                @Override
-                protected String tagName()
-                {
-                    return "mapped-superclass";
-                }
-            };
-        return new MappingFile(entityDescriptorBuilder.build(doc), superClassBuilder.build(doc));
-    }
-
-    private String extractNodeAttribute(Element element, String childName, String attribute)
-    {
-        NodeList list = element.getElementsByTagName(childName);
-        if (list.getLength() == 0)
-        {
-            return null;
-        }
-        return extractAttribute(list.item(0), attribute);
-    }
-
-    private String extractAttribute(Node item, String name)
-    {
-        Node node = item.getAttributes().getNamedItem(name);
-        if (node != null)
-        {
-            return node.getTextContent();
-        }
-        return null;
-    }
-
-    private String extractNodeContent(Element element, String name)
-    {
-        NodeList list = element.getElementsByTagName(name);
-        if (list.getLength() == 0)
-        {
-            return null;
-        }
-        return list.item(0).getTextContent();
-    }
-
-    public static class MappingFile
-    {
-        private final List<EntityDescriptor> entities;
-        private final List<MappedSuperclassDescriptor> superClasses;
-
-        public MappingFile(List<EntityDescriptor> entities, List<MappedSuperclassDescriptor> superClasses)
-        {
-            this.entities = entities;
-            this.superClasses = superClasses;
-        }
-
-        public List<EntityDescriptor> getEntities()
-        {
-            return entities;
-        }
-
-        public List<MappedSuperclassDescriptor> getSuperClasses()
-        {
-            return superClasses;
-        }
-    }
-
-
-    private abstract class PersistenceBuilder<T extends PersistentClassDescriptor>
-    {
-        protected List<T> result;
-        protected String packageName;
-        protected String name;
-        protected String className;
-        protected String idClass;
-        protected String id;
-        protected String version;
-        protected String embeddedId;
-
-        public List<T> build(Document doc)
-        {
-            this.result = new LinkedList<T>();
-            this.packageName = extractNodeContent(doc.getDocumentElement(), "package");
-            NodeList mappings = doc.getElementsByTagName(tagName());
-            for (int i = 0; i < mappings.getLength(); i++)
-            {
-                this.name = extractAttribute(mappings.item(i), "name");
-                this.className = extractAttribute(mappings.item(i), "class");
-                this.idClass = extractNodeAttribute((Element) mappings.item(i), "id-class", "class");
-                this.id = extractNodeAttribute((Element) mappings.item(i), "id", "name");
-                this.version = extractNodeAttribute((Element) mappings.item(i), "version", "name");
-                this.embeddedId = extractNodeAttribute((Element) mappings.item(i), "embedded-id", "name");
-                addFields((Element) mappings.item(i));
-                addInResult();
-            }
-            return this.result;
-        }
-
-        protected abstract String tagName();
-
-        protected abstract void addInResult();
-
-        protected abstract void addFields(Element element);
-    }
-
-    private abstract class MappedSuperClassBuilder<T extends PersistentClassDescriptor> extends PersistenceBuilder<T>
-    {
-        protected abstract T instance(String name, String packageName, String className, String idClass, String id,
-                                      String version);
-
-        protected abstract String tagName();
-
-        @Override
-        protected void addInResult()
-        {
-            result.add(instance(name, packageName, className, idClass, id != null ? id : embeddedId, version));
-        }
-
-        @Override
-        protected void addFields(Element element)
-        {
-            // do nothing;
-        }
-    }
-
-    private abstract class EntityBuilder<T extends PersistentClassDescriptor> extends PersistenceBuilder<T>
-    {
-
-        protected String tableName;
-
-        protected abstract T instance(String name, String packageName, String className, String idClass, String id,
-                                      String version, String tableName);
-
-        protected abstract String tagName();
-
-        @Override
-        protected void addInResult()
-        {
-            result.add(instance(name, packageName, className, idClass, id != null ? id : embeddedId,
-                version, tableName));
-        }
-
-        @Override
-        protected void addFields(Element element)
-        {
-            this.tableName = extractNodeAttribute(element, "table", "name");
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/MappedSuperclassDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/MappedSuperclassDescriptor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/MappedSuperclassDescriptor.java
deleted file mode 100644
index 58d752b..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/MappedSuperclassDescriptor.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.io.Serializable;
-import org.apache.deltaspike.core.util.StringUtils;
-
-class MappedSuperclassDescriptor extends PersistentClassDescriptor
-{
-
-    MappedSuperclassDescriptor(String name, String packageName, String className, String idClass, String id,
-                               String version)
-    {
-        super(name, packageName, className, idClass, id, version);
-    }
-
-    @Override
-    public Class<? extends Serializable> getIdClass()
-    {
-        if (idClass == null && getParent() != null)
-        {
-            return getParent().getIdClass();
-        }
-        return super.getIdClass();
-    }
-
-    @Override
-    public String getId()
-    {
-        if (StringUtils.isEmpty(id) && getParent() != null)
-        {
-            return getParent().getId();
-        }
-        return super.getId();
-    }
-
-    @Override
-    public String toString()
-    {
-        StringBuilder builder = new StringBuilder();
-        builder.append("MappedSuperclassDescriptor ")
-                .append("[entityClass=").append(className(entityClass))
-                .append(", name=").append(name)
-                .append(", idClass=").append(className(idClass))
-                .append(", id=").append(id)
-                .append(", parent=").append(getParent())
-                .append("]");
-        return builder.toString();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java
deleted file mode 100644
index e238385..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnit.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.util.List;
-import java.util.Map;
-
-public class PersistenceUnit
-{
-
-    public static final String RESOURCE_PATH = "META-INF/persistence.xml";
-    public static final String DEFAULT_ORM_PATH = "META-INF/orm.xml";
-
-    private final String unitName;
-    private final List<EntityDescriptor> entities;
-    private final Map<String, String> properties;
-
-    PersistenceUnit(String unitName, List<EntityDescriptor> entities, Map<String, String> properties)
-    {
-        this.unitName = unitName;
-        this.entities = entities;
-        this.properties = properties;
-    }
-
-    public EntityDescriptor find(Class<?> entityClass)
-    {
-        for (EntityDescriptor entity : entities)
-        {
-            if (entity.is(entityClass))
-            {
-                return entity;
-            }
-        }
-        return null;
-    }
-
-    public String getUnitName()
-    {
-        return unitName;
-    }
-    
-    public Map<String, String> getProperties()
-    {
-        return properties;
-    }
-
-    @Override
-    public String toString()
-    {
-        StringBuilder builder = new StringBuilder();
-        builder.append("PersistenceUnit [unitName=").append(unitName)
-                .append(", entities=").append(entities).append("]");
-        return builder.toString();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java
deleted file mode 100644
index ed30e32..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitReader.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import org.apache.deltaspike.data.impl.meta.unit.EntityDescriptorReader.MappingFile;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-
-public class PersistenceUnitReader extends DescriptorReader
-{
-
-    public List<PersistenceUnit> readAll() throws IOException
-    {
-        List<PersistenceUnit> result = new LinkedList<PersistenceUnit>();
-        List<Descriptor> persistenceXmls = readAllFromClassPath(PersistenceUnit.RESOURCE_PATH);
-        for (Descriptor desc : persistenceXmls)
-        {
-            result.addAll(lookupUnits(desc));
-        }
-        return Collections.unmodifiableList(result);
-    }
-
-    private List<PersistenceUnit> lookupUnits(Descriptor descriptor)
-    {
-        List<PersistenceUnit> result = new LinkedList<PersistenceUnit>();
-        NodeList list = descriptor.getDocument().getDocumentElement().getElementsByTagName("persistence-unit");
-        for (int i = 0; i < list.getLength(); i++)
-        {
-            Node node = list.item(i);
-            String unitName = extractUnitName(node);
-            String baseUrl = extractBaseUrl(descriptor.getUrl(), PersistenceUnit.RESOURCE_PATH);
-            List<EntityDescriptor> entities = extractMappings((Element) node, baseUrl, unitName);
-            Map<String, String> properties = extractProperties((Element) node);
-            result.add(new PersistenceUnit(unitName, entities, properties));
-        }
-        return result;
-    }
-
-    private List<EntityDescriptor> extractMappings(Element element, String baseUrl, String unitName)
-    {
-        try
-        {
-            EntityDescriptorReader reader = new EntityDescriptorReader();
-            List<EntityDescriptor> entities = new LinkedList<EntityDescriptor>();
-            List<MappedSuperclassDescriptor> superClasses = new LinkedList<MappedSuperclassDescriptor>();
-            NodeList list = element.getElementsByTagName("mapping-file");
-            readMappingFiles(baseUrl, unitName, reader, entities, superClasses, list);
-            MappingFile mappings = reader.readDefaultOrm(baseUrl);
-            entities.addAll(mappings.getEntities());
-            superClasses.addAll(mappings.getSuperClasses());
-            DescriptorHierarchyBuilder.newInstance(entities, superClasses).buildHierarchy();
-            return entities;
-        }
-        catch (Exception e)
-        {
-            throw new RuntimeException("Failed initializing mapping files", e);
-        }
-    }
-
-    private void readMappingFiles(String baseUrl, String unitName, EntityDescriptorReader reader,
-                                  List<EntityDescriptor> entities, List<MappedSuperclassDescriptor> superClasses,
-                                  NodeList list)
-    {
-        for (int i = 0; i < list.getLength(); i++)
-        {
-            String resource = list.item(i).getTextContent();
-            try
-            {
-                MappingFile mappings = reader.readAll(baseUrl, resource);
-                entities.addAll(mappings.getEntities());
-                superClasses.addAll(mappings.getSuperClasses());
-            }
-            catch (Exception e)
-            {
-                throw new RuntimeException("[PersistenceUnit: " + unitName + "] " +
-                        "Unable to resolve named mapping-file [" + resource + "]");
-            }
-        }
-    }
-
-    private String extractUnitName(Node node)
-    {
-        return node.getAttributes().getNamedItem("name").getTextContent();
-    }
-
-    private Map<String, String> extractProperties(Element element)
-    {
-        Map<String, String> propertiesMap = new HashMap<String, String>();
-
-        Node propertiesNode = element.getElementsByTagName("properties").item(0);
-        if (propertiesNode != null)
-        {
-            NodeList propertyNodes = propertiesNode.getChildNodes();
-            for (int i = 0; i < propertyNodes.getLength(); i++)
-            {
-                if ("property".equals(propertyNodes.item(i).getNodeName()))
-                {
-                    Element propertyNode = (Element) propertyNodes.item(i);
-                    propertiesMap.put(propertyNode.getAttribute("name"), propertyNode.getAttribute("value"));
-                }
-            }
-        }
-
-        return Collections.unmodifiableMap(propertiesMap);
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java
deleted file mode 100644
index 9bbb0e7..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnits.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.io.IOException;
-import java.util.Collections;
-import java.util.List;
-
-import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
-
-public final class PersistenceUnits
-{
-
-    private static PersistenceUnits instance = new PersistenceUnits();
-
-    private List<PersistenceUnit> persistenceUnits = Collections.emptyList();
-
-    private PersistenceUnits()
-    {
-    }
-
-    public static PersistenceUnits instance()
-    {
-        return instance;
-    }
-
-    public void init()
-    {
-        persistenceUnits = readPersistenceXmls();
-    }
-
-    public PersistenceUnit get(String name)
-    {
-        for (PersistenceUnit unit : persistenceUnits)
-        {
-            if (name.equalsIgnoreCase(unit.getUnitName()))
-            {
-                return unit;
-            }
-        }
-        return null;
-    }
-
-    public boolean isEntity(Class<?> entityClass)
-    {
-        return find(entityClass) != null;
-    }
-
-    public String primaryKeyField(Class<?> entityClass)
-    {
-        EntityDescriptor entity = find(entityClass);
-        if (entity != null)
-        {
-            return entity.getId();
-        }
-        return null;
-    }
-
-    public String versionField(Class<?> entityClass)
-    {
-        EntityDescriptor entity = find(entityClass);
-        if (entity != null)
-        {
-            return entity.getVersion();
-        }
-        return null;
-    }
-
-    public Class<?> primaryKeyIdClass(Class<?> entityClass)
-    {
-        EntityDescriptor entity = find(entityClass);
-        if (entity != null && entity.getIdClass() != null)
-        {
-            return entity.getIdClass();
-        }
-        return null;
-    }
-
-    public String entityName(Class<?> entityClass)
-    {
-        EntityDescriptor entity = find(entityClass);
-        if (entity != null)
-        {
-            return entity.getName();
-        }
-        return null;
-    }
-
-    public RepositoryEntity lookupMetadata(Class<?> entityClass)
-    {
-        EntityDescriptor entity = find(entityClass);
-        if (entity != null)
-        {
-            return new RepositoryEntity(entityClass, entity.getIdClass());
-        }
-        return null;
-    }
-
-    private List<PersistenceUnit> readPersistenceXmls()
-    {
-        try
-        {
-            PersistenceUnitReader reader = new PersistenceUnitReader();
-            return reader.readAll();
-        }
-        catch (IOException e)
-        {
-            throw new RuntimeException("Failed to read persistence unit info", e);
-        }
-    }
-
-    private EntityDescriptor find(Class<?> entityClass)
-    {
-        for (PersistenceUnit unit : persistenceUnits)
-        {
-            EntityDescriptor entity = unit.find(entityClass);
-            if (entity != null)
-            {
-                return entity;
-            }
-        }
-        return null;
-    }
-
-    public String entityTableName(Class<?> entityClass)
-    {
-        EntityDescriptor entity = find(entityClass);
-        if (entity != null)
-        {
-            return entity.getTableName();
-        }
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistentClassDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistentClassDescriptor.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistentClassDescriptor.java
deleted file mode 100644
index 6c45b4f..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/unit/PersistentClassDescriptor.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * 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.deltaspike.data.impl.meta.unit;
-
-import java.io.Serializable;
-
-import org.apache.deltaspike.data.impl.property.query.NamedPropertyCriteria;
-import org.apache.deltaspike.data.impl.property.query.PropertyQueries;
-import org.apache.deltaspike.data.impl.property.query.PropertyQuery;
-
-abstract class PersistentClassDescriptor
-{
-
-    protected final String name;
-    protected final Class<?> entityClass;
-    protected final Class<? extends Serializable> idClass;
-    protected final String id;
-    protected final String version;
-    private PersistentClassDescriptor parent;
-
-    PersistentClassDescriptor(String name, String packageName, String className, String idClass, String id,
-                              String version)
-    {
-        Class<?> clazz = entityClass(className, packageName);
-        this.name = name;
-        this.entityClass = clazz;
-        this.idClass = idClass(clazz, idClass, packageName, id);
-        this.id = id;
-        this.version = version;
-    }
-
-    public Class<? extends Serializable> getIdClass()
-    {
-        return idClass;
-    }
-
-    public String getId()
-    {
-        return id;
-    }
-
-    public String getVersion()
-    {
-        return version;
-    }
-
-    public String getName()
-    {
-        return name;
-    }
-
-    public Class<?> getEntityClass()
-    {
-        return entityClass;
-    }
-
-    String className(Class<?> clazz)
-    {
-        return clazz == null ? null : clazz.getSimpleName();
-    }
-
-    private Class<?> entityClass(String entityClass, String packageName)
-    {
-        try
-        {
-            String clazzName = buildClassName(entityClass, packageName);
-            return Class.forName(clazzName);
-        }
-        catch (ClassNotFoundException e)
-        {
-            throw new IllegalArgumentException("Can't create class " + buildClassName(entityClass, packageName), e);
-        }
-    }
-
-    @SuppressWarnings("unchecked")
-    private Class<? extends Serializable> idClass(Class<?> entity, String idClass, String packageName, String id)
-    {
-        try
-        {
-            return (Class<? extends Serializable>) (idClass != null ? Class
-                    .forName(buildClassName(idClass, packageName)) : lookupIdClass(entity, id));
-        }
-        catch (ClassNotFoundException e)
-        {
-            throw new IllegalArgumentException("Failed to get ID class", e);
-        }
-    }
-
-    private Class<?> lookupIdClass(Class<?> entity, String id)
-    {
-        if (entity == null || id == null)
-        {
-            return null;
-        }
-        PropertyQuery<Serializable> query = PropertyQueries.<Serializable> createQuery(entity)
-                .addCriteria(new NamedPropertyCriteria(id));
-        return query.getFirstResult().getJavaClass();
-    }
-
-    private String buildClassName(String clazzName, String packageName)
-    {
-        if (clazzName == null && packageName == null)
-        {
-            return null;
-        }
-        return (packageName != null && !isClassNameQualified(clazzName)) ? packageName + "." + clazzName : clazzName;
-    }
-
-    private boolean isClassNameQualified(String name)
-    {
-        return name.contains(".");
-    }
-
-    public PersistentClassDescriptor getParent()
-    {
-        return parent;
-    }
-
-    public void setParent(PersistentClassDescriptor parent)
-    {
-        this.parent = parent;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/verifier/EntityVerifier.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/verifier/EntityVerifier.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/verifier/EntityVerifier.java
index e37d1a8..ada5776 100644
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/verifier/EntityVerifier.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/meta/verifier/EntityVerifier.java
@@ -19,8 +19,7 @@
 package org.apache.deltaspike.data.impl.meta.verifier;
 
 import javax.persistence.Entity;
-
-import org.apache.deltaspike.data.impl.meta.unit.PersistenceUnits;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptorProvider;
 
 public class EntityVerifier implements Verifier<Class<?>>
 {
@@ -28,7 +27,8 @@ public class EntityVerifier implements Verifier<Class<?>>
     @Override
     public boolean verify(Class<?> entity)
     {
-        return entity.isAnnotationPresent(Entity.class) || PersistenceUnits.instance().isEntity(entity);
+        return entity.isAnnotationPresent(Entity.class)
+                || PersistenceUnitDescriptorProvider.getInstance().isEntity(entity);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/EntityUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/EntityUtils.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/EntityUtils.java
index ec38e34..736452f 100755
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/EntityUtils.java
+++ b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/EntityUtils.java
@@ -32,7 +32,6 @@ import javax.persistence.Version;
 import javax.persistence.metamodel.EntityType;
 import org.apache.deltaspike.core.util.StringUtils;
 
-import org.apache.deltaspike.data.impl.meta.unit.PersistenceUnits;
 import org.apache.deltaspike.data.impl.meta.verifier.EntityVerifier;
 import org.apache.deltaspike.data.impl.property.Property;
 import org.apache.deltaspike.data.impl.property.query.AnnotatedPropertyCriteria;
@@ -40,6 +39,7 @@ import org.apache.deltaspike.data.impl.property.query.NamedPropertyCriteria;
 import org.apache.deltaspike.data.impl.property.query.PropertyCriteria;
 import org.apache.deltaspike.data.impl.property.query.PropertyQueries;
 import org.apache.deltaspike.data.impl.property.query.PropertyQuery;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptorProvider;
 
 public final class EntityUtils
 {
@@ -56,7 +56,7 @@ public final class EntityUtils
             return entityClass.getAnnotation(IdClass.class).value(); // Serializablity isn't required, could cause
                                                                      // problems
         }
-        Class clazz = PersistenceUnits.instance().primaryKeyIdClass(entityClass);
+        Class clazz = PersistenceUnitDescriptorProvider.getInstance().primaryKeyIdClass(entityClass);
         if (clazz != null)
         {
             return clazz;
@@ -85,14 +85,14 @@ public final class EntityUtils
         }
         else
         {
-            result = PersistenceUnits.instance().entityName(entityClass);
+            result = PersistenceUnitDescriptorProvider.getInstance().entityName(entityClass);
         }
         return (result != null && !"".equals(result)) ? result : entityClass.getSimpleName();
     }
 
     public static String tableName(Class<?> entityClass, EntityManager entityManager)
     {
-        String tableName = PersistenceUnits.instance().entityTableName(entityClass);
+        String tableName = PersistenceUnitDescriptorProvider.getInstance().entityTableName(entityClass);
         if (StringUtils.isEmpty(tableName))
         {
             EntityType<?> entityType = entityManager.getMetamodel().entity(entityClass);
@@ -109,7 +109,7 @@ public final class EntityUtils
 
     public static Property<Serializable> primaryKeyProperty(Class<?> entityClass)
     {
-        for (PropertyCriteria c : criteriaList(entityClass))
+        for (PropertyCriteria c : primaryKeyPropertyCriteriaList(entityClass))
         {
             PropertyQuery<Serializable> query = PropertyQueries.<Serializable> createQuery(entityClass)
                     .addCriteria(c);
@@ -121,15 +121,18 @@ public final class EntityUtils
         throw new IllegalStateException("Class " + entityClass + " has no id defined");
     }
 
-    private static List<PropertyCriteria> criteriaList(Class<?> entityClass)
+    private static List<PropertyCriteria> primaryKeyPropertyCriteriaList(Class<?> entityClass)
     {
         List<PropertyCriteria> criteria = new LinkedList<PropertyCriteria>();
         criteria.add(new AnnotatedPropertyCriteria(Id.class));
         criteria.add(new AnnotatedPropertyCriteria(EmbeddedId.class));
-        String fromMappingFiles = PersistenceUnits.instance().primaryKeyField(entityClass);
+        String[] fromMappingFiles = PersistenceUnitDescriptorProvider.getInstance().primaryKeyFields(entityClass);
         if (fromMappingFiles != null)
         {
-            criteria.add(new NamedPropertyCriteria(fromMappingFiles));
+            for (String id : fromMappingFiles)
+            {
+                criteria.add(new NamedPropertyCriteria(id));
+            }
         }
         return criteria;
     }
@@ -139,7 +142,7 @@ public final class EntityUtils
         List<PropertyCriteria> criteriaList = new LinkedList<PropertyCriteria>();
         criteriaList.add(new AnnotatedPropertyCriteria(Version.class));
 
-        String fromMappingFiles = PersistenceUnits.instance().versionField(entityClass);
+        String fromMappingFiles = PersistenceUnitDescriptorProvider.getInstance().versionField(entityClass);
         if (fromMappingFiles != null)
         {
             criteriaList.add(new NamedPropertyCriteria(fromMappingFiles));

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/cl/AggregatedClassLoader.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/cl/AggregatedClassLoader.java b/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/cl/AggregatedClassLoader.java
deleted file mode 100644
index 65864c9..0000000
--- a/deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/util/cl/AggregatedClassLoader.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.deltaspike.data.impl.util.cl;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Set;
-
-public class AggregatedClassLoader extends ClassLoader
-{
-
-    private final List<ClassLoader> classLoaders;
-
-    public AggregatedClassLoader(List<ClassLoader> classLoaders)
-    {
-        super();
-        this.classLoaders = classLoaders;
-    }
-
-    public static AggregatedClassLoader newInstance()
-    {
-        return new AggregatedClassLoader(Arrays.asList(
-                AggregatedClassLoader.class.getClassLoader(),
-                Thread.currentThread().getContextClassLoader(),
-                ClassLoader.getSystemClassLoader()));
-    }
-
-    @Override
-    public URL getResource(String name)
-    {
-        for (ClassLoader loader : classLoaders)
-        {
-            URL url = loader.getResource(name);
-            if (url != null)
-            {
-                return url;
-            }
-        }
-        return super.getResource(name);
-    }
-
-    @Override
-    public Enumeration<URL> getResources(String name) throws IOException
-    {
-        final Set<URL> result = new LinkedHashSet<URL>();
-        for (ClassLoader loader : classLoaders)
-        {
-            Enumeration<URL> urls = loader.getResources(name);
-            while (urls.hasMoreElements())
-            {
-                result.add(urls.nextElement());
-            }
-        }
-        return new Enumeration<URL>()
-        {
-            private final Iterator<URL> iterator = result.iterator();
-
-            @Override
-            public URL nextElement()
-            {
-                return iterator.next();
-            }
-
-            @Override
-            public boolean hasMoreElements()
-            {
-                return iterator.hasNext();
-            }
-        };
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilderTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilderTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilderTest.java
index 4cf9a43..d050589 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilderTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/DescriptorHierarchyBuilderTest.java
@@ -23,10 +23,10 @@ import static org.junit.Assert.assertNull;
 
 import java.util.LinkedList;
 import java.util.List;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.AbstractEntityHierarchyBuilder;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.EntityDescriptor;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.MappedSuperclassDescriptor;
 
-import org.apache.deltaspike.data.impl.meta.unit.DescriptorHierarchyBuilder;
-import org.apache.deltaspike.data.impl.meta.unit.EntityDescriptor;
-import org.apache.deltaspike.data.impl.meta.unit.MappedSuperclassDescriptor;
 import org.junit.Before;
 import org.junit.Test;
 
@@ -39,23 +39,21 @@ public class DescriptorHierarchyBuilderTest
     @Before
     public void before()
     {
-        entities.add(new EntityDescriptor("test", null, EntityLevel3.class.getName(), null, null, null, null));
-        entities.add(new EntityDescriptor("test", null, EntityLevel5.class.getName(), null, null, null, null));
-
-        superClasses.add(new MappedSuperclassDescriptor("test", null, MappedLevel1.class.getName(), null, "id", null));
-        superClasses.add(new MappedSuperclassDescriptor("test", null, MappedLevel4.class.getName(), null, null, null));
-        superClasses.add(new MappedSuperclassDescriptor("test", null, MappedUnrelated.class.getName(), null, null, null));
-        superClasses.add(new MappedSuperclassDescriptor("test", null, MappedLevel2.class.getName(), null, null, null));
+        entities.add(new EntityDescriptor(null, null, "test", EntityLevel3.class, null, null, null));
+        entities.add(new EntityDescriptor(null, null, "test", EntityLevel5.class, null, null, null));
+
+        superClasses.add(new MappedSuperclassDescriptor(new String[] { "id" }, null, "test", MappedLevel1.class,
+            null, null));
+        superClasses.add(new MappedSuperclassDescriptor(null, null, "test", MappedLevel4.class, null, null));
+        superClasses.add(new MappedSuperclassDescriptor(null, null, "test", MappedUnrelated.class, null, null));
+        superClasses.add(new MappedSuperclassDescriptor(null, null, "test", MappedLevel2.class, null, null));
     }
 
     @Test
     public void should_build_hierarchy()
     {
-        // given
-        DescriptorHierarchyBuilder builder = DescriptorHierarchyBuilder.newInstance(entities, superClasses);
-
         // when
-        builder.buildHierarchy();
+        AbstractEntityHierarchyBuilder.buildHierarchy(entities, superClasses);
 
         // then
         assertEquals(entities.size(), 2);

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java
index b9bfb88..33fe4bd 100644
--- a/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java
+++ b/deltaspike/modules/data/impl/src/test/java/org/apache/deltaspike/data/impl/meta/unit/PersistenceUnitsTest.java
@@ -20,10 +20,12 @@ package org.apache.deltaspike.data.impl.meta.unit;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
 import org.apache.deltaspike.data.impl.meta.RepositoryEntity;
+import org.apache.deltaspike.data.impl.util.EntityUtils;
 import org.apache.deltaspike.data.test.domain.Parent;
 import org.apache.deltaspike.data.test.domain.TeeId;
 import org.apache.deltaspike.data.test.domain.mapped.MappedOne;
@@ -31,6 +33,8 @@ import org.apache.deltaspike.data.test.domain.mapped.MappedThree;
 import org.apache.deltaspike.data.test.domain.mapped.MappedTwo;
 import org.apache.deltaspike.data.test.service.MappedOneRepository;
 import org.apache.deltaspike.data.test.util.TestDeployments;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.EntityDescriptor;
+import org.apache.deltaspike.jpa.spi.descriptor.xml.PersistenceUnitDescriptorProvider;
 import org.apache.deltaspike.test.category.WebProfileCategory;
 import org.jboss.arquillian.container.test.api.Deployment;
 import org.jboss.arquillian.junit.Arquillian;
@@ -43,8 +47,7 @@ import org.junit.runner.RunWith;
 @RunWith(Arquillian.class)
 @Category(WebProfileCategory.class)
 public class PersistenceUnitsTest
-{
-
+{    
     @Deployment
     public static Archive<?> deployment()
     {
@@ -66,10 +69,10 @@ public class PersistenceUnitsTest
         // given
 
         // when
-        boolean positive1 = PersistenceUnits.instance().isEntity(MappedOne.class);
-        boolean positive2 = PersistenceUnits.instance().isEntity(MappedTwo.class);
-        boolean positive3 = PersistenceUnits.instance().isEntity(MappedThree.class);
-        boolean negative = PersistenceUnits.instance().isEntity(Long.class);
+        boolean positive1 = PersistenceUnitDescriptorProvider.getInstance().isEntity(MappedOne.class);
+        boolean positive2 = PersistenceUnitDescriptorProvider.getInstance().isEntity(MappedTwo.class);
+        boolean positive3 = PersistenceUnitDescriptorProvider.getInstance().isEntity(MappedThree.class);
+        boolean negative = PersistenceUnitDescriptorProvider.getInstance().isEntity(Long.class);
 
         // then
         assertTrue(positive1);
@@ -84,12 +87,14 @@ public class PersistenceUnitsTest
         // given
 
         // when
-        String idField1 = PersistenceUnits.instance().primaryKeyField(MappedOne.class);
-        String idField2 = PersistenceUnits.instance().primaryKeyField(MappedThree.class);
+        String[] idField1 = PersistenceUnitDescriptorProvider.getInstance().primaryKeyFields(MappedOne.class);
+        String[] idField2 = PersistenceUnitDescriptorProvider.getInstance().primaryKeyFields(MappedThree.class);
 
         // then
-        assertEquals("id", idField1);
-        assertEquals("id", idField2);
+        assertEquals(1, idField1.length);
+        assertEquals("id", idField1[0]);
+        assertEquals(1, idField2.length);
+        assertEquals("id", idField2[0]);
     }
 
     @Test
@@ -98,7 +103,7 @@ public class PersistenceUnitsTest
         // given
 
         // when
-        String name = PersistenceUnits.instance().entityName(MappedOne.class);
+        String name = PersistenceUnitDescriptorProvider.getInstance().entityName(MappedOne.class);
 
         // then
         assertEquals("Mapped_One", name);
@@ -110,7 +115,7 @@ public class PersistenceUnitsTest
         // given
 
         // when
-        Class<?> idClass = PersistenceUnits.instance().primaryKeyIdClass(MappedTwo.class);
+        Class<?> idClass = PersistenceUnitDescriptorProvider.getInstance().primaryKeyIdClass(MappedTwo.class);
 
         // then
         assertEquals(TeeId.class, idClass);
@@ -122,9 +127,9 @@ public class PersistenceUnitsTest
         // given
 
         // when
-        RepositoryEntity entity1 = PersistenceUnits.instance().lookupMetadata(MappedOne.class);
-        RepositoryEntity entity2 = PersistenceUnits.instance().lookupMetadata(MappedTwo.class);
-        RepositoryEntity entity3 = PersistenceUnits.instance().lookupMetadata(MappedThree.class);
+        RepositoryEntity entity1 = lookupMetadata(MappedOne.class);
+        RepositoryEntity entity2 = lookupMetadata(MappedTwo.class);
+        RepositoryEntity entity3 = lookupMetadata(MappedThree.class);
 
         // then
         assertNotNull(entity1);
@@ -134,4 +139,13 @@ public class PersistenceUnitsTest
         assertEquals(Long.class, entity3.getPrimaryKeyClass());
     }
 
+    protected RepositoryEntity lookupMetadata(Class<?> entityClass)
+    {
+        EntityDescriptor entity = PersistenceUnitDescriptorProvider.getInstance().find(entityClass);
+        if (entity != null)
+        {
+            return new RepositoryEntity(entityClass, EntityUtils.primaryKeyClass(entityClass));
+        }
+        return null;
+    }
 }

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/AbstractEntityDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/AbstractEntityDescriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/AbstractEntityDescriptor.java
new file mode 100644
index 0000000..776943d
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/AbstractEntityDescriptor.java
@@ -0,0 +1,108 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.io.Serializable;
+
+public abstract class AbstractEntityDescriptor
+{
+    private String id[];
+    private String version;
+    private String name;
+    private Class<?> entityClass;
+    private Class<? extends Serializable> idClass;
+
+    private AbstractEntityDescriptor parent;
+
+    public AbstractEntityDescriptor()
+    {
+        
+    }
+    
+    public AbstractEntityDescriptor(String[] id, String version, String name, Class<?> entityClass,
+            Class<? extends Serializable> idClass, AbstractEntityDescriptor parent)
+    {
+        this.id = id;
+        this.version = version;
+        this.name = name;
+        this.entityClass = entityClass;
+        this.idClass = idClass;
+        this.parent = parent;
+    }
+
+    public String[] getId()
+    {
+        return id;
+    }
+
+    public void setId(String[] id)
+    {
+        this.id = id;
+    }
+
+    public String getVersion()
+    {
+        return version;
+    }
+
+    public void setVersion(String version)
+    {
+        this.version = version;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName(String name)
+    {
+        this.name = name;
+    }
+
+    public Class<?> getEntityClass()
+    {
+        return entityClass;
+    }
+
+    public void setEntityClass(Class<?> entityClass)
+    {
+        this.entityClass = entityClass;
+    }
+
+    public Class<? extends Serializable> getIdClass()
+    {
+        return idClass;
+    }
+
+    public void setIdClass(Class<? extends Serializable> idClass)
+    {
+        this.idClass = idClass;
+    }
+
+    public AbstractEntityDescriptor getParent()
+    {
+        return parent;
+    }
+
+    public void setParent(AbstractEntityDescriptor parent)
+    {
+        this.parent = parent;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/AbstractEntityHierarchyBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/AbstractEntityHierarchyBuilder.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/AbstractEntityHierarchyBuilder.java
new file mode 100644
index 0000000..3ad255e
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/AbstractEntityHierarchyBuilder.java
@@ -0,0 +1,81 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.util.List;
+
+public final class AbstractEntityHierarchyBuilder
+{
+    private AbstractEntityHierarchyBuilder()
+    {
+    }
+
+    public static void buildHierarchy(List<EntityDescriptor> entities, List<MappedSuperclassDescriptor> superClasses)
+    {
+        for (EntityDescriptor descriptor : entities)
+        {
+            buildHierarchy(descriptor, entities, superClasses);
+        }
+    }
+
+    protected static void buildHierarchy(AbstractEntityDescriptor descriptor,
+            List<EntityDescriptor> entities, List<MappedSuperclassDescriptor> superClasses)
+    {
+        Class<?> superClass = descriptor.getEntityClass().getSuperclass();
+        while (superClass != null)
+        {
+            AbstractEntityDescriptor superDescriptor =
+                    findPersistentClassDescriptor(superClass, entities, superClasses);
+            if (superDescriptor != null)
+            {
+                if (descriptor.getParent() == null)
+                {
+                    buildHierarchy(superDescriptor, entities, superClasses);
+                }
+
+                descriptor.setParent(superDescriptor);
+                return;
+            }
+
+            superClass = superClass.getSuperclass();
+        }
+    }
+
+    protected static AbstractEntityDescriptor findPersistentClassDescriptor(Class<?> superClass,
+            List<EntityDescriptor> entities, List<MappedSuperclassDescriptor> superClasses)
+    {
+        for (MappedSuperclassDescriptor descriptor : superClasses)
+        {
+            if (descriptor.getEntityClass().equals(superClass))
+            {
+                return descriptor;
+            }
+        }
+
+        for (EntityDescriptor descriptor : entities)
+        {
+            if (descriptor.getEntityClass().equals(superClass))
+            {
+                return descriptor;
+            }
+        }
+
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/Descriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/Descriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/Descriptor.java
new file mode 100644
index 0000000..177adfe
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/Descriptor.java
@@ -0,0 +1,46 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.net.URL;
+
+import org.w3c.dom.Document;
+
+public class Descriptor
+{
+    private final Document document;
+    private final URL url;
+
+    public Descriptor(Document document, URL url)
+    {
+        this.document = document;
+        this.url = url;
+    }
+
+    public Document getDocument()
+    {
+        return document;
+    }
+
+    public URL getUrl()
+    {
+        return url;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/DescriptorReader.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/DescriptorReader.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/DescriptorReader.java
new file mode 100644
index 0000000..68d89ac
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/DescriptorReader.java
@@ -0,0 +1,114 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.deltaspike.core.util.AggregatedClassLoader;
+
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+abstract class DescriptorReader
+{
+    private static final Logger LOG = Logger.getLogger(DescriptorReader.class.getName());
+
+    private final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+
+    protected List<Descriptor> readAllFromClassPath(String resource) throws IOException
+    {
+        List<Descriptor> result = new LinkedList<Descriptor>();
+        Enumeration<URL> urls = classLoader().getResources(resource);
+        while (urls.hasMoreElements())
+        {
+            URL u = urls.nextElement();
+            try
+            {
+                result.add(readFromUrl(u));
+            }
+            catch (Exception e)
+            {
+                LOG.log(Level.WARNING, "Could not load " + resource + " from " + u, e);
+            }
+        }
+        return Collections.unmodifiableList(result);
+    }
+
+    protected Descriptor readFromClassPath(String resource) throws IOException
+    {
+        return readFromUrl(classLoader().getResource(resource));
+    }
+
+    protected Descriptor readFromUrl(URL url) throws IOException
+    {
+        InputStream stream = url.openStream();
+        try
+        {
+            DocumentBuilder builder = factory.newDocumentBuilder();
+            return new Descriptor(builder.parse(new InputSource(stream)), url);
+        }
+        catch (SAXException e)
+        {
+            throw new RuntimeException("Failed reading XML document", e);
+        }
+        catch (ParserConfigurationException e)
+        {
+            throw new RuntimeException("Failed reading XML document", e);
+        }
+        finally
+        {
+            stream.close();
+        }
+    }
+
+    protected Descriptor read(String baseUrl, String resource) throws IOException
+    {
+        try
+        {
+            URL url = new URL(baseUrl + resource);
+            return readFromUrl(url);
+        }
+        catch (Exception e)
+        {
+            return readFromClassPath(resource);
+        }
+    }
+
+    protected String extractBaseUrl(URL fileUrl, String resource)
+    {
+        String file = fileUrl.toString();
+        return file.substring(0, file.length() - resource.length());
+    }
+
+    protected ClassLoader classLoader()
+    {
+        return AggregatedClassLoader.newInstance();
+    }
+}

http://git-wip-us.apache.org/repos/asf/deltaspike/blob/6480a0e5/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityDescriptor.java
----------------------------------------------------------------------
diff --git a/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityDescriptor.java b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityDescriptor.java
new file mode 100644
index 0000000..f8bf884
--- /dev/null
+++ b/deltaspike/modules/jpa/api/src/main/java/org/apache/deltaspike/jpa/spi/descriptor/xml/EntityDescriptor.java
@@ -0,0 +1,63 @@
+/*
+ * 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.deltaspike.jpa.spi.descriptor.xml;
+
+import java.io.Serializable;
+
+public class EntityDescriptor extends AbstractEntityDescriptor
+{
+    private String tableName;
+
+    public EntityDescriptor()
+    {
+    }
+
+    public EntityDescriptor(String[] id, String version, String name, Class<?> entityClass,
+            Class<? extends Serializable> idClass, AbstractEntityDescriptor parent,
+            String tableName)
+    {
+        super(id, version, name, entityClass, idClass, parent);
+        this.tableName = tableName;
+    }
+    
+    public String getTableName()
+    {
+        return tableName;
+    }
+
+    public void setTableName(String tableName)
+    {
+        this.tableName = tableName;
+    }
+    
+    @Override
+    public String toString()
+    {
+        StringBuilder builder = new StringBuilder();
+        builder.append("EntityDescriptor ")
+                .append("[entityClass=").append(getEntityClass().getName())
+                .append(", name=").append(getName())
+                .append(", idClass=").append(getIdClass().getName())
+                .append(", id=").append(getId())
+                .append(", superClass=").append(getParent())
+                .append(", tableName=").append(tableName)
+                .append("]");
+        return builder.toString();
+    }
+}