[
https://issues.apache.org/jira/browse/VELOCITY-102?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12623010#action_12623010
]
Christopher Schultz commented on VELOCITY-102:
----------------------------------------------
Adrian,
If you are willing to subclass a certain class to change its "automatic" name,
then why not also subclass said class to provide methods to access the static
members and methods from a concrete instance of that class?
I tend to agree with Nathan that custom tools are a good way to go, here. It's
unfortunate that you can't create an instance of java.lang.Math (nor can you
extend it), but this class was simply not designed to be used in any way other
than statically.
Are we picking java.lang.Math as a truly representative class of useful items
in the Java universe? I feel like that example is a bit contrived, and leads us
down a path requiring lots of code and special cases to handle a situation that
has minimal applicability.
> Add Support for Static Utility Classes
> --------------------------------------
>
> Key: VELOCITY-102
> URL: https://issues.apache.org/jira/browse/VELOCITY-102
> Project: Velocity
> Issue Type: Improvement
> Components: Engine
> Affects Versions: 1.3-rc1
> Environment: Operating System: All
> Platform: All
> Reporter: Juozas Baliuka
> Priority: Minor
> Fix For: 1.6
>
>
> Support for Static Utility Classes is:
> 1) define namespaces
>
> context.defineNamespace("Math").add( java.lang.Math.class ) ;
> used as $Math.sin(0)
> 2) Add / Replace / remove methods in namespace :
>
> context.getNamespace("Math").add(MyRandom.class.getMethod("randomString",new
> Class[]{int.class}))
> used as $Math.randomString(12)
> 3) "union" on namespaces
> context.defineNamespace("Utils")
> .add(context.getNamespace("Math"))
> .add(context.defineNamespace("Collections",Collections.class ) );
> used as:
> $Utils.sin(0)
> $Utils.sort($list)
> 4) Global namespace
> context.getGlobalNamespace().add( Math.class );
> used as $sin(0)
> 5) inline namespaces:
> #use java.lang.Math as Math
> $Math.sin(0)
> #end
> #with Math
> $sin(0)
> #end
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]