[antlr-interest] StringTemplate/MVC design issue

Nathan Ward nward at resqsoft.com
Sun Dec 30 10:01:41 PST 2007


The separation-of-concern that are enforced by StingTemplate makes a lot of
sense, but I have a case where what should be the responsibility of the
model vs the view is not clear to me. My gut feeling is that an additional
construct should be provided by StringTemplate (i.e. the view).

I've inherited code that uses ANTLR 2.0 and StringTemplate 3.0 that uses the
visitor pattern instead of a tree walker to convert PL/SQL to Java. There
are several cases where I need to convert a name that I find in the PL/SQL
code to multiple statements in Java where the first letter is sometimes
uppercase and sometimes lowercase in order to follow Java naming
conventions. For example, a PL/SQL package named DK_PSQL3400 will be
converted to a Java class named DkPsql3400Services. However, other java
classes for other packages that have calls to stored procedures in this
package will have an instance of this class named "dkPsql3400Services". 

In terms of StringTemplate and MVC pattern, should the model, view, or
controller be responsible for ensuring that DK_PSQL3400 is converted to
DkPsql3400Services in some cases and dkPsql3400Services in other cases? We
do build up a number of objects that act as the model. When we find a
definition of a PL/SQL package, we create a PackageDefinition object and
this object can be responsible for converting the package name of
DK_PSQL3400 to DkPsql3400 and perhaps also appending "Services" to it.
However, I don't see why the model should have to provide a means to convert
the first letter to uppercase and sometimes to lowercase in certain cases. 

This is actual a simple example compared to other cases that we are dealing
with. We also create an interface in Java related to each PL/SQL package.
When we find variables defined in a PL/SQL package specification, we create
a getter and a setter method in the interface and also a member variable in
the implementation class that we generate. So, the variable name needs to be
uppercase first letter when we build the getter method, e.g. we have a
template of: "public <type> get<name>()", but we need first letter lowercase
when we define the instance variable. 

It seems to me, that in these types of cases, there should be a template
construct that allows me to perform string manipulation operations on a
single value. If a template is passes a "name" parameter, would it be
reasonable to provide a template construct to convert the first letter to
uppercase or lowercase? 

What we've done so far, is to provide additional methods on our model
objects. For example, PackageDefinition class has a toClassName() and a
toVariableName() method that simply handles the first letter upper/lower.
The visitor calls these methods to set attributes on templates. But, I think
this is the wrong way to do it. With this approach, the model knows too much
about the view. If we convert to something other than Java in the future,
the uppercase/lowercase first letter, not to mention the other naming
conventions may not be necessary and/or may be different. Will I have to
subclass my model objects, such as PackageDefinition, just to manage these
syntax conversion issues? Is there any examples, articles, etc. that
describe how best to deal with these kinds of design issues? 

   Nathan

Nathan Ward
ResQSoft, Inc.
703.861.9103
www.resqsoft.com



More information about the antlr-interest mailing list