use of org.hibernate.internal.util.config.ConfigurationException in project hibernate-orm by hibernate.
the class SessionFactoryImpl method applyCfgXmlValues.
private void applyCfgXmlValues(LoadedConfig aggregatedConfig, SessionFactoryServiceRegistry serviceRegistry) {
final JaccService jaccService = serviceRegistry.getService(JaccService.class);
if (jaccService.getContextId() != null) {
final JaccPermissionDeclarations permissions = aggregatedConfig.getJaccPermissions(jaccService.getContextId());
if (permissions != null) {
for (GrantedPermission grantedPermission : permissions.getPermissionDeclarations()) {
jaccService.addPermission(grantedPermission);
}
}
}
if (aggregatedConfig.getEventListenerMap() != null) {
final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService(EventListenerRegistry.class);
for (Map.Entry<EventType, Set<String>> entry : aggregatedConfig.getEventListenerMap().entrySet()) {
final EventListenerGroup group = eventListenerRegistry.getEventListenerGroup(entry.getKey());
for (String listenerClassName : entry.getValue()) {
try {
group.appendListener(cls.classForName(listenerClassName).newInstance());
} catch (Exception e) {
throw new ConfigurationException("Unable to instantiate event listener class : " + listenerClassName, e);
}
}
}
}
}
use of org.hibernate.internal.util.config.ConfigurationException in project hibernate-orm by hibernate.
the class ConfigLoader method loadProperties.
public Properties loadProperties(String resourceName) {
final InputStream stream = bootstrapServiceRegistry.getService(ClassLoaderService.class).locateResourceStream(resourceName);
if (stream == null) {
throw new ConfigurationException("Unable to apply settings from properties file [" + resourceName + "]");
}
try {
Properties properties = new Properties();
properties.load(stream);
return properties;
} catch (IOException e) {
throw new ConfigurationException("Unable to apply settings from properties file [" + resourceName + "]", e);
} finally {
try {
stream.close();
} catch (IOException e) {
log.debug(String.format("Unable to close properties file [%s] stream", resourceName), e);
}
}
}
use of org.hibernate.internal.util.config.ConfigurationException in project hibernate-orm by hibernate.
the class ConfigLoader method loadProperties.
public Properties loadProperties(File file) {
try {
final InputStream stream = new FileInputStream(file);
try {
Properties properties = new Properties();
properties.load(stream);
return properties;
} catch (IOException e) {
throw new ConfigurationException("Unable to apply settings from properties file [" + file.getAbsolutePath() + "]", e);
} finally {
try {
stream.close();
} catch (IOException e) {
log.debug(String.format("Unable to close properties file [%s] stream", file.getAbsolutePath()), e);
}
}
} catch (FileNotFoundException e) {
throw new ConfigurationException("Unable locate specified properties file [" + file.getAbsolutePath() + "]", e);
}
}
use of org.hibernate.internal.util.config.ConfigurationException in project hibernate-orm by hibernate.
the class JaxbCfgProcessor method unmarshal.
@SuppressWarnings({ "unchecked" })
private JaxbCfgHibernateConfiguration unmarshal(XMLEventReader staxEventReader, final Origin origin) {
XMLEvent event;
try {
event = staxEventReader.peek();
while (event != null && !event.isStartElement()) {
staxEventReader.nextEvent();
event = staxEventReader.peek();
}
} catch (Exception e) {
throw new HibernateException("Error accessing stax stream", e);
}
if (event == null) {
throw new HibernateException("Could not locate root element");
}
if (!isNamespaced(event.asStartElement())) {
// if the elements are not namespaced, wrap the reader in a reader which will namespace them as pulled.
log.debug("cfg.xml document did not define namespaces; wrapping in custom event reader to introduce namespace information");
staxEventReader = new NamespaceAddingEventReader(staxEventReader, HIBERNATE_CONFIGURATION_URI);
}
final ContextProvidingValidationEventHandler handler = new ContextProvidingValidationEventHandler();
try {
JAXBContext jaxbContext = JAXBContext.newInstance(JaxbCfgHibernateConfiguration.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setSchema(schema());
unmarshaller.setEventHandler(handler);
return (JaxbCfgHibernateConfiguration) unmarshaller.unmarshal(staxEventReader);
} catch (JAXBException e) {
throw new ConfigurationException("Unable to perform unmarshalling at line number " + handler.getLineNumber() + " and column " + handler.getColumnNumber() + " in " + origin.getType().name() + " " + origin.getName() + ". Message: " + handler.getMessage(), e);
}
}
Aggregations