Code generation through Java Reflection

Hi
I am after some clarification about the possibility of mapping of method outputs to other method inputs, using java reflection.
The java objects are described in an XML based language (called DAML) as follows
<java:Method rdf:ID="meth1" java:priority="1">
<java:methodName>buildQuery</java:methodName>
<java:parentClass>afsw.query.QueryBuilder</java:parentClass>
<java:methodParameters rdf:parseType="daml:collection">
<java:Parameter>
<java:inORout>input</java:inORout>
<java:type>java.util.Hashtable</java:type>
</java:Parameter>
</java:methodParameters>
</java:Method>
and I want to map them back to method calls and instantiations, so to be able to generate code on the fly. I need to know if its is possible to pass the output of a method such as getQuery() which in this case is a Document to the input of constructor MsgModule as in the following example:
Document queryDoc =qc.getQuery();
MsgModule mg= new MsgModule(queryDoc);
regards
Charlie

This is possible. What you need to do in the 'new' instance case is to find the best constructor. So let's say you have Class clazz, the class you want to create a new instance of, and Class[] params, an array of objects to pass in the constructor. Using the Class api you can do:
Constructor constructor = clazz.getConstructor(params);The getConstructor method will only return an exact match. Let's say one of the parameters was a subclass of an class that is allowable in the constructor. You can get all the constructors via clazz.getConstructors() and get all the parameters types via Constructor.getParameterTypes() and check to see if the params you passed in are compatible. You can use Class.isAssignableFrom() to help resolve this. Once you find the constructor, use Constructor.newInstance(params) to create the new instance. Hope this helps.

Similar Messages

  • Import statement code generation from Java-Platform Model in Java Studio

    Problem : When you create a Java-Platform Model type project in Java Studio 8.1 and as an example You would like to create an Attribute with java.util.Date type for a Class than how can You set this Attribute type in order to create the Code Generator the standard java package reference in Your code like : "import java.util.Date;" ? What is the right syntax in the "Type'" field of the Attribute Properties dialog ?

    You should also consider using NetBeans as an alternative to JSE8.1.
    Java Studio Enterprise 8.1 is itself built on top of NetBeans version 5.0. NetBeans is an ide developed as opensource at www.netbeans.org; it is extensible ide and so add-on modules can be developed to run on top of netbeans. And that is what JSE8.1 does; JSE 8.1 is NetBeans 5.0 plus several add-on modules (like UML etc).
    The latest stable version of NetBeans is 6.0 and provides improved versions of all relevant addons found in JSE.
    Home page: www.netbeans.org
    Download: http://www.netbeans.info/downloads/index.php
    Docs: http://www.netbeans.org/kb/index.html
    Further community resources (mailing lists, issue tracking etc) : http://www.netbeans.org/community/index.html
    wiki.netbeans.org
    NetBeans download is free. And since it is developed as an opensource project, the source is freely available under CDDL license.

  • CE 7.1 SP3 Code generation for Java 1.4.2

    Hi,
    Is it possible to use the Ce 7.1 SP3 environment to develop components for WAS 6.4 ?. 
    Though I have configured the compiler to be Java 1.4 compliant, the code generated still contains Java 5 constructs and thus will not compile correctly. (e.g. @SuppressWarnings("unused")).
    Thanks

    NO chance.
    Regards,
    Benny

  • HTML code generation with Java

    Hi, I don't know how pertinent it is to ask this question
    whether we have java api anywhere to generate html code.

    You can use any implementation of the xml api (jaxp)
    do generate XML and the new versions of html are xml.
    or you can use Java Server Pages and custom taglibraries like the struts framework for example.
    It really depends on what you want to do exactly...
    create a web application ... store documents as html ...
    Spieler

  • Turn off automatic code generation in Java Studio Creator

    A feature in Java Studio Creator automatically adds getter methods for all managed beans in every Page Bean, getter methods for all Session Beans and Application Beans in every newly created Session Bean and so on.
    What is annoying is if these automatically generated code is commented out or deleted, they are added back again by the IDE.
    We have a large project where the number of managed beans is quite significant. It doesn't make sense to clutter the code for every managed bean with unnecessary getter methods. Is there a way this feature can be disabled?

    I have a similar situation.
    I have a large project with several classes with properties.
    It is convenient to use the 'add properties' option to add a property to the class.
    However, when you do that, it is a private member and you need getter and setter methods to access the private members.
    What I do to get around this is to just create a class and manually add properties as public members so they can be accessed without getter or setter methods.
    By doing this, you expose these members to the world, but for large projects where the classes are not intended to be available for general use, you cut down the generated code by about 80%.
    The other advantage is that you can define all the class members at the start of your class and avoid the problem of having the definition and getter / setter methods concatenated at the bottom of the class.

  • Re: BAR Codes generation through SAP

    Dear All,
    Is it possible to generate BAR Codes in SAP.
    Regards,
    Vivek

    Hi,
    Yes this is possible to print the bar code thorough SAP.
    For KANBAN process SAP has given standard functionality to print the bar code.
    T CODE: PK17.
    For other like bar code on production order print , job ticket print ..........
    is possible. For this first you have to create one form which contains the layout of the print out.
    You can see the std layout though SE17 transaction.
    Barcode is noting but it's one type font like Normal, arial..
    So bar print is possible, please take some help from developer.
    Regards,
    Vijay

  • Calling web service scenario through java console application

    hi all,
    I was able to invoke webservice through XML spy by following this link
    "/people/siva.maranani/blog/2005/09/03/invoke-webservices-using-sapxi
    But in real time environment client may not accept XML spy to run webservice application..So can any assist me how can i send and receive soap requests through Java application.
    If it is not possible by using java , please give reason as well....
    If it possible, please provide a blog or relevent information to the above request.
    Thanks..

    HI,
    This is possible to use from JAVA code , either through Java proxy , or you can directly send to IE.
    See the below links
    Communication between SAP System & Webservice Using Proxies - /people/siva.maranani/blog/2005/05/23/communication-between-sap-system-webservice-using-proxies
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/java/integrating%20web%20dynpro%20and%20sap%20xi%20using%20jaxb%20part%20ii.article
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/10d1bde2-699f-2910-8e86-f46bfe045fdc
    Regards
    Chilla

  • Generic oracle eway code generation error in Java caps 5.1.3

    Hi,
    I'm using an oracle eway for adding records to a table. I have a prepared statement in the otd. When I try to build the project I'm getting the following error. Could any one let me know how this problem can be fixed?
    com.stc.codegen.framework.model.CodeGenException: Generic Oracle eway code generation error(ERROR_CODEGEN_GENERIC_CODELET_GENERAL)
         at com.stc.oracle.codegen.OracleEWayCodeletFactory$OracleEWayCodelet.generateFiles(OracleEWayCodeletFactory.java:1860)
         at com.stc.codegen.frameworkImpl.model.CodeGenFrameworkImpl.processCodelets(CodeGenFrameworkImpl.java:640)
         at com.stc.codegen.frameworkImpl.model.CodeGenFrameworkImpl.process(CodeGenFrameworkImpl.java:1544)
         at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.process(DeploymentVisitorImpl.java:405)
         at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.process(DeploymentVisitorImpl.java:308)
         at com.stc.codegen.frameworkImpl.model.DeploymentVisitorImpl.traverseDeployment(DeploymentVisitorImpl.java:268)
         at com.stc.codegen.driver.module.DeploymentBuildAction.loadCodeGen(DeploymentBuildAction.java:923)
         at com.stc.codegen.driver.module.DeploymentBuildAction.access$1000(DeploymentBuildAction.java:174)
         at com.stc.codegen.driver.module.DeploymentBuildAction$1.run(DeploymentBuildAction.java:599)
         at org.openide.util.Task.run(Task.java:136)
         at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:599)
    Caused by: com.stc.codegen.framework.model.CodeGenException: Exception when generating OTD code ...Exception: javaClass: Oracle_std_otdOTD: Exception when invoke DB Codegen Task...Exception: Invalid parameter type: Class : [Std_insert_PreapredStat] Object: [Param1] Param Type : [DECIMAL].(ERROR_CODEGEN_DB)(ERROR_CREATE_OTD)
         at com.stc.oracle.codegen.OracleEWayCodeletFactory$OracleEWayCodelet.generateOtdJarFile(OracleEWayCodeletFactory.java:2045)
         at com.stc.oracle.codegen.OracleEWayCodeletFactory$OracleEWayCodelet.generateFiles(OracleEWayCodeletFactory.java:1756)
         ... 10 more
    Regards,
    Abdul

    hi...
    i too getting same problem..how did u reslove this...
    please help me out...
    thanks in advance
    KK

  • How to get the source code of an HTML page in Text file Through java?

    How to get the source code of an HTML page in Text file Through java?
    I am coding an application.one module of that application is given below:
    The first part of the application is to connect our application to the existing HTML form.
    This module would make a connection with the HTML page. The HTML page contains the coding for the Form with various elements. The form may be a simple form with one or two fields or a complex one like the form for registering for a new Bank Account or new email account.
    The module will first connect through the HTML page and will fetch the HTML code into a Text File so that the code can be further processed.
    Could any body provide coding hint for that

    You're welcome. How about awarding them duke stars?
    edit: cheers!

  • Running windows command through java code

    Hello
    i want to execute jar.exe through java code , i have written following piece of code , but it isn't working
    ProcessBuilder processBuilder = new ProcessBuilder(new String[]{"cmd.exe","/c","%java_home%\\bin\\jar.exe"});
              Process process = processBuilder.start();
              BufferedReader inputReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
              String line = inputReader.readLine();
              while(line != null){
                   System.out.println(line);
                   line = inputReader.readLine();
    does anybody knows why
    Regards
    Edited by: Mayur Mitkari on Mar 5, 2013 10:19 PM
    Edited by: Mayur Mitkari on Mar 5, 2013 10:20 PM
    Edited by: Mayur Mitkari on Mar 5, 2013 10:20 PM

    sorry for that , but the
    Runtime runtime = Runtime.getRuntime();
              Process proc = runtime.exec(new String[]{"cmd.exe","/c","jar"});
              proc.waitFor();
    int i = proc.exitValue();
    this code was different from first one
    and in case of Process if runtime .exec is succesful it is wainting for long time , in this case i want if the runtime.exec is succesful something should be returned
    Regards

  • Adding rows to J2ME WTK/Settings/User Defined (through Java code)

    Hi all..
    Just a quick question..
    Is it possible to add Key/Value pairs to a MIDlet's 'User Defined' field through Java code..(ie) - add a new row to the User Defined field..
    If not, can anyone tell me how a Bluetooth-Client GUI can save an image it has been sent by a Bluetooth-Server GUI?
    Thanks in advance..
    Rookie

    if i understand you, you want to call application module method when user clicks on add button on the UI and your table is from VO
    so what i can come up for now is:
    1) create variable binding from the iterator for both name and price.
    2) on your UI action button :
    <af:commandButton actionListener="yourbean.addToCart">
    <f:attribute name="pName" value ="binding.<created name bind variable>"
    <f:attribute name="pPrice" value = "binding.<created price bind variable>"
    </af:commandButton>
    3) custom Managed Bean:
    //yourBean.java
    public void addToCart(ActionEvent e){
    // get binding here
    // use executeWitParams method to send parameter to the function "testMethod" and execute
    //AppModuleImp.java
    public void testMethod(String pName,String pPrice) {
    CardVOImpl vo = this.getCartVO1();
    CardVORowImpl r = (CardVORowImpl)vo.createRow();
    r.setAttribute("NAME", pName);
    r.setAttribute("PRICE", pPrice);
    vo.insertRow(r);
    Hope this helps...
    Let me know if not..
    Thanks
    Edited by: MavenDev on Oct 30, 2011 8:08 PM

  • How to Increase Java Heap Size through Java Code. Increase inside Code?

    Hi All,
    I am using a third party tool. When i run a particular program it says OutOfMemory error. I like to increase heap size through Java Code before calling the particular Java application or Code..
    Is there is any way to set the Heap Size through Java Code in run time ???
    Pls Kindly help.
    Thanks.

    if you start the program with a -Xmx512m flag, the virtual machine gets half a gigabyte of memory to use (or that's the max it's allowed to use). All things run in the same virtual machine will have the same limit, third party tools run in the same virtual machine can't "not care about this" unless they're throwing OOMs themselves for some stupid reason.

  • How do I trigger an Oracle report through Java Code?

    Hello,
    I am new to reports. Is there any way to trigger a report through java code - I know there is an OS command to trigger a report automatically. Has anybody done this through a high level PL?
    Amit

    We are in a similar situation. If you receive any answers can you forward the same to [email protected]

  • Problem with executing shell script on linux through java code.

    i am facing problem to kill jboss process on linux that is my application requirement. for that i created one shell script that will get all the process for jboss instance and kill them when i am running that script from command prompt on linux its working perfectly.
    The command i am using ---
    /opt/RW9/jboss/v4.0.5.GA/bin/restartjboss.sh.
    but when i am running through java code its not working.
    the java code i am using is:-
    pp = Runtime.getRuntime().exec(new String[]{"/bin/sh", "-c", "/opt/RW9/jboss/v4.0.5.GA/bin/restartjboss.sh"});
    could anyone tell me what is the problem ?
    Edited by: akm198110 on Sep 2, 2008 9:24 AM

    I got the problem after long struggle ,after doing proper path i am able to execute the shell script..

  • Invoke exe through java code(using java.lang.Runtime)

    Iam trying to invoke an exe from java code.If i give the complete path for that exe it is running fine .But if i set the environment variable and directly execute the exe through command prompt it iss running fine , but it fails to run when i do the same using java code i.e. java.lang.Runtime.exec function

    Give "//" for directory seperator.
    E.g. r.exec("c://test//test.exe",null);
    Why? That doesn't look correct.It is correct. It will work fine. Try it out.But it doesn't add or solve anything. A forward slash
    does not need to be escaped.'
    It's not even escaping. It's just doubling up. If that works, I'd bet "C://///test///////test.exe" does also.

Maybe you are looking for

  • Error while loading data into clob data type.

    Hi, I have created interface to load data from oracle table into oracle table.In target table we have attribute with clob data type. while loading data into clob field ODI gave below error. I use odi 10.1.3.6.0 java.lang.NumberFormatException: For in

  • Cost center wise expense tracking

    Dear all, We are using the reports KSB1 and FBL3N. When selected for a given period, the ammount displayed in both the reports are not tallying. Can anyone tell me the what could be the reason?,also tell me on what condition will KSB1 report get upda

  • Performance of View

    Hi, I have created a complex view A with user defined function as column. Then created another view B by selecting from the previous view. Now when I query the view B the perfornance well but when I use order by clause in the query then the performan

  • To use the transformation process I hear you have to code using OOP, True?

    I've heard that to use the transformation process all update rules, routines must be writtend with OOP and you can't use  the older coding method.  Is this true

  • [Solved]The linux kernel with build in bootloader?

    First of let me apologize if I'm making no sense at all. This isn't really my area of expertise. I just recently stumbled upon some rather interesting "news" about the linux kernel developers working to implement a an EFI/GTP (I think) bootloader in