use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class TypeDefinitionBinder method processTypeDefinition.
/**
* Handling for a {@code <typedef/>} declaration
*
* @param context Access to information relative to the mapping document containing this binding
* @param typeDefinitionBinding The {@code <typedef/>} binding
*/
public static void processTypeDefinition(HbmLocalMetadataBuildingContext context, JaxbHbmTypeDefinitionType typeDefinitionBinding) {
final ClassLoaderService cls = context.getBuildingOptions().getServiceRegistry().getService(ClassLoaderService.class);
final TypeDefinition definition = new TypeDefinition(typeDefinitionBinding.getName(), cls.classForName(typeDefinitionBinding.getClazz()), null, ConfigParameterHelper.extractConfigParameters(typeDefinitionBinding));
log.debugf("Processed type-definition : %s -> %s", definition.getName(), definition.getTypeImplementorClass().getName());
context.getMetadataCollector().addTypeDefinition(definition);
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class BeanValidationIntegrator method integrate.
@Override
public void integrate(final Metadata metadata, final SessionFactoryImplementor sessionFactory, final SessionFactoryServiceRegistry serviceRegistry) {
final ConfigurationService cfgService = serviceRegistry.getService(ConfigurationService.class);
// IMPL NOTE : see the comments on ActivationContext.getValidationModes() as to why this is multi-valued...
final Set<ValidationMode> modes = ValidationMode.getModes(cfgService.getSettings().get(MODE_PROPERTY));
if (modes.size() > 1) {
LOG.multipleValidationModes(ValidationMode.loggable(modes));
}
if (modes.size() == 1 && modes.contains(ValidationMode.NONE)) {
// we have nothing to do; just return
return;
}
final ClassLoaderService classLoaderService = serviceRegistry.getService(ClassLoaderService.class);
// see if the Bean Validation API is available on the classpath
if (isBeanValidationApiAvailable(classLoaderService)) {
// and if so, call out to the TypeSafeActivator
try {
final Class typeSafeActivatorClass = loadTypeSafeActivatorClass(classLoaderService);
@SuppressWarnings("unchecked") final Method activateMethod = typeSafeActivatorClass.getMethod(ACTIVATE_METHOD_NAME, ActivationContext.class);
final ActivationContext activationContext = new ActivationContext() {
@Override
public Set<ValidationMode> getValidationModes() {
return modes;
}
@Override
public Metadata getMetadata() {
return metadata;
}
@Override
public SessionFactoryImplementor getSessionFactory() {
return sessionFactory;
}
@Override
public SessionFactoryServiceRegistry getServiceRegistry() {
return serviceRegistry;
}
};
try {
activateMethod.invoke(null, activationContext);
} catch (InvocationTargetException e) {
if (HibernateException.class.isInstance(e.getTargetException())) {
throw ((HibernateException) e.getTargetException());
}
throw new IntegrationException("Error activating Bean Validation integration", e.getTargetException());
} catch (Exception e) {
throw new IntegrationException("Error activating Bean Validation integration", e);
}
} catch (NoSuchMethodException e) {
throw new HibernateException("Unable to locate TypeSafeActivator#activate method", e);
}
} else {
// otherwise check the validation modes
// todo : in many ways this duplicates thew checks done on the TypeSafeActivator when a ValidatorFactory could not be obtained
validateMissingBeanValidationApi(modes);
}
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class StandardJtaPlatformResolver method resolveJtaPlatform.
@Override
public JtaPlatform resolveJtaPlatform(Map configurationValues, ServiceRegistryImplementor registry) {
final ClassLoaderService classLoaderService = registry.getService(ClassLoaderService.class);
// Initially look for a JtaPlatformProvider
for (JtaPlatformProvider provider : classLoaderService.loadJavaServices(JtaPlatformProvider.class)) {
final JtaPlatform providedPlatform = provider.getProvidedJtaPlatform();
log.tracef("Located JtaPlatformProvider [%s] provided JtaPlaform : %s", provider, providedPlatform);
if (providedPlatform != null) {
return providedPlatform;
}
}
// JBoss ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try {
classLoaderService.classForName(JBossStandAloneJtaPlatform.JBOSS_TM_CLASS_NAME);
classLoaderService.classForName(JBossStandAloneJtaPlatform.JBOSS_UT_CLASS_NAME);
// should be relying on that
return new JBossStandAloneJtaPlatform();
} catch (ClassLoadingException ignore) {
}
// Bitronix ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try {
classLoaderService.classForName(BitronixJtaPlatform.TM_CLASS_NAME);
return new BitronixJtaPlatform();
} catch (ClassLoadingException ignore) {
}
// JOnAS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try {
classLoaderService.classForName(JOnASJtaPlatform.TM_CLASS_NAME);
return new JOnASJtaPlatform();
} catch (ClassLoadingException ignore) {
}
// JOTM ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try {
classLoaderService.classForName(JOTMJtaPlatform.TM_CLASS_NAME);
return new JOTMJtaPlatform();
} catch (ClassLoadingException ignore) {
}
// WebSphere ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (WebSphereJtaPlatform.WebSphereEnvironment webSphereEnvironment : WebSphereJtaPlatform.WebSphereEnvironment.values()) {
try {
Class accessClass = classLoaderService.classForName(webSphereEnvironment.getTmAccessClassName());
return new WebSphereJtaPlatform(accessClass, webSphereEnvironment);
} catch (ClassLoadingException ignore) {
}
}
// Finally, return the default...
log.debugf("Could not resolve JtaPlatform, using default [%s]", NoJtaPlatform.class.getName());
return NoJtaPlatform.INSTANCE;
}
use of org.hibernate.boot.registry.classloading.spi.ClassLoaderService 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.boot.registry.classloading.spi.ClassLoaderService in project hibernate-orm by hibernate.
the class UUIDGenerator method configure.
@Override
public void configure(Type type, Properties params, ServiceRegistry serviceRegistry) throws MappingException {
// check first for the strategy instance
strategy = (UUIDGenerationStrategy) params.get(UUID_GEN_STRATEGY);
if (strategy == null) {
// next check for the strategy class
final String strategyClassName = params.getProperty(UUID_GEN_STRATEGY_CLASS);
if (strategyClassName != null) {
try {
final ClassLoaderService cls = serviceRegistry.getService(ClassLoaderService.class);
final Class strategyClass = cls.classForName(strategyClassName);
try {
strategy = (UUIDGenerationStrategy) strategyClass.newInstance();
} catch (Exception ignore) {
LOG.unableToInstantiateUuidGenerationStrategy(ignore);
}
} catch (ClassLoadingException ignore) {
LOG.unableToLocateUuidGenerationStrategy(strategyClassName);
}
}
}
if (strategy == null) {
// lastly use the standard random generator
strategy = StandardRandomStrategy.INSTANCE;
}
if (UUID.class.isAssignableFrom(type.getReturnedClass())) {
valueTransformer = UUIDTypeDescriptor.PassThroughTransformer.INSTANCE;
} else if (String.class.isAssignableFrom(type.getReturnedClass())) {
valueTransformer = UUIDTypeDescriptor.ToStringTransformer.INSTANCE;
} else if (byte[].class.isAssignableFrom(type.getReturnedClass())) {
valueTransformer = UUIDTypeDescriptor.ToBytesTransformer.INSTANCE;
} else {
throw new HibernateException("Unanticipated return type [" + type.getReturnedClass().getName() + "] for UUID conversion");
}
}
Aggregations