| 1 |
/** |
| 2 |
* ======================================== |
| 3 |
* JFreeReport : a free Java report library |
| 4 |
* ======================================== |
| 5 |
* |
| 6 |
* Project Info: http://reporting.pentaho.org/ |
| 7 |
* |
| 8 |
* (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors. |
| 9 |
* |
| 10 |
* This library is free software; you can redistribute it and/or modify it under the terms |
| 11 |
* of the GNU Lesser General Public License as published by the Free Software Foundation; |
| 12 |
* either version 2.1 of the License, or (at your option) any later version. |
| 13 |
* |
| 14 |
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 15 |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 16 |
* See the GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License along with this |
| 19 |
* library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, |
| 20 |
* Boston, MA 02111-1307, USA. |
| 21 |
* |
| 22 |
* [Java is a trademark or registered trademark of Sun Microsystems, Inc. |
| 23 |
* in the United States and other countries.] |
| 24 |
* |
| 25 |
* ------------ |
| 26 |
* $Id: BeanPropertyLookupParser.java 10756 2009-12-02 15:58:24Z tmorgner $ |
| 27 |
* ------------ |
| 28 |
* (C) Copyright 2000-2005, by Object Refinery Limited. |
| 29 |
* (C) Copyright 2005-2007, by Pentaho Corporation. |
| 30 |
*/ |
| 31 |
package org.jfree.report.util.beans; |
| 32 |
|
| 33 |
import org.jfree.report.util.CSVTokenizer; |
| 34 |
import org.jfree.report.util.PropertyLookupParser; |
| 35 |
|
| 36 |
public abstract class BeanPropertyLookupParser extends PropertyLookupParser |
| 37 |
{ |
| 38 |
public BeanPropertyLookupParser () |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
/** |
| 43 |
* |
| 44 |
* @param name |
| 45 |
* @return |
| 46 |
*/ |
| 47 |
protected abstract Object performInitialLookup (String name); |
| 48 |
|
| 49 |
protected String lookupVariable (final String entity) |
| 50 |
{ |
| 51 |
// first, split the entity into separate strings (separator is '.'). |
| 52 |
|
| 53 |
final CSVTokenizer tokenizer = new CSVTokenizer(entity, "."); |
| 54 |
if (tokenizer.hasMoreTokens()) |
| 55 |
{ |
| 56 |
final String name = tokenizer.nextToken(); |
| 57 |
final Object base = performInitialLookup(name); |
| 58 |
try |
| 59 |
{ |
| 60 |
if (tokenizer.hasMoreTokens()) |
| 61 |
{ |
| 62 |
return continueLookupVariable(tokenizer, base); |
| 63 |
} |
| 64 |
else |
| 65 |
{ |
| 66 |
return ConverterRegistry.toAttributeValue(base); |
| 67 |
} |
| 68 |
} |
| 69 |
catch (BeanException e) |
| 70 |
{ |
| 71 |
return entity; |
| 72 |
} |
| 73 |
} |
| 74 |
return entity; |
| 75 |
} |
| 76 |
|
| 77 |
private static String continueLookupVariable (final CSVTokenizer tokenizer, |
| 78 |
final Object parent) |
| 79 |
throws BeanException |
| 80 |
{ |
| 81 |
if (tokenizer.hasMoreTokens()) |
| 82 |
{ |
| 83 |
final String name = tokenizer.nextToken(); |
| 84 |
final Object base = ConverterRegistry.toPropertyValue(name, parent.getClass()); |
| 85 |
if (tokenizer.hasMoreTokens()) |
| 86 |
{ |
| 87 |
return continueLookupVariable(tokenizer, base); |
| 88 |
} |
| 89 |
else |
| 90 |
{ |
| 91 |
return ConverterRegistry.toAttributeValue(base); |
| 92 |
} |
| 93 |
} |
| 94 |
return null; |
| 95 |
} |
| 96 |
|
| 97 |
} |