summaryrefslogtreecommitdiff
path: root/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java
diff options
context:
space:
mode:
Diffstat (limited to 'projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java')
-rw-r--r--projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java57
1 files changed, 30 insertions, 27 deletions
diff --git a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java
index 79019de..c4425cb 100644
--- a/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java
+++ b/projects/net.wotonomy.persistence/src/main/java/net/wotonomy/control/EOClassDescription.java
@@ -36,7 +36,7 @@ import net.wotonomy.foundation.internal.WotonomyException;
* The default implementation works for most well-formed java beans, but you
* will want to create your own subclass most typically to customize the toOne
* and toMany relationships for your class to ensure that an entire graph of
- * objects is not persisted in order to perist a single object. <br>
+ * objects is not persisted in order to persist a single object. <br>
* <br>
*
* The easiest way to register your subclass is to create it in the same package
@@ -53,7 +53,7 @@ import net.wotonomy.foundation.internal.WotonomyException;
* @author $Author: cgruber $
* @version $Revision: 900 $
*/
-public class EOClassDescription {
+public class EOClassDescription<C> {
/**
* A delete rule specifying that object(s) that reference this object should
* have those references set to null when this object is deleted.
@@ -67,7 +67,7 @@ public class EOClassDescription {
public static final int DeleteRuleCascade = 1;
/**
- * A delete rule specicying that this object should not be allowed to be deleted
+ * A delete rule specifying that this object should not be allowed to be deleted
* if it references any object(s).
*/
public static final int DeleteRuleDeny = 2;
@@ -110,24 +110,25 @@ public class EOClassDescription {
* still not found, a class description is returned that uses java bean
* introspection to provide reasonable values.
*/
- public static EOClassDescription classDescriptionForClass(Class aClass) {
+ @SuppressWarnings("unchecked")
+ public static <C> EOClassDescription<C> classDescriptionForClass(Class<C> aClass) {
if (classMap == null)
- classMap = new HashMap();
- EOClassDescription result = (EOClassDescription) classMap.get(aClass);
+ classMap = new HashMap<>();
+ EOClassDescription<C> result = (EOClassDescription<C>) classMap.get(aClass);
if (result == null) {
// if not found, post notification
NSNotificationCenter.defaultCenter().postNotification(ClassDescriptionNeededForClassNotification, aClass,
null);
- result = (EOClassDescription) classMap.get(aClass);
+ result = (EOClassDescription<C>) classMap.get(aClass);
}
if (result == null) {
// if not found, look for similarly named class
String className = aClass.getName() + ClassNameSuffix;
- Class classDesc;
+ Class<EOClassDescription<C>> classDesc;
try {
- classDesc = aClass.getClassLoader().loadClass(className);
+ classDesc = (Class<EOClassDescription<C>>) aClass.getClassLoader().loadClass(className);
if (classDesc != null) {
- result = (EOClassDescription) classDesc.newInstance();
+ result = classDesc.getDeclaredConstructor().newInstance();
registerClassDescription(result, aClass);
}
} catch (Exception exc) {
@@ -136,7 +137,7 @@ public class EOClassDescription {
}
if (result == null) {
// if not found, default to this class
- result = new EOClassDescription(aClass);
+ result = new EOClassDescription<>(aClass);
registerClassDescription(result, aClass);
}
return result;
@@ -148,15 +149,16 @@ public class EOClassDescription {
* ClassDescriptionNeededForEntityNameNotification is posted. Returns null if no
* class description can be found for the entity name.
*/
- public static EOClassDescription classDescriptionForEntityName(String aName) {
+ @SuppressWarnings("unchecked")
+ public static <C> EOClassDescription<C> classDescriptionForEntityName(String aName) {
if (entityMap == null)
- entityMap = new HashMap();
- EOClassDescription result = (EOClassDescription) entityMap.get(aName);
+ entityMap = new HashMap<>();
+ EOClassDescription<C> result = (EOClassDescription<C>) entityMap.get(aName);
if (result == null) {
// if not found, post notification
NSNotificationCenter.defaultCenter().postNotification(ClassDescriptionNeededForEntityNameNotification,
aName, null);
- result = (EOClassDescription) entityMap.get(aName);
+ result = (EOClassDescription<C>) entityMap.get(aName);
}
return result;
}
@@ -171,14 +173,14 @@ public class EOClassDescription {
}
/**
- * Registers the specified class descriptiong for the specified class. Nulls are
+ * Registers the specified class description for the specified class. Nulls are
* not allowed - to clear the cache call invalidateClassDescriptionCache().
*/
- public static void registerClassDescription(EOClassDescription description, Class aClass) {
+ public static <C> void registerClassDescription(EOClassDescription<C> description, Class<C> aClass) {
if (classMap == null)
- classMap = new HashMap();
+ classMap = new HashMap<>();
if (entityMap == null)
- entityMap = new HashMap();
+ entityMap = new HashMap<>();
description.theClass = aClass;
classMap.put(aClass, description);
entityMap.put(description.entityName(), description);
@@ -198,16 +200,16 @@ public class EOClassDescription {
*/
private final static String ClassNameSuffix = "ClassDesc";
- private static Map classMap;
- private static Map entityMap;
+ private static Map<Class<?>, EOClassDescription<?>> classMap;
+ private static Map<String, EOClassDescription<?>> entityMap;
- protected Class theClass;
+ protected Class<?> theClass;
private NSMutableArray attributes;
/**
* Constructor may only be called by subclasses.
*/
- protected EOClassDescription(Class aClass) {
+ protected EOClassDescription(Class<?> aClass) {
theClass = aClass;
}
@@ -265,7 +267,7 @@ public class EOClassDescription {
* relationship key, or null if the class description cannot be determined for
* that key. This implementation returns null.
*/
- public EOClassDescription classDescriptionForDestinationKey(String detailKey) {
+ public EOClassDescription<?> classDescriptionForDestinationKey(String detailKey) {
return null;
}
@@ -280,11 +282,12 @@ public class EOClassDescription {
* editing context is specified, the global id is ignored and the new instance
* of the class is returned.
*/
- public Object createInstanceWithEditingContext(EOEditingContext anEditingContext, EOGlobalID globalID) {
+ @SuppressWarnings("unchecked")
+ public C createInstanceWithEditingContext(EOEditingContext anEditingContext, EOGlobalID globalID) {
//System.out.println( "createInstanceWithEditingContext: " + this + " : " + theClass );
Object result = null;
try {
- result = theClass.newInstance();
+ result = theClass.getDeclaredConstructor().newInstance();
if (anEditingContext != null) {
if (globalID != null) {
if (result instanceof EOEnterpriseObject) {
@@ -305,7 +308,7 @@ public class EOClassDescription {
// error instantiating
throw new WotonomyException(exc);
}
- return result;
+ return (C) result;
}
/*