1 16 17 package org.springframework.orm.hibernate3.annotation; 18 19 import org.hibernate.HibernateException; 20 import org.hibernate.cfg.AnnotationConfiguration; 21 import org.hibernate.cfg.Configuration; 22 23 import org.springframework.orm.hibernate3.LocalSessionFactoryBean; 24 25 57 public class AnnotationSessionFactoryBean extends LocalSessionFactoryBean { 58 59 private Class [] annotatedClasses; 60 61 private String [] annotatedPackages; 62 63 64 public AnnotationSessionFactoryBean() { 65 setConfigurationClass(AnnotationConfiguration.class); 66 } 67 68 public void setConfigurationClass(Class configurationClass) { 69 if (configurationClass == null || !AnnotationConfiguration.class.isAssignableFrom(configurationClass)) { 70 throw new IllegalArgumentException ( 71 "AnnotationSessionFactoryBean only supports AnnotationConfiguration or subclasses"); 72 } 73 super.setConfigurationClass(configurationClass); 74 } 75 76 81 public void setAnnotatedClasses(Class [] annotatedClasses) { 82 this.annotatedClasses = annotatedClasses; 83 } 84 85 90 public void setAnnotatedPackages(String [] annotatedPackages) { 91 this.annotatedPackages = annotatedPackages; 92 } 93 94 95 102 protected final void postProcessConfiguration(Configuration config) throws HibernateException { 103 AnnotationConfiguration annConfig = (AnnotationConfiguration) config; 104 105 if (this.annotatedClasses != null) { 106 for (int i = 0; i < this.annotatedClasses.length; i++) { 107 annConfig.addAnnotatedClass(this.annotatedClasses[i]); 108 } 109 } 110 if (this.annotatedPackages != null) { 111 for (int i = 0; i < this.annotatedPackages.length; i++) { 112 annConfig.addPackage(this.annotatedPackages[i]); 113 } 114 } 115 116 postProcessAnnotationConfiguration(annConfig); 118 } 119 120 127 protected void postProcessAnnotationConfiguration(AnnotationConfiguration config) 128 throws HibernateException { 129 } 130 131 } 132 | Popular Tags |