You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by MN...@tacintel.com on 2004/03/09 22:20:59 UTC

[VERDICT] instanceof

We can argue all day long about the appropriateness of 'instanceof'
functionality in the template, but I need to actually do something.

So, will 'instanceof' be added to VTL or is the marching order "Teach
non-Java developers Java, so they can 'Create a Tool'"?

Michael

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: [VERDICT] instanceof

Posted by Nathan Green <ng...@inco5.com>.
Here is 'instanceof' directly in VTL, no tools or changes:

#set( $s = "A String" )
$s.getClass().forName("java.util.ArrayList").isAssignableFrom($s.getClass())

--OR--

#set( $s = "A String" )
#set( $sc = $s.getClass() )
#if ( $sc.forName("java.lang.String").isAssignableFrom($sc) )
  java.lang.String
#end

Of course, I can't recommend this technique at all, but it does
work.  :)


MNewcomb@tacintel.com wrote:

> We can argue all day long about the appropriateness of 'instanceof'
> functionality in the template, but I need to actually do something.
> 
> So, will 'instanceof' be added to VTL or is the marching order "Teach
> non-Java developers Java, so they can 'Create a Tool'"?
> 
> Michael
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: [VERDICT] instanceof

Posted by Barbara Baughman <ba...@utdallas.edu>.
The MVC model that Velocity supports does assume some Java support
from the "C"(controller) part of the model to pass the information and
tools that the designer will need. You have been given the program
with the tool and the code to pass the tool to the template.  It's not
that hard, and makes Velocity very customizable and flexible.

If the designer will not have that support, then Velocity may not be
the tool for you.

Velocity's philosophy is to have a set of directives and functions
that are intuitive to someone with VERY minimal programming skills.
The proper use of the instanceof function requires more than minimal
programming skills, so I don't think it's appropriate for core
Velocity.

My two cents.

Barbara Baughman
X2157

On Tue, 9 Mar 2004 MNewcomb@tacintel.com wrote:

> We can argue all day long about the appropriateness of 'instanceof'
> functionality in the template, but I need to actually do something.
>
> So, will 'instanceof' be added to VTL or is the marching order "Teach
> non-Java developers Java, so they can 'Create a Tool'"?
>
> Michael
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: velocity-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: [VERDICT] instanceof

Posted by Nathan Bubna <na...@esha.com>.
MNewcomb@tacintel.com said:
> We can argue all day long about the appropriateness of 'instanceof'
> functionality in the template,

we sure can!! :)

> but I need to actually do something.

Use-A-Tool (tm) :)

> So, will 'instanceof' be added to VTL or is the marching order "Teach
> non-Java developers Java, so they can 'Create a Tool'"?

i've always loved "this or that" questions where the right answer is just
"yes" or "no."  The answer to this particular one is "no."  :)

Nathan Bubna
nathan@esha.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: [VERDICT] instanceof

Posted by Geir Magnusson Jr <ge...@4quarters.com>.
On Mar 9, 2004, at 4:20 PM, MNewcomb@tacintel.com wrote:

> We can argue all day long about the appropriateness of 'instanceof'
> functionality in the template, but I need to actually do something.
>
> So, will 'instanceof' be added to VTL or is the marching order "Teach
> non-Java developers Java, so they can 'Create a Tool'"?

This is a baffling conclusion. The fact that we are talking about 
'instanceOf' means we are talking about teaching non-jAva developers 
Java anyway, because you need to know about classes, inheritance and 
interfaces to understand what it means to do 'instanceof'.

I guess then I don't understand why you won't just add a tool to the 
context.  Since you have to do this - and I believe that this is the 
way that you feel best it should be done - a tool into the context 
would solve the whole problem....

geir
-- 
Geir Magnusson Jr                                   203-247-1713(m)
geir@4quarters.com


---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Re: [VERDICT] instanceof

Posted by Mike Kienenberger <mk...@alaska.net>.
MNewcomb@tacintel.com wrote:
> We can argue all day long about the appropriateness of 'instanceof'
> functionality in the template, but I need to actually do something.
> 
> So, will 'instanceof' be added to VTL or is the marching order "Teach
> non-Java developers Java, so they can 'Create a Tool'"?

I think your two choices are one of the following.

1) create an instanceof tool.

2) return a String for each object that identifies the type of object you're 
working with.

For example, I generate java code from database models using VTL like this:

#foreach( $attribute in $classGen.Entity.Attributes )
#if 	($attribute.Type == "java.lang.String")
			"${attribute.name}", "${classGen.capitalizeString($attribute.name)}", 
ReportComponent.DATA_TYPE_STRING, null, Boolean.TRUE,
#else
#if 		( ($attribute.Type == "java.lang.Number") || ($attribute.Type == 
"java.lang.Integer") || ($attribute.Type == "java.lang.Long") || 
($attribute.Type == "java.lang.Byte") )
			"${attribute.name}", "${classGen.capitalizeString($attribute.name)}", 
ReportComponent.DATA_TYPE_NUMBER, null, Boolean.TRUE,
#else
#if 		($attribute.Type == "java.math.BigDecimal")
			"${attribute.name}", "${classGen.capitalizeString($attribute.name)}", 
ReportComponent.DATA_TYPE_NUMBER, 
"${dollarSign}${poundSign},${poundSign}${poundSign}0.00", Boolean.TRUE,
#else
#if 		($attribute.Type == "java.lang.Boolean")
			"${attribute.name}", "${classGen.capitalizeString($attribute.name)}", 
ReportComponent.DATA_TYPE_BOOLEAN, null, Boolean.TRUE,
#else
#if			($attribute.Type == "java.util.Date")
			"${attribute.name}", "${classGen.capitalizeString($attribute.name)}", 
ReportComponent.DATA_TYPE_DATE, "y-M-d h:m:s zzz", Boolean. TRUE,
#else##		NSTimestamp
			// unsupported attribute type: $attribute.Type
			"${attribute.name}.toString", 
"${classGen.capitalizeString($attribute.name)}", 
ReportComponent.DATA_TYPE_STRING, null, Boolean.TRUE,
#end## 		NSTimestamp
#end## 		Boolean
#end## 		BigDecimal
#end## 		Number
#end## 		String
#end##	($attribute in $classAttributes)



Without a "real world" example of what you're doing, it's hard to suggest 
what's more appropriate in your case.

However, I doubt that instanceof will be added to the standard VTL.   If you 
really need to have it added, you can always maintain your own patches to 
Velocity to do so.

-Mike

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


RE: [VERDICT] instanceof

Posted by Tim Colson <tc...@cisco.com>.
> So, will 'instanceof' be added to VTL or is the marching order "Teach
> non-Java developers Java, so they can 'Create a Tool'"?
Wow. A suggestion and patch is made to change a core part of the
template language. The patch has spiked much debate (not much in favor
it seems). And the chap expects a verdict -- TODAY! 

Wow. I'm almost speechless. ;-)

Obviously he hasn't seen the length and breadth of the Float or
Whitespace threads. <grin>

We've often said it's hard to get a feel for the "group opinion" - so I
threw together a poll to find out. 
-------------------------------
Michael suggested adding "instanceof" and kindly provided a patch so the
following could be chanted: #if ($foo instanceof "java.lang.String" )

Do you think "instanceof" should be added to the Velocity Template
Language core?
http://www.pollmonkey.com/p.asp?U=10959931
-------------------------------

Cheers 
-Timo





---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org