/** * Tries to load Hibernate Search event listener. * * @return An event listener instance in case the jar was available. */ private static Class<?> attemptToLoadSearchEventListener() { Class searchEventListenerClass = null; try { searchEventListenerClass = ReflectHelper.classForName( FULL_TEXT_INDEX_EVENT_LISTENER_CLASS, HibernateSearchEventListenerRegister.class); } catch (ClassNotFoundException e) { log.debug("Search not present in classpath, ignoring event listener registration."); } return searchEventListenerClass; }
public ScrollableResultsImpl( ResultSet rs, PreparedStatement ps, SessionImplementor sess, Loader loader, QueryParameters queryParameters, Type[] types, Class holderClass) throws MappingException { this.rs=rs; this.ps=ps; this.sess = sess; this.loader = loader; this.queryParameters = queryParameters; this.types = types; if (holderClass != null) { holderConstructor = ReflectHelper.getConstructor(holderClass, types); } }
public static Class reflectedPropertyClass(String className, String name) throws MappingException { try { Class clazz = ReflectHelper.classForName(className); return getter(clazz, name).getReturnType(); } catch (ClassNotFoundException cnfe) { throw new MappingException("class " + className + " not found while looking for property: " + name, cnfe); } }
private Constructor resolveConstructor(String path) throws SemanticException { String importedClassName = getSessionFactoryHelper().getImportedClassName( path ); String className = StringHelper.isEmpty( importedClassName ) ? path : importedClassName; if ( className == null ) { throw new SemanticException( "Unable to locate class [" + path + "]" ); } try { Class holderClass = ReflectHelper.classForName( className ); return ReflectHelper.getConstructor( holderClass, constructorArgumentTypes ); } catch ( ClassNotFoundException e ) { throw new DetailedSemanticException( "Unable to locate class [" + className + "]", e ); } catch ( PropertyNotFoundException e ) { // this is the exception returned by ReflectHelper.getConstructor() if it cannot // locate an appropriate constructor throw new DetailedSemanticException( "Unable to locate appropriate constructor on class [" + className + "]", e ); } }
private static Field getField(Class clazz, String name) throws PropertyNotFoundException { if ( clazz==null || clazz==Object.class ) { throw new PropertyNotFoundException("field not found: " + name); // TODO: we should report what class we started searching for the property - right now it will always end on Object.class. } Field field; try { field = clazz.getDeclaredField(name); } catch (NoSuchFieldException nsfe) { field = getField( clazz.getSuperclass(), name ); } if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true); return field; }
private void readObject(java.io.ObjectInputStream stream) throws ClassNotFoundException, IOException { stream.defaultReadObject(); constructor = ReflectHelper.getDefaultConstructor(mappedClass); }
public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotFoundException { if ( isAbstractClass(clazz) ) return null; try { Constructor constructor = clazz.getDeclaredConstructor(NO_CLASSES); if ( !isPublic(clazz, constructor) ) { constructor.setAccessible(true); } return constructor; } catch (NoSuchMethodException nme) { throw new PropertyNotFoundException( "Object class " + clazz.getName() + " must declare a default (no-argument) constructor" ); } }
private Method getGetterFor(String property) { Class cl = this.metadata.getMappedClass(EntityMode.POJO); Getter getter = ReflectHelper.getGetter(cl, property); return getter.getMethod(); }
public void lookupConstant(DotNode node) throws SemanticException { String text = getText( node ); Queryable persister = walker.getSessionFactoryHelper().findQueryableUsingImports( text ); if ( persister != null ) { // the name of an entity class final String discrim = persister.getDiscriminatorSQLValue(); if ( InFragment.NULL.equals(discrim) || InFragment.NOT_NULL.equals(discrim) ) { throw new InvalidPathException( "subclass test not allowed for null or not null discriminator: '" + text + "'" ); } else { setSQLValue( node, text, discrim ); //the class discriminator value } } else { Object value = ReflectHelper.getConstantValue( text ); if ( value == null ) { throw new InvalidPathException( "Invalid path: '" + text + "'" ); } else { setConstantValue( node, text, value ); } } }
public static Class reflectedPropertyClass(String className, String name) throws MappingException { try { Class clazz = ReflectHelper.classForName(className); return getter(clazz, name).getReturnType(); } catch (ClassNotFoundException cnfe) { throw new MappingException("class " + className + " not found while looking for property: " + name, cnfe); } }
private Constructor resolveConstructor(String path) throws SemanticException { String importedClassName = getSessionFactoryHelper().getImportedClassName( path ); String className = StringHelper.isEmpty( importedClassName ) ? path : importedClassName; if ( className == null ) { throw new SemanticException( "Unable to locate class [" + path + "]" ); } try { Class holderClass = ReflectHelper.classForName( className ); return ReflectHelper.getConstructor( holderClass, constructorArgumentTypes ); } catch ( ClassNotFoundException e ) { throw new DetailedSemanticException( "Unable to locate class [" + className + "]", e ); } catch ( PropertyNotFoundException e ) { // this is the exception returned by ReflectHelper.getConstructor() if it cannot // locate an appropriate constructor throw new DetailedSemanticException( "Unable to locate appropriate constructor on class [" + className + "]", e ); } }
private static Field getField(Class root, Class clazz, String name) throws PropertyNotFoundException { if ( clazz==null || clazz==Object.class ) { throw new PropertyNotFoundException("field [" + name + "] not found on " + root.getName()); } Field field; try { field = clazz.getDeclaredField(name); } catch (NoSuchFieldException nsfe) { field = getField( root, clazz.getSuperclass(), name ); } if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true); return field; }
private void readObject(java.io.ObjectInputStream stream) throws ClassNotFoundException, IOException { stream.defaultReadObject(); constructor = ReflectHelper.getDefaultConstructor(mappedClass); }
public static Constructor getDefaultConstructor(Class clazz) throws PropertyNotFoundException { if ( isAbstractClass(clazz) ) return null; try { Constructor constructor = clazz.getDeclaredConstructor(NO_CLASSES); if ( !isPublic(clazz, constructor) ) { constructor.setAccessible(true); } return constructor; } catch (NoSuchMethodException nme) { throw new PropertyNotFoundException( "Object class " + clazz.getName() + " must declare a default (no-argument) constructor" ); } }
public Query setProperties(Object bean) throws HibernateException { Class clazz = bean.getClass(); String[] params = getNamedParameters(); for (int i = 0; i < params.length; i++) { String namedParam = params[i]; try { Getter getter = ReflectHelper.getGetter( clazz, namedParam ); Class retType = getter.getReturnType(); final Object object = getter.get( bean ); if ( Collection.class.isAssignableFrom( retType ) ) { setParameterList( namedParam, ( Collection ) object ); } else if ( retType.isArray() ) { setParameterList( namedParam, ( Object[] ) object ); } else { setParameter( namedParam, object, determineType( namedParam, retType ) ); } } catch (PropertyNotFoundException pnfe) { // ignore } } return this; }
public void lookupConstant(DotNode node) throws SemanticException { String text = getText( node ); Queryable persister = walker.getSessionFactoryHelper().findQueryableUsingImports( text ); if ( persister != null ) { // the name of an entity class final String discrim = persister.getDiscriminatorSQLValue(); if ( InFragment.NULL.equals(discrim) || InFragment.NOT_NULL.equals(discrim) ) { throw new InvalidPathException( "subclass test not allowed for null or not null discriminator: '" + text + "'" ); } else { setSQLValue( node, text, discrim ); //the class discriminator value } } else { Object value = ReflectHelper.getConstantValue( text ); if ( value == null ) { throw new InvalidPathException( "Invalid path: '" + text + "'" ); } else { setConstantValue( node, text, value ); } } }
public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty( ENUM ); try { enumClass = ReflectHelper.classForName( enumClassName, this.getClass() ).asSubclass( Enum.class ); } catch (ClassNotFoundException exception) { throw new HibernateException( "Enum class not found", exception ); } // is might be good to call it here, to see a possible error immediately // initEnumValue(); //nullify unnullified properties yuck! schema = parameters.getProperty( SCHEMA ); if ( "".equals( schema ) ) schema = null; catalog = parameters.getProperty( CATALOG ); if ( "".equals( catalog ) ) catalog = null; // table = parameters.getProperty( TABLE ); // column = parameters.getProperty( COLUMN ); String type = parameters.getProperty( TYPE ); if ( type != null ) { sqlType = Integer.decode( type ).intValue(); // guessed = true; } }
final Object returnValue; try { if (ReflectHelper.isPublic(persistentClass, thisMethod)) { if (!thisMethod.getDeclaringClass().isInstance(target)) { throw new ClassCastException(target.getClass().getName());
public PojoInstantiator(Class mappedClass, Class proxyInterface, FastClass fastClass, boolean embedded) { this.mappedClass = mappedClass; this.proxyInterface = proxyInterface; this.fastClass = fastClass; this.embeddedIdentifier = embedded; try { constructor = ReflectHelper.getDefaultConstructor(mappedClass); } catch ( PropertyNotFoundException pnfe ) { log.info( "no default (no-argument) constructor for class: " + mappedClass.getName() + " (class must be instantiated by Interceptor)" ); constructor = null; } }
public Query setProperties(Object bean) throws HibernateException { Class clazz = bean.getClass(); String[] params = getNamedParameters(); for (int i = 0; i < params.length; i++) { String namedParam = params[i]; try { Getter getter = ReflectHelper.getGetter(clazz, namedParam); Class retType = getter.getReturnType(); final Object object = getter.get( bean ); if ( Collection.class.isAssignableFrom(retType) ) { setParameterList( namedParam, (Collection) object ); } else if ( retType.isArray() ) { setParameterList( namedParam, (Object[]) object ); } else { setParameter( namedParam, object, guessType( getter.getReturnType() ) ); } } catch (PropertyNotFoundException pnfe) {} } return this; }