You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2007/12/16 22:09:53 UTC
svn commit: r604702 - in
/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect:
./ pojo/
Author: aadamchik
Date: Sun Dec 16 13:09:52 2007
New Revision: 604702
URL: http://svn.apache.org/viewvc?rev=604702&view=rev
Log:
generics
Modified:
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptorMap.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/Converter.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PropertyUtils.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java
cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java?rev=604702&r1=604701&r2=604702&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptor.java Sun Dec 16 13:09:52 2007
@@ -41,7 +41,7 @@
/**
* Returns a class mapped by this descriptor.
*/
- Class getObjectClass();
+ Class<?> getObjectClass();
/**
* Returns a descriptor of the mapped superclass or null if the descriptor's entity
@@ -57,7 +57,7 @@
* this.getObjectClass().isAssignableFrom(objectClass)
* </pre>
*/
- ClassDescriptor getSubclassDescriptor(Class objectClass);
+ ClassDescriptor getSubclassDescriptor(Class<?> objectClass);
/**
* Creates a new instance of a class described by this object.
@@ -98,14 +98,14 @@
* @deprecated since 3.0. Use {@link #visitProperties(PropertyVisitor)} method
* instead.
*/
- Iterator getProperties();
+ Iterator<Property> getProperties();
/**
* Returns an iterator over the properties mapped to id columns.
*
* @since 3.0
*/
- Iterator getIdProperties();
+ Iterator<Property> getIdProperties();
/**
* Returns an iterator over the arc properties whose reverse arcs are to-many maps.
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptorMap.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptorMap.java?rev=604702&r1=604701&r2=604702&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptorMap.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/ClassDescriptorMap.java Sun Dec 16 13:09:52 2007
@@ -39,13 +39,13 @@
public class ClassDescriptorMap {
protected EntityResolver resolver;
- protected Map descriptors;
- protected List factories;
+ protected Map<String, ClassDescriptor> descriptors;
+ protected List<ClassDescriptorFactory> factories;
public ClassDescriptorMap(EntityResolver resolver) {
- this.descriptors = new HashMap();
+ this.descriptors = new HashMap<String, ClassDescriptor>();
this.resolver = resolver;
- this.factories = new ArrayList();
+ this.factories = new ArrayList<ClassDescriptorFactory>();
}
public EntityResolver getResolver() {
@@ -95,7 +95,7 @@
throw new NullPointerException("Null 'entityName'");
}
- ClassDescriptor cached = (ClassDescriptor) descriptors.get(entityName);
+ ClassDescriptor cached = descriptors.get(entityName);
if (cached != null) {
return cached;
}
@@ -122,9 +122,10 @@
// scan the factory chain until some factory returns a non-null descriptor;
// scanning is done in reverse order so that the factories added last take higher
// precedence...
- ListIterator it = factories.listIterator(factories.size());
+ ListIterator<ClassDescriptorFactory> it = factories
+ .listIterator(factories.size());
while (it.hasPrevious()) {
- ClassDescriptorFactory factory = (ClassDescriptorFactory) it.previous();
+ ClassDescriptorFactory factory = it.previous();
ClassDescriptor descriptor = factory.getDescriptor(entityName);
if (descriptor != null) {
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/Converter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/Converter.java?rev=604702&r1=604701&r2=604702&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/Converter.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/Converter.java Sun Dec 16 13:09:52 2007
@@ -31,5 +31,5 @@
/**
* Converts object to supported class without doing any type checking.
*/
- abstract Object convert(Object value, Class type);
+ abstract Object convert(Object value, Class<?> type);
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java?rev=604702&r1=604701&r2=604702&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PersistentDescriptorFactory.java Sun Dec 16 13:09:52 2007
@@ -18,14 +18,14 @@
****************************************************************/
package org.apache.cayenne.reflect;
-import java.util.Iterator;
-
import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.map.Attribute;
import org.apache.cayenne.map.EmbeddedAttribute;
import org.apache.cayenne.map.EntityInheritanceTree;
import org.apache.cayenne.map.ObjAttribute;
import org.apache.cayenne.map.ObjEntity;
import org.apache.cayenne.map.ObjRelationship;
+import org.apache.cayenne.map.Relationship;
/**
* A convenience superclass for {@link ClassDescriptorFactory} implementors.
@@ -47,11 +47,11 @@
throw new CayenneRuntimeException("Unmapped entity: " + entityName);
}
- Class entityClass = entity.getJavaClass();
+ Class<?> entityClass = entity.getJavaClass();
return getDescriptor(entity, entityClass);
}
- protected ClassDescriptor getDescriptor(ObjEntity entity, Class entityClass) {
+ protected ClassDescriptor getDescriptor(ObjEntity entity, Class<?> entityClass) {
String superEntityName = entity.getSuperEntityName();
ClassDescriptor superDescriptor = (superEntityName != null) ? descriptorMap
@@ -68,45 +68,41 @@
Integer.TYPE));
// only include this entity attributes and skip superclasses...
- Iterator attributes = descriptor.getEntity().getDeclaredAttributes().iterator();
- while (attributes.hasNext()) {
- Object attribute = attributes.next();
+ for (Attribute attribute : descriptor.getEntity().getDeclaredAttributes()) {
if (attribute instanceof ObjAttribute) {
createAttributeProperty(descriptor, (ObjAttribute) attribute);
}
else if (attribute instanceof EmbeddedAttribute) {
EmbeddedAttribute embedded = (EmbeddedAttribute) attribute;
- Iterator embeddedAttributes = embedded.getAttributes().iterator();
- while (embeddedAttributes.hasNext()) {
- createEmbeddedAttributeProperty(
- descriptor,
- embedded,
- (ObjAttribute) embeddedAttributes.next());
+ for (ObjAttribute objAttribute : embedded.getAttributes()) {
+ createEmbeddedAttributeProperty(descriptor, embedded, objAttribute);
}
}
}
// only include this entity relationships and skip superclasses...
- Iterator it = descriptor.getEntity().getDeclaredRelationships().iterator();
- while (it.hasNext()) {
+ for (Relationship relationship : descriptor
+ .getEntity()
+ .getDeclaredRelationships()) {
+
+ ObjRelationship objRelationship = (ObjRelationship) relationship;
- ObjRelationship relationship = (ObjRelationship) it.next();
if (relationship.isToMany()) {
- String collectionType = relationship.getCollectionType();
+ String collectionType = objRelationship.getCollectionType();
if (collectionType == null
|| ObjRelationship.DEFAULT_COLLECTION_TYPE.equals(collectionType)) {
- createToManyListProperty(descriptor, relationship);
+ createToManyListProperty(descriptor, objRelationship);
}
else if (collectionType.equals("java.util.Map")) {
- createToManyMapProperty(descriptor, relationship);
+ createToManyMapProperty(descriptor, objRelationship);
}
else if (collectionType.equals("java.util.Set")) {
- createToManySetProperty(descriptor, relationship);
+ createToManySetProperty(descriptor, objRelationship);
}
else if (collectionType.equals("java.util.Collection")) {
- createToManyCollectionProperty(descriptor, relationship);
+ createToManyCollectionProperty(descriptor, objRelationship);
}
else {
throw new IllegalArgumentException(
@@ -114,7 +110,7 @@
}
}
else {
- createToOneProperty(descriptor, relationship);
+ createToOneProperty(descriptor, objRelationship);
}
}
@@ -133,7 +129,7 @@
protected void createAttributeProperty(
PersistentDescriptor descriptor,
ObjAttribute attribute) {
- Class propertyType = attribute.getJavaClass();
+ Class<?> propertyType = attribute.getJavaClass();
Accessor accessor = createAccessor(descriptor, attribute.getName(), propertyType);
descriptor.addDeclaredProperty(new SimpleAttributeProperty(
descriptor,
@@ -146,7 +142,7 @@
EmbeddedAttribute embeddedAttribute,
ObjAttribute attribute) {
- Class embeddableClass = embeddedAttribute.getJavaClass();
+ Class<?> embeddableClass = embeddedAttribute.getJavaClass();
String propertyPath = attribute.getName();
int lastDot = propertyPath.lastIndexOf('.');
@@ -204,9 +200,7 @@
if (inheritanceTree != null) {
- Iterator it = inheritanceTree.getChildren().iterator();
- while (it.hasNext()) {
- EntityInheritanceTree child = (EntityInheritanceTree) it.next();
+ for (EntityInheritanceTree child : inheritanceTree.getChildren()) {
descriptor.addSubclassDescriptor(descriptorMap.getDescriptor(child
.getEntity()
.getName()));
@@ -222,7 +216,7 @@
protected Accessor createAccessor(
PersistentDescriptor descriptor,
String propertyName,
- Class propertyType) throws PropertyException {
+ Class<?> propertyType) throws PropertyException {
return new FieldAccessor(descriptor.getObjectClass(), propertyName, propertyType);
}
@@ -245,9 +239,9 @@
* Creates an accessor for the property of the embeddable class.
*/
protected Accessor createEmbeddableAccessor(
- Class embeddableClass,
+ Class<?> embeddableClass,
String propertyName,
- Class propertyType) {
+ Class<?> propertyType) {
return new FieldAccessor(embeddableClass, propertyName, propertyType);
}
}
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PropertyUtils.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PropertyUtils.java?rev=604702&r1=604701&r2=604702&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PropertyUtils.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/PropertyUtils.java Sun Dec 16 13:09:52 2007
@@ -73,7 +73,10 @@
if (value == null) {
// null value in the middle....
throw new UnresolvablePathException(
- "Null value in the middle of the path, failed on " + nestedPropertyName + " from " + object);
+ "Null value in the middle of the path, failed on "
+ + nestedPropertyName
+ + " from "
+ + object);
}
value = getSimpleProperty(value, pathSegment);
@@ -155,12 +158,12 @@
+ "'");
}
- return reader.invoke(object, null);
+ return reader.invoke(object, (Object[]) null);
}
// note that Map has two traditional bean properties - 'empty' and 'class', so
// do a check here only after descriptor lookup failed.
else if (object instanceof Map) {
- return ((Map) object).get(pathSegment);
+ return ((Map<?, ?>) object).get(pathSegment);
}
else {
throw new IntrospectionException("No property '"
@@ -201,7 +204,7 @@
// note that Map has two traditional bean properties - 'empty' and 'class', so
// do a check here only after descriptor lookup failed.
else if (object instanceof Map) {
- ((Map) object).put(pathSegment, value);
+ ((Map<Object, Object>) object).put(pathSegment, value);
}
else {
throw new IntrospectionException("No property '"
@@ -211,8 +214,9 @@
}
}
- static PropertyDescriptor getPropertyDescriptor(Class beanClass, String propertyName)
- throws IntrospectionException {
+ static PropertyDescriptor getPropertyDescriptor(
+ Class<?> beanClass,
+ String propertyName) throws IntrospectionException {
// bean info is cached by introspector, so this should have reasonable
// performance...
BeanInfo info = Introspector.getBeanInfo(beanClass);
@@ -230,7 +234,7 @@
/**
* "Normalizes" passed type, converting primitive types to their object counterparts.
*/
- static Class normalizeType(Class type) {
+ static Class<?> normalizeType(Class<?> type) {
if (type.isPrimitive()) {
String className = type.getName();
@@ -264,7 +268,7 @@
* Returns default value that should be used for nulls. For non-primitive types, null
* is returned. For primitive types a default such as zero or false is returned.
*/
- static Object defaultNullValueForType(Class type) {
+ static Object defaultNullValueForType(Class<?> type) {
if (type.isPrimitive()) {
String className = type.getName();
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java?rev=604702&r1=604701&r2=604702&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java Sun Dec 16 13:09:52 2007
@@ -52,8 +52,8 @@
this.faultFactory = faultFactory;
}
- protected ClassDescriptor getDescriptor(ObjEntity entity, Class entityClass) {
- // check whether we are dealing with enhaced pojo
+ protected ClassDescriptor getDescriptor(ObjEntity entity, Class<?> entityClass) {
+ // check whether we are dealing with enhanced pojo
try {
Integer.TYPE.equals(entityClass
.getDeclaredField(PERSISTENCE_STATE_FIELD)
Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java?rev=604702&r1=604701&r2=604702&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java (original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java Sun Dec 16 13:09:52 2007
@@ -33,7 +33,7 @@
private Accessor faultResolvedFlagAccessor;
- EnhancedPojoPropertyFaultHandler(Class objectClass, String propertyName) {
+ EnhancedPojoPropertyFaultHandler(Class<?> objectClass, String propertyName) {
this.faultResolvedFlagAccessor = new FieldAccessor(
objectClass,
FAULT_FIELD_PREFIX + propertyName,