[jboss-cvs] jboss-seam/src/main/org/jboss/seam ...
Gavin King
gavin.king at jboss.com
Tue Feb 27 10:03:07 EST 2007
User: gavin
Date: 07/02/27 10:03:07
Modified: src/main/org/jboss/seam Entity.java Model.java
Log:
support entities with no @Entity annotation
Revision Changes Path
1.2 +22 -0 jboss-seam/src/main/org/jboss/seam/Entity.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Entity.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Entity.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- Entity.java 14 Feb 2007 05:46:29 -0000 1.1
+++ Entity.java 27 Feb 2007 15:03:07 -0000 1.2
@@ -9,6 +9,7 @@
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
+import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.util.Reflections;
/**
@@ -124,4 +125,25 @@
}
}
+ public static Entity forClass(Class clazz)
+ {
+ if ( !Contexts.isApplicationContextActive() )
+ {
+ throw new IllegalStateException("No application context active");
+ }
+
+ String name = getModelName(clazz);
+ Model model = (Model) Contexts.getApplicationContext().get(name);
+ if ( model==null || !(model instanceof Entity) )
+ {
+ Entity entity = new Entity(clazz);
+ Contexts.getApplicationContext().set(name, model);
+ return entity;
+ }
+ else
+ {
+ return (Entity) model;
+ }
+ }
+
}
1.3 +6 -1 jboss-seam/src/main/org/jboss/seam/Model.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: Model.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/Model.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- Model.java 14 Feb 2007 07:05:41 -0000 1.2
+++ Model.java 27 Feb 2007 15:03:07 -0000 1.3
@@ -56,7 +56,7 @@
throw new IllegalStateException("No application context active");
}
- String name = clazz.getName() + ".model";
+ String name = getModelName(clazz);
Model model = (Model) Contexts.getApplicationContext().get(name);
if ( model==null )
{
@@ -67,4 +67,9 @@
return model;
}
+ static String getModelName(Class clazz)
+ {
+ return clazz.getName() + ".model";
+ }
+
}
More information about the jboss-cvs-commits
mailing list