abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r598477 - in /incubator/abdera/java/trunk: dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/ObjectContext.java examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java
Date Tue, 27 Nov 2007 00:41:20 GMT
Author: jmsnell
Date: Mon Nov 26 16:41:20 2007
New Revision: 598477

URL: http://svn.apache.org/viewvc?rev=598477&view=rev
Log:
Provide an annotation that allows an alternative varname to be specified for a getter

Modified:
    incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/ObjectContext.java
    incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java

Modified: incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/ObjectContext.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/ObjectContext.java?rev=598477&r1=598476&r2=598477&view=diff
==============================================================================
--- incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/ObjectContext.java
(original)
+++ incubator/abdera/java/trunk/dependencies/i18n/src/main/java/org/apache/abdera/i18n/templates/ObjectContext.java
Mon Nov 26 16:41:20 2007
@@ -56,7 +56,7 @@
       Field[] fields = _class.getFields();
       for (Field field : fields) {
         if (!Modifier.isPrivate(field.getModifiers())) {
-          accessors.put(field.getName().toLowerCase(), field);
+          accessors.put(getName(field), field);
         }
       }
     }
@@ -67,12 +67,23 @@
           method.getParameterTypes().length == 0 && 
           !method.getReturnType().equals(Void.class) && 
           !isReserved(name)) {
-        name = name.toLowerCase();
-        if (name.startsWith("get")) name = name.substring(3);
-        else if (name.startsWith("is")) name = name.substring(2);
-        accessors.put(name, method);
+        accessors.put(getName(method), method);
       }
     }
+  }
+  
+  private String getName(AccessibleObject object) {
+    String name = null;
+    VarName varName = object.getAnnotation(VarName.class);
+    if (varName != null) return varName.value();
+    if (object instanceof Field) { 
+      name = ((Field)object).getName().toLowerCase();
+    } else if (object instanceof Method) {
+      name = ((Method)object).getName().toLowerCase();
+      if (name.startsWith("get")) name = name.substring(3);
+      else if (name.startsWith("is")) name = name.substring(2);
+    }
+    return name;
   }
   
   private boolean isReserved(String name) {

Modified: incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java?rev=598477&r1=598476&r2=598477&view=diff
==============================================================================
--- incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java
(original)
+++ incubator/abdera/java/trunk/examples/src/main/java/org/apache/abdera/examples/uritemplates/AtomLinkTemplate.java
Mon Nov 26 16:41:20 2007
@@ -20,6 +20,7 @@
 import org.apache.abdera.Abdera;
 import org.apache.abdera.i18n.templates.Template;
 import org.apache.abdera.i18n.templates.URITemplate;
+import org.apache.abdera.i18n.templates.VarName;
 
 public class AtomLinkTemplate {
 
@@ -63,7 +64,8 @@
     public int getPage() {
       return page;
     }
-    public int getCount() {
+    @VarName("count")
+    public int getPageSize() {
       return count;
     }
   }



Mime
View raw message