Use sun-codemodel to generate expression like b().c() - java

I'm trying to use sun-codemodel to generate source code, checking the API for a long time however no luck.
JBlock body2 = method2.body();
JInvocation arg = body2.invoke( "a" ).arg( xxx ).invoke( "c" ).arg( xxx );
only generate the first part, i.e. a(xxx)
Any ideas?

Problem solved by using
JInvocation invoke = JExpr._this()
.invoke( "fun" )
.arg( "arg1" )
.invoke( "fun2" )
.arg( "arg2" );
method.body().add(invoke);

Related

SpagoBI multi value parameter

I'm trying to create a multi-value parameter in SpagoBI.
Here is my data set query whose last line appears to be causing an issue.
select C."CUSTOMERNAME", C."CITY", D."YEAR", P."NAME"
from "CUSTOMER" C, "DAY" D, "PRODUCT" P, "TRANSACTIONS" T
where C."CUSTOMERID" = T."CUSTOMERID"
and D."DAYID" = T."DAYID"
and P."PRODUCTID" = T."PRODUCTID"
and _CITY_
I created before open script in my dataset which looks like this:
this.queryText = this.queryText.replace(_CITY_, " CUSTOMER.CITY in ( "+params["cp"].value+" ) ");
My parameter is set as string, display type dynamic list box.
When I run the report I'm getting that error.
org.eclipse.birt.report.engine.api.EngineException: There are errors evaluating script "
this.queryText = this.queryText.replace(_CITY_, " CUSTOMER.CITY in ( "+params["cp"].value+" ) ");
":
Fail to execute script in function __bm_beforeOpen(). Source:
Could anyone please help me?
Hello I managed to solve the problem. Here is my code:
var substring = "" ;
var strParamValsSelected=reportContext.getParameterValue("citytext");
substring += "?," + strParamValsSelected ;
this.queryText = this.queryText.replace("'xxx'",substring);
As You can see the "?" is necessary before my parameter. Maybe It will help somebody. Thank You so much for Your comments.
If you are using SpagoBI server and High charts (JFreeChart Engine) / JSChat Engine you can just use ($P{param_url}) in query,
or build dynamic query using Java script / groovy Script
so your query could also be:
select C."CUSTOMERNAME", C."CITY", D."YEAR", P."NAME"
from "CUSTOMER" C, "DAY" D, "PRODUCT" P, "TRANSACTIONS" T
where C."CUSTOMERID" = T."CUSTOMERID"
and D."DAYID" = T."DAYID"
and P."PRODUCTID" = T."PRODUCTID"
and CUSTOMER."CITY" in ('$P{param_url}')

How to solve lua errors: "attempt to index ? (a nil value)" [duplicate]

This question already has an answer here:
Attempt to index local 'v' (a nil value)
(1 answer)
Closed 5 years ago.
There has been a lot of post about this kind of error and most people say it is related to table and array indexing problems. But I am not using tables at all, I am just trying to call a library function I made and I get this error. Here is the lua script called from java:
String script = new String (
"function event_touch ( )"
+ " pb.open_form ('view_monster');"
+ " print ('I ran the lua script');"
+ "end");
PBLUAengine.run_script(script, "event_touch");
This gives me the following error when trapping the exception:
"function event_touch ( ) pb.open_form ('view_monster'); print ('I ran the lua script');end:1 attempt to index ? (a nil value)"
The run_script() function calls the script like this( I am using luaj):
public static LuaValue run_script ( String script )
{
try
{
LuaValue chunk = s_globals.load( script );
return chunk.call();
}
catch ( Exception e)
{
Gdx.app.error ("PBLUAengine.run_script()", e.getMessage() );
}
return null;
}
The library method goes like this and the same piece of code works when called from java:
static class open_form extends OneArgFunction
{
public LuaValue call (LuaValue formname)
{
String tmpstr = (String ) CoerceLuaToJava.coerce(formname, java.lang.String.class );
try
{
PBscreen_game.hide_subscreen(PBscreen_game.MENU_SUBS);
PBscreen_game.show_subscreen ( PBscreen_game.FORM_SUBS);
PBsubscreen_form.open_form ( new PBform_regular ( tmpstr ) );
}
catch (Exception e)
{
Gdx.app.error("PBLUAlibrary.open_form", e.getMessage());
}
return valueOf ( 0 );
}
}
It basically convert the lua parameter to string, create a new from and pass in parameter the string.
The declaration of the library functions goes like this:
public LuaValue call( LuaValue modname, LuaValue env )
{
LuaValue library = tableOf();
library.set( "open_form", new open_form() );
library.set( "open_system_form", new open_system_form() );
env.set( "pb", library );
return library;
}
Which could be the only "table" I can see in the whole system. This is generally used link the right class with the right function name.
Anybody have an idea?
most people say it is related to table and array indexing problems
It's related to table and array indexing. If you try to index an object and that object is nil, you'll get that error:
I am not using tables at all [..] Here is the lua script:
pb.open_form
pb is being indexed. It's probably nil.
I seems that I solved the problem by adding a require line to include the library. So the new script is:
String script = new String (
"require 'com.lariennalibrary.pixelboard.library.PBLUAlibrary'"
+ "function event_touch ( )"
+ " pb.open_form ('view_monster');"
+ " print ('I ran the next button lua script');"
+ "end");
It ask to include my library class which will add all the "pb.*" functions. I probably deleted the line by error, or managed to make it work somehow without it. Since this library will be required by all script, I might append it by default before each script I try to run.
Thanks Again

When to use $em->getConnection()->close();, should I use it after every query

I am new to doctrine2(PHP) which is inspired from hibernate(java). I have searched at many places by didn't get appropriate answer.
what is the use of following code of line, what will happen if I do not use it?
$em->getConnection()->close();
For example If I have made following method in my class :
public static function deleteWish( $about_ilook_user_id, $link_ilook_user_id, $flush_automatic = TRUE )
{
$em = \Zend_Registry::get('em');
$new_link_wishes_objs = $em->getRepository( '\Entities\new_link_wishes' )->findBy( array( 'ilookUser' => $about_ilook_user_id, 'link_ilook_user_id' => $link_ilook_user_id ) );
foreach ( $new_link_wishes_objs as $new_link_wishes_obj )
{
$em -> remove($new_link_wishes_obj);
}
$em -> flush();
$em->getConnection()->close();
}
Should I call getConnection()->close(); on $em(entity manager).

How to convert a string to camel case in phpstorms (velocity based) file tempates?

What I've tried so far is:
## $NAME is something like 'my_controller_c'
#set($NAME = $NAME.removeAndHump($NAME))
#set($NAME = $NAME.underscoresToCamelCase(String)
But that does not work. The first one does nothing, the second one throws an java error.
I also tried using regular expressions and to loop through the string, but my java knowledge is very basic.
The following works in PhpStorm 9 (and probably all of the other JetBrains IDEs, I would guess):
#set($new_name = ${StringUtils.removeAndHump(${NAME}, "-")})
class $new_name {
}
This is, what I ended up doing:
#set($ctrlName = $NAME.replaceAll("-c$", ""))
#set($ctrlNewName = "")
#foreach($str in $ctrlName.split("-"))
#set($str = $str.substring(0,1).toUpperCase()+$str.substring(1))
#set($ctrlNewName = $ctrlNewName + $str)
#end
#set ( $ctrlNewName = $ctrlNewName + "Ctrl" )

Railo Java Printing

I'm trying to get a program to print labels to a print attached (USB) to the server. I've been able to print to it from a batch file but for some reason the print command fails inside of coldfusion execute command. My current solution is to access the printer through Java. My problem with this solution is that I can't call any of them java methods.
The solution is based off of this answer How to print strings with line breaks in java
The following section of code appears to work fine.
var printService = createObject("java","javax.print.PrintService");
var printServiceLookup = createObject("java","javax.print.PrintServiceLookup");
var docFlavor = createObject("java","javax.print.DocFlavor");
writeDump( printService.init() );
writeOutput('<hr>');
writeDump( printServiceLookup );
writeOutput('<hr>');
writeDump( docFlavor );
The problem comes when I try to do a execute any of the methods that exist in the objects that were just created.
When I try to execute
writeDump( DocFlavor.STRING.TEXT_PLAIN );
I get:
Application Execution Exception
Error Type: java.lang.NoSuchMethodException : 0
Error Messages: No matching Constructor for javax.print.DocFlavor() found
Remember I'm trying to send a set of ZPL print commands to a printer attached to the computer. If been able to successfully do this through sockets but also need to be able to do it through a locally connected printer. So alternate solutions are acceptable provided they work with Railo & Windows.
Updated: 4/3/2013
var printer = javacast("null","");
var printers = printServiceLookup.lookupPrintServices( javacast("null",""), javacast("null","") );
for( var i=1; i le ArrayLen( printers ); i++ ) {
if( printers[i].getName() eq printername ) {
printer = printers[i];
break;
}
}
if( i gt ArrayLen( printer ) ) {
throw('Printer #printername# was not found');
}
var Job = printer.createPrintJob();
var LabelCmdbytes = javaCast( "byte[]", javaCast( "String", LabelCmd ).getBytes() );
var Labeldoc = Doc.init( LabelCmdbytes, printer.getSupportedDocFlavors()[1].AUTOSENSE, javacast("null","" ) );
Job.print( Labeldoc, javacast("null","")
This solution works but I don't think that printer.getSupportedDocFlavors()[1].AUTOSENSE is the best solution to the DocFlavor value.
The environment is Windows 7 with Railo 4.1.x
Actually DocFlavor.STRING is a nested class. So you need to use $ to grab a reference to it:
StringFlavor = createObject("java","javax.print.DocFlavor$STRING");
Then you can access the public field:
writeDump( StringFlavor.TEXT_PLAIN );
Side note, printService.init() should not work. PrintService is an interface and cannot be instantiated. So calling init() should throw an error.

Categories

Resources