Package org.hibernate.annotations.common.reflection

Examples of org.hibernate.annotations.common.reflection.XClass


  public static Callback[] resolveCallback(XClass beanClass, Class annotation, ReflectionManager reflectionManager) {
    List<Callback> callbacks = new ArrayList<Callback>();
    List<String> callbacksMethodNames = new ArrayList<String>(); //used to track overridden methods
    List<Class> orderedListeners = new ArrayList<Class>();
    XClass currentClazz = beanClass;
    boolean stopListeners = false;
    boolean stopDefaultListeners = false;
    do {
      Callback callback = null;
      List<XMethod> methods = currentClazz.getDeclaredMethods();
      final int size = methods.size();
      for ( int i = 0; i < size ; i++ ) {
        final XMethod xMethod = methods.get( i );
        if ( xMethod.isAnnotationPresent( annotation ) ) {
          Method method = reflectionManager.toMethod( xMethod );
          final String methodName = method.getName();
          if ( ! callbacksMethodNames.contains( methodName ) ) {
            //overridden method, remove the superclass overridden method
            if ( callback == null ) {
              callback = new BeanCallback( method );
              Class returnType = method.getReturnType();
              Class[] args = method.getParameterTypes();
              if ( returnType != Void.TYPE || args.length != 0 ) {
                throw new RuntimeException(
                    "Callback methods annotated on the bean class must return void and take no arguments: " + annotation
                        .getName() + " - " + xMethod
                );
              }
                            if (!method.isAccessible()) method.setAccessible(true);
                            LOG.debugf("Adding %s as %s callback for entity %s",
                                       methodName,
                                       annotation.getSimpleName(),
                                       beanClass.getName());
              callbacks.add( 0, callback ); //superclass first
              callbacksMethodNames.add( 0, methodName );
            }
            else {
              throw new PersistenceException(
                  "You can only annotate one callback method with "
                      + annotation.getName() + " in bean class: " + beanClass.getName()
              );
            }
          }
        }
      }
      if ( !stopListeners ) {
        getListeners( currentClazz, orderedListeners );
        stopListeners = currentClazz.isAnnotationPresent( ExcludeSuperclassListeners.class );
        stopDefaultListeners = currentClazz.isAnnotationPresent( ExcludeDefaultListeners.class );
      }

      do {
        currentClazz = currentClazz.getSuperclass();
      }
      while ( currentClazz != null
          && ! ( currentClazz.isAnnotationPresent( Entity.class )
          || currentClazz.isAnnotationPresent( MappedSuperclass.class ) )
          );
    }
    while ( currentClazz != null );

    //handle default listeners
    if ( ! stopDefaultListeners ) {
      List<Class> defaultListeners = (List<Class>) reflectionManager.getDefaults().get( EntityListeners.class );

      if ( defaultListeners != null ) {
        int defaultListenerSize = defaultListeners.size();
        for ( int i = defaultListenerSize - 1; i >= 0 ; i-- ) {
          orderedListeners.add( defaultListeners.get( i ) );
        }
      }
    }

    for ( Class listener : orderedListeners ) {
      Callback callback = null;
      if ( listener != null ) {
        XClass xListener = reflectionManager.toXClass( listener );
        callbacksMethodNames = new ArrayList<String>();
        List<XMethod> methods = xListener.getDeclaredMethods();
        final int size = methods.size();
        for ( int i = 0; i < size ; i++ ) {
          final XMethod xMethod = methods.get( i );
          if ( xMethod.isAnnotationPresent( annotation ) ) {
            final Method method = reflectionManager.toMethod( xMethod );
View Full Code Here


          member.getAnnotation( org.hibernate.search.annotations.DateBridge.class ).resolution();
      bridge = getDateField( resolution );
    }
    else {
      //find in built-ins
      XClass returnType = member.getType();
      bridge = builtInBridges.get( returnType.getName() );
      if ( bridge == null && returnType.isEnum() ) {
        bridge = new TwoWayString2FieldBridgeAdaptor(
            new EnumBridge( (Class<? extends Enum>) reflectionManager.toClass( returnType ) )
        );
      }
    }
View Full Code Here

    DirectoryProviderFactory factory = new DirectoryProviderFactory();

    while ( iter.hasNext() ) {
      Class mappedClass = iter.next();
      if (mappedClass != null) {
        XClass mappedXClass = reflectionManager.toXClass(mappedClass);
        if ( mappedXClass != null) {
          if ( mappedXClass.isAnnotationPresent( Indexed.class ) ) {
            DirectoryProviderFactory.DirectoryProviders providers = factory.createDirectoryProviders( mappedXClass, cfg, this, reflectionManager );
            //FIXME DocumentBuilder needs to be built by a helper method receiving Class<T> to infer T properly
            //XClass unfortunately is not (yet) genericized: TODO?
            final DocumentBuilder<?> documentBuilder = new DocumentBuilder(
                mappedXClass, context, providers.getProviders(), providers.getSelectionStrategy(),
View Full Code Here

    }
  }

  private ProvidedId findProvidedId(XClass clazz, ReflectionManager reflectionManager) {
    ProvidedId id = null;
    XClass currentClass = clazz;
    while ( id == null && ( !reflectionManager.equals( currentClass, Object.class ) ) ) {
      id = currentClass.getAnnotation( ProvidedId.class );
      currentClass = clazz.getSuperclass();
    }
    return id;
  }
View Full Code Here

    for (XClass currClass = clazz; currClass != null; currClass = currClass.getSuperclass()) {
      hierarchy.add( currClass );
    }
    Class similarityClass = null;
    for (int index = hierarchy.size() - 1; index >= 0; index--) {
      XClass currClass = hierarchy.get( index );
      /**
       * Override the default analyzer for the properties if the class hold one
       * That's the reason we go down the hierarchy
       */
      Analyzer analyzer = getAnalyzer( currClass, context );

      if ( analyzer != null ) {
        propertiesMetadata.analyzer = analyzer;
      }
      getAnalyzerDefs( currClass, context );
      // Check for any ClassBridges annotation.
      ClassBridges classBridgesAnn = currClass.getAnnotation( ClassBridges.class );
      if ( classBridgesAnn != null ) {
        ClassBridge[] cbs = classBridgesAnn.value();
        for (ClassBridge cb : cbs) {
          bindClassAnnotation( prefix, propertiesMetadata, cb, context );
        }
      }

      // Check for any ClassBridge style of annotations.
      ClassBridge classBridgeAnn = currClass.getAnnotation( ClassBridge.class );
      if ( classBridgeAnn != null ) {
        bindClassAnnotation( prefix, propertiesMetadata, classBridgeAnn, context );
      }

      //Get similarity
      //TODO: similarity form @IndexedEmbedded are not taken care of. Exception??
      if ( isRoot ) {
        org.hibernate.search.annotations.Similarity similarityAnn = currClass.getAnnotation( org.hibernate.search.annotations.Similarity.class );
        if ( similarityAnn != null ) {
          if ( similarityClass != null ) {
            throw new SearchException( "Multiple Similarities defined in the same class hierarchy: " + beanClass.getName() );
          }
          similarityClass = similarityAnn.impl();
        }
      }

      //rejecting non properties (ie regular methods) because the object is loaded from Hibernate,
      // so indexing a non property does not make sense
      List<XProperty> methods = currClass.getDeclaredProperties( XClass.ACCESS_PROPERTY );
      for (XProperty method : methods) {
        initializeMember( method, propertiesMetadata, isRoot, prefix, processedClasses, context );
      }

      List<XProperty> fields = currClass.getDeclaredProperties( XClass.ACCESS_FIELD );
      for (XProperty field : fields) {
        initializeMember( field, propertiesMetadata, isRoot, prefix, processedClasses, context );
      }
    }
    if ( isRoot && similarityClass != null ) {
View Full Code Here

        potentialLevel = Integer.MAX_VALUE;
      }
      maxLevel = potentialLevel > maxLevel ? maxLevel : potentialLevel;
      level++;

      XClass elementClass;
      if ( void.class == embeddedAnn.targetElement() ) {
        elementClass = member.getElementClass();
      }
      else {
        elementClass = reflectionManager.toXClass( embeddedAnn.targetElement() );
      }
      if ( maxLevel == Integer.MAX_VALUE //infinite
          && processedClasses.contains( elementClass ) ) {
        throw new SearchException(
            "Circular reference. Duplicate use of "
                + elementClass.getName()
                + " in root entity " + beanClass.getName()
                + "#" + buildEmbeddedPrefix( prefix, embeddedAnn, member )
        );
      }
      if ( level <= maxLevel ) {
View Full Code Here

  @Override
  public void processCallbacksForEntity(Object entityObject, CallbackRegistryImpl callbackRegistry) {
    final String entityClassName = (String) entityObject;
    try {
      final XClass entityXClass = reflectionManager.classForName( entityClassName, this.getClass() );
      final Class entityClass = reflectionManager.toClass( entityXClass );
      for ( Class annotationClass : CALLBACK_ANNOTATION_CLASSES ) {
        final Callback[] callbacks = resolveCallbacks( entityXClass, annotationClass, reflectionManager );
        callbackRegistry.addEntityCallbacks( entityClass, annotationClass, callbacks );
      }
View Full Code Here

  public Callback[] resolveCallbacks(XClass beanClass, Class annotation, ReflectionManager reflectionManager) {
    List<Callback> callbacks = new ArrayList<Callback>();
    List<String> callbacksMethodNames = new ArrayList<String>(); //used to track overridden methods
    List<Class> orderedListeners = new ArrayList<Class>();
    XClass currentClazz = beanClass;
    boolean stopListeners = false;
    boolean stopDefaultListeners = false;
    do {
      Callback callback = null;
      List<XMethod> methods = currentClazz.getDeclaredMethods();
      final int size = methods.size();
      for ( int i = 0; i < size ; i++ ) {
        final XMethod xMethod = methods.get( i );
        if ( xMethod.isAnnotationPresent( annotation ) ) {
          Method method = reflectionManager.toMethod( xMethod );
          final String methodName = method.getName();
          if ( ! callbacksMethodNames.contains( methodName ) ) {
            //overridden method, remove the superclass overridden method
            if ( callback == null ) {
              callback = new EntityCallback( method );
              Class returnType = method.getReturnType();
              Class[] args = method.getParameterTypes();
              if ( returnType != Void.TYPE || args.length != 0 ) {
                throw new RuntimeException(
                    "Callback methods annotated on the bean class must return void and take no arguments: " + annotation
                        .getName() + " - " + xMethod
                );
              }
              method.setAccessible(true);
              log.debugf("Adding %s as %s callback for entity %s",
                     methodName,
                     annotation.getSimpleName(),
                     beanClass.getName());
              callbacks.add( 0, callback ); //superclass first
              callbacksMethodNames.add( 0, methodName );
            }
            else {
              throw new PersistenceException(
                  "You can only annotate one callback method with "
                      + annotation.getName() + " in bean class: " + beanClass.getName()
              );
            }
          }
        }
      }
      if ( !stopListeners ) {
        getListeners( currentClazz, orderedListeners );
        stopListeners = currentClazz.isAnnotationPresent( ExcludeSuperclassListeners.class );
        stopDefaultListeners = currentClazz.isAnnotationPresent( ExcludeDefaultListeners.class );
      }

      do {
        currentClazz = currentClazz.getSuperclass();
      }
      while ( currentClazz != null
          && ! ( currentClazz.isAnnotationPresent( Entity.class )
          || currentClazz.isAnnotationPresent( MappedSuperclass.class ) )
          );
    }
    while ( currentClazz != null );

    //handle default listeners
    if ( ! stopDefaultListeners ) {
      List<Class> defaultListeners = (List<Class>) reflectionManager.getDefaults().get( EntityListeners.class );

      if ( defaultListeners != null ) {
        int defaultListenerSize = defaultListeners.size();
        for ( int i = defaultListenerSize - 1; i >= 0 ; i-- ) {
          orderedListeners.add( defaultListeners.get( i ) );
        }
      }
    }

    for ( Class listener : orderedListeners ) {
      Callback callback = null;
      if ( listener != null ) {
        XClass xListener = reflectionManager.toXClass( listener );
        callbacksMethodNames = new ArrayList<String>();
        List<XMethod> methods = xListener.getDeclaredMethods();
        final int size = methods.size();
        for ( int i = 0; i < size ; i++ ) {
          final XMethod xMethod = methods.get( i );
          if ( xMethod.isAnnotationPresent( annotation ) ) {
            final Method method = reflectionManager.toMethod( xMethod );
View Full Code Here

  public static Callback[] resolveCallback(XClass beanClass, Class annotation, ReflectionManager reflectionManager) {
    List<Callback> callbacks = new ArrayList<Callback>();
    List<String> callbacksMethodNames = new ArrayList<String>(); //used to track overriden methods
    List<Class> orderedListeners = new ArrayList<Class>();
    XClass currentClazz = beanClass;
    boolean stopListeners = false;
    boolean stopDefaultListeners = false;
    do {
      Callback callback = null;
      List<XMethod> methods = currentClazz.getDeclaredMethods();
      final int size = methods.size();
      for ( int i = 0; i < size ; i++ ) {
        final XMethod xMethod = methods.get( i );
        if ( xMethod.isAnnotationPresent( annotation ) ) {
          Method method = reflectionManager.toMethod( xMethod );
          final String methodName = method.getName();
          if ( ! callbacksMethodNames.contains( methodName ) ) {
            //overriden method, remove the superclass overriden method
            if ( callback == null ) {
              callback = new BeanCallback( method );
              Class returnType = method.getReturnType();
              Class[] args = method.getParameterTypes();
              if ( returnType != Void.TYPE || args.length != 0 ) {
                throw new RuntimeException(
                    "Callback methods annotated on the bean class must return void and take no arguments: " + annotation
                        .getName() + " - " + xMethod
                );
              }
                            if (!method.isAccessible()) method.setAccessible(true);
                            LOG.debugf("Adding %s as %s callback for entity %s",
                                       methodName,
                                       annotation.getSimpleName(),
                                       beanClass.getName());
              callbacks.add( 0, callback ); //superclass first
              callbacksMethodNames.add( 0, methodName );
            }
            else {
              throw new PersistenceException(
                  "You can only annotate one callback method with "
                      + annotation.getName() + " in bean class: " + beanClass.getName()
              );
            }
          }
        }
      }
      if ( !stopListeners ) {
        getListeners( currentClazz, orderedListeners );
        stopListeners = currentClazz.isAnnotationPresent( ExcludeSuperclassListeners.class );
        stopDefaultListeners = currentClazz.isAnnotationPresent( ExcludeDefaultListeners.class );
      }

      do {
        currentClazz = currentClazz.getSuperclass();
      }
      while ( currentClazz != null
          && ! ( currentClazz.isAnnotationPresent( Entity.class )
          || currentClazz.isAnnotationPresent( MappedSuperclass.class ) )
          );
    }
    while ( currentClazz != null );

    //handle default listeners
    if ( ! stopDefaultListeners ) {
      List<Class> defaultListeners = (List<Class>) reflectionManager.getDefaults().get( EntityListeners.class );

      if ( defaultListeners != null ) {
        int defaultListenerSize = defaultListeners.size();
        for ( int i = defaultListenerSize - 1; i >= 0 ; i-- ) {
          orderedListeners.add( defaultListeners.get( i ) );
        }
      }
    }

    for ( Class listener : orderedListeners ) {
      Callback callback = null;
      if ( listener != null ) {
        XClass xListener = reflectionManager.toXClass( listener );
        callbacksMethodNames = new ArrayList<String>();
        do {
          List<XMethod> methods = xListener.getDeclaredMethods();
          final int size = methods.size();
          for ( int i = 0; i < size ; i++ ) {
            final XMethod xMethod = methods.get( i );
            if ( xMethod.isAnnotationPresent( annotation ) ) {
              final Method method = reflectionManager.toMethod( xMethod );
View Full Code Here

    public ClassValidator(
      Class<T> beanClass, ResourceBundle resourceBundle, MessageInterpolator interpolator,
            Map<XClass, ClassValidator> childClassValidators, ReflectionManager reflectionManager
    ) {
        this.reflectionManager = reflectionManager != null ? reflectionManager : new JavaReflectionManager();
        XClass beanXClass = this.reflectionManager.toXClass( beanClass );
    this.beanClass = beanClass;
    this.messageBundle = resourceBundle == null ?
        getDefaultResourceBundle() :
        resourceBundle;
    this.defaultMessageBundle = ResourceBundle.getBundle( DEFAULT_VALIDATOR_MESSAGE );
View Full Code Here

TOP

Related Classes of org.hibernate.annotations.common.reflection.XClass

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.