Object-XML Binding: How do I map from java to enumerated xml tags

Hi. I'm new to Object-XML binding and toplink. XML that I'm trying to model in a schema has enumerated elements, e.g. </module_0></module_1><module_n> instead of many </module> elements. To simplify the schema I've opted to use </module> anyway with unbounded cardinality and imported this into a new project.
What I would like to know is if I can use Toplink to map the java object back to the enumerate element types and vice versa?
Thanks for your help.
GeePee

Hi Geepee,
Below is an approach you can use if you have a fixed number of moduleX elements. In the example below X=3.
Assume a 2 object model Root & Module, where Root has a list of Module instances:
@XmlRootElement(name="root")
public class Root {
    private List<Module> module = new ArrayList<Module>(3);
    ...// Accessors omitted
}It is currently not possible to map the items in the module list to the XML elements (module1-module3), but it would be possbile to map an object (see below) with 3 properties to those XML elements:
public class AdaptedModuleList {
    private Module module1;
    private Module module2;
    private Module module3;
    ...// Accessors omitted
}What is required is a means to convert the unmappable object to a mappable one. This is done using a Converter:
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.mappings.converters.Converter;
import org.eclipse.persistence.sessions.Session;
public class ModuleListConverter implements Converter {
    public void initialize(DatabaseMapping mapping, Session session) {}
    public Object convertDataValueToObjectValue(Object dataValue, Session session) {
        AdaptedModuleList adaptedModuleList = (AdaptedModuleList) dataValue;
        if(null == adaptedModuleList) {
            return null;
        List<Module> moduleList = new ArrayList<Module>(3);
        moduleList.add(adaptedModuleList.getModule1());
        moduleList.add(adaptedModuleList.getModule2());
        moduleList.add(adaptedModuleList.getModule3());
        return moduleList;
    public Object convertObjectValueToDataValue(Object objectValue, Session session) {
        List<Module> moduleList = (List<Module>) objectValue;
        if(null == moduleList) {
            return null;
        AdaptedModuleList adaptedModuleList = new AdaptedModuleList();
        int moduleListSize = moduleList.size();
        if(moduleListSize > 0) {
            adaptedModuleList.setModule1(moduleList.get(0));
        if(moduleListSize > 1) {
            adaptedModuleList.setModule2(moduleList.get(1));
        if(moduleListSize > 2) {
            adaptedModuleList.setModule3(moduleList.get(2));
        return adaptedModuleList;
    public boolean isMutable() {
        return true;
}The converter is added to the mapping metadata through the use of a Customizer:
import org.eclipse.persistence.config.DescriptorCustomizer;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping;
import org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping;
public class RootCustomizer implements DescriptorCustomizer {
    public void customize(ClassDescriptor descriptor) throws Exception {
        XMLCompositeCollectionMapping originalModuleMapping = (XMLCompositeCollectionMapping) descriptor.removeMappingForAttributeName("module");
        XMLCompositeObjectMapping newModuleMapping = new XMLCompositeObjectMapping();
        newModuleMapping.setAttributeName(originalModuleMapping.getAttributeName());
        newModuleMapping.setXPath(".");
        newModuleMapping.setReferenceClass(AdaptedModuleList.class);
        newModuleMapping.setConverter(new ModuleListConverter());
        descriptor.addMapping(newModuleMapping);
}Part 1/2

Similar Messages

  • How to invoke Matlab from Java

    Hi, I want to pass some data generated from Java class to Matlab, then invoke Matlab from Java to run the computation program (file written in Matlab, myfile.m). I know Matlab can use classes generated from Java, how to drive Matlab from Java?
    I appreciate your help!
    yaya

    According to their documentation, you can't. Having said that, again according to their documentation, there are plans to support this in future releases.
    m

  • How to initiate process from Java?

    Hello,
    Does anyone knows how to initiate Process from java code???
    or Which API can start a new instance of Business process??

    If you are on Oracle BPM 10g, here's a link to a thread on this forum that might also help. It is a step-by-step.
    Creating a new work item instance in a process using PAPI
    Dan

  • How do i map from file name to the device it resides on

    hi
    i need to find a way to map from a file name to the disk device it resides on( so i can do ioctl to that device ).
    i know that stat(2) returns a dev_t value, but i don't know how to translate from that dev_t to the device name( e.g. /dev/dsk/c0d0... )
    THANKS
    Gabriel

    thanks for the reply,
    i'm using a similar mechnisem on linux - using getmntent(3) to find the longest prefix of the filename realpath(3).
    i was actually looking for a mechnisem similar to the devname(2) syscall on the BSD os. with this call the kernel do all the work for you simply by mapping from dev_t( which the kernel stored in the indoe) to the device name by keeping a simple mapping table.
    if this mechinsem doesn't exists i will have to (eventually) duplicate the kernel work(namei) and create my own mapping.
    THX
    gabriel

  • Oracle XML Gateway How to download .xgm from the database

    I am trying to find the utitlity called DownloadMap.java to dowload the .xgm mapping from the database as stipulated in the Oracle XML Gateway Users Guide. I am not able to find this utility and could not get any leads.
    Our requirement is to extend the seeded outbound invoice mappings to add additional data elements before generating XML document.
    We will appreciate if any lead or explanation is provided by our community.
    Looking forward for a voice in our community in this regard.
    Thank you,
    Jothiram

    This post is to the wrong Forum, try the XML forum

  • How to call xsl from java?

    Hi All,
    My main java class 'OrderCustomerEntry' is located in package 'Order.Profiles.Customer'
    I have my xml input stored in a String object. Now I have stored a xsl in the same package 'Order.Profiles.Customer'.
    I make certain updations to my xml. After that, I have to call a xsl, which will finally do some transformations on my xml.
    Kindly tell me how to call this xsl file from java.
    Thanks,
    Sabarisri. N
    Edited by: Sabarisri N on Oct 11, 2011 11:15 AM

    This can be complicated with many factors coming into play. Suppose everything is set up in good order, if the xsl is stored in the jar containing the package Order.Profiles.Customer at its root. That means, the jar has some structure like this:
    Order/Profiles/CustomerOrderCustomerEntry.class
    META-INF/...
    xyz.xsl
    etcYou may try this when load it up.
    String xslFile="xyz.xsl";
    //tf being the factory
    Transformer transformer = tf.newTransformer(new StreamSource(ClassLoader.getSystemResourceAsStream(xslFile)));The change with respect to the case where the xslFile is in the current directory is the ClassLoader part.
    Suppose it is stored in a resource directory say "res".
    Order/Profiles/CustomerOrderCustomerEntry.class
    META-INF/...
    res/xyz.xsl
    etcThe corresponding lines would look like this.
    String xslFile="res/xyz.xsl";
    //tf being the factory
    Transformer transformer = tf.newTransformer(new StreamSource(ClassLoader.getSystemResourceAsStream(xslFile)));Hopefully, this may be enough to get you going...
    ps: Although no one should force anyone on the way to name packages, the majority in the industry uses all lowercase characters whenever possible.

  • How to return sdo_geometry from java procedure

    How can I return a SDO_GEOMETRY object from a java-stored-procedure to PL/SQL.
    I have a java class with methods that creates a specific polygon based on some user values. I want to return this polygon as a SDO_GEOMETRY object to a PL/SQL procedure.
    JDeveloper does not accept SDO_GEOMETRY as a return type.
    Can this be done?

    Justin,
    I have a PL/SQL package that contains several functions. One of them does selection and filtering of spatial features based on a user's location and preferences. For this purpose a web-application runs this function.
    I would like this function to do the following:
    1. the function is called, user parameters are passed in
    2. a call to a java-stored-procedure is made. This java procedure creates a polygon based on the user's location and preferences.
    3. the polygon is returned to the PL/SQL function
    4. the funtion uses the returned polygon to query spatial features that intersect, etc.
    I can do the call to the java-stored-procedure but where I get stuck is how to get the polygon from java to pl/sql. I can return a String or a number from java but how can I return the polygon (e.g., STRUCT, java object)?
    The current solution uses a work-around by storing the polygon in a temporary table. I would like to change this because once the function has run, the polygon is not needed anymore so I would like to do without having to store the polygon.
    Markus

  • How to invoke javafx from java code

    hi all,
    i'm trying to invoke my .fx class from java class, but getting exception.
    Exception thrown in JavaFX pretty printing: java.io.FileNotFoundException: \tmp\___FX_SCRIPT___.fxdump from StringInputBuffer (The system cannot find the path specified)
    Exception thrown in JavaFX pretty printing: java.io.FileNotFoundException: \tmp\___FX_SCRIPT___.fxdump from StringInputBuffer (The system cannot find the path specified)
    javax.script.ScriptException: compilation failed
    at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.parse(JavaFXScriptEngineImpl.java:255)
    at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:145)
    at com.sun.tools.javafx.script.JavaFXScriptEngineImpl.eval(JavaFXScriptEngineImpl.java:136)
    at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:247)
    at myclockproject.Main2.main(Main2.java:34)
    I read in article http://java.sun.com/developer/technicalArticles/scripting/javafx/javafx_and_java/ about including javafxc.jar in classpath .. could some one tell me what classpath he meant, i have included it in my environment variable and also project libraries .. still getting error :(

    coolsayan.2009 wrote:
    thanx.is communication api required?but is the communication api available for windows?its available for linux and sparc??Are you referring to the COMM API that is referenced in the first link when you google - the one entitled "How to Send SMS using Java Program (full code sample included)"? If so, Here: [http://java.sun.com/products/javacomm/|http://java.sun.com/products/javacomm/]
    what to do in serverside?is any change required in web.xml or any jndi setup in serverside if i call the java class from a jsp page?I don't know, are you planning on making your class available through JNDI?

  • How to call webservice from Java application

    Hi XI gurus
    Pls let me know how to call a webservice from Java application.
    I wanted to build synchronous interface from Java Application to SAP using SAP XI
    For example, i need to create Material master from Java application and the return message from SAP, should be seen in Java application
    Regards
    MD

    Hi,
    If your  JAVA Application is Web based application, you can expose it as Webservice.
    JAVA People will pick the data from Dbase using their application and will send the data to XI by using our XI Details like Message Interface and Data type structure and all.
    So we can Use SOAP Adapter or HTTP in XI..
    If you use HTTP for sending the data to XI means there is no need of Adapter also. why because HTTP sits on ABAP Stack and can directly communicate with the XI Integration Server Directly
    If you are dealing with the Webservice and SAP Applications means check this
    Walkthrough - SOAP  XI  RFC/BAPI
    REgards
    Seshagiri

  • How to set classpath from java class ??

    I have tried to use System.setProperty("java.class.path", "my class path string ") to set classpath dynamically. But it is not working. How to set it dynamically from java class ?? Thanks , gary

    Look into the java.net.URLClassLoader. You can't set the classpath after the fact but you can specify URL's that will checked when you try to load a class with that loader.

  • How to execute commands from Java

    hi,
    i m trying to execute a CVS command from a java environment. i m writing this code to create a user. for this i m executing this cvs command "cmd /c cvs passwd -r <username> -a <new-username>"
    after executing this cmd the command prompt will prompt for a pasword and then after entring the password i have to retype the password for confirmation. the existing code execcutes the command but i don t know how to read the prompt for password.
    <code>
    import java.io.*;
    import java.lang.*;
    public class first {
    public static void main(String[] args) {
    try {
    Process p = Runtime.getRuntime().exec("cmd /c cvs passwd -r gopalakrishnan_k -a ram");
    InputStreamReader reader=new InputStreamReader(System.in);
    BufferedReader OptFromCmd = new BufferedReader(new InputStreamReader(
    p.getInputStream()));
    BufferedReader fromKeyboard = new BufferedReader(reader);
    BufferedReader stdError = new BufferedReader(new InputStreamReader(
    p.getErrorStream()));
    OutputStream stdOut = p.getOutputStream();
    String s;
    String pswd = "mahesh";
    System.out.println("Success");
    int i = 0;
    while ((s = OptFromCmd.readLine()) != null) {
    //s = OptFromCmd.readLine();
    i++;
    System.out.println(s);
    System.out.println(i);
    if (i > 1) {
    stdOut.write(pswd.getBytes());
    stdOut.flush();
    System.out.println(
    "Here is the standard error of the command (if any):\n");
    while ((s = stdError.readLine()) != null) {
    System.out.println(s);
         /* Your Password Here */
         String password="Password Please";
         stdOut.write(password.getBytes());
    stdOut.flush();
         stdOut.write(password.getBytes());
    stdOut.flush();
         /* Your Password here */
    OptFromCmd.close();
    stdError.close();
    stdOut.close();
    } catch (Exception e) {
    e.printStackTrace();
    </code>
    [o/p]
    this program gives the output as
    adding the user <username>
    password:
    now i need to enter the password from java envronment and provide it in the command prompt .
    then it prompts for the password again for confirmation so i have to retype the password again
    how to acheive this.

    String abc[]={"sh","-c","/dir1/dir2/dir3/scanVirus/uvscan --clean -- delete --exit-on-error ../*.*>abcde.txt"};
    Runtime runtime = Runtime.getRuntime();
    Process p = runtime.exec(abc);
    when it founds any infected file the process is not terminated correctly and it gives the following error :
    "java.lang.Exception: Process failed to terminate correctly"
    but it deletes the infected file.
    and running the program second time (after deletion of infected file), it executed fine.
    Wating for help.
    Regards,
    Sundeep.

  • Clear text  password - how to send it from java.

    I am trying to reset the password of a user from java.
    So I have to open a socket connection to Unix box and send a packet in following format
    "<adminUserid> <adminPassword> PASSWORD <target-userId> <new-passwd>\n"
    So they say that user credentials are to be send in cleartext
    Please tell me how i can send above string as cleartext
    thanks in advance.
    Renjith.

    But this is not working for me , UNIX gurus please help
    import java.net.InetAddress;
    import java.net.Socket;
    import java.net.UnknownHostException;
    import java.io.BufferedWriter;
    import java.io.OutputStreamWriter;
    import java.io.IOException;
    public class TestUnix {
    public static void main(String args[] ) {
         try {
                 InetAddress addr = InetAddress.getByName("x.x.x.x");
                 int port = 6546;
              System.out.println("Address IP : "+addr);
                 // This constructor will block until the connection succeeds
                 Socket socket = new Socket(addr, port);
              BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
              String command = "<Admin><admin-pwd>PASSWORD<user><user-pwd>\n";
              System.out.println(command);
                     wr.write(command);
                 wr.flush();
              socket.close();
              System.out.println("Finished executing");
             } catch (UnknownHostException e) {
             } catch (IOException e) {
    }

  • How to View Tables from java side from NWDS/NWDI?

    HI All,
    I want to view the following tables from java side
    CRM_ISA_ADDRESS
    CRM_ISA_BASKETS
    CRM_ISA_BUSPARTNER
    CRM_ISA_EXTCONFIG
    CRM_ISA_EXTDATHEAD
    CRM_ISA_EXTDATITEM
    CRM_ISA_ITEMS
    CRM_ISA_OBJECTID
    CRM_ISA_SHIPTOS
    CRM_ISA_TEXTS
    How can I view them using NWDS/NWDI?
    Which DC has this tables?
    Could you please help me with the procedure to view them?
    Thanks and Regards,
    Gauri

    Hi All,
    crm/isa/isacoreddic and crm/isa/shopddic in SAP-CRMDIC are having these tables.
    Thanks and Regards,
    Gauri

  • How to pass session from Java to Perl

    Hi,
    I need to pass a session value from Java to Perl, does anyone knows how can I do it?
    Thanks

    If you want to run java code from Perl, and have it return a single value, that's one thing: but having Perl interact with java code - calling methods, returning values - that may not be possible.
    Look into python to see if it may be what you're looking for. It's a scripting language that allows real interaction with java.
    If all you want to do is run java code and have it return some data, that would be trivial, so I assume that's not what you mean. But in case it is heres an idea:
    Set up a network connection between them with your own protocol, seeing as both languages are good at networking.

  • How to call javascript from java application

    How can we call a function written in javascript from java application (core java not applet)? How will java identify javascript?
    Is there any such options ?

    Try creating a page called launcher.html (for example). That does this:
    <html>
    <head>
    <script language="javascript">
    windowHandle=window.open("http://www.javasoft.com", "", "height=700,width=1000,status=no,scrollbars=yes,resizable=yes,toolbar=no,menubar=no,location=no,top=5,left=5");
    </script>
    </head>
    </html>Now you launch IE (or whatever) with this page using the Runtime class. After x seconds (after the second window has been launched) try killing the process. Hopefully it will kill the original window you opened and not the window you popup (the one without toolbars etc)
    It might kill both windows but I can't be bothered to test it. If it does you'll have to try and find a workaround.

Maybe you are looking for