[hibernate-commits] Hibernate SVN: r11173 - in branches/Branch_3_2/HibernateExt: annotations/lib and 2 other directories.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Thu Feb 8 23:14:31 EST 2007


Author: epbernard
Date: 2007-02-08 23:14:30 -0500 (Thu, 08 Feb 2007)
New Revision: 11173

Modified:
   branches/Branch_3_2/HibernateExt/annotations/build.xml
   branches/Branch_3_2/HibernateExt/annotations/lib/README.txt
   branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java
   branches/Branch_3_2/HibernateExt/search/build.xml
Log:
ANN-553 validator no longer a hard dependency

Modified: branches/Branch_3_2/HibernateExt/annotations/build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/build.xml	2007-02-09 03:41:46 UTC (rev 11172)
+++ branches/Branch_3_2/HibernateExt/annotations/build.xml	2007-02-09 04:14:30 UTC (rev 11173)
@@ -38,13 +38,13 @@
 	<path id="lib.moduleclass.path">
 		<pathelement location="${jpa-api.jar}"/>
 		<pathelement location="${commons-annotations.jar}"/>
-		<pathelement location="${validator.jar}"/>
 	</path>
 
 	<path id="junit.moduleclasspath">
 		<pathelement location="${src.dir}"/>
 		<pathelement location="${test.dir}"/>
-		<pathelement location="lib/testlibs/org.eclipse.jdt.core_3.1.0.jar"/>
+        <!-- pathelement location="${validator.jar}"/ -->
+        <pathelement location="lib/testlibs/org.eclipse.jdt.core_3.1.0.jar"/>
 		<fileset dir="${jdbc.dir}">
 			<include name="**/*.jar"/>
 			<include name="**/*.zip"/>
@@ -74,7 +74,7 @@
 		<ant inheritall="false" dir="${basedir}/../validator" target="jar"/>
 	</target>
 
-	<target name="compile" depends="init,get.jpa-api,get.commons-annotations,get.validator"
+	<target name="compile" depends="init,get.jpa-api,get.commons-annotations"
 			description="Compile the Java source code">
 		<available
 				classname="org.eclipse.core.launcher.Main"
@@ -100,7 +100,7 @@
 		</copy>
 	</target>
 
-	<target name="compiletest" depends="compile" description="Compile the tests">
+	<target name="compiletest" depends="compile,get.validator" description="Compile the tests">
 		<available
 				classname="org.eclipse.core.launcher.Main"
 				property="build.compiler"

Modified: branches/Branch_3_2/HibernateExt/annotations/lib/README.txt
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/lib/README.txt	2007-02-09 03:41:46 UTC (rev 11172)
+++ branches/Branch_3_2/HibernateExt/annotations/lib/README.txt	2007-02-09 04:14:30 UTC (rev 11173)
@@ -1,5 +1,5 @@
-Hibernate Metadata dependencies
-===============================
+Hibernate Annotations dependencies
+==================================
 
 
 Core
@@ -7,8 +7,8 @@
 hibernate-commons-annotations.jar: required
 hibernate3.jar: required
 hibernate core dependencies: required (see Hibernate Core for more information)
-hibernate-validator.jar: required
-ejb3-persistence.jar: optional (needed for Java Persistence integration)
+hibernate-validator.jar: optional
+ejb3-persistence.jar: required
 
 Test
 ====

Modified: branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
--- branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java	2007-02-09 03:41:46 UTC (rev 11172)
+++ branches/Branch_3_2/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java	2007-02-09 04:14:30 UTC (rev 11173)
@@ -17,6 +17,10 @@
 import java.util.SortedSet;
 import java.util.StringTokenizer;
 import java.util.TreeSet;
+import java.util.ResourceBundle;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 
 import javax.persistence.Entity;
 import javax.persistence.MappedSuperclass;
@@ -43,7 +47,6 @@
 import org.hibernate.util.JoinedIterator;
 import org.hibernate.util.ReflectHelper;
 import org.hibernate.util.StringHelper;
-import org.hibernate.validator.ClassValidator;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 
@@ -311,19 +314,39 @@
 				buildUniqueKeyFromColumnNames( columnNames, table, keyName );
 			}
 		}
-		boolean applyOnDdl = getProperties().getProperty( org.hibernate.validator.Environment.APPLY_TO_DDL, "true" )
+		boolean applyOnDdl = getProperties().getProperty(
+				"hibernate.validator.apply_to_ddl", //org.hibernate.validator.Environment.APPLY_TO_DDL
+				"true" )
 				.equalsIgnoreCase( "true" );
-		if (applyOnDdl) {
+
+		Constructor validatorCtr = null;
+		Method applyMethod = null;
+		try {
+			Class classValidator = ReflectHelper.classForName("org.hibernate.validator.ClassValidator", this.getClass() );
+			Class messageInterpolator = ReflectHelper.classForName("org.hibernate.validator.MessageInterpolator", this.getClass() );
+			validatorCtr = classValidator.getDeclaredConstructor( new Class[] {
+					Class.class, ResourceBundle.class, messageInterpolator, Map.class, ReflectionManager.class
+					}
+			);
+			applyMethod = classValidator.getMethod( "apply", PersistentClass.class );
+		}
+		catch (ClassNotFoundException e) {
+			log.info( "Hibernate Validator not found: ignoring");
+		}
+		catch (NoSuchMethodException e) {
+			throw new AnnotationException(e);
+		}
+		if ( applyMethod != null && applyOnDdl) {
 			for ( PersistentClass persistentClazz : (Collection<PersistentClass>) classes.values() ) {
 				//integrate the validate framework
 				String className = persistentClazz.getClassName();
 				if ( StringHelper.isNotEmpty( className ) ) {
 					try {
-						new ClassValidator( ReflectHelper.classForName( className ), null, null, null, reflectionManager )
-								.apply( persistentClazz );
+						validatorCtr.newInstance( ReflectHelper.classForName( className ), null, null, null, reflectionManager );
+						applyMethod.invoke( persistentClazz );
 					}
-					catch (ClassNotFoundException e) {
-						//swallow them
+					catch (Exception e) {
+						log.warn("Unable to apply constraints on DDL for " + className, e);
 					}
 				}
 			}

Modified: branches/Branch_3_2/HibernateExt/search/build.xml
===================================================================
--- branches/Branch_3_2/HibernateExt/search/build.xml	2007-02-09 03:41:46 UTC (rev 11172)
+++ branches/Branch_3_2/HibernateExt/search/build.xml	2007-02-09 04:14:30 UTC (rev 11173)
@@ -29,8 +29,6 @@
 			  value="${basedir}/../annotations/target/hibernate-annotations/hibernate-annotations.jar"/>
 	<property name="commons-annotations.jar"
 			  value="${basedir}/../commons-annotations/target/hibernate-commons-annotations/hibernate-commons-annotations.jar"/>
-	<property name="validator.jar"
-				  value="${basedir}/../validator/target/hibernate-validator/hibernate-validator.jar"/>
 
 	<import file="${common.dir}/common-build.xml"/>
 
@@ -42,7 +40,6 @@
 	<path id="junit.moduleclasspath">
 		<pathelement location="${src.dir}"/>
 		<pathelement location="${test.dir}"/>
-		<pathelement location="${validator.jar}"/>
 		<pathelement location="${annotations.jar}"/>
 		<fileset dir="${jdbc.dir}">
 			<include name="*.jar"/>
@@ -59,7 +56,6 @@
 		<!-- check for dependency artefacts -->
 		<available file="${jpa-api.jar}" type="file" property="jpa-api.jar.available"/>
 		<available file="${commons-annotations.jar}" type="file" property="commons-annotations.jar.available"/>
-		<available file="${validator.jar}" type="file" property="validator.jar.available"/>
 		<available file="${annotations.jar}" type="file" property="annotations.jar.available"/>
         <mkdir dir="${lib.dir}/test"/>
     </target>
@@ -74,11 +70,6 @@
 		<ant inheritall="false" dir="${basedir}/../commons-annotations" target="jar"/>
 	</target>
 
-	<target name="get.validator" depends="init" unless="validator.jar.available">
-		<ant inheritall="false" dir="${basedir}/../validator" target="clean"/>
-		<ant inheritall="false" dir="${basedir}/../validator" target="jar"/>
-	</target>
-
 	<target name="get.annotations" depends="init" unless="annotations.jar.available">
 		<ant inheritall="false" dir="${basedir}/../annotations" target="clean"/>
 		<ant inheritall="false" dir="${basedir}/../annotations" target="jar"/>
@@ -109,7 +100,7 @@
 		</copy>
 	</target>
 
-	<target name="compiletest" depends="init,get.jpa-api,get.validator,get.annotations,compile" description="Compile the tests">
+	<target name="compiletest" depends="init,get.jpa-api,get.annotations,compile" description="Compile the tests">
 		<available
 				classname="org.eclipse.core.launcher.Main"
 				property="build.compiler"
@@ -224,7 +215,6 @@
         <mkdir dir="${dist.lib.dir}/test"/>
         <copy todir="${dist.lib.dir}/test" failonerror="false">
 			<fileset file="${annotations.jar}"/>
-            <fileset file="${validator.jar}"/>
         </copy>
 
         <copy file="${basedir}/build.properties.dist" tofile="${dist.dir}/build.properties" failonerror="false">




More information about the hibernate-commits mailing list