use of org.datanucleus.metadata.xml.MetaDataParser in project datanucleus-api-jdo by datanucleus.
the class MetaDataParserTest method testParseMetaDataURLnullhandler.
public void testParseMetaDataURLnullhandler() {
NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
try {
parser.parseMetaDataURL(getClass().getResource("/org/datanucleus/api/jdo/metadata/xml/package2.jdo"), null);
fail("expected JPOXException");
} catch (NucleusException ex) {
// expected
}
}
use of org.datanucleus.metadata.xml.MetaDataParser in project datanucleus-api-jdo by datanucleus.
the class JDOMetaDataHandlerTest method testParseNamespace.
public void testParseNamespace() {
NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
MetaData md = parser.parseMetaDataURL(getClass().getResource("/org/datanucleus/api/jdo/metadata/xml/package2.jdo"), "jdo");
assertNotNull(md);
}
use of org.datanucleus.metadata.xml.MetaDataParser in project datanucleus-api-jdo by datanucleus.
the class PersistenceFileMetaDataHandlerTest method testParseDefaultNamespace.
public void testParseDefaultNamespace() {
NucleusContext nucCtx = new PersistenceNucleusContextImpl("JDO", null);
MetaDataParser parser = new MetaDataParser(new JDOMetaDataManager(nucCtx), nucCtx.getPluginManager(), true, true);
MetaData md = parser.parseMetaDataURL(getClass().getResource("/org/datanucleus/api/jdo/metadata/xml/persistence1.xml"), "persistence");
assertNotNull(md);
}
use of org.datanucleus.metadata.xml.MetaDataParser in project datanucleus-core by datanucleus.
the class MetaDataUtils method parsePersistenceFiles.
/**
* Method to parse the available "persistence.xml" files returning the metadata for all found.
* Searches for all files "META-INF/persistence.xml" in the CLASSPATH of the current thread.
* @param pluginMgr PluginManager
* @param persistenceFilename Name of persistence file (if null will use "persistence.xml")
* @param validate Whether to validate the persistence file
* @param namespaceAware Whether to support namespaces
* @param clr ClassLoader resolver
* @return The metadata for all "persistence.xml" files
*/
public static PersistenceFileMetaData[] parsePersistenceFiles(PluginManager pluginMgr, String persistenceFilename, boolean validate, boolean namespaceAware, ClassLoaderResolver clr) {
MetaDataParser parser = new MetaDataParser(null, pluginMgr, validate, namespaceAware);
if (persistenceFilename != null) {
// User has specified filename for persistence.xml
try {
URL fileURL = new URL(persistenceFilename);
MetaData permd = parser.parseMetaDataURL(fileURL, "persistence");
return new PersistenceFileMetaData[] { (PersistenceFileMetaData) permd };
} catch (MalformedURLException mue) {
// User provided file is not found
NucleusLogger.METADATA.error("Error reading user-specified persistence.xml file " + persistenceFilename, mue);
return null;
}
}
Set<MetaData> metadata = new LinkedHashSet<>();
try {
// Find all "META-INF/persistence.xml" files in the CLASSPATH of the current thread
Enumeration files = clr.getResources("META-INF/persistence.xml", Thread.currentThread().getContextClassLoader());
if (!files.hasMoreElements()) {
return null;
}
for (; files.hasMoreElements(); ) {
// Parse the "persistence.xml"
URL fileURL = (URL) files.nextElement();
MetaData permd = parser.parseMetaDataURL(fileURL, "persistence");
metadata.add(permd);
}
} catch (IOException ioe) {
// Do nothing
NucleusLogger.METADATA.warn(StringUtils.getStringFromStackTrace(ioe));
}
return metadata.toArray(new PersistenceFileMetaData[metadata.size()]);
}
Aggregations