Package org.hibernate.reflection.java.xml

Examples of org.hibernate.reflection.java.xml.XMLContext


    assertNotNull( reader.getAnnotation( OrderBy.class ) );
    assertEquals( "maxSpeed", reader.getAnnotation( OrderBy.class ).value() );
  }

  public void testEntityListeners() throws Exception {
    XMLContext context = buildContext( "org/hibernate/test/reflection/java/xml/orm.xml" );

    Method method = Administration.class.getDeclaredMethod( "calculate" );
    EJB3OverridenAnnotationReader reader = new EJB3OverridenAnnotationReader( method, context );
    assertTrue( reader.isAnnotationPresent( PrePersist.class ) );

    reader = new EJB3OverridenAnnotationReader( Administration.class, context );
    assertTrue( reader.isAnnotationPresent( EntityListeners.class ) );
    assertEquals( 1, reader.getAnnotation( EntityListeners.class ).value().length );
    assertEquals( LogListener.class, reader.getAnnotation( EntityListeners.class ).value()[0] );

    method = LogListener.class.getDeclaredMethod( "noLog", Object.class );
    reader = new EJB3OverridenAnnotationReader( method, context );
    assertTrue( reader.isAnnotationPresent( PostLoad.class ) );

    method = LogListener.class.getDeclaredMethod( "log", Object.class );
    reader = new EJB3OverridenAnnotationReader( method, context );
    assertTrue( reader.isAnnotationPresent( PrePersist.class ) );
    assertFalse( reader.isAnnotationPresent( PostPersist.class ) );

    assertEquals( 1, context.getDefaultEntityListeners().size() );
    assertEquals( OtherLogListener.class.getName(), context.getDefaultEntityListeners().get(0) );
  }
View Full Code Here


  private XMLContext buildContext(String ormfile) throws SAXException, DocumentException, IOException {
    XMLHelper xmlHelper = new XMLHelper();
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    InputStream is = cl.getResourceAsStream( ormfile );
    assertNotNull( "ORM.xml not found: " + ormfile, is );
    XMLContext context = new XMLContext();
    List errors = new ArrayList();
    SAXReader saxReader = xmlHelper.createSAXReader( "XML InputStream", errors, EJB3DTDEntityResolver.INSTANCE );
    //saxReader.setValidation( false );
    try {
      saxReader.setFeature( "http://apache.org/xml/features/validation/schema", true );
    }
    catch (SAXNotSupportedException e) {
      saxReader.setValidation( false );
    }
    org.dom4j.Document doc;
    try {
      doc = saxReader
          .read( new InputSource( new BufferedInputStream( is ) ) );
    }
    finally {
      is.close();
    }
    assertEquals( 0, errors.size() );
    context.addDocument( doc );
    return context;
  }
View Full Code Here

TOP

Related Classes of org.hibernate.reflection.java.xml.XMLContext

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.