r6972 - dumbhippo/trunk/server/src/com/dumbhippo/dm/schema
- From: commits mugshot org
- To: online-desktop-list gnome org
- Subject: r6972 - dumbhippo/trunk/server/src/com/dumbhippo/dm/schema
- Date: Wed, 5 Dec 2007 14:46:40 -0600 (CST)
Author: otaylor
Date: 2007-12-05 14:46:40 -0600 (Wed, 05 Dec 2007)
New Revision: 6972
Added:
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PropertyInfo.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ResourcePropertyInfo.java
Modified:
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMClassHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMPropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/FeedPropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ListPlainPropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ListResourcePropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PlainPropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ResourcePropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SetPlainPropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SetResourcePropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SinglePlainPropertyHolder.java
dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SingleResourcePropertyHolder.java
Log:
Refactoring: Fix construction of property holders to be reasonably sane by
using helper[Resource]PropertyInfo classes, and get rid of passing around
6-7 parameters and @SupressWarnings("unchecked") all over the place.
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMClassHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMClassHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMClassHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -371,7 +371,7 @@
Map<String, Integer> nameCount = new HashMap<String, Integer>();
for (CtMethod method : baseCtClass.getMethods()) {
- DMPropertyHolder<K,T,?> property = DMPropertyHolder.getForMethod(this, method);
+ DMPropertyHolder<K,T,?> property = DMPropertyHolder.getForMethod(model, baseClass, keyClass, method);
if (property != null) {
foundProperties.add(property);
if (!nameCount.containsKey(property.getName()))
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMPropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMPropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/DMPropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -27,6 +27,7 @@
import com.dumbhippo.dm.DMViewpoint;
import com.dumbhippo.dm.DataModel;
import com.dumbhippo.dm.annotations.DMFilter;
+import com.dumbhippo.dm.annotations.DMO;
import com.dumbhippo.dm.annotations.DMProperty;
import com.dumbhippo.dm.annotations.PropertyType;
import com.dumbhippo.dm.annotations.ViewerDependent;
@@ -35,17 +36,20 @@
import com.dumbhippo.dm.filter.Filter;
import com.dumbhippo.dm.parser.FilterParser;
import com.dumbhippo.dm.parser.ParseException;
+import com.dumbhippo.dm.schema.PropertyInfo.ContainerType;
public abstract class DMPropertyHolder<K, T extends DMObject<K>, TI> implements Comparable<DMPropertyHolder<?,?,?>> {
@SuppressWarnings("unused")
static private final Logger logger = GlobalSetup.getLogger(DMPropertyHolder.class);
+
+ protected PropertyInfo<K,T,TI> propertyInfo;
- protected DMClassHolder<K,T> declaringClassHolder;
+ protected Class<TI> elementType;
protected DMProperty annotation;
+
protected boolean defaultInclude;
private String typeString;
protected String propertyId;
- protected Class<TI> elementType;
protected Filter propertyFilter;
protected boolean completed;
@@ -56,15 +60,18 @@
private String namespace;
private long ordering;
- public DMPropertyHolder (DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, Class<TI> elementType, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- boolean booleanOnly = false;
+ public DMPropertyHolder (PropertyInfo<K,T,TI> propertyInfo) {
+ this.propertyInfo = propertyInfo;
- this.annotation = annotation;
- this.declaringClassHolder = declaringClassHolder;
- this.elementType = elementType;
+ elementType = propertyInfo.getItemType();
+ annotation = propertyInfo.getAnnotation();
+ CtMethod ctMethod = propertyInfo.getCtMethod();
+
+ boolean booleanOnly = false;
+
try {
- method = declaringClassHolder.getBaseClass().getMethod(ctMethod.getName(), new Class[] {});
+ method = propertyInfo.getDeclaringType().getMethod(ctMethod.getName(), new Class[] {});
} catch (NoSuchMethodException e) {
throw new RuntimeException("Can't find Java class object for method return type", e);
}
@@ -97,8 +104,10 @@
throw new RuntimeException("Can't find bytecode for method return or parameters", e);
}
+ DMO classAnnotation = propertyInfo.getDeclaringType().getAnnotation(DMO.class);
+
if (annotation.propertyId().equals(""))
- propertyId = declaringClassHolder.getClassId() + "#" + name;
+ propertyId = classAnnotation.classId() + "#" + name;
else
propertyId = annotation.propertyId();
@@ -121,9 +130,9 @@
computeOrdering();
- if (filter != null) {
+ if (propertyInfo.getFilter() != null) {
try {
- propertyFilter = FilterParser.parse(filter.value());
+ propertyFilter = FilterParser.parse(propertyInfo.getFilter().value());
} catch (ParseException e) {
throw new RuntimeException(propertyId + ": Error parsing filter", e);
}
@@ -243,7 +252,7 @@
}
public DataModel getModel() {
- return declaringClassHolder.getModel();
+ return propertyInfo.getModel();
}
@@ -316,14 +325,20 @@
///////////////////////////////////////////////////////////////////////////////////////////////
- enum ContainerType {
- SINGLE,
- LIST,
- SET,
- FEED
- };
-
- public static <K,T extends DMObject<K>> DMPropertyHolder<K,T,?> getForMethod(DMClassHolder<K,T> classHolder, CtMethod ctMethod) {
+ private static <K, T extends DMObject<K>, TI> PropertyInfo<K,T,TI> createPropertyInfo(Class<T> declaringType, Class<K> keyType, Class<TI> elementType) {
+ return new PropertyInfo<K,T,TI>(declaringType, keyType, elementType);
+ }
+
+ // The purpose of this is that Java (at least over the set of compilers we support) can't keep track
+ // of the relationship between the parameters of DMClassInfo<>, and know that they are appropriate
+ // to pass when creating ResourcePropertyInfo, so we have to do the construction unchecked.
+ //
+ @SuppressWarnings("unchecked")
+ public static <K, T extends DMObject<K>> ResourcePropertyInfo<K,T,?,?> createResourcePropertyInfo(Class<T> declaringType, Class<K> keyType, DMClassInfo<?,?> elementClassInfo) {
+ return new ResourcePropertyInfo(declaringType, keyType, elementClassInfo.getObjectClass(), elementClassInfo.getKeyClass());
+ }
+
+ public static <K,T extends DMObject<K>> DMPropertyHolder<K,T,?> getForMethod(DataModel model, Class<T> declaringType, Class<K> keyType, CtMethod ctMethod) {
DMProperty property = null;
DMFilter filter = null;
ViewerDependent viewerDependent = null;
@@ -350,7 +365,7 @@
Method method;
try {
- method = classHolder.getBaseClass().getMethod(ctMethod.getName(), new Class[] {});
+ method = declaringType.getMethod(ctMethod.getName(), new Class[] {});
} catch (NoSuchMethodException e) {
throw new RuntimeException("Can't find Java class object for method return type", e);
}
@@ -386,121 +401,25 @@
else
throw new RuntimeException("Unexpected non-class type");
- DMClassInfo<?,? extends DMObject<?>> classInfo = DMClassInfo.getForClass(elementType);
+ DMClassInfo<?,? extends DMObject<?>> elementClassInfo = DMClassInfo.getForClass(elementType);
+
+ PropertyInfo<K,T,?> propertyInfo;
- if (classInfo != null) {
- return createResourcePropertyHolder(classHolder, ctMethod, classInfo, property, filter, viewerDependent, containerType);
- } else if (elementType.isPrimitive() || (genericElementType == String.class) || (genericElementType == Date.class)) {
- return createPlainPropertyHolder(classHolder, ctMethod, elementType, property, filter, viewerDependent, containerType);
+ if (elementClassInfo != null) {
+ propertyInfo = createResourcePropertyInfo(declaringType, keyType, elementClassInfo);
+ } else if (elementType.isPrimitive() || (genericElementType == String.class) || (genericElementType == Date.class)) {
+ propertyInfo = createPropertyInfo(declaringType, keyType, elementType);
} else {
throw new RuntimeException("Property type must be DMObject, primitive, Date, or String");
}
- }
-
- // this is somewhat silly, the unchecked is to avoid having type params on the constructor; eclipse
- // will let you put them on there in the way we do with most other cases like this (see below for the plain holders for example),
- // but javac gets confused by that
- @SuppressWarnings("unchecked")
- private static <K, T extends DMObject<K>> ListResourcePropertyHolder<K,T,?,?>
- newListResourcePropertyHolderHack(DMClassHolder<K,T> classHolder, CtMethod ctMethod, DMClassInfo<?,? extends DMObject<?>> classInfo,
- DMProperty property, DMFilter filter, ViewerDependent viewerDependent) {
- return new ListResourcePropertyHolder(classHolder, ctMethod, classInfo,
- property, filter, viewerDependent);
- }
- // this is somewhat silly, the unchecked is to avoid having type params on the constructor; eclipse
- // will let you put them on there in the way we do with most other cases like this (see below for the plain holders for example),
- // but javac gets confused by that
- @SuppressWarnings("unchecked")
- private static <K, T extends DMObject<K>> SetResourcePropertyHolder<K,T,?,?>
- newSetResourcePropertyHolderHack(DMClassHolder<K,T> classHolder, CtMethod ctMethod, DMClassInfo<?,? extends DMObject<?>> classInfo,
- DMProperty property, DMFilter filter, ViewerDependent viewerDependent) {
- return new SetResourcePropertyHolder(classHolder, ctMethod, classInfo,
- property, filter, viewerDependent);
- }
-
- // this is somewhat silly, the unchecked is to avoid having type params on the constructor; eclipse
- // will let you put them on there in the way we do with most other cases like this (see below for the plain holders for example),
- // but javac gets confused by that
- @SuppressWarnings("unchecked")
- private static <K, T extends DMObject<K>> FeedPropertyHolder<K,T,?,?>
- newFeedPropertyHolderHack(DMClassHolder<K,T> classHolder, CtMethod ctMethod, DMClassInfo<?,? extends DMObject<?>> classInfo,
- DMProperty property, DMFilter filter, ViewerDependent viewerDependent) {
- return new FeedPropertyHolder(classHolder, ctMethod, classInfo,
- property, filter, viewerDependent);
- }
-
- // this is somewhat silly, the unchecked is to avoid having type params on the constructor; eclipse
- // will let you put them on there in the way we do with most other cases like this (see below for the plain holders for example),
- // but javac gets confused by that
- @SuppressWarnings("unchecked")
- private static <K, T extends DMObject<K>> SingleResourcePropertyHolder<K,T,?,?>
- newSingleResourcePropertyHolderHack(DMClassHolder<K,T> classHolder, CtMethod ctMethod, DMClassInfo<?,? extends DMObject<?>> classInfo,
- DMProperty property, DMFilter filter, ViewerDependent viewerDependent) {
- return new SingleResourcePropertyHolder(classHolder, ctMethod, classInfo,
- property, filter, viewerDependent);
- }
-
- private static <K, T extends DMObject<K>> DMPropertyHolder<K,T,?> createResourcePropertyHolder(DMClassHolder<K,T> classHolder, CtMethod ctMethod,
- DMClassInfo<?,? extends DMObject<?>> classInfo, DMProperty property, DMFilter filter, ViewerDependent viewerDependent, ContainerType containerType) {
+ propertyInfo.setModel(model);
+ propertyInfo.setCtMethod(ctMethod);
+ propertyInfo.setAnnotation(property);
+ propertyInfo.setFilter(filter);
+ propertyInfo.setViewerDependent(viewerDependent);
+ propertyInfo.setContainerType(containerType);
- switch (containerType) {
- case SINGLE:
- return newSingleResourcePropertyHolderHack(classHolder, ctMethod, classInfo, property, filter, viewerDependent);
- case LIST:
- return newListResourcePropertyHolderHack(classHolder, ctMethod, classInfo, property, filter, viewerDependent);
- case SET:
- return newSetResourcePropertyHolderHack(classHolder, ctMethod, classInfo, property, filter, viewerDependent);
- case FEED:
- return newFeedPropertyHolderHack(classHolder, ctMethod, classInfo, property, filter, viewerDependent);
- }
-
- throw new RuntimeException("Unexpected container type");
+ return propertyInfo.createPropertyHolder();
}
-
- // this gives us a "TI" to tack on to the constructor for the property holder, by
- // just casting the elementType to give it a TI
- @SuppressWarnings("unchecked")
- private static <K, T extends DMObject<K>, TI> ListPlainPropertyHolder<K,T,TI>
- newListPlainPropertyHolderHack(DMClassHolder<K,T> classHolder, CtMethod ctMethod, Class<?> elementType,
- DMProperty property, DMFilter filter, ViewerDependent viewerDependent) {
- return new ListPlainPropertyHolder<K,T,TI>(classHolder, ctMethod, (Class<TI>) elementType,
- property, filter, viewerDependent);
- }
-
- // this gives us a "TI" to tack on to the constructor for the property holder, by
- // just casting the elementType to give it a TI
- @SuppressWarnings("unchecked")
- private static <K, T extends DMObject<K>, TI> SetPlainPropertyHolder<K,T,TI>
- newSetPlainPropertyHolderHack(DMClassHolder<K,T> classHolder, CtMethod ctMethod, Class<?> elementType,
- DMProperty property, DMFilter filter, ViewerDependent viewerDependent) {
- return new SetPlainPropertyHolder<K,T,TI>(classHolder, ctMethod, (Class<TI>) elementType,
- property, filter, viewerDependent);
- }
-
- // this gives us a "TI" to tack on to the constructor for the property holder, by
- // just casting the elementType to give it a TI
- @SuppressWarnings("unchecked")
- private static <K, T extends DMObject<K>, TI> SinglePlainPropertyHolder<K,T,TI>
- newSinglePlainPropertyHolderHack(DMClassHolder<K,T> classHolder, CtMethod ctMethod, Class<?> elementType,
- DMProperty property, DMFilter filter, ViewerDependent viewerDependent) {
- return new SinglePlainPropertyHolder<K,T,TI>(classHolder, ctMethod, (Class<TI>) elementType,
- property, filter, viewerDependent);
- }
-
- private static <K, T extends DMObject<K>> DMPropertyHolder<K,T,?> createPlainPropertyHolder(DMClassHolder<K,T> classHolder, CtMethod ctMethod,
- Class<?> elementType, DMProperty property, DMFilter filter, ViewerDependent viewerDependent, ContainerType containerType) {
- switch (containerType) {
- case SINGLE:
- return newSinglePlainPropertyHolderHack(classHolder, ctMethod, elementType, property, filter, viewerDependent);
- case LIST:
- return newListPlainPropertyHolderHack(classHolder, ctMethod, elementType, property, filter, viewerDependent);
- case SET:
- return newSetPlainPropertyHolderHack(classHolder, ctMethod, elementType, property, filter, viewerDependent);
- case FEED:
- throw new RuntimeException("Feed properties must be resource-valued");
- }
-
- throw new RuntimeException("Unexpected container type");
- }
}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/FeedPropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/FeedPropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/FeedPropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -2,8 +2,6 @@
import java.util.Iterator;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.Cardinality;
import com.dumbhippo.dm.DMClient;
import com.dumbhippo.dm.DMFeed;
@@ -12,10 +10,7 @@
import com.dumbhippo.dm.DMSession;
import com.dumbhippo.dm.DMViewpoint;
import com.dumbhippo.dm.DataModel;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
import com.dumbhippo.dm.annotations.PropertyType;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.Fetch;
import com.dumbhippo.dm.fetch.FetchVisitor;
import com.dumbhippo.dm.filter.AndFilter;
@@ -28,8 +23,8 @@
public class FeedPropertyHolder<K, T extends DMObject<K>, KI, TI extends DMObject<KI>> extends ResourcePropertyHolder<K,T,KI,TI> {
private CompiledItemFilter<K,T,KI,TI> itemFilter;
- public FeedPropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, DMClassInfo<KI,TI> classInfo, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, classInfo, annotation, filter, viewerDependent);
+ public FeedPropertyHolder(ResourcePropertyInfo<K,T,KI,TI> propertyInfo) {
+ super(propertyInfo);
}
@Override
@@ -46,9 +41,9 @@
else
toCompile = propertyFilter;
- itemFilter = FilterCompiler.compileItemFilter(declaringClassHolder.getModel(),
- declaringClassHolder.getKeyClass(),
- keyType, toCompile);
+ itemFilter = FilterCompiler.compileItemFilter(getModel(),
+ propertyInfo.getKeyType(),
+ itemKeyType, toCompile);
}
}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ListPlainPropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ListPlainPropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ListPlainPropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -3,20 +3,15 @@
import java.util.Collections;
import java.util.List;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.Cardinality;
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.DMSession;
import com.dumbhippo.dm.DMViewpoint;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.FetchVisitor;
public class ListPlainPropertyHolder<K, T extends DMObject<K>, TI> extends PlainPropertyHolder<K,T,TI> {
- public ListPlainPropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, Class<TI> elementType, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, elementType, annotation, filter, viewerDependent);
+ public ListPlainPropertyHolder(PropertyInfo<K,T,TI> propertyInfo) {
+ super(propertyInfo);
}
@Override
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ListResourcePropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ListResourcePropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ListResourcePropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -5,15 +5,10 @@
import java.util.Collections;
import java.util.List;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.Cardinality;
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.DMSession;
import com.dumbhippo.dm.DMViewpoint;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.Fetch;
import com.dumbhippo.dm.fetch.FetchVisitor;
import com.dumbhippo.dm.filter.AndFilter;
@@ -24,8 +19,8 @@
public class ListResourcePropertyHolder<K, T extends DMObject<K>, KI, TI extends DMObject<KI>> extends ResourcePropertyHolder<K,T,KI,TI> {
private CompiledListFilter<K,T,KI,TI> listFilter;
- public ListResourcePropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, DMClassInfo<KI,TI> classInfo, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, classInfo, annotation, filter, viewerDependent);
+ public ListResourcePropertyHolder(ResourcePropertyInfo<K,T,KI,TI> propertyInfo) {
+ super(propertyInfo);
}
@Override
@@ -42,9 +37,9 @@
else
toCompile = propertyFilter;
- listFilter = FilterCompiler.compileListFilter(declaringClassHolder.getModel(),
- declaringClassHolder.getKeyClass(),
- keyType, toCompile);
+ listFilter = FilterCompiler.compileListFilter(getModel(),
+ propertyInfo.getKeyType(),
+ itemKeyType, toCompile);
}
}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PlainPropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PlainPropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PlainPropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -2,15 +2,10 @@
import java.util.Collection;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.DMSession;
import com.dumbhippo.dm.DMViewpoint;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
import com.dumbhippo.dm.annotations.PropertyType;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.Fetch;
import com.dumbhippo.dm.fetch.FetchVisitor;
import com.dumbhippo.dm.filter.CompiledItemFilter;
@@ -20,12 +15,12 @@
protected CompiledItemFilter<K,T,Object,DMObject<Object>> itemFilter;
private PropertyType propertyType;
- public PlainPropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, Class<TI> elementType, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, elementType, annotation, filter, viewerDependent);
+ public PlainPropertyHolder(PropertyInfo<K,T,TI> propertyInfo) {
+ super(propertyInfo);
if (propertyFilter != null)
- itemFilter = FilterCompiler.compileItemFilter(declaringClassHolder.getModel(),
- declaringClassHolder.getKeyClass(),
+ itemFilter = FilterCompiler.compileItemFilter(getModel(),
+ propertyInfo.getKeyType(),
Object.class, propertyFilter);
PropertyType derivedType;
@@ -71,6 +66,8 @@
break;
case RESOURCE:
throw new RuntimeException("PropertyType.RESOURCE for non-resource property");
+ case FEED:
+ throw new RuntimeException("PropertyType.RESOURCE for non-resource property");
}
propertyType = annotation.type();
Added: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PropertyInfo.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PropertyInfo.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/PropertyInfo.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -0,0 +1,111 @@
+package com.dumbhippo.dm.schema;
+
+import javassist.CtMethod;
+
+import com.dumbhippo.dm.DMObject;
+import com.dumbhippo.dm.DataModel;
+import com.dumbhippo.dm.annotations.DMFilter;
+import com.dumbhippo.dm.annotations.DMProperty;
+import com.dumbhippo.dm.annotations.ViewerDependent;
+
+class PropertyInfo<K, T extends DMObject<K>, TI> {
+ public enum ContainerType {
+ SINGLE,
+ LIST,
+ SET,
+ FEED
+ };
+
+ private DataModel model;
+ private Class<T> declaringType;
+ private Class<K> keyType;
+ private Class<TI> itemType;
+
+ private CtMethod ctMethod;
+ private DMProperty annotation;
+ private DMFilter filter;
+ private ViewerDependent viewerDependent;
+
+ private ContainerType containerType;
+
+ public PropertyInfo(Class<T> declaringType, Class<K> keyType, Class<TI> elementType) {
+ this.declaringType = declaringType;
+ this.keyType = keyType;
+ this.itemType = elementType;
+ }
+
+ public ContainerType getContainerType() {
+ return containerType;
+ }
+
+ public void setContainerType(ContainerType containerType) {
+ this.containerType = containerType;
+ }
+
+ public CtMethod getCtMethod() {
+ return ctMethod;
+ }
+
+ public void setCtMethod(CtMethod ctMethod) {
+ this.ctMethod = ctMethod;
+ }
+
+ public Class<T> getDeclaringType() {
+ return declaringType;
+ }
+
+ public Class<TI> getItemType() {
+ return itemType;
+ }
+
+ public DMFilter getFilter() {
+ return filter;
+ }
+
+ public void setFilter(DMFilter filter) {
+ this.filter = filter;
+ }
+
+ public Class<K> getKeyType() {
+ return keyType;
+ }
+
+ public DataModel getModel() {
+ return model;
+ }
+
+ public void setModel(DataModel model) {
+ this.model = model;
+ }
+
+ public DMProperty getAnnotation() {
+ return annotation;
+ }
+
+ public void setAnnotation(DMProperty property) {
+ this.annotation = property;
+ }
+
+ public ViewerDependent getViewerDependent() {
+ return viewerDependent;
+ }
+
+ public void setViewerDependent(ViewerDependent viewerDependent) {
+ this.viewerDependent = viewerDependent;
+ }
+
+ public DMPropertyHolder<K,T,TI> createPropertyHolder() {
+ switch (containerType) {
+ case SINGLE:
+ return new SinglePlainPropertyHolder<K,T,TI>(this);
+ case LIST:
+ return new ListPlainPropertyHolder<K,T,TI>(this);
+ case SET:
+ return new SetPlainPropertyHolder<K,T,TI>(this);
+ case FEED:
+ throw new RuntimeException("Feed properties must be resource-valued");
+ }
+
+ throw new RuntimeException("Unexpected container type");
+ }
+}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ResourcePropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ResourcePropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ResourcePropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -2,15 +2,10 @@
import java.util.Collection;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.DMKey;
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.DMSession;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
import com.dumbhippo.dm.annotations.PropertyType;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.Fetch;
import com.dumbhippo.dm.fetch.FetchNode;
import com.dumbhippo.dm.fetch.FetchVisitor;
@@ -20,14 +15,14 @@
public abstract class ResourcePropertyHolder<K,T extends DMObject<K>, KI,TI extends DMObject<KI>> extends DMPropertyHolder<K,T,TI> {
private DMClassHolder<KI,TI> resourceClassHolder;
- protected Class<TI> objectType;
- protected Class<KI> keyType;
+ protected Class<TI> itemObjectType;
+ protected Class<KI> itemKeyType;
private Fetch<KI,TI> defaultChildren;
- public ResourcePropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, DMClassInfo<KI,TI> classInfo, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, classInfo.getObjectClass(), annotation, filter, viewerDependent);
- objectType = classInfo.getObjectClass();
- keyType = classInfo.getKeyClass();
+ public ResourcePropertyHolder(ResourcePropertyInfo<K,T,KI,TI> propertyInfo) {
+ super(propertyInfo);
+ itemObjectType = propertyInfo.getItemType();
+ itemKeyType = propertyInfo.getItemKeyType();
if (annotation.type() != PropertyType.AUTO && annotation.type() != PropertyType.RESOURCE) {
throw new RuntimeException("type=PropertyType." + annotation.type() + " found for a property with a resource return type");
@@ -41,7 +36,7 @@
super.complete();
- resourceClassHolder = declaringClassHolder.getModel().getClassHolder(keyType, getResourceType());
+ resourceClassHolder = getModel().getClassHolder(itemKeyType, getResourceType());
if (!"".equals(annotation.defaultChildren())) {
defaultInclude = true;
@@ -85,7 +80,7 @@
return resourceClassHolder;
else {
@SuppressWarnings("unchecked")
- DMClassHolder<KI,TI> classHolder = declaringClassHolder.getModel().getClassHolder(keyType, getResourceType());
+ DMClassHolder<KI,TI> classHolder = getModel().getClassHolder(itemKeyType, getResourceType());
return classHolder;
}
}
@@ -103,7 +98,7 @@
public TI rehydrateDMO(Object value, DMSession session) {
@SuppressWarnings("unchecked")
KI key = (KI)value;
- return session.findUnchecked(objectType, key);
+ return session.findUnchecked(itemObjectType, key);
}
protected void visitChild(DMSession session, Fetch<KI,TI> children, TI value, FetchVisitor visitor) {
Added: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ResourcePropertyInfo.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ResourcePropertyInfo.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/ResourcePropertyInfo.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -0,0 +1,32 @@
+package com.dumbhippo.dm.schema;
+
+import com.dumbhippo.dm.DMObject;
+
+class ResourcePropertyInfo<K, T extends DMObject<K>, KI, TI extends DMObject<KI>> extends PropertyInfo<K,T,TI> {
+ private Class<KI> itemKeytype;
+
+ public ResourcePropertyInfo(Class<T> declaringType, Class<K> keyType, Class<TI> elementType, Class<KI> itemKeyType) {
+ super(declaringType, keyType, elementType);
+ this.itemKeytype = itemKeyType;
+ }
+
+ @Override
+ public DMPropertyHolder<K,T,TI> createPropertyHolder() {
+ switch (getContainerType()) {
+ case SINGLE:
+ return new SingleResourcePropertyHolder<K,T,KI,TI>(this);
+ case LIST:
+ return new ListResourcePropertyHolder<K,T,KI,TI>(this);
+ case SET:
+ return new SetResourcePropertyHolder<K,T,KI,TI>(this);
+ case FEED:
+ return new FeedPropertyHolder<K,T,KI,TI>(this);
+ }
+
+ throw new RuntimeException("Unexpected container type");
+ }
+
+ public Class<KI> getItemKeyType() {
+ return itemKeytype;
+ }
+}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SetPlainPropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SetPlainPropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SetPlainPropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -3,20 +3,15 @@
import java.util.Collections;
import java.util.Set;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.Cardinality;
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.DMSession;
import com.dumbhippo.dm.DMViewpoint;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.FetchVisitor;
public class SetPlainPropertyHolder<K, T extends DMObject<K>, TI> extends PlainPropertyHolder<K,T,TI> {
- public SetPlainPropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, Class<TI> elementType, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, elementType, annotation, filter, viewerDependent);
+ public SetPlainPropertyHolder(PropertyInfo<K,T,TI> propertyInfo) {
+ super(propertyInfo);
}
@Override
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SetResourcePropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SetResourcePropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SetResourcePropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -5,15 +5,10 @@
import java.util.HashSet;
import java.util.Set;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.Cardinality;
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.DMSession;
import com.dumbhippo.dm.DMViewpoint;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.Fetch;
import com.dumbhippo.dm.fetch.FetchVisitor;
import com.dumbhippo.dm.filter.AndFilter;
@@ -24,8 +19,8 @@
public class SetResourcePropertyHolder<K, T extends DMObject<K>, KI, TI extends DMObject<KI>> extends ResourcePropertyHolder<K,T,KI,TI> {
private CompiledSetFilter<K,T,KI,TI> setFilter;
- public SetResourcePropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, DMClassInfo<KI,TI> classInfo, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, classInfo, annotation, filter, viewerDependent);
+ public SetResourcePropertyHolder(ResourcePropertyInfo<K,T,KI,TI> propertyInfo) {
+ super(propertyInfo);
}
@Override
@@ -42,9 +37,9 @@
else
toCompile = propertyFilter;
- setFilter = FilterCompiler.compileSetFilter(declaringClassHolder.getModel(),
- declaringClassHolder.getKeyClass(),
- keyType, toCompile);
+ setFilter = FilterCompiler.compileSetFilter(getModel(),
+ propertyInfo.getKeyType(),
+ itemKeyType, toCompile);
}
}
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SinglePlainPropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SinglePlainPropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SinglePlainPropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -1,19 +1,14 @@
package com.dumbhippo.dm.schema;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.Cardinality;
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.DMSession;
import com.dumbhippo.dm.DMViewpoint;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.FetchVisitor;
public class SinglePlainPropertyHolder<K,T extends DMObject<K>, TI> extends PlainPropertyHolder<K,T,TI> {
- public SinglePlainPropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, Class<TI> elementType, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, elementType, annotation, filter, viewerDependent);
+ public SinglePlainPropertyHolder(PropertyInfo<K,T,TI> propertyInfo) {
+ super(propertyInfo);
}
@Override
Modified: dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SingleResourcePropertyHolder.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SingleResourcePropertyHolder.java 2007-12-05 20:44:25 UTC (rev 6971)
+++ dumbhippo/trunk/server/src/com/dumbhippo/dm/schema/SingleResourcePropertyHolder.java 2007-12-05 20:46:40 UTC (rev 6972)
@@ -1,14 +1,9 @@
package com.dumbhippo.dm.schema;
-import javassist.CtMethod;
-
import com.dumbhippo.dm.Cardinality;
import com.dumbhippo.dm.DMObject;
import com.dumbhippo.dm.DMSession;
import com.dumbhippo.dm.DMViewpoint;
-import com.dumbhippo.dm.annotations.DMFilter;
-import com.dumbhippo.dm.annotations.DMProperty;
-import com.dumbhippo.dm.annotations.ViewerDependent;
import com.dumbhippo.dm.fetch.Fetch;
import com.dumbhippo.dm.fetch.FetchVisitor;
import com.dumbhippo.dm.filter.AndFilter;
@@ -19,8 +14,8 @@
public class SingleResourcePropertyHolder<K, T extends DMObject<K>, KI, TI extends DMObject<KI>> extends ResourcePropertyHolder<K,T,KI,TI> {
private CompiledItemFilter<K,T,KI,TI> itemFilter;
- public SingleResourcePropertyHolder(DMClassHolder<K,T> declaringClassHolder, CtMethod ctMethod, DMClassInfo<KI,TI> classInfo, DMProperty annotation, DMFilter filter, ViewerDependent viewerDependent) {
- super(declaringClassHolder, ctMethod, classInfo, annotation, filter, viewerDependent);
+ public SingleResourcePropertyHolder(ResourcePropertyInfo<K,T,KI,TI> propertyInfo) {
+ super(propertyInfo);
}
@Override
@@ -40,9 +35,9 @@
else
toCompile = propertyFilter;
- itemFilter = FilterCompiler.compileItemFilter(declaringClassHolder.getModel(),
- declaringClassHolder.getKeyClass(),
- keyType, toCompile);
+ itemFilter = FilterCompiler.compileItemFilter(getModel(),
+ propertyInfo.getKeyType(),
+ itemKeyType, toCompile);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]