summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/info
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2007-07-23 23:12:37 +0000
committerBrian S. O'Neill <bronee@gmail.com>2007-07-23 23:12:37 +0000
commit7fb12b2208d9f16f0fca2a7facd849f2ec40de2f (patch)
tree6b1cd1512c4da93c33fe1bbd404501c1db5257fe /src/main/java/com/amazon/carbonado/info
parentdf422c9673316b6a7ecdb96e314aeabd660985ad (diff)
Allow Storable definition to accept Repository in constructor.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/info')
-rw-r--r--src/main/java/com/amazon/carbonado/info/StorableIntrospector.java25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java
index ce704e3..133e175 100644
--- a/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java
+++ b/src/main/java/com/amazon/carbonado/info/StorableIntrospector.java
@@ -62,6 +62,7 @@ import com.amazon.carbonado.Nullable;
import com.amazon.carbonado.Independent;
import com.amazon.carbonado.PrimaryKey;
import com.amazon.carbonado.Query;
+import com.amazon.carbonado.Repository;
import com.amazon.carbonado.Sequence;
import com.amazon.carbonado.Storable;
import com.amazon.carbonado.Version;
@@ -490,27 +491,35 @@ public class StorableIntrospector {
checkTypeParameter(errorMessages, type);
- // If type is a class, it must have a public or protected no-arg
- // constructor.
+ // If type is a class, it must have a public/protected constructor that
+ // takes no arguments or a Repository. If overloaded, the constructor
+ // with the Repository parameter is preferred by the code generator.
if (!type.isInterface()) {
Constructor[] ctors = type.getDeclaredConstructors();
findCtor: {
for (Constructor c : ctors) {
+ modifiers = c.getModifiers();
+ if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) {
+ continue;
+ }
if (c.getParameterTypes().length == 0) {
- modifiers = c.getModifiers();
- if (!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) {
- errorMessages.add("Cannot call constructor: " + c);
- }
break findCtor;
}
+ if (c.getParameterTypes().length == 1) {
+ if (c.getParameterTypes()[0] == Repository.class) {
+ break findCtor;
+ }
+ }
}
if (type.getEnclosingClass() == null) {
errorMessages.add
- ("Class must have an accesible no-arg constructor");
+ ("Class must have a public or protected constructor " +
+ "that takes no arguments or a Repository");
} else {
errorMessages.add
- ("Inner class must be static and have an accesible no-arg constructor");
+ ("Inner class must have a public or protected constructor " +
+ "that takes no arguments or a Repository");
}
}
}