I do a similar thing; have a lightweight SQL resource utility
QueryMap, which takes resource(s) full of queries and puts them in a
map identified by the comment right in front of it:

-- ALL_CUSTOMERS
select
  ...
from
  ...
where
  ...
;

QueryMap q = new QueryMap("customer.sql);
q.get("ALL_CUSTOMERS");

A simple NetBeans plugin is then able to find my customer.sql, and in
the get accessor, provide me a list of available queries, required
bind variables along with showing the SQL in the popup. Admittedly the
main motivation behind this is to allow users to manipulate queries in
their favorite SQL tool, whereas on Android the main motivation seems
to be a desire to encapsulate (and package) dynamic resources
statically.

I'm torn on the Android R generator running behind, on one hand I
understand its purpose (this is how it works in .NET), on the other
hand I am not certain the folloing code:

Drawable image = getResources().getDrawable(R.drawable.myimage);
String mystring = this.getString(R.string.mystring);
ImageView imageView = (ImageView) findViewById(R.id.myimageview);

...is more consistent, more type-safe or as mockable as:

Drawable image = getResources().get(Drawable.class, "myimage")
String mystring = getResources().get(String.class, "mystring");
ImageView imageView = findViewById(imageView.class,"myimageview");

Let the IDE do code completion and the compiler do validation and
optimization.

/Casper

On Jun 22, 9:08 pm, Ricky Clarkson <[email protected]> wrote:
> For what it's worth, I try to load all language keys at least when the class
> is loaded, i.e., assigning them all to static finals, and then have a
> LoadAllClassesTest that goes over the classpath and attempts to load all
> classes.
>
> Not quite the same, but probably catches most of the same bugs.  It could be
> adapted to other kinds of resource, but perhaps you wouldn't want to load
> all images eagerly.
>
>
>
>
>
>
>
> On Wed, Jun 22, 2011 at 3:01 PM, Sam Reid <[email protected]> wrote:
> > Hi Java Posse People,
>
> > I've found the automatic generation of R.java in android development
> > to be a significant improvement over the way we usually load resources
> > in our J2SE applications, attaining benefits like compile time
> > checking for missing resources.  Does anyone know of a tool or
> > technique for doing something like this in J2SE?
>
> > Thanks!
> > Sam
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "The Java Posse" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> > [email protected].
> > For more options, visit this group at
> >http://groups.google.com/group/javaposse?hl=en.

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to