It's by design that the second and subsequent calls to tryCreate
return null.  The null return value indicates that the generator has
already created an implementation for the given type.  You should just
bail out early in that case.  I usually write my generators like this:

public String generate(TreeLogger logger, GeneratorContext context,
String typeName) throws UnableToCompleteException {

  // setup code

  String packageName = ...;
  String className = ...;

  PrintWriter pw = context.tryCreate(logger, packageName, className);

  if (pw != null) {
    writeClass(pw, ...);
  }

  return packageName + "." + className;
}

The writeClass method contains all the logic for actually generating
an implementation, but I only invoke it if it hasn't been invoked
before.  The reason for this is that generate() is invoked once per
permutation.  If you wanted to generate a different AboutData
implementation for different user agents, different locales, or some
other axis of deferred binding, you'd have to pick a different name
for each implementation and you'd generate more than one file.  As it
is, you only need one implementation for all the axes, so you can just
bail early on every call to generate() after the first.

Ian

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to