use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testGetEntityResolver.
@Test
public void testGetEntityResolver() throws Exception {
EntityResolver testResolver = new DefaultHandler();
ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
Field entityResolverField = ConfigurationFacadeImpl.class.getDeclaredField("entityResolver");
entityResolverField.setAccessible(true);
assertNotSame(testResolver, configurationFacade.getEntityResolver());
entityResolverField.set(facade, testResolver);
assertSame(testResolver, configurationFacade.getEntityResolver());
}
use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class ConfigurationFactory method configureStandardConfiguration.
private IConfiguration configureStandardConfiguration(final boolean includeMappings, IConfiguration localCfg, Properties properties) {
if (properties != null) {
localCfg = localCfg.setProperties(properties);
}
EntityResolver entityResolver = new DTDEntityResolver(service);
if (StringHelper.isNotEmpty(prefs.getEntityResolverName())) {
try {
entityResolver = (EntityResolver) ReflectHelper.classForName(prefs.getEntityResolverName()).newInstance();
} catch (Exception c) {
throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_configure_entity_resolver + prefs.getEntityResolverName(), c);
}
}
localCfg.setEntityResolver(entityResolver);
if (StringHelper.isNotEmpty(prefs.getNamingStrategy())) {
try {
INamingStrategy ns = service.newNamingStrategy(prefs.getNamingStrategy());
localCfg.setNamingStrategy(ns);
} catch (Exception c) {
throw new HibernateConsoleRuntimeException(ConsoleMessages.ConsoleConfiguration_could_not_configure_naming_strategy + prefs.getNamingStrategy(), c);
}
}
localCfg = loadConfigurationXML(localCfg, includeMappings, entityResolver);
changeDatasourceProperties(localCfg);
localCfg = configureConnectionProfile(localCfg);
// replace dialect if it is set in preferences
if (StringHelper.isNotEmpty(prefs.getDialectName())) {
localCfg.setProperty(environment.getDialect(), prefs.getDialectName());
}
if (StringHelper.isEmpty(localCfg.getProperty("javax.persistence.validation.mode"))) {
// $NON-NLS-1$
// $NON-NLS-1$//$NON-NLS-2$
localCfg.setProperty("javax.persistence.validation.mode", "none");
}
return localCfg;
}
use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testSetEntityResolver.
@Test
public void testSetEntityResolver() throws Exception {
EntityResolver testResolver = new DefaultHandler();
ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
Field entityResolverField = ConfigurationFacadeImpl.class.getDeclaredField("entityResolver");
entityResolverField.setAccessible(true);
assertNull(entityResolverField.get(facade));
configurationFacade.setEntityResolver(testResolver);
assertSame(testResolver, entityResolverField.get(facade));
}
use of org.xml.sax.EntityResolver in project jbosstools-hibernate by jbosstools.
the class ConfigurationFacadeTest method testGetEntityResolver.
@Test
public void testGetEntityResolver() throws Exception {
EntityResolver testResolver = new DefaultHandler();
ConfigurationFacadeImpl facade = (ConfigurationFacadeImpl) configurationFacade;
Field entityResolverField = ConfigurationFacadeImpl.class.getDeclaredField("entityResolver");
entityResolverField.setAccessible(true);
assertNotSame(testResolver, configurationFacade.getEntityResolver());
entityResolverField.set(facade, testResolver);
assertSame(testResolver, configurationFacade.getEntityResolver());
}
use of org.xml.sax.EntityResolver in project datanucleus-core by datanucleus.
the class MetaDataParser method parseMetaDataStream.
/**
* Method to parse a MetaData file given an InputStream.
* Closes the input stream when finished.
* @param in input stream
* @param filename Name of the file (if applicable)
* @param handlerName Name of the handler plugin to use when parsing
* @return The MetaData for this file
* @throws NucleusException thrown if error occurred
*/
public MetaData parseMetaDataStream(InputStream in, String filename, String handlerName) {
if (in == null) {
throw new NullPointerException("input stream is null");
}
if (NucleusLogger.METADATA.isDebugEnabled()) {
NucleusLogger.METADATA.debug(Localiser.msg("044030", filename, handlerName, validate ? "true" : "false"));
}
try {
synchronized (parser) {
// Generate the required handler to process this metadata
DefaultHandler handler = null;
try {
parser.getXMLReader().setEntityResolver(entityResolver);
if ("persistence".equalsIgnoreCase(handlerName)) {
// "persistence.xml"
handler = new org.datanucleus.metadata.xml.PersistenceFileMetaDataHandler(mgr, filename, entityResolver);
} else {
// Fallback to the plugin mechanism for other MetaData handlers
Class[] argTypes = new Class[] { ClassConstants.METADATA_MANAGER, ClassConstants.JAVA_LANG_STRING, EntityResolver.class };
Object[] argValues = new Object[] { mgr, filename, entityResolver };
handler = (DefaultHandler) pluginMgr.createExecutableExtension("org.datanucleus.metadata_handler", "name", handlerName, "class-name", argTypes, argValues);
if (handler == null) {
// Plugin of this name not found
throw new NucleusUserException(Localiser.msg("044028", handlerName)).setFatal();
}
}
} catch (Exception e) {
String msg = Localiser.msg("044029", handlerName, e.getMessage());
throw new NucleusException(msg, e);
}
// Set whether to validate
((AbstractMetaDataHandler) handler).setValidate(validate);
// Parse the metadata
parser.parse(in, handler);
// Return the FileMetaData that has been parsed
return ((AbstractMetaDataHandler) handler).getMetaData();
}
} catch (NucleusException e) {
throw e;
} catch (Exception e) {
Throwable cause = e;
if (e instanceof SAXException) {
cause = ((SAXException) e).getException();
}
cause = e.getCause() == null ? cause : e.getCause();
NucleusLogger.METADATA.error(Localiser.msg("044040", filename, cause));
if (cause instanceof InvalidMetaDataException) {
throw (InvalidMetaDataException) cause;
}
throw new NucleusException(Localiser.msg("044033", e), cause);
} finally {
try {
in.close();
} catch (Exception ignore) {
// Do nothing
}
}
}
Aggregations