org.hibernate.boot.registry.classloading.spi.ClassLoaderService#classForName ( )源码实例Demo

下面列出了org.hibernate.boot.registry.classloading.spi.ClassLoaderService#classForName ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: lams   文件: SimpleValue.java
public void setTypeName(String typeName) {
	if ( typeName != null && typeName.startsWith( AttributeConverterTypeAdapter.NAME_PREFIX ) ) {
		final String converterClassName = typeName.substring( AttributeConverterTypeAdapter.NAME_PREFIX.length() );
		final ClassLoaderService cls = getMetadata()
				.getMetadataBuildingOptions()
				.getServiceRegistry()
				.getService( ClassLoaderService.class );
		try {
			final Class<? extends AttributeConverter> converterClass = cls.classForName( converterClassName );
			this.attributeConverterDescriptor = new ClassBasedConverterDescriptor(
					converterClass,
					false,
					( (InFlightMetadataCollector) getMetadata() ).getClassmateContext()
			);
			return;
		}
		catch (Exception e) {
			log.logBadHbmAttributeConverterType( typeName, e.getMessage() );
		}
	}

	this.typeName = typeName;
}
 
private Driver loadDriverIfPossible(String driverClassName) {
	if ( driverClassName == null ) {
		log.debug( "No driver class specified" );
		return null;
	}

	if ( serviceRegistry != null ) {
		final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
		final Class<Driver> driverClass = classLoaderService.classForName( driverClassName );
		try {
			return driverClass.newInstance();
		}
		catch ( Exception e ) {
			throw new ServiceException( "Specified JDBC Driver " + driverClassName + " could not be loaded", e );
		}
	}

	try {
		return (Driver) Class.forName( driverClassName ).newInstance();
	}
	catch ( Exception e1 ) {
		throw new ServiceException( "Specified JDBC Driver " + driverClassName + " could not be loaded", e1 );
	}
}
 
源代码3 项目: lams   文件: DefaultIdentifierGeneratorFactory.java
@Override
public Class getIdentifierGeneratorClass(String strategy) {
	if ( "hilo".equals( strategy ) ) {
		throw new UnsupportedOperationException( "Support for 'hilo' generator has been removed" );
	}
	String resolvedStrategy = "native".equals( strategy ) ?
			getDialect().getNativeIdentifierGeneratorStrategy() : strategy;

	Class generatorClass = generatorStrategyToClassNameMap.get( resolvedStrategy );
	try {
		if ( generatorClass == null ) {
			final ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class );
			generatorClass = cls.classForName( resolvedStrategy );
		}
	}
	catch ( ClassLoadingException e ) {
		throw new MappingException( String.format( "Could not interpret id generator strategy [%s]", strategy ) );
	}
	return generatorClass;
}
 
源代码4 项目: lams   文件: TypeDefinitionBinder.java
/**
 * 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 );
}
 
源代码5 项目: lams   文件: BootstrapContextImpl.java
private ClassLoaderDelegate generateHcannClassLoaderDelegate() {
	//	class loading here needs to be drastically different for 7.0
	//		but luckily 7.0 will do away with HCANN use and be easier to
	//		implement this.
	//
	// todo (6.0) : *if possible* make similar change in 6.0
	// 		possibly using the JPA temp class loader or create our own "throw awy" ClassLoader;
	//		the trouble there is that we eventually need to load the Class into the real
	//		ClassLoader prior to use

	final ClassLoaderService classLoaderService = getServiceRegistry().getService( ClassLoaderService.class );

	return new ClassLoaderDelegate() {
		@Override
		public <T> Class<T> classForName(String className) throws ClassLoadingException {
			try {
				return classLoaderService.classForName( className );
			}
			catch (org.hibernate.boot.registry.classloading.spi.ClassLoadingException e) {
				return StandardClassLoaderDelegateImpl.INSTANCE.classForName( className );
			}
		}
	};
}
 
源代码6 项目: lams   文件: BeanValidationIntegrator.java
private boolean isBeanValidationApiAvailable(ClassLoaderService classLoaderService) {
	try {
		classLoaderService.classForName( BV_CHECK_CLASS );
		return true;
	}
	catch (Exception e) {
		return false;
	}
}
 
源代码7 项目: lams   文件: BeanValidationIntegrator.java
private Class loadTypeSafeActivatorClass(ClassLoaderService classLoaderService) {
	try {
		return classLoaderService.classForName( ACTIVATOR_CLASS_NAME );
	}
	catch (Exception e) {
		throw new HibernateException( "Unable to load TypeSafeActivator class", e );
	}
}
 
源代码8 项目: lams   文件: Component.java
public Class getComponentClass() throws MappingException {
	final ClassLoaderService classLoaderService = getMetadata()
			.getMetadataBuildingOptions()
			.getServiceRegistry()
			.getService( ClassLoaderService.class );
	try {
		return classLoaderService.classForName( componentClassName );
	}
	catch (ClassLoadingException e) {
		throw new MappingException("component class not found: " + componentClassName, e);
	}
}
 
源代码9 项目: lams   文件: ManagedBeanRegistryInitiator.java
private BeanContainer interpretExplicitBeanContainer(
		Object explicitSetting,
		ClassLoaderService classLoaderService, ServiceRegistryImplementor serviceRegistry) {
	if ( explicitSetting == null ) {
		return null;
	}

	if ( explicitSetting instanceof BeanContainer ) {
		return (BeanContainer) explicitSetting;
	}

	// otherwise we ultimately need to resolve this to a class
	final Class containerClass;
	if ( explicitSetting instanceof Class ) {
		containerClass = (Class) explicitSetting;
	}
	else {
		final String name = explicitSetting.toString();
		// try the StrategySelector service
		final Class selected = serviceRegistry.getService( StrategySelector.class )
				.selectStrategyImplementor( BeanContainer.class, name );
		if ( selected != null ) {
			containerClass = selected;
		}
		else {
			containerClass = classLoaderService.classForName( name );
		}
	}

	try {
		return (BeanContainer) containerClass.newInstance();
	}
	catch (Exception e) {
		throw new InstantiationException( "Unable to instantiate specified BeanContainer : " + containerClass.getName(), containerClass, e );
	}
}
 
源代码10 项目: lams   文件: ReflectHelper.java
/**
 * Attempt to resolve the specified property type through reflection.
 *
 * @param className The name of the class owning the property.
 * @param name The name of the property.
 * @param classLoaderService ClassLoader services
 *
 * @return The type of the property.
 *
 * @throws MappingException Indicates we were unable to locate the property.
 */
public static Class reflectedPropertyClass(
		String className,
		String name,
		ClassLoaderService classLoaderService) throws MappingException {
	try {
		Class clazz = classLoaderService.classForName( className );
		return getter( clazz, name ).getReturnType();
	}
	catch ( ClassLoadingException e ) {
		throw new MappingException( "class " + className + " not found while looking for property: " + name, e );
	}
}
 
源代码11 项目: lams   文件: ManagedBeanRegistryInitiator.java
public static Class cdiBeanManagerClass(ClassLoaderService classLoaderService) throws ClassLoadingException {
	return classLoaderService.classForName( "javax.enterprise.inject.spi.BeanManager" );
}
 
@Override
@SuppressWarnings( {"unchecked"})
public MultiTenantConnectionProvider initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	final MultiTenancyStrategy strategy = MultiTenancyStrategy.determineMultiTenancyStrategy(  configurationValues );
	if ( !strategy.requiresMultiTenantConnectionProvider() ) {
		// nothing to do, but given the separate hierarchies have to handle this here.
		return null;
	}

	final Object configValue = configurationValues.get( AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER );
	if ( configValue == null ) {
		// if they also specified the data source *name*, then lets assume they want
		// DataSourceBasedMultiTenantConnectionProviderImpl
		final Object dataSourceConfigValue = configurationValues.get( AvailableSettings.DATASOURCE );
		if ( dataSourceConfigValue != null && String.class.isInstance( dataSourceConfigValue ) ) {
			return new DataSourceBasedMultiTenantConnectionProviderImpl();
		}

		return null;
	}

	if ( MultiTenantConnectionProvider.class.isInstance( configValue ) ) {
		return (MultiTenantConnectionProvider) configValue;
	}
	else {
		final Class<MultiTenantConnectionProvider> implClass;
		if ( Class.class.isInstance( configValue ) ) {
			implClass = (Class) configValue;
		}
		else {
			final String className = configValue.toString();
			final ClassLoaderService classLoaderService = registry.getService( ClassLoaderService.class );
			try {
				implClass = classLoaderService.classForName( className );
			}
			catch (ClassLoadingException cle) {
				log.warn( "Unable to locate specified class [" + className + "]", cle );
				throw new ServiceException( "Unable to locate specified multi-tenant connection provider [" + className + "]" );
			}
		}

		try {
			return implClass.newInstance();
		}
		catch (Exception e) {
			log.warn( "Unable to instantiate specified class [" + implClass.getName() + "]", e );
			throw new ServiceException( "Unable to instantiate specified multi-tenant connection provider [" + implClass.getName() + "]" );
		}
	}
}
 
源代码13 项目: lams   文件: TypeResolver.java
/**
 * Uses heuristics to deduce the proper {@link Type} given a string naming the type or Java class.
 * <p/>
 * The search goes as follows:<ol>
 * 	<li>search for a basic type with 'typeName' as a registration key</li>
 * 	<li>
 * 		look for 'typeName' as a class name and<ol>
 *			<li>if it names a {@link Type} implementor, return an instance</li>
 *			<li>if it names a {@link CompositeUserType} or a {@link UserType}, return an instance of class wrapped intot the appropriate {@link Type} adapter</li>
 * 			<li>if it implements {@link org.hibernate.classic.Lifecycle}, return the corresponding entity type</li>
 * 			<li>if it implements {@link Serializable}, return the corresponding serializable type</li>
 * 		</ol>
 * 	</li>
 * </ol>
 *
 * @param typeName The name (see heuristic algorithm above).
 * @param parameters Any parameters for the type.  Only applied if built!
 *
 * @return The deduced type; may be null.
 *
 * @throws MappingException Indicates a problem attempting to resolve 'typeName' as a {@link Class}
 */
public Type heuristicType(String typeName, Properties parameters) throws MappingException {
	Type type = basic( typeName );
	if ( type != null ) {
		return type;
	}

	try {
		final ClassLoaderService classLoaderService = typeConfiguration.getServiceRegistry().getService( ClassLoaderService.class );
		Class typeClass = classLoaderService.classForName( typeName );
		if ( typeClass != null ) {
			return typeFactory.byClass( typeClass, parameters );
		}
	}
	catch ( ClassLoadingException ignore ) {
	}

	return null;
}