class PersistenceUnitDescriptorLoader {

    public List<PersistenceUnitDescriptor> loadPersistenceUnitDescriptors(final Map<String, Object> properties) throws IOException {
        final Enumeration<URL> resources = Thread.currentThread().getContextClassLoader().getResources("META-INF/persistence.xml");

        final List<PersistenceUnitDescriptor> units = new ArrayList<>();
        while (resources.hasMoreElements()) {
            final Document doc = loadDocument(resources.nextElement());

            final NodeList children = doc.getDocumentElement().getChildNodes();
            for (int i = 0; i < children.getLength(); i++) {
                final Node node = children.item(i);
                if (node.getNodeType() == Node.ELEMENT_NODE && "persistence-unit".equals(((Element) node).getTagName())) {
                    units.add(new PersistenceUnitDescriptorImpl((Element) node, properties));
                }
            }
        }

        return units;

    }

}