Package org.hibernate.annotations.common.reflection

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


  @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
                );
              }
              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

  static PropertyData getPropertyOverriddenByMapperOrMapsId(
      boolean isId,
      PropertyHolder propertyHolder,
      String propertyName,
      Mappings mappings) {
    final XClass persistentXClass;
    try {
       persistentXClass = mappings.getReflectionManager()
          .classForName( propertyHolder.getPersistentClass().getClassName(), AnnotationBinder.class );
    }
    catch ( ClassNotFoundException e ) {
View Full Code Here

   *
   * @return this (for method chaining)
   */
  @SuppressWarnings({ "unchecked" })
  public Configuration addAnnotatedClass(Class annotatedClass) {
    XClass xClass = reflectionManager.toXClass( annotatedClass );
    metadataSourceQueue.add( xClass );
    return this;
  }
View Full Code Here

      return targetEntity.getName();
    }
  }

  public static String getReferenceEntityName(PropertyData propertyData, Mappings mappings) {
    XClass targetEntity = getTargetEntity( propertyData, mappings );
    if ( AnnotationBinder.isDefault( targetEntity, mappings ) ) {
      return propertyData.getClassOrElementName();
    }
    else {
      return targetEntity.getName();
    }
  }
View Full Code Here

   *
   * @return this (for method chaining)
   */
  @SuppressWarnings({ "unchecked" })
  public Configuration addAnnotatedClass(Class annotatedClass) {
    XClass xClass = reflectionManager.toXClass( annotatedClass );
    metadataSourceQueue.add( xClass );
    return this;
  }
View Full Code Here

    }

    protected void syncAnnotatedClasses() {
      final Iterator<XClass> itr = annotatedClasses.iterator();
      while ( itr.hasNext() ) {
        final XClass annotatedClass = itr.next();
        if ( annotatedClass.isAnnotationPresent( Entity.class ) ) {
          annotatedClassesByEntityNameMap.put( annotatedClass.getName(), annotatedClass );
          continue;
        }

        if ( !annotatedClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) {
          itr.remove();
        }
      }
    }
View Full Code Here

      // order the hierarchy
      List<XClass> workingCopy = new ArrayList<XClass>( copy );
      List<XClass> newList = new ArrayList<XClass>( copy.size() );
      while ( workingCopy.size() > 0 ) {
        XClass clazz = workingCopy.get( 0 );
        orderHierarchy( workingCopy, newList, copy, clazz );
      }
      return newList;
    }
View Full Code Here

      return newList;
    }

    private void insertMappedSuperclasses(List<XClass> original, List<XClass> copy) {
      for ( XClass clazz : original ) {
        XClass superClass = clazz.getSuperclass();
        while ( superClass != null
            && !reflectionManager.equals( superClass, Object.class )
            && !copy.contains( superClass ) ) {
          if ( superClass.isAnnotationPresent( Entity.class )
              || superClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class ) ) {
            copy.add( superClass );
          }
          superClass = superClass.getSuperclass();
        }
      }
    }
View Full Code Here

   * @param embeddedXProperty The property that is the composite being described by this ComponentPropertyHolder
   */
  private Map<String,AttributeConversionInfo> processAttributeConversions(XProperty embeddedXProperty) {
    final Map<String,AttributeConversionInfo> infoMap = new HashMap<String, AttributeConversionInfo>();

    final XClass embeddableXClass = embeddedXProperty.getType();

    // as a baseline, we want to apply conversions from the Embeddable and then overlay conversions
    // from the Embedded

    // first apply conversions from the Embeddable...
    {
      // @Convert annotation on the Embeddable class level
      final Convert convertAnnotation = embeddableXClass.getAnnotation( Convert.class );
      if ( convertAnnotation != null ) {
        final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, embeddableXClass );
        if ( StringHelper.isEmpty( info.getAttributeName() ) ) {
          throw new IllegalStateException( "@Convert placed on @Embeddable must define attributeName" );
        }
        infoMap.put( info.getAttributeName(), info );
      }
    }
    {
      // @Converts annotation on the Embeddable class level
      final Converts convertsAnnotation = embeddableXClass.getAnnotation( Converts.class );
      if ( convertsAnnotation != null ) {
        for ( Convert convertAnnotation : convertsAnnotation.value() ) {
          final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, embeddableXClass );
          if ( StringHelper.isEmpty( info.getAttributeName() ) ) {
            throw new IllegalStateException( "@Converts placed on @Embeddable must define attributeName" );
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.