You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by ge...@apache.org on 2001/11/19 14:52:30 UTC
cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node BooleanPropertyExecutor.java
geirm 01/11/19 05:52:30
Added: src/java/org/apache/velocity/runtime/parser/node
BooleanPropertyExecutor.java
Log:
Separate property executor for isProperty() introspection, to allow us to do
it after the GetExecutor() in order to retain existing semantics in finding
property accessors.
Revision Changes Path
1.1 jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node/BooleanPropertyExecutor.java
Index: BooleanPropertyExecutor.java
===================================================================
package org.apache.velocity.runtime.parser.node;
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2000-2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Velocity", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.lang.reflect.Method;
import java.lang.reflect.InvocationTargetException;
import org.apache.velocity.util.introspection.Introspector;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.app.event.EventCartridge;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.runtime.RuntimeServices;
import org.apache.velocity.util.introspection.Introspector;
/**
* Handles discovery and valuation of a
* boolean object property, of the
* form public boolean is<property> when executed.
*
* We do this separately as to preserve the current
* quasi-broken semantics of get<as is property>
* get< flip 1st char> get("property") and now followed
* by is<Property>
*
* @author <a href="geirm@apache.org">Geir Magnusson Jr.</a>
* @version $Id: BooleanPropertyExecutor.java,v 1.1 2001/11/19 13:52:30 geirm Exp $
*/
public class BooleanPropertyExecutor extends PropertyExecutor
{
public BooleanPropertyExecutor( RuntimeServices r, Class clazz, String property)
{
super( r, clazz, property );
}
protected void discover( Class clazz, String property )
{
try
{
char c;
StringBuffer sb;
Object[] params = { };
Introspector introspector = rsvc.getIntrospector();
/*
* now look for a boolean isFoo
*/
sb = new StringBuffer( "is" );
sb.append( property );
c = sb.charAt(2);
if( Character.isLowerCase(c) )
{
sb.setCharAt( 2 , Character.toUpperCase(c) );
}
methodUsed = sb.toString();
method = introspector.getMethod( clazz, methodUsed, params);
if (method != null)
{
/*
* now, this has to return a boolean
*/
if ( method.getReturnType() == Boolean.TYPE )
return;
method = null;
}
}
catch( Exception e )
{
rsvc.error("PROGRAMMER ERROR : BooleanPropertyExector() : " + e );
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit:
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node
BooleanPropertyExecutor.java
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/19/01 12:56 PM, "Jon Stevens" <jo...@latchkey.com> wrote:
> on 11/19/01 5:52 AM, "geirm@apache.org" <ge...@apache.org> wrote:
>
>> * @author <a href="geirm@apache.org">Geir Magnusson Jr.</a>
>
> Mailto:
>
>
> --
> To unsubscribe, e-mail: <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>
>
LOL
Thanks
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit:
jakarta-velocity/src/java/org/apache/velocity/runtime/parser/node
BooleanPropertyExecutor.java
Posted by Jon Stevens <jo...@latchkey.com>.
on 11/19/01 5:52 AM, "geirm@apache.org" <ge...@apache.org> wrote:
> * @author <a href="geirm@apache.org">Geir Magnusson Jr.</a>
Mailto:
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>