Casting List to Array of Unknown SubClass

How do I cast a java.util.List to an array of a unknown subclass of a known parent class?
Parent[] parents = someMethod();
// someMethod returns ChildA[] or ChildB[] both extends Parent and are unknown to this method
List list = new Vector();
for (int i=0;i<parents.length;i++) {
  if (parents.someBoolean)
    list.add(parents[ i ]);
return (Parent[])list.toArray(?????);
// return (Parent[])list.toArray(new Parent[]{});
// Not of the child type, will cause ClassCastException
// return (Parent[])list.toArray(parents);
// Correct type, but uses size of parents which is potentially too big.Any way to do this without reflection?

But is is that at any given time, the array contains all elements of
either ChildA or ChildB? If not, I'm not sure how can you cast the
entire array. If so, why not check for one of the elements in the list
for its type using instanceof operator and then cast the entire array
appropriately.
I'm actually getting confused as to what exactly you are looking for.I should have been more clear on that point. Yes all elements will be of the same type, i.e., all of type ChildA or all of type ChildB.
The problem comes in the fact that even though one has an Object[] array where all Objects are of type ChildA, a ClassCastException will still be thrown when casting to ChildA[]
I have no idea what you're looking to do, but, regardless of what
parent class you cast some instance as, the current implementation
of each method is still going to execute. In other words, the
toString method of some instance always returns the same String,
whether you have it casted as a Parent or Child because it just
returns the implemetnation of the current classTrue, except of course for methods that only exist on the child objects.
A friend has given me a solution that I suspect will work:
import java.lang.reflect.*;
return (Parent[])list.toArray(Array.newInstance(parents[0].getClass(),0));

Similar Messages

  • UISelectMany :  must be of type List or Array (ERROR with rich:pickLisT )

    Hi
    I have a problem with my <rich:pickList> I can't display the items. When executing the application I got the following error:
    java.lang.IllegalArgumentException: ValueBinding for UISelectMany :  must be of type List or Array
            at org.richfaces.utils.PickListUtils.findUISelectManyConverter(PickListUtils.java:59)
            at org.richfaces.utils.PickListUtils.findUISelectManyConverterFailsafe(PickListUtils.java:79)as the error message the selectItems is not a List but it is I can't understand.
    I transmit to you my backing bean
    @Stateful
    @Name("adminAction")
    @Scope(ScopeType.SESSION)
    public class AdminActionBean implements AdminActionLocal {
    @In(required=false)
       private List<String> customersChoice;
    @Out(required=false)
       private List<String> companyNames;
    @Factory("companyNames")
       public void selectCompanyNames(){
           setCompanyNames((List<String>) getEm().createQuery("select c.companyName from Customer c")
                        .getResultList());
    //getter() and settter...... my .xhtml page
    <rich:pickList id="customersChoice" value="#{customersChoice}">
                        <f:selectItems  id="companyNames" value="#{companyNames}" />
              </rich:pickList>Have you got any Idea. thanks for help
    regards
    bibou

    You might look up the SelectItem, as the value parameter for a f:selectItems must be a List<SelectItem>. Each SelectItem has both a value and a label.
    Or, you could use Tomahawk's t:selectItems which uses a more dataList-style attribute set to allow you to have the value be any List, and you can select items in the List's node to be the Label and the Value of the select option.
    Look em up, they're useful.

  • CUPS, HP PSC 2355 and "Unable to get list of printer drivers: Unknown"

    Hey fellow Archers!
    The Introduction
    The other day, I installed ArchLinux for the ARM processor on my GoFlex Home. Straight away I installed samba, got it set up and everything works like a charm with explosive transfer-rates compared to the old factory-firmware. Also put on a mysql server to centralize my xbmc database and pyload to download large files without having to have my laptop opened all the time. Have to admit, this Arch Linux is a glorious world!
    The Setup
    Well, after this positive input, now comes my problem. I wanted to share our printer on our LAN, so I did a little search to quickly find CUPS. Installed it together with all the dependencies, like foomatic, python (which was installed as pyload uses it) and all that stuff.
    Changed the /etc/cups/cupsd.conf to listen on 0.0.0.0 and started the daemon.. Woohoo! Turned on the printer, opened the web interface, went to administration -> add printer and selected one of the printers available from this list:
    Local printers
    CUPS-PDF (Virtual PDF Printer)
    HP PSC 2350 series USB MY5BNF4423KJ HPLIP (HP PSC 2350 series)
    Seriel port #1
    HP PSC 2350 series (HP PSC 2350 series)
    HP Fax (HPLIP)
    Before I proceed, I want to say that I have tried the following with both of the PSC-entries.
    The Problem
    Now, i selected the printer and just let the default values be, pressed continue and got this error message:
    "Unable to get list of printer drivers: Unknown"
    Well, googled it a bit and tried to blacklist lsusb, as well as chmod /dev/bus/usb/001/002 to 665 (even 777). Still the same error message. Also tried to install the printer with hp-setup -i which let me pick a ppd myself; didn't work either. Gave me an error message saying that it was unable to add the printer to cups. I have run out of options, and the almighty sir Google wont give me any solutions other than those which I have tried.
    I even get this error message when I try to add cups-pdf (which I also installed oc).
    Kind regards,
    Rasmus Dencker
    Last edited by dencker90 (2011-12-30 17:53:10)

    Hey fellow Archers!
    The Introduction
    The other day, I installed ArchLinux for the ARM processor on my GoFlex Home. Straight away I installed samba, got it set up and everything works like a charm with explosive transfer-rates compared to the old factory-firmware. Also put on a mysql server to centralize my xbmc database and pyload to download large files without having to have my laptop opened all the time. Have to admit, this Arch Linux is a glorious world!
    The Setup
    Well, after this positive input, now comes my problem. I wanted to share our printer on our LAN, so I did a little search to quickly find CUPS. Installed it together with all the dependencies, like foomatic, python (which was installed as pyload uses it) and all that stuff.
    Changed the /etc/cups/cupsd.conf to listen on 0.0.0.0 and started the daemon.. Woohoo! Turned on the printer, opened the web interface, went to administration -> add printer and selected one of the printers available from this list:
    Local printers
    CUPS-PDF (Virtual PDF Printer)
    HP PSC 2350 series USB MY5BNF4423KJ HPLIP (HP PSC 2350 series)
    Seriel port #1
    HP PSC 2350 series (HP PSC 2350 series)
    HP Fax (HPLIP)
    Before I proceed, I want to say that I have tried the following with both of the PSC-entries.
    The Problem
    Now, i selected the printer and just let the default values be, pressed continue and got this error message:
    "Unable to get list of printer drivers: Unknown"
    Well, googled it a bit and tried to blacklist lsusb, as well as chmod /dev/bus/usb/001/002 to 665 (even 777). Still the same error message. Also tried to install the printer with hp-setup -i which let me pick a ppd myself; didn't work either. Gave me an error message saying that it was unable to add the printer to cups. I have run out of options, and the almighty sir Google wont give me any solutions other than those which I have tried.
    I even get this error message when I try to add cups-pdf (which I also installed oc).
    Kind regards,
    Rasmus Dencker
    Last edited by dencker90 (2011-12-30 17:53:10)

  • Need tips to keep cast list organized

    This is my first time working on a big project in Director,
    and I find I am having incredible trouble keeping my cast list
    organized. I am used to using After Effects, where you can create
    folders in your project window, and organize all your assets into
    them. While overall, I prefer Director's interface to Flash, the
    inability to organize the cast properly (not to mention the lack of
    multiple undos!) really get to me. With the director cast, not only
    can I not create folders, I am afraid to even move cast members
    around for fear of breaking something because so many director
    functions refer to a cast member by number. I have always found it
    difficult to organize at the same time that I am trying to be
    creative. Because of this, I tend to be initially messy with my
    cast and code while I try to get things looking right on stage.
    Then, when I have things looking and working how I like them, I go
    back and clean up before moving on to the next scene or segment of
    the project. I am getting the impression, that this doesn't work so
    well in Director. As a result, my cast list keeps getting messier
    and messier. Any tips on A: staying organized in the first place,
    and B: organizing an already messy cast would be helpful.

    1. Create multiple casts. These would be the equivalent of
    folders, in
    terms of a metaphor. You can name the casts anything that you
    like. I
    prefer to segregate my members by type. So I may have casts
    titled
    "code", "graphics", "text", etc. The names change based on
    the needs of
    the project.
    2. Name your members. If you import graphics from PS layers,
    for
    instance, each new graphic will come in with the layer name.
    Name your
    behaviors, this makes them easier to find when you need to
    apply them.
    Any imported cast member will be named with the file name of
    the
    original minus the file extension. You may want to develop a
    naming
    convention to make organization of the members more simple.
    If you reference your members by name in your code, and you
    don't have
    any duplicate names, Director will manage the members for
    you, you don't
    need to remember what cast they are located in.
    3. If you move a member from one location to another by
    dragging the
    member, Director will remember and update all of the
    relationships for
    that member. If you cut and paste, you will lose the
    relationships.
    Rob
    Rob Dillon
    Adobe Community Expert
    http://www.ddg-designs.com
    412-243-9119
    http://www.macromedia.com/software/trial/

  • Need help on creating a linked list with array...

    I want to create a linked listed using array method. Any suggestion on how would I start it.
    thanks

    That means I want to implement linked list using an
    array.I believe you mean you want to implement list using an array. Linked list is a very different implementation of a list, which can be combined with arrays for a niche implementation of list, but I don't think this is what you're talking about.
    Do you mind if we ask why you don't want to use ArrayList? It does exactly what you specify, plus it will increase the size of the internal array as necessary to ensure it can store the required elements.
    If you really want to make your own, have a look at the source for ArrayList (in src.jar in your JDK installation folder) - it will answer any questions you have. If you don't understand any of the code, feel free to post the relevant code here and ask for clarification.

  • Error unsupported memory access on variable 'Decoder.number_of_values' which is (or contain) an array with unknown size at compile time

    Dear All,
    I am a new user of Vivado HLS. I want to pass an array of struct to a function and use elements of struct multiple times in a function (read and write). I find this error "error unsupported memory access on variable 'Decoder.number_of_values' which is (or contain) an array with unknown size at compile time " . Kindly can anyone tell that is it an issue of directive? if yes then which directive to use for struct and its element. Struct and function are as follows.
    typedef struct {
    uint32_t number_of_values ;
    uint32_t  address[16];
    uint8_t Processed_bit :1 ;
    uint32_t links[6];
    } Decoder_Fields;
    void Raptor_LT_decode(int To_Send,Decoder_Fields *Decoder){
        int counter=0;
        int i=0,j=0,k=0,x,aaa;
        Raptor_LT_decode_label0:while(counter<To_Send){
            if((Decoder[counter].number_of_values ==1) &&(Decoder[counter].Processed_bit==0) ){
                Decoder[counter].Processed_bit=1;
                Raptor_LT_decode_label1:for (i=0; i<To_Send;i++){
                   Raptor_LT_decode_label2:for (k=0;k<Decoder[i].number_of_values;k++){
                         if (( Decoder[counter].links[0]==Decoder[i].links[k]) && (counter != i)&&       (Decoder[i].number_of_values!= 1)) {
                            Raptor_LT_decode_label3:for (j=0;j<BLOCK_SIZE_BYTES/4;j++){
                                     Decoder[i].address[i]= Decoder[i].address[j] ^ Decoder[counter].address[j];
                            for (x=k;x<Decoder[i].number_of_values-1;x++) Decoder[i].links[x]=Decoder[i].links[x+1];
                                      Decoder[i].number_of_values--;
                counter=0;
            else
                counter++;
     

    Hi ,
    This question is asked on the forum from time to time and should be described in the UG902
    In your top level, Decoder is a pointer; this is not supported as-is as you need to know its size when you do something like Decoder[i].XXXX : the tool need to know how many bits to size the addess bus.
    you need to change Decoder_Fields *Decoder to Decoder_Fields Decoder[YOURSIZE]
    with YOURSIZE that makes sense; in this case the tool will know that it need N=log2(YOURSIZE) to fully address the Decoder array variable.
    next when you solve that and that all is good... the question that you will need to transfer the data of the structs from host memory to your VHLS IP; you need to think about this.
    I hope this helps.

  • Put list in array

    Hi all,
    How to put list in array?? Is it true or not??
    What I mean is&#8230;I have list data like
    List 1 : 1 2 3 4
    List 2 : 2 3 4 5
    I want to put the list in array like
    [[1 2 3 4], [2 3 4 5]]
    Actually, can we do like this?
    Thank you very much.

    Hi jverd...
    Thank you very much....you help me a lot...I have another problem after settle the problem before...
    My problem is how to pass the list to another method??? I try to code but I get the object after I pass the list...My goals is want to compare line by line each other....
    Below is some of my code:      public static void hantarEquivalantClass(ArrayList s) {
              String[] s2 = (String[]) s.toArray(new String[0]);
              System.out.println("List Equivalance Class");
              System.out.println();
              for (int index = 0; index < s2.length; index++)
                        System.out.println(s2[index]);
              gunaStringTokenizer(s2);
             public static void gunaStringTokenizer(String[] s2) {
              List list = new LinkedList();
              for (int i = 0; i < s2.length; i++){
                   List list2 = new LinkedList();
                   StringTokenizer token = new StringTokenizer(s2, ",");
                   while (token.hasMoreTokens())
                        list2.add(token.nextToken());
                   list.add(list2);
              for (int i=0; i < list.size(); i++){
                   for (int j=0; j < list.size(); j++)
                        discernibility(list.get(i), list.get(j));
    //Here is problem....the object will pass not the list
    public static Set discernibility(List sRow, List sRowR) {
              Set s = new TreeSet();
              Iterator it = sRow.iterator();
                   while (it.hasNext()){
                        Object o = it.next();
                        if(!sRowR.contains( o ))
                        s.add( o );
              Iterator it2 = sRowR.iterator();
                   while (it2.hasNext()){
                        Object o2 = it2.next();
                        if(!sRow.contains( o2 ))
                        s.add( o2 );
              return s;

  • List to Array with Type

    Hi guys,
    I need to turn a List (an ArrayList specifically) into an array of Components.
    This is because I can't call a function like doSomething(Component ... components) with a collection. It needs to be an array correct?
    So, if it needs to be an array, I can't find a clean way to do it....or maybe I'm just a whiner.
    I can do this with
    theList.toArray(new Component[theList.size()]);or I can do it with
    (Component[])theList.toArray()But I don't like either of those...why should I have to pass an array in the first one and why should I be the one doing the cast in the second one?
    Shouldn't the ArrayList know how to return a correctly typed array?
    I wrote this little static method that I put in a helper class...does anything like this exist in the Collections class as a static method?
    I couldn't find anything like it in Arrays, or Collections etc.
    public static <T> T[] collectionToArray(Collection<T> l){
        Object ret[] = new Object[l.size()];
        int i = 0;
        for(T t : l){
            ret[i++] = t;
        return (T[]) ret;
    }If there is a better way to do this please let me know.
    Thanks,
    ~Eric

    ganeshmb wrote:
    It wasn't done because you either need an array of the proper type passed as a parameter, or a Class<T> passed as a parameter.Why? ArrayList is parametrized, which means it should be able to figure the data type by inspecting its contents, right? The only problem I see is, when its contents are empty, it will have to return null instead of an empty array. This is a different behavior from toArray, but should be acceptabe given the ease of use for clients - they don't have to pass an array instance to get the list back as an array.Wrong. In addition to the empty array behavior, suppose I have an List<Map>. I could have HashMap, ConcurrentHashMap, Properties, etc, all in this list. I still want a Map[] returned. What if my list is filled with HashMap? I still want a Map[] returned. Inspecting the contents is not a workable solution.

  • Need help with ouput of a list or array of numbers input from user

    I'm only a few weeks into learning java, so this may seem simple to some, but...
    I am trying to write a program that will receive numbers from a user,
    and then list, add, average those numbers. I've got the program to
    work except for listing the numbers that were input.
    Can someone help guide me????
    i've left the code I've tried in as comments.
    Enter an integer value, the program exits if the input is 0:
    20
    Enter an integer value, the program exits if the input is 0:
    40
    Enter an integer value, the program exits if the input is 0:
    60
    Enter an integer value, the program exits if the input is 0:
    80
    Enter an integer value, the program exits if the input is 0:
    0
    Total numbers entered: 4
    The array of numbers is: 0 0 0 0
    The sum is 200
    The average is 50
    The maximum number is 0
    The minimum is 0
    Here is my code:
    * Title:        Reads integers and finds the total, average, maximum of the input values
    * Description:
    * Copyright:    Copyright (c) 2002
    * Company:      Duke Court.
    * @author Mary Davenport
    * @version 1.0
    public class part3page6
      public static void main(String[] args)
      int data = 0;
      int sum = 0;
      int countnum = -1;
      int maximum = 0;
      int minimum = 0;
      int average = (countnum - 1);
      do
          System.out.println("Enter an integer value, " +
            " the program exits if the input is 0:  ");
          data = MyInput.readInt();
          sum += data;
          countnum++;
        } while (data != 0);
          //in order to figure the max & the min it appears that the
        //program will need to utilize arrays to store the individual numbers
        //that are input from the user.
        //create an array of the input data
        int[] number = new int[countnum];
        //creat a list of the input data
        int []myList = {data};
        //lists how many numbers entered
        System.out.println("Total numbers entered:  " + number.length);
        //list array of numbers -- this is giving me [I@3179c3,
        //instead of 20, 40, 60, 80 when I use "new int[countnum]"
    //     System.out.print("The array of numbers is: "
    //      + new int[countnum]);
        //list array of numbers:  this is giving me " 0 0 0 0 "
           //instead of 20, 40, 60, 80  with the following for statement
           // (number[i] + " ")
        System.out.print("The array of numbers is: ");
          for(int i=0; i<number.length; i++)
            System.out.print(number[i] + "  ");
      //list mylist of numbers from input, 20, 40, 60, 80
      //output is The list of numbers is: [I@3179c3
    //  System.out.print("The list of numbers is: " + myList);
        System.out.println();
        System.out.println("The sum is " +  sum);
        average = sum/countnum;
        System.out.println("The average is " + average);
        System.out.println("The maximum number is " +  maximum);
        System.out.println("The minimum is " +  minimum);

    When you input the data you need to save it to the array. Currently you are not saving the value you are just adding it
    ArrayList nums = new ArrayList();
       do
           System.out.println("Enter an integer value, " +
             " the program exits if the input is 0:  ");
           data = MyInput.readInt();
    nums.add(new Integer(data));
           sum += data;
           countnum++;
         } while (data != 0);

  • RV325 DHCP static address list and duplicates in unknown IP & MAC Binding List Table

    DHCP Manual Bindings are entered and are displayed correctly in the IP & MAC Binding Table.
    The error is that there are duplications of the IP address in the Unknown MAC Address List and hitting the Refresh button does nothing.
    These duplicates remain in the Unknown table forever. Only a reboot of the router really refreshes the Unknown table.
    Any suggestion?

    The problem has been solved.
    All the settings are apparently stored in the open directory database.  I had to enable system records and viola there was the extra entry complete with MAC address and IP address.

  • What is the proper and best way to destroy a java.util.List or Array for GC

    Hi,
    If I have a java.util.List of objects lets say:
    List<File> files = new ArrayList();The List contains 1000 file objects. When my class finishes, is it enough to do
    files = null;to make GC able to release it from memory?
    Cause it seems like I can't do the following:
    for(int i = 0; i < extracted_files.size(); i++){
                extracted_files.get(i) = null;
    }Or should I use this one:
    files.clear()What is the proper and best way to do this in order to avoid memory leaks? How about normal Arrays like File[]?
    Edited by: TolvanTolvanTolvan on 2009-sep-10 16:58

    TolvanTolvanTolvan wrote:
    Thanks for the info!
    But what if the List is a class variable running in a Web Service for like months without terminating?You mean if the List variable is a member variable of a long-lived object? Then presumably the list needs to live as long as the object does. In the unlikely scenario that the object needs to live on but its list member variable does not, then yes, setting the member to null will be needed to make the list eligible for GC. But I highly doubt this is your situation, and if it is, you probably have a design flaw.
    And if the list is referenced only by a local variable, then, as I already said, when the method ends, the variable goes out of scope, and the List is eligible for GC.
    Now, a slightly different situation is when the List needs to live a long time, and at some point during its life, you're done using some object that it refers to. In that situation, simply remove the element from the list (or set the element to null if it's an array rather than a list), and then if it's not referenced anywhere else, it can be GCed.
    How about Arrays like File[]? Do I need to iterate through the array and null all the objects or is it enough to just null the Array?YOU. DON'T. NEED. TO. HELP. GC. You don't need to set the elements to null, and you most likely don't even need to set the array variable to null.
    Also note that only references can be null, not objects.

  • Execute a procedure with a list of array in sql server 2008

    HI all,
    I have a procedure which has a list of values passed as an array . How can i execute my procedure with array list? how to implement this?Please help me.
    Thanks in advance
    Deepa

    Hi Deepa,
    basically Microsoft SQL Server does not support arrays as data types for procedures. What you can do is creating a type which represents a table definition. This type can than be used in a procedure as the following demo will show:
    The first script creates the environment which will be used for the execution
    -- 1. create the table as a type in the database
    CREATE TYPE OrderItems AS TABLE
    ItemId int PRIMARY KEY CLUSTERED
    GO
    -- 2. demo table for demonstration of results
    CREATE TABLE dbo.CustomerOrders
    Id int NOT NULL IDENTITY (1, 1) PRIMARY KEY CLUSTERED,
    CustomerId int NOT NULL,
    ItemId int
    GO
    -- 3. Insert a few records in demo table
    INSERT INTO dbo.CustomerOrders
    (CustomerId, ItemId)
    VALUES
    (1, 1),
    (2, 1),
    (3, 3),
    (1, 3);
    GO
    -- 4. Create the procedure which accepts the table variable
    CREATE PROC dbo.OrderedItemsList
    @Orders AS OrderItems READONLY
    AS
    SET NOCOUNT ON;
    SELECT o.*
    FROM dbo.CustomerOrders AS O INNER JOIN @Orders AS T_O
    ON (o.ItemId = T_O.ItemId);
    SET NOCOUNT OFF;
    GO
    The above script creates the table data type and a demo table with a few demo data. The procedure will accept the table data type as parameter. Keep in mind that table variable parameters have to be READONLY as parameter for procedures!
    The second script demonstrates the usage of the above scenario
    When the environment has been created the usage is a very simple one as you can see from the next script...
    -- 1. Fill the variable table with item ids
    DECLARE @o AS OrderItems;
    INSERT INTO @o (ItemId)
    VALUES
    (1), (3);
    -- 2. Get the list of customers who bought these items
    EXEC dbo.OrderedItemsList @Orders = @o;
    MCM - SQL Server 2008
    MCSE - SQL Server 2012
    db Berater GmbH
    SQL Server Blog (german only)

  • GWMonitor lists GWIA as state Unknown

    We've been having issues with GroupWise ever since we upgraded to Linux. Today's issue is the GWIA web interface. Whenever I try to connect to our gwia web interface directly on port 9850 it redirects me to GWMonitor.
    And under GWMon it lists all of the GroupWise components as running normally except the GWIA.
    The GWIA state is unknown. I've tried changing the port, restarting groupwise, restarting the server, changing the HTTP username and password in C1,
    Normal 0 d 1 h 6 m crofton MTA 0 d 1 h 10 m 0 0 Linux 8.0.2 (12/11/2010)
    Unknown 0 d 1 h 11 m GWIA.crofton GWIA 0 d 0 h 0 m N/A N/A ?
    Normal 0 d 1 h 6 m po.crofton POA 0 d 1 h 10 m N/A N/A Linux 8.0.2 (12/11/2010)
    Normal 0 d 1 h 6 m webacc.crofton WEBACC 0 d 1 h 10 m N/A N/A Linux 8.0.2 (12/11/2010)
    Name GWIA.crofton
    Type GWIA
    Address SERVER-IP:9850
    Poll Type XML
    State Unknown
    It was set to SNMP but I brought down GWMon and then Restarted the GWIA and then brought GWMon back up and it set to XML. But the same error either way.
    I also made sure that the port 9850 was not in use by something else while both were down.
    Tyler

    Well, when we switched to Linux, our GroupWise issues pretty much went away. Exact opposite of what you site. I guess YMMV.
    This would not be on the other side of a Firewall by chance? Check that. You should also be able to telnet to the port if it is running and you have connectivity.
    --El
    Originally Posted by croftonhouse
    Of course right after posting this thread it switched to not listening. :-/

  • Empty array of unknown size in formula node

    I have to declare an empty array say, P of unknown size in formula node. How to do that?

    Hi sukhiray,
    an empty array has a known size...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Lists or Arrays

    Hi,
    I'm reading in a very complex XML file that has this format -- very simplified.
    <Report>
        <rule id="1">
            <testedObject/>
            <testedObject/>
        </rule>
        <rule id="2">
            <testedObject/>
            <testedObject/>
            <testedObject/>
            <testedObject/>
        </rule>
        <rule id="3"/>
    </Report>I was thinking the best way to do this is that I'll create a Parser, Report and TestedObject class. The question is how to keep track of the multiple Rules, and testedObjects? I was thinking of creating a List, but than an array would be easier. Is there a better way to do this without having to write everything to an external database?
    This is some of what I have so far ... if at all possible, I rather keep everything in memory so that I can do manipulations and calculations before writting everything out to a database in a new format.
    Parser.java
                   NodeList rules = doc.getElementsByTagName("Rule");
                   for (int s = 0; s < rules.getLength(); s++)
                        Element rule = (Element)rules.item(s);
                        // ReportEntry
                        ReportEntry ore = new ReportEntry(rule); ReportEntry.java
                   (bunch of setters)
                   NodeList Results = rule.getElementsByTagName("testedObject");
              if (Results.getLength() > 0) {
                   for (int s = 0; s < Results.getLength(); s++)
                     Element result = (Element)Results.item(s);
                    Rule or = new Rule(result);
              }

    Thank you for the feedback.
    I'll take a look at JAXB and XMLBeans. I've also contacted the developer to see if I can get the schema. I'm sure I can't come up with it, it's a very very convoluted xml file.
    The final destination of the tool is going to be a database, so I'm not using that as an interim holding area. I just wanted to do what I needed before connecting and dumping the rows, which sounds like I can without having too much issues.
    The reason I said that an array wold be easier is that if I parse the XML I know exactly how many time the element is repeated, so I can create the array to the size I need, (i.e. no trim needed), but that was before I know about JAXB or XMLBeans.

Maybe you are looking for

  • DVHSCap to Capture HDV VIdeo

    FCP does not support the JVC GR-HD1U but I have found that people have been successful capturing the video through Apple's DVHSCap then converting the data to .m2t transport files using MPEG Streamclip (I will post what I read below). I have download

  • Guitar audio drop-out at lower volumes

    I have tried out mainstage on a friends macbook pro, to check if it will be worth an investment into Logic over Garageband, mainly as an effects emulator for my guitar so I don't need to worry about amps in my small flat.   I connected through an Edi

  • Photos do not appear in imovie 11. black screen with frozen movie clip

    Imovie 11 Photos do not appear in the movie a black screen for picture in picture or a frozen screen with sound and no photo

  • Read XML file

    Hi people, I need your help. My scenario is XML to file and both are using file adapter, but i want to read the xml file. XML file Example   <?xml version="1.0" encoding="UTF-8" ?> - <Interface_XXX>         <FIELD1>2023967</FIELD1>         <FIELD2>00

  • XML error for Invoice iN SNC

    Hi Gurus Need help for the error we are getting in XML when Invoice is posted in SNC 7 version Error :" Message Interface or senders party hasn't been provided" please let me know the cause of error Thanks Vishal