PDA

View Full Version : defining a function



Anonymous
08-29-2002, 08:05 AM
Please, tell me what is wrong with the following:

I have a function in class "gorivo.BPModelTabliceRacuna" defined like this
public String getUkupniIznos()

I declared a function in my XML report like this:
<function name="getUkupniIznos"
class="gorivo.BPModelTabliceRacuna"/>

I get the following exception:

org.xml.sax.SAXException: Function getUkupniIznos class=gorivo.BPModelTabliceRacuna is not valid: IllegalAccess: Class com.jrefinery.report.io.FunctionFactory can not access a member of class gorivo.BPModelTabliceRacuna with modifiers ""
at com.jrefinery.report.io.FunctionFactory.startFunction(FunctionFactory.java:202)
at com.jrefinery.report.io.FunctionFactory.startElement(FunctionFactory.java:76)
at com.jrefinery.report.io.ReportDefinitionContentHandler.startElement(ReportDefinitionContentHandler.java:143)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1490)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)
at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)
at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)
at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:217)
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:144)
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:127)
at gorivo.Printanje.<init>(Printanje.java:37)
at gorivo.GlavniProzor.but_printanje_actionPerformed(GlavniProzor.java:357)
at gorivo.GlavniProzor$3.actionPerformed(GlavniProzor.java:210)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1767)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1820)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:258)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:227)
at java.awt.Component.processMouseEvent(Component.java:5021)
at java.awt.Component.processEvent(Component.java:4818)
at java.awt.Container.processEvent(Container.java:1380)
at java.awt.Component.dispatchEventImpl(Component.java:3526)
at java.awt.Container.dispatchEventImpl(Container.java:1437)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2929)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)
at java.awt.Container.dispatchEventImpl(Container.java:1423)
at java.awt.Window.dispatchEventImpl(Window.java:1566)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)
com.jrefinery.report.io.ReportDefinitionException: Function getUkupniIznos class=gorivo.BPModelTabliceRacuna is not valid: IllegalAccess: Class com.jrefinery.report.io.FunctionFactory can not access a member of class gorivo.BPModelTabliceRacuna with modifiers ""
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:231)
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:144)
at com.jrefinery.report.io.ReportGenerator.parseReport(ReportGenerator.java:127)
at gorivo.Printanje.<init>(Printanje.java:37)
at gorivo.GlavniProzor.but_printanje_actionPerformed(GlavniProzor.java:357)
at gorivo.GlavniProzor$3.actionPerformed(GlavniProzor.java:210)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1767)
at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1820)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:258)
at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:227)
at java.awt.Component.processMouseEvent(Component.java:5021)
at java.awt.Component.processEvent(Component.java:4818)
at java.awt.Container.processEvent(Container.java:1380)
at java.awt.Component.dispatchEventImpl(Component.java:3526)
at java.awt.Container.dispatchEventImpl(Container.java:1437)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2929)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)
at java.awt.Container.dispatchEventImpl(Container.java:1423)
at java.awt.Window.dispatchEventImpl(Window.java:1566)
at java.awt.Component.dispatchEvent(Component.java:3367)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)

thanx

Anonymous
08-29-2002, 12:33 PM
Hi,

There is some misunderstanding involved here: A function is not defined by writing a certain method in an arbitary class. Functions in JFreeReport are Objects which implement the com.jrefinery.report.Function interface. To make implementation easier, you may extend the AbstractFunction class.

If your function does not require maintaining a state, that means your calculation is completly based on the data available in a certain row and does not use results from previous calculations, you can also use an expression for your calculation.

An Expression is implemented by using the com.jrefinery.report.Expression interface or by extending com.jrefinery.report.AbstractExpression. Simple expressions can also be formed by using the com.jrefinery.report.BSHExpression.

The BSHExpression uses the BeanShell-Scripting framework to perform the calculation, the expression itself is contained in a function called

Object getValue()

and this function is defined in the expression property "expression".

An example in the XML format: (from report1.xml)
<expression name="expression" class="com.jrefinery.report.function.BSHExpression">
<properties>
<property name="expression">
// use simple java code to perform the expression. You may use all classes
// available in your classpath as if you write "real" java code in your favourite
// IDE.
// See the www.beanshell.org site for more information ...
//
// A return value of type "Object" is alway implied ...
getValue ()
{
return new String ("Expression");
}
</property>
</properties>
</expression>

You will need the latest sources from the cvs for the expressions and you will also need the beanshell-jar to compile and execute the BSHExpression.
The BeanShell-Jar is available from www.beanshell.org/download.html

Have more fun,
said Thomas

Anonymous
08-29-2002, 03:07 PM
thank you

Anonymous
08-29-2002, 05:39 PM
I tried to create a function object but I just don't know how to implement all those functions. I an exception every time.
and the Expression interface I don't even have.

all I need is a string to be printed at the end of each report. the string is different for every report and I need to get it from one of my classes.
what would be the easiest way to do this?

Anonymous
08-30-2002, 02:29 AM
Hi,

use a ReportPropertyFunction and set the String as ReportProperty in the report after you created it.

ReportProperties are set using the JFreeReport.setProperty() method, and can be read using the com.jrefinery.report.function.ReportPropertyFunction. Have a look at the demos, the report property function is used to print the date in the reports.

The expression interface is new in the cvs, you'll have to checkout the latest sources from there for this to work.

Have more fun,
said Thomas

Anonymous
08-30-2002, 07:09 AM
I did that.
thanks