net.sf.morph.lang.languages
Class SimpleLanguage

java.lang.Object
  extended by net.sf.morph.lang.languages.BaseLanguage
      extended by net.sf.morph.lang.languages.SimpleLanguage
All Implemented Interfaces:
DecoratedLanguage, Language

public class SimpleLanguage
extends BaseLanguage

A simple language that is similar to the languages used by the JSTL EL, the Spring framework, Jakarta Commons BeanUtils, and Struts. Any "simple" expression in any of these languages should be recognized by this language. An example of a simple expression is myBean.myProperty. An example of a "non-simple" expression is

myBean.myProperty + myOtherBean.myOtherProperty

To be more precise, this language treats numbers as indexes into array-like objects and treats other alphanumeric identifiers as property names of bean-like objects. The following characters are all considered delimiters with no particularly special meaning: []()."'. Thus, all of the expressions in the table below have the same value in this language.

Language Expression
JSTL EL , Morph's simple language myBean.myMap["mapProperty"].myArray[0]
Spring , Morph's simple language myBean.myMap[mapProperty].myArray[0]
Jakarta Commons BeanUtils , Struts , Morph's simple language myBean.myMap(mapProperty).myArray[0]
Morph's simple language myBean.myMap.mapProperty.myArray[0]
Morph's simple language myBean.myMap.mapProperty.myArray.0
Morph's simple language myBean"myMap"'''['.']'('.')mapProperty""""myArray[]0....

A simple language that will work for most use cases, but has the limitation that bean property names cannot be numbers. Numbers like 123 are always considered indices into an indexed object. For example, 123 is an invalid bean property name in this language, but 12Monkies and fridayThe13th are valid property names.

Since:
Nov 28, 2004
Author:
Matt Sgarlata

Constructor Summary
SimpleLanguage()
           
 
Method Summary
 ExpressionParser getExpressionParser()
          Get the expression parser.
protected  java.lang.Object getImpl(java.lang.Object target, java.lang.String expression)
          Implement get(target, expression).
 BeanReflector getReflector()
          Get the reflector.
protected  java.lang.Class getTypeImpl(java.lang.Object target, java.lang.String expression)
          Implement getType(target, expression).
protected  boolean isPropertyImpl(java.lang.String expression)
          Implement isProperty(expression).
 void setExpressionParser(ExpressionParser expressionParser)
          Set the expression parser.
protected  void setImpl(java.lang.Object target, java.lang.String expression, java.lang.Object value)
          Implement set(target, expression, value).
 void setReflector(BeanReflector reflector)
          Set the reflector.
 
Methods inherited from class net.sf.morph.lang.languages.BaseLanguage
get, get, get, get, getConverter, getLanguageName, getType, isProperty, set, set, setConverter, setLanguageName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleLanguage

public SimpleLanguage()
Method Detail

isPropertyImpl

protected boolean isPropertyImpl(java.lang.String expression)
                          throws java.lang.Exception
Implement isProperty(expression).

Specified by:
isPropertyImpl in class BaseLanguage
Returns:
boolean
Throws:
java.lang.Exception

getTypeImpl

protected java.lang.Class getTypeImpl(java.lang.Object target,
                                      java.lang.String expression)
                               throws java.lang.Exception
Implement getType(target, expression).

Specified by:
getTypeImpl in class BaseLanguage
Parameters:
target - bean
expression - to read
Returns:
Class
Throws:
java.lang.Exception

getImpl

protected java.lang.Object getImpl(java.lang.Object target,
                                   java.lang.String expression)
                            throws java.lang.Exception
Implement get(target, expression).

Specified by:
getImpl in class BaseLanguage
Parameters:
target - bean
expression - to get
Returns:
Object
Throws:
java.lang.Exception

setImpl

protected void setImpl(java.lang.Object target,
                       java.lang.String expression,
                       java.lang.Object value)
                throws java.lang.Exception
Implement set(target, expression, value).

Specified by:
setImpl in class BaseLanguage
Parameters:
target - bean
expression - to set
value - to set
Throws:
java.lang.Exception

getExpressionParser

public ExpressionParser getExpressionParser()
Get the expression parser.

Returns:
Returns the expressionParser.

setExpressionParser

public void setExpressionParser(ExpressionParser expressionParser)
Set the expression parser.

Parameters:
expressionParser - The expressionParser to set.

getReflector

public BeanReflector getReflector()
Get the reflector.

Returns:
BeanReflector

setReflector

public void setReflector(BeanReflector reflector)
Set the reflector.

Parameters:
reflector - BeanReflector to set


Copyright © 2004-2008.