Mapping Generated JAXB Classes to JAVA Classes

Hi,
i�m writing a framework to allow building swing components from xml files. So i use JAXB to generate the stubs and then in
my JAVA app i do an unmarshal process to get the jaxb elements. Then i process all the elements in the jaxb tree and
i create the corresponding swing components (i.e. JPanel, GridLayout, JButton, JTextField, etc). This is very annoying,
since each component has different properties and this leads to many if statements which just make my code messy
and not reusable.
Could someone give me an advice of how i could make this solution more elegant?
Thanks for any ideas,
Chris

Hi,
Can you please let me know if you found a solution? I have the same exact problem. I have pretty solid collection of similar questions in the NET, but not a single answer yet... Keep searching...
Thanks!
Rouben.
P.S can you please CC your answer to [email protected]?

Similar Messages

  • Generate XML Schema from Java classes?

    Hi,
    Considering an XML Mapping, i would like to generate a default XML Schema from my Java class.
    Is there a tool in toplink (10.1.3) to do that or does anyone have an easy way to generate this XML schema?
    Thanks,
    Ludovic

    Hi Ludovic,
    We don't have support for schema generation from Java classes in TopLink 10.1.3. It's required for JAXB 2.0 so it will be available in a future release.
    --Shaun                                                                                                                                                                                                                                                                                                                                                                           

  • Generating database tables from Java classes

    Hi,
    I've encountered a number of tools which will create Java classes from database tables (e.g. JDeveloper has this functionality, Abator provides this for iBATIS, etc...).
    However, I've not been able to locate any tools that perform the opposite job - i.e. given a Java class, it generates a database table (or, presumably, some SQL).
    It's been suggested to me that Hibernate might provide this sort of capability, but if anybody has any experience of doing this, in any tool, I'd be interested to hear about it.
    Thanks,
    Alistair.

    Many thanks for the pointers.
    duffymo: I've taken a look at Middlegen (http://boss.bekk.no/boss/middlegen/index.html) but it seems that the first step is to specify the database schema, whereas I'm looking to generate the schema from existing code. Or have I missed something?
    Alistair.

  • Wscompile generating SOAPElement vs. Java class

    Given this part of a wsdl file:
    <xs:complexType name="structXyz">
       <xs:sequence minOccurs="1" maxOccurs="unbounded">
               <xs:element name="numberTelephone" nillable="false">
                          <xs:simpleType>
                                       <xs:restriction base="xs:string">
                                                     <xs:length value="10"/>
                                      </xs:restriction>
                          </xs:simpleType>
                </xs:element>
        </xs:sequence>
    </xs:complexType>wscompile doesn't generate a Java classes as expected. Instead, I get just a holder class that uses javax.xml.soap.SOAPElement.
    Removing the minOccurs and maxOccurs results in Java classes, but that's not an option since the wsdl is from a web site not under my control.
    Is there an issue/problem with occurs attributes on a <sequence> element?

    Actually, neither of your answers is correct.
    TextBox.getClass() doesn't work because getClass() is not a static method (in my actual code, I don't want to instantiate a class just to get the Class reference).
    TextBox.class is a proper class literal and should work (and does with CLDC1.1).
    I just need help working around an apparent bug in NetBeans, JDK1.4, or WTK2.1 where it doesn't work when compiling for CLDC1.1.

  • JavaDoc HTML link of  classes in Java class diagram not correct

    Hi,
    I created a Java class diagram in a certain package (e.g. com.mycompany.p1) and placed some classes on this diagram from the same package and from other packages. Then I created JavaDocs. When I click on the classes in the created JavaDoc diagram, only the links of the classes in the same package as the diagram (com.mycompany.p1) wor correctly. When I click on a class outside this package I get an error message that the file is not found. It looks for the class documentation in the package of the diagram and this is obviousely wrong!
    Is there a property I missed to set or is it a bug?
    Thanks for help
    Thomas

    Hi Thomas,
    I don't use the diagrammers much, so I cannot comment on this directly; however, based on your description, it does sound like a defect. Do you have access to Oracle Support to file an SR?
    John

  • Generate sql from mappingtool java class

    I have been trying without any luck to get the MappingTool.run(...) method
    to generate an SQL update script. To do this I figure that I need to
    specify the "sqlWriter" parameter as a valid FileWriter. But the file
    mappingtool generates is always empty. Any hints/clues?
    Note that I have no problem generating the sql files from ant or commandline
    by specifying -sql xxx.sql
    Here is my calling code...
    Writer dest = new FileWriter(...);
    boolean ok =
    MappingTool.run(
    this.getJDBCConfiguration(), // JDBCConfiguration
    MappingTool.ACTION_BUILD_SCHEMA, // action
    this.getResourceKeys().getJDOResourceFileNames(), // jdo file names
    null, // mappingWriter
    SchemaTool.ACTION_ADD,// schemaAction
    false,// dropTables
    false,// ignoreErrors
    true, // readSchema
    true, // include pks
    true, // include fks
    true, // include indexes
    null, // schemaWriter
    dest, // sqlWriter
    this.getClass().getClassLoader() // class loader
    Cheers and thanks.
    ..droo.

    Does the schema already exist? If so, SchemaTool.ACTION_ADD won't do
    anything (nothing to add). Try SchemaTool.ACTION_BUILD

  • Tool for Reversing (.class to .java classes)

    Can somebody tell me about an open soft tool for reverting code.
    Thanks.
    FS

    java decompiler. Try google. There are dozens of them.

  • Java Mapping Error - Unable to instantiate the Java class

    Hi,
    I am trying out a Java Mapping scenario.
    The code worked fine in eclipse.i could get the desired output.
    but when i tried it out in XI ....i got the following error in moni:
    *Unable to instantiate the Java class*
    <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
    - <!--  Request Message Mapping
      -->
    - <SAP:Error xmlns:SAP="http://sap.com/xi/XI/Message/30" xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/" SOAP:mustUnderstand="">
      <SAP:Category>Application</SAP:Category>
      <SAP:Code area="MAPPING">CANNOT_INSTANCIATE_CLASS</SAP:Code>
      <SAP:P1>JavaMapping</SAP:P1>
      <SAP:P2>http://www.sdsdsd.com/XI/Sales/T~</SAP:P2>
      <SAP:P3>3bd13b30-6300-11dc-b9f1-f0050aa5c91a</SAP:P3>
      <SAP:P4>-1</SAP:P4>
      <SAP:AdditionalText />
      <SAP:ApplicationFaultMessage namespace="" />
      <SAP:Stack>Unable to instantiate the Java class JavaMapping (http://www.sdsdsd.com/XI/Sales/T~, 3bd13b30-6300-11dc-b9f1-f0050aa5c91a, -1)</SAP:Stack>
      <SAP:Retry>M</SAP:Retry>
      </SAP:Error>
    Please help me out with this error.

    Hi Anu,
    Currently I am also facing the same Unable to instantiate the Java class  same java class is working fine in eclipse .
    Could you please confirm Is this because of version mismatch that in Eclipse JAVA and SAP JAVA ?
    Thanks in Advance.
    Best,
    Srinivas

  • Sql type to Java class?

    I want to write a utility class to generate a java source file (bean) from out of the metadata of a database table. the metadata returns the column type as a java.sql.Types constant (int value). now, i want to map these int values to Java classes. (e.g. Types.INT => java.lang.Integer). Is there already such a method in the API or do i have to write my own switch ... case Types.INT ... result = Integer.class ... method?

    well, i wrote my own utility method to generate such beans:
         * Convert SQL type code to corresponding Java class.
         * @param sqlType One of java.sql.Types.xxx.
         * @return Class that corresponds to the given type.
        public static Class toClass(int sqlType) {
            Class result = null;
            switch (sqlType) {
            case Types.BIGINT :
            case Types.INTEGER :
            case Types.SMALLINT :
            case Types.TINYINT :
                result = Integer.class;
                break;
            case Types.BIT :
            case Types.BOOLEAN :
                result = Boolean.class;
                break;
            case Types.CHAR :
                result = Character.class;
                break;
            case Types.DATE :
            case Types.TIMESTAMP :
                result = java.util.Date.class;
                break;
            case Types.DECIMAL :
            case Types.DOUBLE :
            case Types.FLOAT :
                result = BigDecimal.class;
                break;
            case Types.NULL :
                result = null;
                break;
            case Types.LONGVARCHAR :
            case Types.VARCHAR :
            default :
                result = String.class;
                break;
            return result;
        }//toClass()
         * Create a Java bean (source file) to map a database table. The class name is the table name, the bean
         * properties are the table columns. Each column will result in a property with a corresponding set() and
         * get() method.
         * @param connection Database connection to load table from.
         * @param schema Schema to get tables for.
         * @param tableName Name of table to create the bean for.
         * @param className Name of Java class to create.
         * @param fileName Name of Java source file to create.
         * @throws SQLException, IOException
        public static void createTableBean(Connection connection, String schema, String tableName, String className, String fileName)
                throws SQLException, IOException {
            if (connection != null && tableName != null && fileName != null) {
                //read table columns:
                DatabaseMetaData dmd = connection.getMetaData();
                ResultSet resultSet = dmd.getColumns(null, "%", tableName, null);
                Properties props = new Properties();
                if (resultSet != null) {
                    while (resultSet.next()) { //for each table
                        String name = resultSet.getString("COLUMN_NAME");
                        int type = resultSet.getInt("DATA_TYPE");
                        props.setProperty(name, ""+type);
                    }//next table
                }//else: resultSet unavailable
                //create source file:
                File file = new File(fileName);
                StringBuffer sb = new StringBuffer();
                sb.append("/* $Header:$ */\n");
                sb.append("package TODO;\n\n");
                sb.append("/**\n");
                sb.append(" * Container class to store data of one record (row) of table '"+tableName+"'.\n");
                sb.append(" *\n");
                sb.append(" * @version $Revision:$ ($Date:$)\n");
                sb.append(" * @author $Author:$\n");
                sb.append(" */\n");
                sb.append("public class ");
                sb.append(className);
                sb.append(" {\n\n");
                Enumeration enum = props.keys();
                StringBuffer sb2 = new StringBuffer(); //methods
                StringBuffer sb3 = new StringBuffer(); //toString()
                while (enum.hasMoreElements()) {
                    String columnName = (String) enum.nextElement();
                    //change first character of column name to lower case:
                    String fieldName = columnName.substring(0, 1).toLowerCase() + columnName.substring(1);
                    String stype = props.getProperty(columnName, ""+Types.VARCHAR);
                    int type = (new Integer(stype)).intValue();
                    Class javaClass = toClass(type);
                    String typeName = "String"; //default
                    if (javaClass != null) {
                        String javaClassName = javaClass.getName();
                        int lastDot = javaClassName.lastIndexOf('.');
                        if (lastDot >= 0) {
                            typeName = javaClassName.substring(lastDot + 1);
                    //field:
                    sb.append("    /** ");
                    sb.append(columnName);
                    sb.append(" */\n");
                    sb.append("    private ");
                    sb.append(typeName);
                    sb.append(" ");
                    sb.append(fieldName);
                    sb.append(" = null;\n");
                    //toString() method:
                    sb3.append("        sb.append(\",");
                    sb3.append(fieldName);
                    sb3.append("=\");\n");
                    sb3.append("        sb.append(");
                    sb3.append(fieldName);
                    sb3.append(");\n");
                    //set method:
                    sb2.append("    /**\n");
                    sb2.append("     * Set ");
                    sb2.append(columnName);
                    sb2.append(".\n     *\n     * @param value ");
                    sb2.append(columnName);
                    sb2.append(" to set.\n");
                    sb2.append("     */\n");
                    sb2.append("    public void set");
                    sb2.append(columnName);
                    sb2.append("(");
                    sb2.append(typeName);
                    sb2.append(" value) {\n        ");
                    sb2.append(fieldName);
                    sb2.append(" = value;\n    }\n\n");
                    //get method:
                    sb2.append("    /**\n");
                    sb2.append("     * Get ");
                    sb2.append(columnName);
                    sb2.append(".\n     *\n     * @return ");
                    sb2.append(columnName);
                    sb2.append(".\n     */\n");
                    sb2.append("    public ");
                    sb2.append(typeName);
                    sb2.append(" get");
                    sb2.append(columnName);
                    sb2.append("() {\n");
                    sb2.append("        return ");
                    sb2.append(fieldName);
                    sb2.append(";\n    }\n\n");
                }//next column
                sb.append("\n\n");
                sb.append(sb2.toString()); //methods
                //overwrite toString() method:
                sb.append("    /**\n");
                sb.append("     * Overwrite super.\n");
                sb.append("     *\n     * @return String representation of the object.\n");
                sb.append("     */\n");
                sb.append("    public String toString() {\n");
                sb.append("        StringBuffer sb = new StringBuffer(super.toString());\n\n");
                sb.append(sb3.toString());
                sb.append("\n        return sb.toString();\n");
                sb.append("    }\n\n");
                sb.append("}//"+className);
                //write to file:
                String text = sb.toString();
                BufferedWriter bw = null;
                try {
                    bw = new BufferedWriter(new FileWriter(file));
                    bw.write(text, 0, text.length());
                } finally {
                    if (bw != null) {
                        try { bw.close(); } catch (IOException ioe) { /* ignore */ }
            }//else: input unavailable
        }//createTableBean()

  • How to produce Java class from xsd programmatically?

    As titled, I want to generage Java class/interface from xml schema via a program. There is a tool "xjc" that can do this manually.
    I saw a sample that generates xsd file from Java class programmatically, I am figuring out if there is such a API to do the similar thing vice versa.
    Thank you in advance!

    You may want to check out this Java EE 5 Tutorial: http://docs.oracle.com/javaee/5/tutorial/doc/bnbah.html
    It has an example of generating JAXB Java classes from an XML schema.
    Can you provide a sample xsd schema and the resulting Java class/classes you want to have produced?
    XMLBeans can use an xsd and generate Java classes for containing/manipulating XML objects, though I don't think that is what you are wanting.
    You can also write an XSLT stylesheet that generates Java classes based on parameters that you provide to the stylesheet but there is no xsd schema involved. We used this at a major national bank to produce Java classes for batch processing of files sent/received between the bank and third pary companies. The Java classes generated were used to read/write delimited files, xml files and fixed format files to/from Java bean classes with the necessary getters/setters for manipulating the data.
    Without a sample of what you are trying to doi it is hard to offer much help.

  • How get ddl of JAVA CLASS? dbms_meta.get_ddl do not work with java_source

    hi all,
    i can not generate the DDL of java class in 10g r2 as below.
    sys@RPTDB > select dbms_metadata.get_ddl('JAVA_SOURCE','BRStatus','HDADMIN') from dual;
    ERROR:
    ORA-31603: object "BRStatus" of type JAVA_SOURCE not found in schema "HDADMIN"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.DBMS_METADATA", line 2806
    ORA-06512: at "SYS.DBMS_METADATA", line 4333
    ORA-06512: at line 1
    actually, the object exists.
    sys@RPTDB > select object_name,object_type,owner from dba_objects where object_name='BRStatus';
    OBJECT_NAME OBJECT_TYPE OWNER
    BRStatus JAVA CLASS HDADMIN
    thanks for any inputs.

    sys@RPTDB > select dbms_metadata.get_ddl('JAVA SOURCE','BRStatus','HDADMIN') from dual;
    ERROR:
    ORA-31600: invalid input value JAVA SOURCE for parameter OBJECT_TYPE in
    function GET_DDL
    ORA-06512: at "SYS.DBMS_METADATA", line 2682
    ORA-06512: at "SYS.DBMS_METADATA", line 2733
    ORA-06512: at "SYS.DBMS_METADATA", line 4333
    ORA-06512: at line 1
    no rows selected
    did you really get right results with JAVA SOURCE? my version is 10g r2

  • Scope of java class used for building data control

    Hello,
    I have tried a sample application where in we are using Datacontrols to render the UI.
    The data control is generated off a simple java class(abc.java) which is used to render a "Page called - Employee". This java class then uses a session bean which in turn talks with the database entities. The database entities(POJO's - employee.java) are then exposed in the abc.java and used to display data on the UI such as employee name, id , etc.
    My question is regarding the scope of abc.java. I presume, that the constructor of this class will be called when the page is rendered.
    Now say i am navigating from some Page-A to Page-Employee. On click of a button in Page A, i want to go to the Database, retrieve a particular employee's details and then place it in the employee entity exposed in abc.java so that it gets displayed when Page-Employee is rendered.
    If the actionlistener method of the button click in Page A has the code of - 1)create new instance of abc - new abc() 2)retrieve employee entity 3) set employee entity in the class level attribute of abc
    But on going to the next page-employee, a new instance of abc is getting created and i am losing the employee that i had retrieved in the previous screen.
    Is there a scope for abc that can be set somewhere similar to managed beans? or is there some other solution.
    -thanks

    Hi,
    Say, on an 'employee create page' we use data controls which are generated from a java class, 'EmployeeService'.
    This java class has the POJO(entity) - Employee whose attributes like name, description are used to create input text boxes on the employee page.
    Now, assume we come to the Employee create page from some other page in the application; where exactly is the best place to make an instance of the employee entity.
    Do we place- Employee emp = new Employee(); in the constructor of the EmployeeService.java class or is there some other way?
    Any pointers would help.
    Thanks
    Edited by: user9935204 on Feb 4, 2010 8:44 PM

  • How can I either move or view the source of a JAVA CLASS user object?

    I am using Oracle 8i and I have the following JAVA CLASS objects in my database. I need to move some of these objects to a different database.
    1) How can I do this?
    2) How can I view the JAVA source code since these are classes?
    My knowledge of Oracle is limited. I have searched and searched and I can't find the answer. Any help would be greatly appreciated
    SELECT object_name, object_type
    FROM user_objects
    WHERE object_type IN ('JAVA SOURCE', 'JAVA CLASS', 'JAVA RESOURCE')
    ORDER BY object_type, object_name;
    OBJECT_NAME OBJECT_TYPE
    /d082321a_DpsJarStaticFilename JAVA CLASS
    DirHelperStatic JAVA CLASS
    DirHelperStatic$1 JAVA CLASS
    DpsJar JAVA CLASS
    DpsJarException JAVA CLASS
    DpsJarStatic JAVA CLASS
    FilenameFilterImpl JAVA CLASS
    FtpClient JAVA CLASS
    FtpClient$InputStreamProxy JAVA CLASS
    FtpClient$OutputStreamProxy JAVA CLASS
    FtpClientStatic JAVA CLASS
    FtpException JAVA CLASS
    FtpReply JAVA CLASS
    FtpTest JAVA CLASS
    LoadXml JAVA CLASS
    LoadXmlStatic JAVA CLASS
    UrlFileUtils JAVA CLASS
    Utils JAVA CLASS
    dir JAVA CLASS
    Thanks,
    Brian

    The source far java class objects that are not derived from java source objects
    (which is the case here, and is typically the case, such as when one loads
    classes into the database using loadjava on a jar that contains only .class
    files) does not exist in the database (just as it does not exist in a jar which
    contains only .class files). So there is essentially no way to view the source, short of extracting the bytecodes and using some decompiling tool. I don't recall what methodologies exist for extracting bytecodes in 8i. As for transferring
    the classes to another database, the standard Oracle import/export tool can do this.

  • NetBean - java class add to JFrame form?

    i have already type my own class using 'java class type' . The problem is, now i wanted to add a new class using the GUI in netbeans, so i create a JFrame using GUI in netbean, how do i connect the 'java class type' with the 'JFrame Form type' in netbean?
    I'll be able to call a frame to another frame if i using both JFrame form type. The problem came in when i try to link the java class i just mention above. Please help.

    karhong,
    Sorry mate, your question is impossible to interpret. Try asking your question again in different words... and include your code, and error any message(s)...
    ... and read the Formatting tips before you post.
    ... and this is a Java coding forum... so you might have better luck posting this one on a netbeans specific forum like JGuru's Netbeans Forum.

  • Call Bean from normal java class

    Dear Friends,
    Is it ok to call an entity bean or session bean frm normal Java class.
    (Java class is in the same application as the beans).
    Is there a special way to lookup the beans from normal java classes.
    Thanking You,
    Chamal.

    it is ok and very commonly done.
    Note that the simple java program must be running in the same local network. You cannot have the java program and EJBs distributed over internet. (I m not certain of it, but mostly I shoudl be correct. If you have the resources, try it out and let me know)
    In most of the cases, EJBs are called by
    1. A servlet
    2. Another EJB
    3. a simple java program.
    In the first 2 cases, you can go for Local Interfaces (more so in the second case than the first). The reason being that the the client and server will be in the same JVM (typically the Application server). Thus, in the first case, if the Web container and the ejb container are in the same app server, EJBs can be local.
    However, in the third case, it is unlikey that you will have the client runnng and the same jvm as the server, because the app server has its own jvm.
    sample code (this method is being called from the main method of a simple java program. it is self explanatory):
    public  void processRequestForSessionBean()
             System.out.println("REQUEST RECEIVED");
             try
                   Hashtable nameHashtable = new Hashtable();
                   nameHashtable.put( Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory" );
                   nameHashtable.put( Context.PROVIDER_URL, "t3://localhost:7001" );
                   InitialContext context = new InitialContext(nameHashtable);
                   System.out.println("created initial context");
                   Object lookupObject = context.lookup("CustomerBean");
                   System.out.println("Got the lookup object");
                   CustomerDataHome home = (CustomerDataHome) PortableRemoteObject.narrow(lookupObject,
                             Class.forName("com.shiv.business.CustomerDataHome"));
                   System.out.println("Home interface");
                   customerData = home.create();
                   System.out.println("Remote Interface");
                   addDataToSB(customerData);
                   ArrayList namesList = customerData.getNames();
                   System.out.println(namesList.toString());
                   //customerData.remove();             
              catch (Exception exception)
                   System.out.println("FATAL ERRORS");
                   exception.printStackTrace();
              }

Maybe you are looking for