You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2011/05/14 15:18:36 UTC
svn commit: r1103095 [7/24] - in /incubator/ognl/trunk/src:
main/java/org/apache/commons/ognl/ main/java/org/apache/commons/ognl/enhance/
main/java/org/apache/commons/ognl/internal/
test/java/org/apache/commons/ognl/ test/java/org/apache/commons/ognl/t...
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JavaCharStream.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JavaCharStream.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JavaCharStream.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JavaCharStream.java Sat May 14 13:18:29 2011
@@ -22,612 +22,643 @@
package org.apache.commons.ognl;
/**
- * An implementation of interface CharStream, where the stream is assumed to
- * contain only ASCII characters (with java-like unicode escape processing).
+ * An implementation of interface CharStream, where the stream is assumed to contain only ASCII characters (with
+ * java-like unicode escape processing).
*/
public class JavaCharStream
{
-/** Whether parser is static. */
- public static final boolean staticFlag = false;
- static final int hexval(char c) throws java.io.IOException {
- switch(c)
- {
- case '0' :
- return 0;
- case '1' :
- return 1;
- case '2' :
- return 2;
- case '3' :
- return 3;
- case '4' :
- return 4;
- case '5' :
- return 5;
- case '6' :
- return 6;
- case '7' :
- return 7;
- case '8' :
- return 8;
- case '9' :
- return 9;
-
- case 'a' :
- case 'A' :
- return 10;
- case 'b' :
- case 'B' :
- return 11;
- case 'c' :
- case 'C' :
- return 12;
- case 'd' :
- case 'D' :
- return 13;
- case 'e' :
- case 'E' :
- return 14;
- case 'f' :
- case 'F' :
- return 15;
- }
-
- throw new java.io.IOException(); // Should never come here
- }
-
-/** Position in buffer. */
- public int bufpos = -1;
- int bufsize;
- int available;
- int tokenBegin;
- protected int bufline[];
- protected int bufcolumn[];
-
- protected int column = 0;
- protected int line = 1;
-
- protected boolean prevCharIsCR = false;
- protected boolean prevCharIsLF = false;
-
- protected java.io.Reader inputStream;
-
- protected char[] nextCharBuf;
- protected char[] buffer;
- protected int maxNextCharInd = 0;
- protected int nextCharInd = -1;
- protected int inBuf = 0;
- protected int tabSize = 8;
-
- protected void setTabSize(int i) { tabSize = i; }
- protected int getTabSize(int i) { return tabSize; }
-
- protected void ExpandBuff(boolean wrapAround)
- {
- char[] newbuffer = new char[bufsize + 2048];
- int newbufline[] = new int[bufsize + 2048];
- int newbufcolumn[] = new int[bufsize + 2048];
-
- try
- {
- if (wrapAround)
- {
- System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
- System.arraycopy(buffer, 0, newbuffer,
- bufsize - tokenBegin, bufpos);
- buffer = newbuffer;
-
- System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
- System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos);
- bufline = newbufline;
-
- System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
- System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos);
- bufcolumn = newbufcolumn;
+ /** Whether parser is static. */
+ public static final boolean staticFlag = false;
- bufpos += (bufsize - tokenBegin);
+ static final int hexval( char c )
+ throws java.io.IOException
+ {
+ switch ( c )
+ {
+ case '0':
+ return 0;
+ case '1':
+ return 1;
+ case '2':
+ return 2;
+ case '3':
+ return 3;
+ case '4':
+ return 4;
+ case '5':
+ return 5;
+ case '6':
+ return 6;
+ case '7':
+ return 7;
+ case '8':
+ return 8;
+ case '9':
+ return 9;
+
+ case 'a':
+ case 'A':
+ return 10;
+ case 'b':
+ case 'B':
+ return 11;
+ case 'c':
+ case 'C':
+ return 12;
+ case 'd':
+ case 'D':
+ return 13;
+ case 'e':
+ case 'E':
+ return 14;
+ case 'f':
+ case 'F':
+ return 15;
}
- else
+
+ throw new java.io.IOException(); // Should never come here
+ }
+
+ /** Position in buffer. */
+ public int bufpos = -1;
+
+ int bufsize;
+
+ int available;
+
+ int tokenBegin;
+
+ protected int bufline[];
+
+ protected int bufcolumn[];
+
+ protected int column = 0;
+
+ protected int line = 1;
+
+ protected boolean prevCharIsCR = false;
+
+ protected boolean prevCharIsLF = false;
+
+ protected java.io.Reader inputStream;
+
+ protected char[] nextCharBuf;
+
+ protected char[] buffer;
+
+ protected int maxNextCharInd = 0;
+
+ protected int nextCharInd = -1;
+
+ protected int inBuf = 0;
+
+ protected int tabSize = 8;
+
+ protected void setTabSize( int i )
+ {
+ tabSize = i;
+ }
+
+ protected int getTabSize( int i )
+ {
+ return tabSize;
+ }
+
+ protected void ExpandBuff( boolean wrapAround )
+ {
+ char[] newbuffer = new char[bufsize + 2048];
+ int newbufline[] = new int[bufsize + 2048];
+ int newbufcolumn[] = new int[bufsize + 2048];
+
+ try
{
- System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin);
- buffer = newbuffer;
+ if ( wrapAround )
+ {
+ System.arraycopy( buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin );
+ System.arraycopy( buffer, 0, newbuffer, bufsize - tokenBegin, bufpos );
+ buffer = newbuffer;
+
+ System.arraycopy( bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin );
+ System.arraycopy( bufline, 0, newbufline, bufsize - tokenBegin, bufpos );
+ bufline = newbufline;
- System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin);
- bufline = newbufline;
+ System.arraycopy( bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin );
+ System.arraycopy( bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos );
+ bufcolumn = newbufcolumn;
- System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin);
- bufcolumn = newbufcolumn;
+ bufpos += ( bufsize - tokenBegin );
+ }
+ else
+ {
+ System.arraycopy( buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin );
+ buffer = newbuffer;
- bufpos -= tokenBegin;
- }
- }
- catch (Throwable t)
- {
- throw new Error(t.getMessage());
- }
-
- available = (bufsize += 2048);
- tokenBegin = 0;
- }
-
- protected void FillBuff() throws java.io.IOException
- {
- int i;
- if (maxNextCharInd == 4096)
- maxNextCharInd = nextCharInd = 0;
-
- try {
- if ((i = inputStream.read(nextCharBuf, maxNextCharInd,
- 4096 - maxNextCharInd)) == -1)
+ System.arraycopy( bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin );
+ bufline = newbufline;
+
+ System.arraycopy( bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin );
+ bufcolumn = newbufcolumn;
+
+ bufpos -= tokenBegin;
+ }
+ }
+ catch ( Throwable t )
{
- inputStream.close();
- throw new java.io.IOException();
+ throw new Error( t.getMessage() );
}
- else
- maxNextCharInd += i;
- return;
- }
- catch(java.io.IOException e) {
- if (bufpos != 0)
+
+ available = ( bufsize += 2048 );
+ tokenBegin = 0;
+ }
+
+ protected void FillBuff()
+ throws java.io.IOException
+ {
+ int i;
+ if ( maxNextCharInd == 4096 )
+ maxNextCharInd = nextCharInd = 0;
+
+ try
+ {
+ if ( ( i = inputStream.read( nextCharBuf, maxNextCharInd, 4096 - maxNextCharInd ) ) == -1 )
+ {
+ inputStream.close();
+ throw new java.io.IOException();
+ }
+ else
+ maxNextCharInd += i;
+ return;
+ }
+ catch ( java.io.IOException e )
+ {
+ if ( bufpos != 0 )
+ {
+ --bufpos;
+ backup( 0 );
+ }
+ else
+ {
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+ throw e;
+ }
+ }
+
+ protected char ReadByte()
+ throws java.io.IOException
+ {
+ if ( ++nextCharInd >= maxNextCharInd )
+ FillBuff();
+
+ return nextCharBuf[nextCharInd];
+ }
+
+ /** @return starting character for token. */
+ public char BeginToken()
+ throws java.io.IOException
+ {
+ if ( inBuf > 0 )
{
- --bufpos;
- backup(0);
+ --inBuf;
+
+ if ( ++bufpos == bufsize )
+ bufpos = 0;
+
+ tokenBegin = bufpos;
+ return buffer[bufpos];
}
+
+ tokenBegin = 0;
+ bufpos = -1;
+
+ return readChar();
+ }
+
+ protected void AdjustBuffSize()
+ {
+ if ( available == bufsize )
+ {
+ if ( tokenBegin > 2048 )
+ {
+ bufpos = 0;
+ available = tokenBegin;
+ }
+ else
+ ExpandBuff( false );
+ }
+ else if ( available > tokenBegin )
+ available = bufsize;
+ else if ( ( tokenBegin - available ) < 2048 )
+ ExpandBuff( true );
else
+ available = tokenBegin;
+ }
+
+ protected void UpdateLineColumn( char c )
+ {
+ column++;
+
+ if ( prevCharIsLF )
{
- bufline[bufpos] = line;
- bufcolumn[bufpos] = column;
+ prevCharIsLF = false;
+ line += ( column = 1 );
}
- throw e;
- }
- }
-
- protected char ReadByte() throws java.io.IOException
- {
- if (++nextCharInd >= maxNextCharInd)
- FillBuff();
-
- return nextCharBuf[nextCharInd];
- }
-
-/** @return starting character for token. */
- public char BeginToken() throws java.io.IOException
- {
- if (inBuf > 0)
- {
- --inBuf;
-
- if (++bufpos == bufsize)
- bufpos = 0;
-
- tokenBegin = bufpos;
- return buffer[bufpos];
- }
-
- tokenBegin = 0;
- bufpos = -1;
-
- return readChar();
- }
-
- protected void AdjustBuffSize()
- {
- if (available == bufsize)
- {
- if (tokenBegin > 2048)
+ else if ( prevCharIsCR )
{
- bufpos = 0;
- available = tokenBegin;
+ prevCharIsCR = false;
+ if ( c == '\n' )
+ {
+ prevCharIsLF = true;
+ }
+ else
+ line += ( column = 1 );
+ }
+
+ switch ( c )
+ {
+ case '\r':
+ prevCharIsCR = true;
+ break;
+ case '\n':
+ prevCharIsLF = true;
+ break;
+ case '\t':
+ column--;
+ column += ( tabSize - ( column % tabSize ) );
+ break;
+ default:
+ break;
}
- else
- ExpandBuff(false);
- }
- else if (available > tokenBegin)
- available = bufsize;
- else if ((tokenBegin - available) < 2048)
- ExpandBuff(true);
- else
- available = tokenBegin;
- }
-
- protected void UpdateLineColumn(char c)
- {
- column++;
-
- if (prevCharIsLF)
- {
- prevCharIsLF = false;
- line += (column = 1);
- }
- else if (prevCharIsCR)
- {
- prevCharIsCR = false;
- if (c == '\n')
+
+ bufline[bufpos] = line;
+ bufcolumn[bufpos] = column;
+ }
+
+ /** Read a character. */
+ public char readChar()
+ throws java.io.IOException
+ {
+ if ( inBuf > 0 )
{
- prevCharIsLF = true;
+ --inBuf;
+
+ if ( ++bufpos == bufsize )
+ bufpos = 0;
+
+ return buffer[bufpos];
+ }
+
+ char c;
+
+ if ( ++bufpos == available )
+ AdjustBuffSize();
+
+ if ( ( buffer[bufpos] = c = ReadByte() ) == '\\' )
+ {
+ UpdateLineColumn( c );
+
+ int backSlashCnt = 1;
+
+ for ( ;; ) // Read all the backslashes
+ {
+ if ( ++bufpos == available )
+ AdjustBuffSize();
+
+ try
+ {
+ if ( ( buffer[bufpos] = c = ReadByte() ) != '\\' )
+ {
+ UpdateLineColumn( c );
+ // found a non-backslash char.
+ if ( ( c == 'u' ) && ( ( backSlashCnt & 1 ) == 1 ) )
+ {
+ if ( --bufpos < 0 )
+ bufpos = bufsize - 1;
+
+ break;
+ }
+
+ backup( backSlashCnt );
+ return '\\';
+ }
+ }
+ catch ( java.io.IOException e )
+ {
+ if ( backSlashCnt > 1 )
+ backup( backSlashCnt - 1 );
+
+ return '\\';
+ }
+
+ UpdateLineColumn( c );
+ backSlashCnt++;
+ }
+
+ // Here, we have seen an odd number of backslash's followed by a 'u'
+ try
+ {
+ while ( ( c = ReadByte() ) == 'u' )
+ ++column;
+
+ buffer[bufpos] =
+ c =
+ (char) ( hexval( c ) << 12 | hexval( ReadByte() ) << 8 | hexval( ReadByte() ) << 4 | hexval( ReadByte() ) );
+
+ column += 4;
+ }
+ catch ( java.io.IOException e )
+ {
+ throw new Error( "Invalid escape character at line " + line + " column " + column + "." );
+ }
+
+ if ( backSlashCnt == 1 )
+ return c;
+ else
+ {
+ backup( backSlashCnt - 1 );
+ return '\\';
+ }
}
else
- line += (column = 1);
- }
+ {
+ UpdateLineColumn( c );
+ return c;
+ }
+ }
+
+ /**
+ * @deprecated
+ * @see #getEndColumn
+ */
+ public int getColumn()
+ {
+ return bufcolumn[bufpos];
+ }
- switch (c)
- {
- case '\r' :
- prevCharIsCR = true;
- break;
- case '\n' :
- prevCharIsLF = true;
- break;
- case '\t' :
- column--;
- column += (tabSize - (column % tabSize));
- break;
- default :
- break;
- }
-
- bufline[bufpos] = line;
- bufcolumn[bufpos] = column;
- }
-
-/** Read a character. */
- public char readChar() throws java.io.IOException
- {
- if (inBuf > 0)
- {
- --inBuf;
-
- if (++bufpos == bufsize)
- bufpos = 0;
-
- return buffer[bufpos];
- }
-
- char c;
-
- if (++bufpos == available)
- AdjustBuffSize();
-
- if ((buffer[bufpos] = c = ReadByte()) == '\\')
- {
- UpdateLineColumn(c);
-
- int backSlashCnt = 1;
-
- for (;;) // Read all the backslashes
- {
- if (++bufpos == available)
- AdjustBuffSize();
-
- try
- {
- if ((buffer[bufpos] = c = ReadByte()) != '\\')
- {
- UpdateLineColumn(c);
- // found a non-backslash char.
- if ((c == 'u') && ((backSlashCnt & 1) == 1))
- {
- if (--bufpos < 0)
- bufpos = bufsize - 1;
-
- break;
- }
-
- backup(backSlashCnt);
- return '\\';
- }
- }
- catch(java.io.IOException e)
- {
- if (backSlashCnt > 1)
- backup(backSlashCnt-1);
+ /**
+ * @deprecated
+ * @see #getEndLine
+ */
+ public int getLine()
+ {
+ return bufline[bufpos];
+ }
- return '\\';
- }
+ /** Get end column. */
+ public int getEndColumn()
+ {
+ return bufcolumn[bufpos];
+ }
- UpdateLineColumn(c);
- backSlashCnt++;
- }
+ /** Get end line. */
+ public int getEndLine()
+ {
+ return bufline[bufpos];
+ }
- // Here, we have seen an odd number of backslash's followed by a 'u'
- try
+ /** @return column of token start */
+ public int getBeginColumn()
+ {
+ return bufcolumn[tokenBegin];
+ }
+
+ /** @return line number of token start */
+ public int getBeginLine()
+ {
+ return bufline[tokenBegin];
+ }
+
+ /** Retreat. */
+ public void backup( int amount )
+ {
+
+ inBuf += amount;
+ if ( ( bufpos -= amount ) < 0 )
+ bufpos += bufsize;
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.Reader dstream, int startline, int startcolumn, int buffersize )
+ {
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ nextCharBuf = new char[4096];
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.Reader dstream, int startline, int startcolumn )
+ {
+ this( dstream, startline, startcolumn, 4096 );
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.Reader dstream )
+ {
+ this( dstream, 1, 1, 4096 );
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.Reader dstream, int startline, int startcolumn, int buffersize )
+ {
+ inputStream = dstream;
+ line = startline;
+ column = startcolumn - 1;
+
+ if ( buffer == null || buffersize != buffer.length )
+ {
+ available = bufsize = buffersize;
+ buffer = new char[buffersize];
+ bufline = new int[buffersize];
+ bufcolumn = new int[buffersize];
+ nextCharBuf = new char[4096];
+ }
+ prevCharIsLF = prevCharIsCR = false;
+ tokenBegin = inBuf = maxNextCharInd = 0;
+ nextCharInd = bufpos = -1;
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.Reader dstream, int startline, int startcolumn )
+ {
+ ReInit( dstream, startline, startcolumn, 4096 );
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.Reader dstream )
+ {
+ ReInit( dstream, 1, 1, 4096 );
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize )
+ throws java.io.UnsupportedEncodingException
+ {
+ this( encoding == null ? new java.io.InputStreamReader( dstream ) : new java.io.InputStreamReader( dstream,
+ encoding ),
+ startline, startcolumn, buffersize );
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.InputStream dstream, int startline, int startcolumn, int buffersize )
+ {
+ this( new java.io.InputStreamReader( dstream ), startline, startcolumn, 4096 );
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.InputStream dstream, String encoding, int startline, int startcolumn )
+ throws java.io.UnsupportedEncodingException
+ {
+ this( dstream, encoding, startline, startcolumn, 4096 );
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.InputStream dstream, int startline, int startcolumn )
+ {
+ this( dstream, startline, startcolumn, 4096 );
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.InputStream dstream, String encoding )
+ throws java.io.UnsupportedEncodingException
+ {
+ this( dstream, encoding, 1, 1, 4096 );
+ }
+
+ /** Constructor. */
+ public JavaCharStream( java.io.InputStream dstream )
+ {
+ this( dstream, 1, 1, 4096 );
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize )
+ throws java.io.UnsupportedEncodingException
+ {
+ ReInit( encoding == null ? new java.io.InputStreamReader( dstream ) : new java.io.InputStreamReader( dstream,
+ encoding ),
+ startline, startcolumn, buffersize );
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.InputStream dstream, int startline, int startcolumn, int buffersize )
+ {
+ ReInit( new java.io.InputStreamReader( dstream ), startline, startcolumn, buffersize );
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.InputStream dstream, String encoding, int startline, int startcolumn )
+ throws java.io.UnsupportedEncodingException
+ {
+ ReInit( dstream, encoding, startline, startcolumn, 4096 );
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.InputStream dstream, int startline, int startcolumn )
+ {
+ ReInit( dstream, startline, startcolumn, 4096 );
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.InputStream dstream, String encoding )
+ throws java.io.UnsupportedEncodingException
+ {
+ ReInit( dstream, encoding, 1, 1, 4096 );
+ }
+
+ /** Reinitialise. */
+ public void ReInit( java.io.InputStream dstream )
+ {
+ ReInit( dstream, 1, 1, 4096 );
+ }
+
+ /** @return token image as String */
+ public String GetImage()
+ {
+ if ( bufpos >= tokenBegin )
+ return new String( buffer, tokenBegin, bufpos - tokenBegin + 1 );
+ else
+ return new String( buffer, tokenBegin, bufsize - tokenBegin ) + new String( buffer, 0, bufpos + 1 );
+ }
+
+ /** @return suffix */
+ public char[] GetSuffix( int len )
+ {
+ char[] ret = new char[len];
+
+ if ( ( bufpos + 1 ) >= len )
+ System.arraycopy( buffer, bufpos - len + 1, ret, 0, len );
+ else
{
- while ((c = ReadByte()) == 'u')
- ++column;
+ System.arraycopy( buffer, bufsize - ( len - bufpos - 1 ), ret, 0, len - bufpos - 1 );
+ System.arraycopy( buffer, 0, ret, len - bufpos - 1, bufpos + 1 );
+ }
- buffer[bufpos] = c = (char)(hexval(c) << 12 |
- hexval(ReadByte()) << 8 |
- hexval(ReadByte()) << 4 |
- hexval(ReadByte()));
+ return ret;
+ }
+
+ /** Set buffers back to null when finished. */
+ public void Done()
+ {
+ nextCharBuf = null;
+ buffer = null;
+ bufline = null;
+ bufcolumn = null;
+ }
+
+ /**
+ * Method to adjust line and column numbers for the start of a token.
+ */
+ public void adjustBeginLineColumn( int newLine, int newCol )
+ {
+ int start = tokenBegin;
+ int len;
- column += 4;
+ if ( bufpos >= tokenBegin )
+ {
+ len = bufpos - tokenBegin + inBuf + 1;
}
- catch(java.io.IOException e)
+ else
{
- throw new Error("Invalid escape character at line " + line +
- " column " + column + ".");
+ len = bufsize - tokenBegin + bufpos + 1 + inBuf;
}
- if (backSlashCnt == 1)
- return c;
- else
+ int i = 0, j = 0, k = 0;
+ int nextColDiff = 0, columnDiff = 0;
+
+ while ( i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize] )
+ {
+ bufline[j] = newLine;
+ nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
+ bufcolumn[j] = newCol + columnDiff;
+ columnDiff = nextColDiff;
+ i++;
+ }
+
+ if ( i < len )
{
- backup(backSlashCnt - 1);
- return '\\';
+ bufline[j] = newLine++;
+ bufcolumn[j] = newCol + columnDiff;
+
+ while ( i++ < len )
+ {
+ if ( bufline[j = start % bufsize] != bufline[++start % bufsize] )
+ bufline[j] = newLine++;
+ else
+ bufline[j] = newLine;
+ }
}
- }
- else
- {
- UpdateLineColumn(c);
- return c;
- }
- }
-
- /**
- * @deprecated
- * @see #getEndColumn
- */
- public int getColumn() {
- return bufcolumn[bufpos];
- }
-
- /**
- * @deprecated
- * @see #getEndLine
- */
- public int getLine() {
- return bufline[bufpos];
- }
-
-/** Get end column. */
- public int getEndColumn() {
- return bufcolumn[bufpos];
- }
-
-/** Get end line. */
- public int getEndLine() {
- return bufline[bufpos];
- }
-
-/** @return column of token start */
- public int getBeginColumn() {
- return bufcolumn[tokenBegin];
- }
-
-/** @return line number of token start */
- public int getBeginLine() {
- return bufline[tokenBegin];
- }
-
-/** Retreat. */
- public void backup(int amount) {
-
- inBuf += amount;
- if ((bufpos -= amount) < 0)
- bufpos += bufsize;
- }
-
-/** Constructor. */
- public JavaCharStream(java.io.Reader dstream,
- int startline, int startcolumn, int buffersize)
- {
- inputStream = dstream;
- line = startline;
- column = startcolumn - 1;
-
- available = bufsize = buffersize;
- buffer = new char[buffersize];
- bufline = new int[buffersize];
- bufcolumn = new int[buffersize];
- nextCharBuf = new char[4096];
- }
-
-/** Constructor. */
- public JavaCharStream(java.io.Reader dstream,
- int startline, int startcolumn)
- {
- this(dstream, startline, startcolumn, 4096);
- }
-
-/** Constructor. */
- public JavaCharStream(java.io.Reader dstream)
- {
- this(dstream, 1, 1, 4096);
- }
-/** Reinitialise. */
- public void ReInit(java.io.Reader dstream,
- int startline, int startcolumn, int buffersize)
- {
- inputStream = dstream;
- line = startline;
- column = startcolumn - 1;
-
- if (buffer == null || buffersize != buffer.length)
- {
- available = bufsize = buffersize;
- buffer = new char[buffersize];
- bufline = new int[buffersize];
- bufcolumn = new int[buffersize];
- nextCharBuf = new char[4096];
- }
- prevCharIsLF = prevCharIsCR = false;
- tokenBegin = inBuf = maxNextCharInd = 0;
- nextCharInd = bufpos = -1;
- }
-
-/** Reinitialise. */
- public void ReInit(java.io.Reader dstream,
- int startline, int startcolumn)
- {
- ReInit(dstream, startline, startcolumn, 4096);
- }
-
-/** Reinitialise. */
- public void ReInit(java.io.Reader dstream)
- {
- ReInit(dstream, 1, 1, 4096);
- }
-/** Constructor. */
- public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
- int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
- {
- this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
- }
-
-/** Constructor. */
- public JavaCharStream(java.io.InputStream dstream, int startline,
- int startcolumn, int buffersize)
- {
- this(new java.io.InputStreamReader(dstream), startline, startcolumn, 4096);
- }
-
-/** Constructor. */
- public JavaCharStream(java.io.InputStream dstream, String encoding, int startline,
- int startcolumn) throws java.io.UnsupportedEncodingException
- {
- this(dstream, encoding, startline, startcolumn, 4096);
- }
-
-/** Constructor. */
- public JavaCharStream(java.io.InputStream dstream, int startline,
- int startcolumn)
- {
- this(dstream, startline, startcolumn, 4096);
- }
-
-/** Constructor. */
- public JavaCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
- {
- this(dstream, encoding, 1, 1, 4096);
- }
-
-/** Constructor. */
- public JavaCharStream(java.io.InputStream dstream)
- {
- this(dstream, 1, 1, 4096);
- }
-
-/** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, String encoding, int startline,
- int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException
- {
- ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize);
- }
-
-/** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, int startline,
- int startcolumn, int buffersize)
- {
- ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize);
- }
-/** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, String encoding, int startline,
- int startcolumn) throws java.io.UnsupportedEncodingException
- {
- ReInit(dstream, encoding, startline, startcolumn, 4096);
- }
-/** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, int startline,
- int startcolumn)
- {
- ReInit(dstream, startline, startcolumn, 4096);
- }
-/** Reinitialise. */
- public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException
- {
- ReInit(dstream, encoding, 1, 1, 4096);
- }
-
-/** Reinitialise. */
- public void ReInit(java.io.InputStream dstream)
- {
- ReInit(dstream, 1, 1, 4096);
- }
-
- /** @return token image as String */
- public String GetImage()
- {
- if (bufpos >= tokenBegin)
- return new String(buffer, tokenBegin, bufpos - tokenBegin + 1);
- else
- return new String(buffer, tokenBegin, bufsize - tokenBegin) +
- new String(buffer, 0, bufpos + 1);
- }
-
- /** @return suffix */
- public char[] GetSuffix(int len)
- {
- char[] ret = new char[len];
-
- if ((bufpos + 1) >= len)
- System.arraycopy(buffer, bufpos - len + 1, ret, 0, len);
- else
- {
- System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0,
- len - bufpos - 1);
- System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1);
- }
-
- return ret;
- }
-
- /** Set buffers back to null when finished. */
- public void Done()
- {
- nextCharBuf = null;
- buffer = null;
- bufline = null;
- bufcolumn = null;
- }
-
- /**
- * Method to adjust line and column numbers for the start of a token.
- */
- public void adjustBeginLineColumn(int newLine, int newCol)
- {
- int start = tokenBegin;
- int len;
-
- if (bufpos >= tokenBegin)
- {
- len = bufpos - tokenBegin + inBuf + 1;
- }
- else
- {
- len = bufsize - tokenBegin + bufpos + 1 + inBuf;
- }
-
- int i = 0, j = 0, k = 0;
- int nextColDiff = 0, columnDiff = 0;
-
- while (i < len &&
- bufline[j = start % bufsize] == bufline[k = ++start % bufsize])
- {
- bufline[j] = newLine;
- nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j];
- bufcolumn[j] = newCol + columnDiff;
- columnDiff = nextColDiff;
- i++;
- }
-
- if (i < len)
- {
- bufline[j] = newLine++;
- bufcolumn[j] = newCol + columnDiff;
-
- while (i++ < len)
- {
- if (bufline[j = start % bufsize] != bufline[++start % bufsize])
- bufline[j] = newLine++;
- else
- bufline[j] = newLine;
- }
- }
-
- line = bufline[j];
- column = bufcolumn[j];
- }
+
+ line = bufline[j];
+ column = bufcolumn[j];
+ }
}
/* JavaCC - OriginalChecksum=7ef64849e2b59fe6d1ffdca3bf0ddd2b (do not edit this line) */
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JavaSource.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JavaSource.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JavaSource.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/JavaSource.java Sat May 14 13:18:29 2011
@@ -25,29 +25,27 @@ package org.apache.commons.ognl;
import org.apache.commons.ognl.enhance.ExpressionAccessor;
/**
- * Defines an object that can return a representation of itself and any objects it contains
- * in the form of a {@link String} embedded with literal java statements.
+ * Defines an object that can return a representation of itself and any objects it contains in the form of a
+ * {@link String} embedded with literal java statements.
*
* @author jkuhnert
*/
public interface JavaSource
{
-
+
/**
- * Expected to return a java source representation of itself such that
- * it could be turned into a literal java expression to be compiled and
- * executed for {@link ExpressionAccessor#get(OgnlContext, Object)} calls.
+ * Expected to return a java source representation of itself such that it could be turned into a literal java
+ * expression to be compiled and executed for {@link ExpressionAccessor#get(OgnlContext, Object)} calls.
*
* @return Literal java string representation of an object get.
*/
- String toGetSourceString(OgnlContext context, Object target);
-
+ String toGetSourceString( OgnlContext context, Object target );
+
/**
- * Expected to return a java source representation of itself such that
- * it could be turned into a literal java expression to be compiled and
- * executed for {@link ExpressionAccessor#get(OgnlContext, Object)} calls.
+ * Expected to return a java source representation of itself such that it could be turned into a literal java
+ * expression to be compiled and executed for {@link ExpressionAccessor#get(OgnlContext, Object)} calls.
*
* @return Literal java string representation of an object get.
*/
- String toSetSourceString(OgnlContext context, Object target);
+ String toSetSourceString( OgnlContext context, Object target );
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/ListPropertyAccessor.java Sat May 14 13:18:29 2011
@@ -23,33 +23,44 @@ import java.lang.reflect.Method;
import java.util.*;
/**
- * Implementation of PropertyAccessor that uses numbers and dynamic subscripts as properties to
- * index into Lists.
- *
+ * Implementation of PropertyAccessor that uses numbers and dynamic subscripts as properties to index into Lists.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class ListPropertyAccessor extends ObjectPropertyAccessor implements PropertyAccessor
+public class ListPropertyAccessor
+ extends ObjectPropertyAccessor
+ implements PropertyAccessor
{
- public Object getProperty(Map context, Object target, Object name)
- throws OgnlException
+ public Object getProperty( Map context, Object target, Object name )
+ throws OgnlException
{
List list = (List) target;
- if (name instanceof String) {
+ if ( name instanceof String )
+ {
Object result = null;
- if (name.equals("size")) {
- result = new Integer(list.size());
- } else {
- if (name.equals("iterator")) {
+ if ( name.equals( "size" ) )
+ {
+ result = new Integer( list.size() );
+ }
+ else
+ {
+ if ( name.equals( "iterator" ) )
+ {
result = list.iterator();
- } else {
- if (name.equals("isEmpty") || name.equals("empty")) {
+ }
+ else
+ {
+ if ( name.equals( "isEmpty" ) || name.equals( "empty" ) )
+ {
result = list.isEmpty() ? Boolean.TRUE : Boolean.FALSE;
- } else {
- result = super.getProperty(context, target, name);
+ }
+ else
+ {
+ result = super.getProperty( context, target, name );
}
}
}
@@ -57,115 +68,137 @@ public class ListPropertyAccessor extend
return result;
}
- if (name instanceof Number)
- return list.get(((Number) name).intValue());
+ if ( name instanceof Number )
+ return list.get( ( (Number) name ).intValue() );
- if (name instanceof DynamicSubscript) {
+ if ( name instanceof DynamicSubscript )
+ {
int len = list.size();
- switch(((DynamicSubscript) name).getFlag()) {
+ switch ( ( (DynamicSubscript) name ).getFlag() )
+ {
case DynamicSubscript.FIRST:
- return len > 0 ? list.get(0) : null;
+ return len > 0 ? list.get( 0 ) : null;
case DynamicSubscript.MID:
- return len > 0 ? list.get(len / 2) : null;
+ return len > 0 ? list.get( len / 2 ) : null;
case DynamicSubscript.LAST:
- return len > 0 ? list.get(len - 1) : null;
+ return len > 0 ? list.get( len - 1 ) : null;
case DynamicSubscript.ALL:
- return new ArrayList(list);
+ return new ArrayList( list );
}
}
- throw new NoSuchPropertyException(target, name);
+ throw new NoSuchPropertyException( target, name );
}
- public void setProperty(Map context, Object target, Object name, Object value)
- throws OgnlException
+ public void setProperty( Map context, Object target, Object name, Object value )
+ throws OgnlException
{
- if (name instanceof String && ((String)name).indexOf("$") < 0) {
- super.setProperty(context, target, name, value);
+ if ( name instanceof String && ( (String) name ).indexOf( "$" ) < 0 )
+ {
+ super.setProperty( context, target, name, value );
return;
}
List list = (List) target;
- if (name instanceof Number) {
- list.set(((Number) name).intValue(), value);
+ if ( name instanceof Number )
+ {
+ list.set( ( (Number) name ).intValue(), value );
return;
}
- if (name instanceof DynamicSubscript) {
+ if ( name instanceof DynamicSubscript )
+ {
int len = list.size();
- switch(((DynamicSubscript) name).getFlag()) {
+ switch ( ( (DynamicSubscript) name ).getFlag() )
+ {
case DynamicSubscript.FIRST:
- if (len > 0) list.set(0, value);
+ if ( len > 0 )
+ list.set( 0, value );
return;
case DynamicSubscript.MID:
- if (len > 0) list.set(len / 2, value);
+ if ( len > 0 )
+ list.set( len / 2, value );
return;
case DynamicSubscript.LAST:
- if (len > 0) list.set(len - 1, value);
+ if ( len > 0 )
+ list.set( len - 1, value );
return;
case DynamicSubscript.ALL:
{
- if (!(value instanceof Collection)) throw new OgnlException("Value must be a collection");
+ if ( !( value instanceof Collection ) )
+ throw new OgnlException( "Value must be a collection" );
list.clear();
- list.addAll((Collection) value);
+ list.addAll( (Collection) value );
return;
}
}
}
- throw new NoSuchPropertyException(target, name);
+ throw new NoSuchPropertyException( target, name );
}
- public Class getPropertyClass(OgnlContext context, Object target, Object index)
+ public Class getPropertyClass( OgnlContext context, Object target, Object index )
{
- if (index instanceof String) {
- String key = ((String)index).replaceAll("\"", "");
- if (key.equals("size")) {
+ if ( index instanceof String )
+ {
+ String key = ( (String) index ).replaceAll( "\"", "" );
+ if ( key.equals( "size" ) )
+ {
return int.class;
- } else {
- if (key.equals("iterator")) {
+ }
+ else
+ {
+ if ( key.equals( "iterator" ) )
+ {
return Iterator.class;
- } else {
- if (key.equals("isEmpty") || key.equals("empty")) {
+ }
+ else
+ {
+ if ( key.equals( "isEmpty" ) || key.equals( "empty" ) )
+ {
return boolean.class;
- } else {
- return super.getPropertyClass(context, target, index);
+ }
+ else
+ {
+ return super.getPropertyClass( context, target, index );
}
}
}
}
- if (index instanceof Number)
+ if ( index instanceof Number )
return Object.class;
return null;
}
- public String getSourceAccessor(OgnlContext context, Object target, Object index)
+ public String getSourceAccessor( OgnlContext context, Object target, Object index )
{
- String indexStr = index.toString().replaceAll("\"", "");
+ String indexStr = index.toString().replaceAll( "\"", "" );
- if (String.class.isInstance(index))
+ if ( String.class.isInstance( index ) )
{
- if (indexStr.equals("size"))
+ if ( indexStr.equals( "size" ) )
{
- context.setCurrentAccessor(List.class);
- context.setCurrentType(int.class);
+ context.setCurrentAccessor( List.class );
+ context.setCurrentType( int.class );
return ".size()";
- } else
+ }
+ else
{
- if (indexStr.equals("iterator"))
+ if ( indexStr.equals( "iterator" ) )
{
- context.setCurrentAccessor(List.class);
- context.setCurrentType(Iterator.class);
+ context.setCurrentAccessor( List.class );
+ context.setCurrentType( Iterator.class );
return ".iterator()";
- } else
+ }
+ else
{
- if (indexStr.equals("isEmpty") || indexStr.equals("empty"))
+ if ( indexStr.equals( "isEmpty" ) || indexStr.equals( "empty" ) )
{
- context.setCurrentAccessor(List.class);
- context.setCurrentType(boolean.class);
+ context.setCurrentAccessor( List.class );
+ context.setCurrentType( boolean.class );
return ".isEmpty()";
}
}
@@ -175,93 +208,106 @@ public class ListPropertyAccessor extend
// TODO: This feels really inefficient, must be some better way
// check if the index string represents a method on a custom class implementing java.util.List instead..
- if (context.getCurrentObject() != null && !Number.class.isInstance(context.getCurrentObject()))
+ if ( context.getCurrentObject() != null && !Number.class.isInstance( context.getCurrentObject() ) )
{
- try {
- Method m = OgnlRuntime.getReadMethod(target.getClass(), indexStr);
+ try
+ {
+ Method m = OgnlRuntime.getReadMethod( target.getClass(), indexStr );
- if (m != null)
- return super.getSourceAccessor(context, target, index);
+ if ( m != null )
+ return super.getSourceAccessor( context, target, index );
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
}
- context.setCurrentAccessor(List.class);
+ context.setCurrentAccessor( List.class );
// need to convert to primitive for list index access
- // System.out.println("Curent type: " + context.getCurrentType() + " current object type " + context.getCurrentObject().getClass());
+ // System.out.println("Curent type: " + context.getCurrentType() + " current object type " +
+ // context.getCurrentObject().getClass());
- if (!context.getCurrentType().isPrimitive() && Number.class.isAssignableFrom(context.getCurrentType()))
+ if ( !context.getCurrentType().isPrimitive() && Number.class.isAssignableFrom( context.getCurrentType() ) )
{
- indexStr += "." + OgnlRuntime.getNumericValueGetter(context.getCurrentType());
- } else if (context.getCurrentObject() != null && Number.class.isAssignableFrom(context.getCurrentObject().getClass())
- && !context.getCurrentType().isPrimitive())
+ indexStr += "." + OgnlRuntime.getNumericValueGetter( context.getCurrentType() );
+ }
+ else if ( context.getCurrentObject() != null
+ && Number.class.isAssignableFrom( context.getCurrentObject().getClass() )
+ && !context.getCurrentType().isPrimitive() )
{
// means it needs to be cast first as well
- String toString = String.class.isInstance(index) && context.getCurrentType() != Object.class ? "" : ".toString()";
+ String toString =
+ String.class.isInstance( index ) && context.getCurrentType() != Object.class ? "" : ".toString()";
indexStr = "org.apache.commons.ognl.OgnlOps#getIntValue(" + indexStr + toString + ")";
}
- context.setCurrentType(Object.class);
+ context.setCurrentType( Object.class );
return ".get(" + indexStr + ")";
}
- public String getSourceSetter(OgnlContext context, Object target, Object index)
+ public String getSourceSetter( OgnlContext context, Object target, Object index )
{
- String indexStr = index.toString().replaceAll("\"", "");
+ String indexStr = index.toString().replaceAll( "\"", "" );
// TODO: This feels really inefficient, must be some better way
// check if the index string represents a method on a custom class implementing java.util.List instead..
- /* System.out.println("Listpropertyaccessor setter using index: " + index + " and current object: " + context.getCurrentObject()
- + " number is current object? " + Number.class.isInstance(context.getCurrentObject()));*/
-
- if (context.getCurrentObject() != null && !Number.class.isInstance(context.getCurrentObject()))
+ /*
+ * System.out.println("Listpropertyaccessor setter using index: " + index + " and current object: " +
+ * context.getCurrentObject() + " number is current object? " +
+ * Number.class.isInstance(context.getCurrentObject()));
+ */
+
+ if ( context.getCurrentObject() != null && !Number.class.isInstance( context.getCurrentObject() ) )
{
- try {
- Method m = OgnlRuntime.getWriteMethod(target.getClass(), indexStr);
-
- if (m != null || !context.getCurrentType().isPrimitive())
+ try
+ {
+ Method m = OgnlRuntime.getWriteMethod( target.getClass(), indexStr );
+
+ if ( m != null || !context.getCurrentType().isPrimitive() )
{
- System.out.println("super source setter returned: " + super.getSourceSetter(context, target, index));
- return super.getSourceSetter(context, target, index);
+ System.out.println( "super source setter returned: "
+ + super.getSourceSetter( context, target, index ) );
+ return super.getSourceSetter( context, target, index );
}
- } catch (Throwable t)
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
}
- /* if (String.class.isInstance(index))
- {
- context.setCurrentAccessor(List.class);
- return "";
- }*/
+ /*
+ * if (String.class.isInstance(index)) { context.setCurrentAccessor(List.class); return ""; }
+ */
- context.setCurrentAccessor(List.class);
+ context.setCurrentAccessor( List.class );
// need to convert to primitive for list index access
- if (!context.getCurrentType().isPrimitive() && Number.class.isAssignableFrom(context.getCurrentType()))
+ if ( !context.getCurrentType().isPrimitive() && Number.class.isAssignableFrom( context.getCurrentType() ) )
{
- indexStr += "." + OgnlRuntime.getNumericValueGetter(context.getCurrentType());
- } else if (context.getCurrentObject() != null && Number.class.isAssignableFrom(context.getCurrentObject().getClass())
- && !context.getCurrentType().isPrimitive())
+ indexStr += "." + OgnlRuntime.getNumericValueGetter( context.getCurrentType() );
+ }
+ else if ( context.getCurrentObject() != null
+ && Number.class.isAssignableFrom( context.getCurrentObject().getClass() )
+ && !context.getCurrentType().isPrimitive() )
{
// means it needs to be cast first as well
- String toString = String.class.isInstance(index) && context.getCurrentType() != Object.class ? "" : ".toString()";
+ String toString =
+ String.class.isInstance( index ) && context.getCurrentType() != Object.class ? "" : ".toString()";
indexStr = "org.apache.commons.ognl.OgnlOps#getIntValue(" + indexStr + toString + ")";
}
- context.setCurrentType(Object.class);
+ context.setCurrentType( Object.class );
return ".set(" + indexStr + ", $3)";
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MapElementsAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MapElementsAccessor.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MapElementsAccessor.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MapElementsAccessor.java Sat May 14 13:18:29 2011
@@ -23,13 +23,15 @@ import java.util.*;
/**
* Implementation of ElementsAccessor that returns an iterator over the map's values.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class MapElementsAccessor implements ElementsAccessor
+public class MapElementsAccessor
+ implements ElementsAccessor
{
public Enumeration getElements( Object target )
{
- return new IteratorEnumeration( ((Map)target).values().iterator() );
+ return new IteratorEnumeration( ( (Map) target ).values().iterator() );
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MapPropertyAccessor.java Sat May 14 13:18:29 2011
@@ -24,122 +24,149 @@ import java.util.Map;
import java.util.Set;
/**
- * Implementation of PropertyAccessor that sets and gets properties by storing and looking up values
- * in Maps.
- *
+ * Implementation of PropertyAccessor that sets and gets properties by storing and looking up values in Maps.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class MapPropertyAccessor implements PropertyAccessor
+public class MapPropertyAccessor
+ implements PropertyAccessor
{
- public Object getProperty(Map context, Object target, Object name)
- throws OgnlException
+ public Object getProperty( Map context, Object target, Object name )
+ throws OgnlException
{
Object result;
Map map = (Map) target;
- Node currentNode = ((OgnlContext) context).getCurrentNode().jjtGetParent();
+ Node currentNode = ( (OgnlContext) context ).getCurrentNode().jjtGetParent();
boolean indexedAccess = false;
- if (currentNode == null) { throw new OgnlException("node is null for '" + name + "'"); }
- if (!(currentNode instanceof ASTProperty)) {
+ if ( currentNode == null )
+ {
+ throw new OgnlException( "node is null for '" + name + "'" );
+ }
+ if ( !( currentNode instanceof ASTProperty ) )
+ {
currentNode = currentNode.jjtGetParent();
}
- if (currentNode instanceof ASTProperty) {
- indexedAccess = ((ASTProperty) currentNode).isIndexedAccess();
+ if ( currentNode instanceof ASTProperty )
+ {
+ indexedAccess = ( (ASTProperty) currentNode ).isIndexedAccess();
}
- if ((name instanceof String) && !indexedAccess) {
- if (name.equals("size")) {
- result = new Integer(map.size());
- } else {
- if (name.equals("keys") || name.equals("keySet")) {
+ if ( ( name instanceof String ) && !indexedAccess )
+ {
+ if ( name.equals( "size" ) )
+ {
+ result = new Integer( map.size() );
+ }
+ else
+ {
+ if ( name.equals( "keys" ) || name.equals( "keySet" ) )
+ {
result = map.keySet();
- } else {
- if (name.equals("values")) {
+ }
+ else
+ {
+ if ( name.equals( "values" ) )
+ {
result = map.values();
- } else {
- if (name.equals("isEmpty")) {
+ }
+ else
+ {
+ if ( name.equals( "isEmpty" ) )
+ {
result = map.isEmpty() ? Boolean.TRUE : Boolean.FALSE;
- } else {
- result = map.get(name);
+ }
+ else
+ {
+ result = map.get( name );
}
}
}
}
- } else {
- result = map.get(name);
+ }
+ else
+ {
+ result = map.get( name );
}
return result;
}
- public void setProperty(Map context, Object target, Object name, Object value)
- throws OgnlException
+ public void setProperty( Map context, Object target, Object name, Object value )
+ throws OgnlException
{
Map map = (Map) target;
- map.put(name, value);
+ map.put( name, value );
}
- public String getSourceAccessor(OgnlContext context, Object target, Object index)
+ public String getSourceAccessor( OgnlContext context, Object target, Object index )
{
- Node currentNode = ((OgnlContext) context).getCurrentNode().jjtGetParent();
+ Node currentNode = ( (OgnlContext) context ).getCurrentNode().jjtGetParent();
boolean indexedAccess = false;
- if (currentNode == null)
- throw new RuntimeException("node is null for '" + index + "'");
+ if ( currentNode == null )
+ throw new RuntimeException( "node is null for '" + index + "'" );
- if (!(currentNode instanceof ASTProperty))
+ if ( !( currentNode instanceof ASTProperty ) )
currentNode = currentNode.jjtGetParent();
- if (currentNode instanceof ASTProperty)
- indexedAccess = ((ASTProperty) currentNode).isIndexedAccess();
+ if ( currentNode instanceof ASTProperty )
+ indexedAccess = ( (ASTProperty) currentNode ).isIndexedAccess();
String indexStr = index.toString();
- context.setCurrentAccessor(Map.class);
- context.setCurrentType(Object.class);
-
- if (String.class.isInstance(index) && !indexedAccess)
+ context.setCurrentAccessor( Map.class );
+ context.setCurrentType( Object.class );
+
+ if ( String.class.isInstance( index ) && !indexedAccess )
{
- String key = indexStr.replaceAll("\"", "");
+ String key = indexStr.replaceAll( "\"", "" );
- if (key.equals("size")) {
- context.setCurrentType(int.class);
+ if ( key.equals( "size" ) )
+ {
+ context.setCurrentType( int.class );
return ".size()";
- } else if (key.equals("keys") || key.equals("keySet")) {
- context.setCurrentType(Set.class);
+ }
+ else if ( key.equals( "keys" ) || key.equals( "keySet" ) )
+ {
+ context.setCurrentType( Set.class );
return ".keySet()";
- } else if (key.equals("values")) {
- context.setCurrentType(Collection.class);
+ }
+ else if ( key.equals( "values" ) )
+ {
+ context.setCurrentType( Collection.class );
return ".values()";
- } else if (key.equals("isEmpty")) {
- context.setCurrentType(boolean.class);
+ }
+ else if ( key.equals( "isEmpty" ) )
+ {
+ context.setCurrentType( boolean.class );
return ".isEmpty()";
}
}
-
+
return ".get(" + indexStr + ")";
}
- public String getSourceSetter(OgnlContext context, Object target, Object index)
+ public String getSourceSetter( OgnlContext context, Object target, Object index )
{
- context.setCurrentAccessor(Map.class);
- context.setCurrentType(Object.class);
+ context.setCurrentAccessor( Map.class );
+ context.setCurrentType( Object.class );
String indexStr = index.toString();
- if (String.class.isInstance(index))
+ if ( String.class.isInstance( index ) )
{
- String key = indexStr.replaceAll("\"", "");
-
- if (key.equals("size"))
+ String key = indexStr.replaceAll( "\"", "" );
+
+ if ( key.equals( "size" ) )
return "";
- else if (key.equals("keys") || key.equals("keySet"))
+ else if ( key.equals( "keys" ) || key.equals( "keySet" ) )
return "";
- else if (key.equals("values"))
+ else if ( key.equals( "values" ) )
return "";
- else if (key.equals("isEmpty"))
+ else if ( key.equals( "isEmpty" ) )
return "";
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MemberAccess.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MemberAccess.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MemberAccess.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MemberAccess.java Sat May 14 13:18:29 2011
@@ -23,10 +23,9 @@ import java.lang.reflect.Member;
import java.util.Map;
/**
- * This interface provides a hook for preparing for accessing members
- * of objects. The Java2 version of this method can allow access
- * to otherwise inaccessable members, such as private fields.
- *
+ * This interface provides a hook for preparing for accessing members of objects. The Java2 version of this method can
+ * allow access to otherwise inaccessable members, such as private fields.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
* @version 15 October 1999
@@ -34,18 +33,17 @@ import java.util.Map;
public interface MemberAccess
{
/**
- Sets the member up for accessibility
+ * Sets the member up for accessibility
*/
- public Object setup(Map context, Object target, Member member, String propertyName);
+ public Object setup( Map context, Object target, Member member, String propertyName );
/**
- Restores the member from the previous setup call.
+ * Restores the member from the previous setup call.
*/
- public void restore(Map context, Object target, Member member, String propertyName, Object state);
+ public void restore( Map context, Object target, Member member, String propertyName, Object state );
/**
- Returns true if the given member is accessible or can be made accessible
- by this object.
+ * Returns true if the given member is accessible or can be made accessible by this object.
*/
- public boolean isAccessible(Map context, Object target, Member member, String propertyName);
+ public boolean isAccessible( Map context, Object target, Member member, String propertyName );
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MethodAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MethodAccessor.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MethodAccessor.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MethodAccessor.java Sat May 14 13:18:29 2011
@@ -22,10 +22,9 @@ package org.apache.commons.ognl;
import java.util.Map;
/**
- * This interface defines methods for calling methods in a target object.
- * Methods are broken up into static and instance methods for convenience.
- * indexes into the target object, which must be an array.
- *
+ * This interface defines methods for calling methods in a target object. Methods are broken up into static and instance
+ * methods for convenience. indexes into the target object, which must be an array.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
@@ -33,26 +32,27 @@ public interface MethodAccessor
{
/**
* Calls the static method named with the arguments given on the class given.
- * @param context expression context in which the method should be called
+ *
+ * @param context expression context in which the method should be called
* @param targetClass the object in which the method exists
- * @param methodName the name of the method
- * @param args the arguments to the method
- *
- * @return result of calling the method
+ * @param methodName the name of the method
+ * @param args the arguments to the method
+ * @return result of calling the method
* @exception MethodFailedException if there is an error calling the method
*/
Object callStaticMethod( Map context, Class targetClass, String methodName, Object[] args )
- throws MethodFailedException;
+ throws MethodFailedException;
/**
* Calls the method named with the arguments given.
- * @param context expression context in which the method should be called
- * @param target the object in which the method exists
- * @param methodName the name of the method
- * @param args the arguments to the method
- * @return result of calling the method
+ *
+ * @param context expression context in which the method should be called
+ * @param target the object in which the method exists
+ * @param methodName the name of the method
+ * @param args the arguments to the method
+ * @return result of calling the method
* @exception MethodFailedException if there is an error calling the method
*/
Object callMethod( Map context, Object target, String methodName, Object[] args )
- throws MethodFailedException;
+ throws MethodFailedException;
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MethodFailedException.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MethodFailedException.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MethodFailedException.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/MethodFailedException.java Sat May 14 13:18:29 2011
@@ -25,14 +25,15 @@ package org.apache.commons.ognl;
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class MethodFailedException extends OgnlException
+public class MethodFailedException
+ extends OgnlException
{
- public MethodFailedException( Object source, String name)
+ public MethodFailedException( Object source, String name )
{
- super( "Method \"" + name + "\" failed for object " + source);
+ super( "Method \"" + name + "\" failed for object " + source );
}
- public MethodFailedException( Object source, String name, Throwable reason )
+ public MethodFailedException( Object source, String name, Throwable reason )
{
super( "Method \"" + name + "\" failed for object " + source, reason );
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NoSuchPropertyException.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NoSuchPropertyException.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NoSuchPropertyException.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NoSuchPropertyException.java Sat May 14 13:18:29 2011
@@ -19,39 +19,39 @@
*/
package org.apache.commons.ognl;
-
/**
- * Exception thrown if a property is attempted to be extracted from an object that does
- * not have such a property.
+ * Exception thrown if a property is attempted to be extracted from an object that does not have such a property.
*
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class NoSuchPropertyException extends OgnlException
+public class NoSuchPropertyException
+ extends OgnlException
{
- private Object target;
- private Object name;
+ private Object target;
+
+ private Object name;
public NoSuchPropertyException( Object target, Object name )
{
- super( getReason(target, name) );
+ super( getReason( target, name ) );
}
public NoSuchPropertyException( Object target, Object name, Throwable reason )
{
- super( getReason(target, name), reason );
- this.target = target;
- this.name = name;
+ super( getReason( target, name ), reason );
+ this.target = target;
+ this.name = name;
}
- static String getReason(Object target, Object name)
+ static String getReason( Object target, Object name )
{
String ret = null;
- if (target == null)
+ if ( target == null )
ret = "null";
- else if (target instanceof Class)
- ret = ((Class)target).getName();
+ else if ( target instanceof Class )
+ ret = ( (Class) target ).getName();
else
ret = target.getClass().getName();
@@ -62,11 +62,11 @@ public class NoSuchPropertyException ext
public Object getTarget()
{
- return target;
+ return target;
}
public Object getName()
{
- return name;
+ return name;
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Node.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Node.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Node.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/Node.java Sat May 14 13:18:29 2011
@@ -22,69 +22,73 @@ package org.apache.commons.ognl;
import org.apache.commons.ognl.enhance.ExpressionAccessor;
/**
- JJTree interface for AST nodes, as modified to handle the OGNL operations getValue and
- setValue. JJTree's original comment:
-
- All AST nodes must implement this interface. It provides basic
- machinery for constructing the parent and child relationships
- between nodes.
-
- @author Luke Blanshard (blanshlu@netscape.net)
- @author Drew Davidson (drew@ognl.org)
-*/
-public interface Node extends JavaSource
+ * JJTree interface for AST nodes, as modified to handle the OGNL operations getValue and setValue. JJTree's original
+ * comment: All AST nodes must implement this interface. It provides basic machinery for constructing the parent and
+ * child relationships between nodes.
+ *
+ * @author Luke Blanshard (blanshlu@netscape.net)
+ * @author Drew Davidson (drew@ognl.org)
+ */
+public interface Node
+ extends JavaSource
{
- /** This method is called after the node has been made the current
- node. It indicates that child nodes can now be added to it. */
+ /**
+ * This method is called after the node has been made the current node. It indicates that child nodes can now be
+ * added to it.
+ */
public void jjtOpen();
- /** This method is called after all the child nodes have been
- added. */
+ /**
+ * This method is called after all the child nodes have been added.
+ */
public void jjtClose();
- /** This pair of methods are used to inform the node of its
- parent. */
- public void jjtSetParent(Node n);
+ /**
+ * This pair of methods are used to inform the node of its parent.
+ */
+ public void jjtSetParent( Node n );
+
public Node jjtGetParent();
- /** This method tells the node to add its argument to the node's
- list of children. */
- public void jjtAddChild(Node n, int i);
-
- /** This method returns a child node. The children are numbered
- from zero, left to right. */
- public Node jjtGetChild(int i);
+ /**
+ * This method tells the node to add its argument to the node's list of children.
+ */
+ public void jjtAddChild( Node n, int i );
+
+ /**
+ * This method returns a child node. The children are numbered from zero, left to right.
+ */
+ public Node jjtGetChild( int i );
/** Return the number of children the node has. */
public int jjtGetNumChildren();
+ // OGNL additions to Node:
-// OGNL additions to Node:
-
/**
- * Extracts the value from the given source object that is appropriate for this node
- * within the given context.
+ * Extracts the value from the given source object that is appropriate for this node within the given context.
*/
- public Object getValue( OgnlContext context, Object source ) throws OgnlException;
+ public Object getValue( OgnlContext context, Object source )
+ throws OgnlException;
/**
- * Sets the given value in the given target as appropriate for this node within the
- * given context.
+ * Sets the given value in the given target as appropriate for this node within the given context.
*/
- public void setValue( OgnlContext context, Object target, Object value ) throws OgnlException;
-
+ public void setValue( OgnlContext context, Object target, Object value )
+ throws OgnlException;
+
/**
* Gets the compiled bytecode enhanced expression accessor for getting/setting values.
*
* @return The accessor for this node, or null if none has been compiled for it.
*/
ExpressionAccessor getAccessor();
-
+
/**
* Sets a new compiled accessor for this node expression.
*
* @param accessor The compiled representation of this node.
*/
- void setAccessor(ExpressionAccessor accessor);
+ void setAccessor( ExpressionAccessor accessor );
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NodeType.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NodeType.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NodeType.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NodeType.java Sat May 14 13:18:29 2011
@@ -22,23 +22,22 @@
*/
package org.apache.commons.ognl;
-
/**
- * Used by some of the {@link ognl.enhance.OgnlExpressionCompiler} logic to determine the object
- * type of {@link Node}s during expression evaluation.
+ * Used by some of the {@link ognl.enhance.OgnlExpressionCompiler} logic to determine the object type of {@link Node}s
+ * during expression evaluation.
*/
public interface NodeType
{
/**
* The type returned from the expression - if any.
- *
+ *
* @return The type.
*/
Class getGetterClass();
/**
* The type used to set the value - if any.
- *
+ *
* @return The type.
*/
Class getSetterClass();
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NullHandler.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NullHandler.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NullHandler.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NullHandler.java Sat May 14 13:18:29 2011
@@ -22,23 +22,21 @@ package org.apache.commons.ognl;
import java.util.Map;
/**
- * Interface for handling null results from Chains.
- * Object has the opportunity to substitute an object for the
- * null and continue.
+ * Interface for handling null results from Chains. Object has the opportunity to substitute an object for the null and
+ * continue.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
public interface NullHandler
{
/**
- Method called on target returned null.
+ * Method called on target returned null.
*/
- public Object nullMethodResult(Map context, Object target, String methodName, Object[] args);
+ public Object nullMethodResult( Map context, Object target, String methodName, Object[] args );
/**
- Property in target evaluated to null. Property can be a constant
- String property name or a DynamicSubscript.
+ * Property in target evaluated to null. Property can be a constant String property name or a DynamicSubscript.
*/
- public Object nullPropertyValue(Map context, Object target, Object property);
+ public Object nullPropertyValue( Map context, Object target, Object property );
}
-
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumberElementsAccessor.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumberElementsAccessor.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumberElementsAccessor.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumberElementsAccessor.java Sat May 14 13:18:29 2011
@@ -22,25 +22,31 @@ package org.apache.commons.ognl;
import java.util.*;
/**
- * Implementation of ElementsAccessor that returns an iterator over integers from 0 up to
- * the given target.
+ * Implementation of ElementsAccessor that returns an iterator over integers from 0 up to the given target.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
-public class NumberElementsAccessor implements ElementsAccessor, NumericTypes
+public class NumberElementsAccessor
+ implements ElementsAccessor, NumericTypes
{
public Enumeration getElements( final Object target )
{
- return new Enumeration() {
+ return new Enumeration()
+ {
private int type = OgnlOps.getNumericType( target );
+
private long next = 0;
+
private long finish = OgnlOps.longValue( target );
- public boolean hasMoreElements() {
+ public boolean hasMoreElements()
+ {
return next < finish;
}
- public Object nextElement() {
+ public Object nextElement()
+ {
if ( next >= finish )
throw new NoSuchElementException();
return OgnlOps.newInteger( type, next++ );
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumericExpression.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumericExpression.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumericExpression.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumericExpression.java Sat May 14 13:18:29 2011
@@ -24,93 +24,100 @@ package org.apache.commons.ognl;
import org.apache.commons.ognl.enhance.ExpressionCompiler;
-
/**
- * Base class for numeric expressions.
+ * Base class for numeric expressions.
*/
-public abstract class NumericExpression extends ExpressionNode implements NodeType
+public abstract class NumericExpression
+ extends ExpressionNode
+ implements NodeType
{
protected Class _getterClass;
-
- public NumericExpression(int id) {
- super(id);
- }
-
- public NumericExpression(OgnlParser p, int id) {
- super(p, id);
+
+ public NumericExpression( int id )
+ {
+ super( id );
}
-
+
+ public NumericExpression( OgnlParser p, int id )
+ {
+ super( p, id );
+ }
+
public Class getGetterClass()
{
- if (_getterClass != null)
+ if ( _getterClass != null )
return _getterClass;
-
+
return Double.TYPE;
}
-
+
public Class getSetterClass()
{
return null;
}
-
- public String toGetSourceString(OgnlContext context, Object target)
+
+ public String toGetSourceString( OgnlContext context, Object target )
{
Object value = null;
- StringBuilder result = new StringBuilder("");
+ StringBuilder result = new StringBuilder( "" );
+
+ try
+ {
- try {
+ value = getValueBody( context, target );
- value = getValueBody(context, target);
-
- if (value != null)
+ if ( value != null )
_getterClass = value.getClass();
- for (int i=0; i < _children.length; i++)
+ for ( int i = 0; i < _children.length; i++ )
{
- if (i > 0)
- result.append(" ").append(getExpressionOperator(i)).append(" ");
+ if ( i > 0 )
+ result.append( " " ).append( getExpressionOperator( i ) ).append( " " );
- String str = OgnlRuntime.getChildSource(context, target, _children[i]);
+ String str = OgnlRuntime.getChildSource( context, target, _children[i] );
- result.append(coerceToNumeric(str, context, _children[i]));
+ result.append( coerceToNumeric( str, context, _children[i] ) );
}
-
- } catch (Throwable t)
+
+ }
+ catch ( Throwable t )
{
- throw OgnlOps.castToRuntime(t);
+ throw OgnlOps.castToRuntime( t );
}
return result.toString();
}
- public String coerceToNumeric(String source, OgnlContext context, Node child)
+ public String coerceToNumeric( String source, OgnlContext context, Node child )
{
String ret = source;
Object value = context.getCurrentObject();
- if (ASTConst.class.isInstance(child) && value != null)
+ if ( ASTConst.class.isInstance( child ) && value != null )
{
return value.toString();
}
- if (context.getCurrentType() != null && !context.getCurrentType().isPrimitive()
- && context.getCurrentObject() != null && Number.class.isInstance(context.getCurrentObject()))
+ if ( context.getCurrentType() != null && !context.getCurrentType().isPrimitive()
+ && context.getCurrentObject() != null && Number.class.isInstance( context.getCurrentObject() ) )
{
- ret = "((" + ExpressionCompiler.getCastString(context.getCurrentObject().getClass()) + ")" + ret + ")";
- ret += "." + OgnlRuntime.getNumericValueGetter(context.getCurrentObject().getClass());
- } else if (context.getCurrentType() != null && context.getCurrentType().isPrimitive()
- && (ASTConst.class.isInstance(child) || NumericExpression.class.isInstance(child)))
+ ret = "((" + ExpressionCompiler.getCastString( context.getCurrentObject().getClass() ) + ")" + ret + ")";
+ ret += "." + OgnlRuntime.getNumericValueGetter( context.getCurrentObject().getClass() );
+ }
+ else if ( context.getCurrentType() != null && context.getCurrentType().isPrimitive()
+ && ( ASTConst.class.isInstance( child ) || NumericExpression.class.isInstance( child ) ) )
{
- ret += OgnlRuntime.getNumericLiteral(context.getCurrentType());
- } else if (context.getCurrentType() != null && String.class.isAssignableFrom(context.getCurrentType()))
+ ret += OgnlRuntime.getNumericLiteral( context.getCurrentType() );
+ }
+ else if ( context.getCurrentType() != null && String.class.isAssignableFrom( context.getCurrentType() ) )
{
ret = "Double.parseDouble(" + ret + ")";
- context.setCurrentType(Double.TYPE);
+ context.setCurrentType( Double.TYPE );
}
- if (NumericExpression.class.isInstance(child))
+ if ( NumericExpression.class.isInstance( child ) )
ret = "(" + ret + ")";
-
+
return ret;
}
}
Modified: incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumericTypes.java
URL: http://svn.apache.org/viewvc/incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumericTypes.java?rev=1103095&r1=1103094&r2=1103095&view=diff
==============================================================================
--- incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumericTypes.java (original)
+++ incubator/ognl/trunk/src/main/java/org/apache/commons/ognl/NumericTypes.java Sat May 14 13:18:29 2011
@@ -19,46 +19,54 @@
*/
package org.apache.commons.ognl;
-
/**
- * This interface defines some useful constants for describing the various possible
- * numeric types of OGNL.
+ * This interface defines some useful constants for describing the various possible numeric types of OGNL.
+ *
* @author Luke Blanshard (blanshlu@netscape.net)
* @author Drew Davidson (drew@ognl.org)
*/
public interface NumericTypes
{
- // Order does matter here... see the getNumericType methods in ognl.g.
+ // Order does matter here... see the getNumericType methods in ognl.g.
+
+ /** Type tag meaning boolean. */
+ int BOOL = 0;
+
+ /** Type tag meaning byte. */
+ int BYTE = 1;
+
+ /** Type tag meaning char. */
+ int CHAR = 2;
+
+ /** Type tag meaning short. */
+ int SHORT = 3;
+
+ /** Type tag meaning int. */
+ int INT = 4;
+
+ /** Type tag meaning long. */
+ int LONG = 5;
+
+ /** Type tag meaning java.math.BigInteger. */
+ int BIGINT = 6;
+
+ /** Type tag meaning float. */
+ int FLOAT = 7;
+
+ /** Type tag meaning double. */
+ int DOUBLE = 8;
+
+ /** Type tag meaning java.math.BigDecimal. */
+ int BIGDEC = 9;
- /** Type tag meaning boolean. */
- int BOOL = 0;
- /** Type tag meaning byte. */
- int BYTE = 1;
- /** Type tag meaning char. */
- int CHAR = 2;
- /** Type tag meaning short. */
- int SHORT = 3;
- /** Type tag meaning int. */
- int INT = 4;
- /** Type tag meaning long. */
- int LONG = 5;
- /** Type tag meaning java.math.BigInteger. */
- int BIGINT = 6;
- /** Type tag meaning float. */
- int FLOAT = 7;
- /** Type tag meaning double. */
- int DOUBLE = 8;
- /** Type tag meaning java.math.BigDecimal. */
- int BIGDEC = 9;
- /** Type tag meaning something other than a number. */
+ /** Type tag meaning something other than a number. */
int NONNUMERIC = 10;
- /**
- * The smallest type tag that represents reals as opposed to integers. You can see
- * whether a type tag represents reals or integers by comparing the tag to this
- * constant: all tags less than this constant represent integers, and all tags
- * greater than or equal to this constant represent reals. Of course, you must also
- * check for NONNUMERIC, which means it is not a number at all.
- */
+ /**
+ * The smallest type tag that represents reals as opposed to integers. You can see whether a type tag represents
+ * reals or integers by comparing the tag to this constant: all tags less than this constant represent integers, and
+ * all tags greater than or equal to this constant represent reals. Of course, you must also check for NONNUMERIC,
+ * which means it is not a number at all.
+ */
int MIN_REAL_TYPE = FLOAT;
}