Extend a Array of a Array of a Object

Hi!
I'm created these types in my DB:
TYPE SONO_ROW AS OBJECT (DATO NUMBER, FECHA DATE);
TYPE SONO_TABLE IS VARRAY(1000) OF SONO_ROW;
TYPE SONO_ARRAY IS VARRAY(1000) OF SONO_TABLE;
Well, I have a problem when I trying to load SONO_ARRAY, because I can't do a EXTEND for this Type:
DECLARE
V_MULTIVARRAY SONO_ARRAY;
BEGIN
-- Initialize the collection
V_MULTIVARRAY := SONO_ARRAY(SONO_TABLE(SONO_ROW(77, SYSDATE)));
-- Extend the collection
V_MULTIVARRAY.EXTEND(10,1);
V_MULTIVARRAY(2)(1) := SONO_ROW(1, SYSDATE);
END;
Whell, this code extend in 10 the element 1(SONO_TABLE), it is ok, but I don't know how to extend SONO_REG in order to insert elements for SONO_ROW: V_MULTIVARRAY(1)(2). I tried to do it of all the ways but without results.
Someone could help me, please?
Thanks,
Fernando.

Hi,
possibly the article http://htmldb.oracle.com/pls/otn/f?p=2853:4:9828983748613764845::NO::P4_QA_ID:4322 will help you
e.g.
DECLARE
V_MULTIVARRAY SONO_ARRAY;
BEGIN
V_MULTIVARRAY := SONO_ARRAY();
V_MULTIVARRAY.EXTEND;
V_MULTIVARRAY(1) := SONO_TABLE(SONO_ROW(1, SYSDATE));
V_MULTIVARRAY(1).EXTEND;
V_MULTIVARRAY(1)(1):= SONO_ROW(1, SYSDATE);
V_MULTIVARRAY.EXTEND(1,1);
V_MULTIVARRAY(2) := SONO_TABLE(SONO_ROW(1, SYSDATE));
V_MULTIVARRAY(2).EXTEND;
V_MULTIVARRAY(1)(2):= SONO_ROW(1, SYSDATE);
V_MULTIVARRAY(2)(2):= SONO_ROW(1, SYSDATE);
V_MULTIVARRAY(2)(1):= SONO_ROW(1, SYSDATE);
END;
Andrey

Similar Messages

  • Extending an Array

    I have created a class of objects, with fields, constructors, methods, etc. So far, so good.
    Now I would like to create an array of these objects, and I have some methods that I would like to create that would manipulate the objects in an array. Is it possible to create a class that extends array, and that is always an array of my object? (I'm not even sure how to ask my question properly)
    Here's an example - given:
    public class MyItem {
    private String name;
    private String description;
    private String material;
    public String getDescription() {
    return description;
    ... (constructors & other methods omitted)
    }// end of MyItem
    I woudl like to create somethign like this
    public class ArrayOfItem extends java.lang.Array {
    public String getDescription (String theName) {
    <code to find the MyItem in the array where MyItem.name = theName>
    return MyItem.getDescription();
    The thing is that this is dependent upon the array always containing MyItems; is this possible? Where could I find some examples of this? Or, am I better off just writing the methods I need into the program, rather than trying to create a new class?
    Edited by: lkb3 on Feb 7, 2011 7:33 AM

    Its more likely you want to extends ArrayList like
    // works but not a good idea.
    public class ArrayOfItem extends ArrayList<MyItem> {
    }You are much better off wrapping the collection
    // works but not very efficient.
    public class ArrayOfItem extends  {
        final List<MyItem> myItems = new ArrayList<MyItem>();
    }Assuming you have to lookup by name often you can wrap a Map instead.
    public class ArrayOfItem extends  {
        final Map<String, MyItem> myItems = new LinekdHashMap<String, MyItem>();
        public void add(MyItem mi) [
            myItems.put(mi.getName(), mi);
        public String getDescription (String theName) {
            return myItems.get(theName).getDescription();
    }Edited by: Peter Lawrey on Feb 7, 2011 3:57 PM

  • How to extend an array?

    Hi,
    how to extend an array
    int[] b = new int[] {1, 2, 3};by adding 4, 5, 6 without copying?
    thanks a lot
    aldo

    You can't
         int [] b = {1,2,3};
         int [] a = {4,5,6};
         int [] tmp = new int [b.length + a.length];
         System.arraycopy(b, 0, tmp, 0, b.length);
         System.arraycopy(a, 0, tmp, b.length ,a.length);
         b = tmp;
         System.out.println(Arrays.toString(b));

  • Extending an array multiple times - Help!

    Hi everyone,
    I am very new to Java (doing my first class now) and I need some help with making an array larger. I have written a program that will display a list of products created in a static array. The program needs to include an "add" button, that will prompt for new product information, and add it to the array.
    I've managed to get this coded up to a point where my add button works (albeit only is adding product name at this point...will add the rest later once this works). The problem is, when I attempt to run the add button a second time, it does not grow out the length of the array. The result is that it updates the last record within the array with the new product information, rather than appending a new one. Here is the code I think is relevant (as I don't think you are allowed to entirely post school work):
    // Assignment: Inventory Program Part 6
    // Author:  Ryan MacDonald
    // Class uses both swing and awt components, also using number format for currency, and AWT events
    import javax.swing.*;
    import java.awt.*;
    import java.text.NumberFormat;
    import java.awt.event.*;
    // InventoryPart4 class
    public class InventoryPart6
         // Declare array of products
         static Product_Extender Item[] = new Product_Extender[4];
         // snip
         // snip
         // Main method
         public static void main ( String args[] )
              // Create a new product object
              Item[0] = new Product_Extender( 1, "Pink Markers", "Pentel", 31, 0.61 );
              Item[1] = new Product_Extender( 2, "Blue Pens", "Bic", 57, 0.30 );
              Item[2] = new Product_Extender( 3, "Red Markers", "Zebra", 62, 0.55 );
              Item[3] = new Product_Extender( 4, "Black Pens", "Bic", 73, 0.33 );
         // snip
         // snip
              // Make add button work
                   addAddButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                        Product_Extender newItem[] = new Product_Extender[Item.length + 1];
                        System.arraycopy(Item, 0, newItem, 0, Item.length);
                        newItem[newItem.length - 1] = new Product_Extender( newItem.length, productNameText.getText(), "Test New Item", 99, 0.99 );
                        Product_Extender Item[] = new Product_Extender[newItem.length];
                        System.arraycopy(newItem, 0, Item, 0, newItem.length);
                        // Update main text area with our new product information
                        mainText.setBorder(BorderFactory.createTitledBorder("Product Inventory (All Items)"));     // Create a title around the textarea with some text
                        mainText.setText( String.format("Product #" + "\t" + "Name" + "\t" + "Manufacturer" + "\t" + "Quantity" + "\t" + "Price" + "\t" + "Value" + "\t" + "Restocking Fee" + "\n") ); // Create a line of text with the product header information
                        // Loop through each item in the product array and append the information to the main text area for the product number, product name, quantity in stock, price per unit, total value of inventory, and restocking fee for this item
                        for(int i = 0; i < Item.length; i++) {
                        mainText.append(String.format(Item.getProductNumber() + "\t" + Item[i].getProductName() + "\t" + Item[i].getProductManufacturer() + "\t" + Item[i].getProductQuantity() + "\t" + NumberFormat.getCurrencyInstance().format(Item[i].getProductPrice()) + "\t" + NumberFormat.getCurrencyInstance().format(Item[i].getInventoryValue()) + "\t" + NumberFormat.getCurrencyInstance().format(Item[i].getRestockingFee()) + "\n" ) );
                        // Set array location
                        currentLoc = -1;
                        // Close window
                        addFrame.dispose();
         // snip
         // snip
         } // End method main
    } // End class InventoryPart6
    Basically here is my train of thought (although my logic could be ENTIRELY off, I'm very new here...).  From what I've read, there is no way to actually grow/extend an array.  The only option is to create a new one and populate it with the same data.
    1.  Since I can't grow it, I make a new array called "newItem" with Item.lengh + 1 as it's size
    2.  I then copy the contents of Item over to newItem
    3.  Since I need Item later, I recreate it with a new size of newItem.length
    4.  Copy the data from newItem over to Item
    5.  Print out the data from Item back to the main text area
    What I would like to do is rinse and repeat this process as many times as the user would like.  However as I said, it doesn't seem to work.  Each time it reiterates again, it sets Item.length back to 4, not having it grow each time (deduced this by adding a bunch of prints of variables to my window).
    Any help would be appreciated!!!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    nvrmore100 wrote:
    I actually have a lot of other buttons that manipulate the displaying of the array in various ways. I thought about creating a much larger array, but this would break all the functionality I have for displaying next, previous, last, items in the array.Then your functionality is incorrect. You should have a variable that keeps track of how many items are stored in the array. This will always allow you to access the last element. And when this variable reaches the size of the array only then do you increase the size of the array.
    I agree, I think this is exactly my issue, unfortunately I do not know where to go from here. Is there a way for me to recreate the Item array entirely, rather than having a local array to the addbutton action method?I already showed you how to fix your problem. Delete your line of code and replace it with mine.

  • Passing Array of java objects to and from oracle database-Complete Example

    Hi all ,
    I am posting a working example of Passing Array of java objects to and from oracle database . I have struggled a lot to get it working and since finally its working , postinmg it here so that it coudl be helpful to the rest of the folks.
    First thinsg first
    i) Create a Java Value Object which you want to pass .
    create or replace and compile java source named Person as
    import java.sql.*;
    import java.io.*;
    public class Person implements SQLData
    private String sql_type = "PERSON_T";
    public int person_id;
    public String person_name;
    public Person () {}
    public String getSQLTypeName() throws SQLException { return sql_type; }
    public void readSQL(SQLInput stream, String typeName) throws SQLException
    sql_type = typeName;
    person_id = stream.readInt();
    person_name = stream.readString();
    public void writeSQL(SQLOutput stream) throws SQLException
    stream.writeInt (person_id);
    stream.writeString (person_name);
    ii) Once you created a Java class compile this class in sql plus. Just Copy paste and run it in SQL .
    you should see a message called "Java created."
    iii) Now create your object Types
    CREATE TYPE person_t AS OBJECT
    EXTERNAL NAME 'Person' LANGUAGE JAVA
    USING SQLData (
    person_id NUMBER(9) EXTERNAL NAME 'person_id',
    person_name VARCHAR2(30) EXTERNAL NAME 'person_name'
    iv) Now create a table of Objects
    CREATE TYPE person_tab IS TABLE OF person_t;
    v) Now create your procedure . Ensure that you create dummy table called "person_test" for loggiing values.
    create or replace
    procedure give_me_an_array( p_array in person_tab,p_arrayout out person_tab)
    as
    l_person_id Number;
    l_person_name Varchar2(200);
    l_person person_t;
    l_p_arrayout person_tab;
    errm Varchar2(2000);
    begin
         l_p_arrayout := person_tab();
    for i in 1 .. p_array.count
    loop
         l_p_arrayout.extend;
         insert into person_test values(p_array(i).person_id, 'in Record '||p_array(i).person_name);
         l_person_id := p_array(i).person_id;
         l_person_name := p_array(i).person_name;
         l_person := person_t(null,null);
         l_person.person_id := l_person_id + 5;
         l_person.person_name := 'Out Record ' ||l_person_name ;
         l_p_arrayout(i) := l_person;
    end loop;
    p_arrayout := l_p_arrayout;
         l_person_id := p_arrayout.count;
    for i in 1 .. p_arrayout.count
    loop
    insert into person_test values(l_person_id, p_arrayout(i).person_name);
    end loop;
    commit;
    EXCEPTION WHEN OTHERS THEN
         errm := SQLERRM;
         insert into person_test values(-1, errm);
         commit;
    end;
    vi) Now finally create your java class which will invoke the pl/sql procedure and get the updated value array and then display it on your screen>Alternatively you can also check the "person_test" tbale
    import java.util.Date;
    import java.io.*;
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.driver.*;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    public class ArrayDemo
    public static void passArray() throws SQLException
    Connection conn = getConnection();
    ArrayDemo a = new ArrayDemo();
    Person pn1 = new Person();
    pn1.person_id = 1;
    pn1.person_name = "SunilKumar";
    Person pn2 = new Person();
    pn2.person_id = 2;
    pn2.person_name = "Superb";
    Person pn3 = new Person();
    pn3.person_id = 31;
    pn3.person_name = "Outstanding";
    Person[] P_arr = {pn1, pn2, pn3};
    Person[] P_arr_out = new Person[3];
    ArrayDescriptor descriptor =
    ArrayDescriptor.createDescriptor( "PERSON_TAB", conn );
    ARRAY array_to_pass =
    new ARRAY( descriptor, conn, P_arr);
    OracleCallableStatement ps =
    (OracleCallableStatement )conn.prepareCall
    ( "begin give_me_an_array(?,?); end;" );
    ps.setARRAY( 1, array_to_pass );
         ps.registerOutParameter( 2, OracleTypes.ARRAY,"PERSON_TAB" );
         ps.execute();
         oracle.sql.ARRAY returnArray = (oracle.sql.ARRAY)ps.getArray(2);
    Object[] personDetails = (Object[]) returnArray.getArray();
    Person person_record = new Person();
    for (int i = 0; i < personDetails.length; i++) {
              person_record = (Person)personDetails;
              System.out.println( "row " + i + " = '" + person_record.person_name +"'" );
                        public static void main (String args[]){
         try
                             ArrayDemo tfc = new ArrayDemo();
                             tfc.passArray();
         catch(Exception e) {
                        e.printStackTrace();
              public static Connection getConnection() {
         try
                             Class.forName ("oracle.jdbc.OracleDriver");
                             return DriverManager.getConnection("jdbc:oracle:thin:@<<HostNanem>>:1523:VIS",
                             "username", "password");
         catch(Exception SQLe) {
                        System.out.println("IN EXCEPTION BLOCK ");
                        return null;
    and thats it. you are done.
    Hope it atleast helps people to get started. Comments are appreciated. I can be reached at ([email protected]) or [email protected]
    Thanks
    Sunil.s

    Hi Sunil,
    I've a similar situation where I'm trying to insert Java objects in db using bulk insert. My issue is with performance for which I've created a new thread.
    http://forum.java.sun.com/thread.jspa?threadID=5270260&tstart=30
    I ran into your code and looked into it. You've used the Person object array and directly passing it to the oracle.sql.ARRAY constructor. Just curios if this works, cos my understanding is that you need to create a oracle.sql.STRUCT out of ur java object collection and pass it to the ARRAY constructor. I tried ur way but got this runtime exception.
    java.sql.SQLException: Fail to convert to internal representation: JavaBulkInsertNew$Option@10bbf9e
                        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
                        at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:146)
                        at oracle.jdbc.oracore.OracleTypeADT.toDatum(OracleTypeADT.java:239)
                        at oracle.jdbc.oracore.OracleTypeADT.toDatumArray(OracleTypeADT.java:274)
                        at oracle.jdbc.oracore.OracleTypeUPT.toDatumArray(OracleTypeUPT.java:115)
                        at oracle.sql.ArrayDescriptor.toOracleArray(ArrayDescriptor.java:1314)
                        at oracle.sql.ARRAY.<init>(ARRAY.java:152)
                        at JavaBulkInsertNew.main(JavaBulkInsertNew.java:76)
    Here's a code snippet I used :
    Object optionVal[] =   {optionArr[0]};   // optionArr[0] is an Option object which has three properties
    oracle.sql.ArrayDescriptor empArrayDescriptor = oracle.sql.ArrayDescriptor.createDescriptor("TT_EMP_TEST",conn);
    ARRAY empArray = new ARRAY(empArrayDescriptor,conn,optionVal);If you visit my thread, u'll see that I'm using STRUCT and then pass it to the ARRAY constructor, which works well, except for the performance issue.
    I'll appreciate if you can provide some information.
    Regards,
    Shamik

  • Best way to perform the same task wih arrays of different Objects

    Hello all.
    This isn't an XPath question, it's a much lower-level Java Object question, but it involves XPath. I hope that doesn't distract from the question, or confuse anything.
    I have 4-5 different types of Objects (call them A, B, C, etc.) that each contain an array of other Objects (call them a[], b[], c[], etc.)
    a, b, c, etc., each have an Xpath object and and XPathExpression. When I create each XPath object I assign it a NamespaceContext object which contains the namespaces needed for that XPath.
    When I create, for example, an A object, I pass is constructor an array of a and an array of Namespaces. With each a object I need to:
    1. create a NamespaceContext object
    2. go through all the Namespace objects and if its route matches,
    (if Namespace.route == a.getRoute() )
    3. add that Namespace to the NamespaceContext Object,
    4. assign the NamespaceContext to the XPath object, and finally
    5. create the a object, passing it the XPath object
    My problem / question is: I also have to do the same thing with B and b[], C and c[], etc. It's not that long of a process, not that much code, but all the same, I was wondering what the best way to write this code once would be, and have it work for all the different types of Objects.
    In other words, I'd like to write a mehod, call it assignNamespaces(), that accepts an array of Objects(a[], b[], c[], etc.) and an array of Namespaces, creates the XPath Object for each a, b, c, etc., and that creates and returns an array of a[],b[],c[], etc., sending the XPath Object as a parameter.
    That way when I create for example an A Object, I call:
    class A
    ObjectsWithXpath[] objectsWithXPath;
    this..objectsWithXPath = assignNamespaces(objectsWithXPath,namespaces);
    Should the assgnNamespaces() method simply use Class.forName() to see what type of Object it is and do a cast accordingly, or is there some other, more elegant way of doing this?
    I hope I've explained myself, and haven't bored you ...
    Thanks in advance,
    Bob

    Thanks for your reply!
    I poked around a bit looking into Factory classes. I've used them a million times but never actually made one. At any rate, they seem like a good idea when you have a bunch of different classes that are similar but not equal.
    In my case my classes ONLY have the XPathExpression in common. Which means that I'd have to make a base abstract class with a bunch of methods of which only a percentage are defined by any class that extends it. In other words, if I had 3 classes -- a, b and c -- that extend the base abstract class, and each had 5 getters and setters, the base abstract class would have 15 methods, 5 only used by a, 5 only used by b and 5 only used by c.
    It seemed a bit ugly to me. Besides, I only have 3 classes. I decided to factor out the inner loop, which is about 70% of the code, stick it in a utility class, and call it from there. I am repeating some code still, but it isn't that bad, and it saves me having to define an interface, an abstract class, a Factory class, etc.
    It ain't perfect, but then nothing ever is.
    Thanks for all the help! Viva the Java community!
    Bob

  • Filling a jtable with an array of Portfolio objects

    I have created a class Portfolio and want to put an array of portfolio objects in a Jtable.
    I created a tablePortfolioClass based on the AbstratTableModel and
    changed the classical 2 dimensional data array into a one dimensional arry of portfolio objects.
    The databaselayer correctly fills the Portfolio but does not display it inthe table...
    what am I doing wrong ?
    package DBpackage;
    import java.lang.String;
    public class Portfolio
    public Portfolio()
    public Portfolio(String sE)
    sEcode=sE;
    //here are normally set and getmethods that I left out
    private String sEcode;
    private double dQuantity;
    private double dAvgPrice;
    private double dPrice;
    private double dExchRate;
    private double dReturn;
    private String sDescr;
    private double dPerc;
    private double dTotal;
    =============================================================
    package DBpackage;
    import javax.swing.table.AbstractTableModel;
    class tablePortfolioClass extends AbstractTableModel
    Portfolio[]data=new Portfolio[50];
    final String[] columnNames={"Ecode","Description","Quantity","Price", "Avg","%","Total","Return"};
    public void tablePortfolioClass (int nrofRows)
    iRows=nrofRows;
    public void tablePortfolioClass(Portfolio[] pp)
    data=pp;
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.length;
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
    return data[row];
    public void setValueAt(Portfolio value, int row, int col) {
    data[row] = value;
    fireTableCellUpdated(row, col);
    private int iRows;
    private int iCols=4;
    =============================================================
    this is what is done in the frame
    Portfolio [] pf=new Portfolio[50];
    tablePortfolioClass pp=new tablePortfolioClass();
    //tablePortfolioClass pp=new tablePortfolioClass(pf); this one does not compile
    JTable grdPP=new JTable(pp);
    grdPP.setPreferredScrollableViewportSize(new Dimension(200,200));
    JScrollPane jscrollPanePP=new JScrollPane(grdPP);
    all more traditional implementations of the jtable work without any problem...
    anyone ?

    Your getValueAt() method should return the actual value you want to display in the table at the given row and column. Right now, it returns the whole Portfolio object. How is the table supposed to render a Portfolio object?
    Something more like this would make more sensepublic Object getValueAt(int row, int col)
      switch (col) {
      case 0:
        return data[row].getEcode();
      case 1:
        return data[row].getDescr();
      case 7:
        return new Double(data[row].getReturn());
    }The same can be said for your setValueAt() method. It should set the individual attributes of the Portfolio object at the given row rather than changing the whole object.

  • Create Class objects from an Array of File Objects

    Hi There,
    I'm having extreme difficulty in trying to convert an array of file objects to Class objects. My problem is as follows: I'm using Jfilechooser to select a directory and get an array of files of which are all .class files. I want to create Class objects from these .class files. Therefore, i can extract all the constructor, method and field information. I eventually want this class information to display in a JTree. Very similar to the explorer used in Netbeans. I've already created some code below, but it seems to be throwing a NoSuchMethodError exception. Can anyone please help??
    Thanks in advance,
    Vikash
    /* the following is the class im using */
    class FileClassLoader extends ClassLoader {
    private File file;
    public FileClassLoader (File ff) {
    this.file = ff;
    protected synchronized Class loadClass() throws ClassNotFoundException {
    Class c = null;
    try {
    // Get size of class file
    int size = (int)file.length();
    // Reserve space to read
    byte buff[] = new byte[size];
    // Get stream to read from
    FileInputStream fis = new FileInputStream(file);
    DataInputStream dis = new DataInputStream (fis);
    // Read in data
    dis.readFully (buff);
    // close stream
    dis.close();
    // get class name and remove ".class"
    String classname = null;
    String filename = file.getName();
    int i = filename.lastIndexOf('.');
    if(i>0 && i<filename.length()-1) {
    classname = filename.substring(0,i);
    // create class object from bytes
    c = defineClass (classname, buff, 0, buff.length);
    resolveClass (c);
    } catch (java.io.IOException e) {
    e.printStackTrace();
    return c;
    } // end of method loadClass
    } // end of class FileClassLoader
    /* The above class is used in the following button action in my gui */
    /* At the moment im trying to output the data to standard output */
    private void SelectPackage_but2ActionPerformed(java.awt.event.ActionEvent evt) {
    final JFileChooser f = new JFileChooser();
    f.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int rVal = f.showOpenDialog(Remedy.this);
    // selects directory
    File dir = f.getSelectedFile();
    // gets a list of files within the directory
    File[] allfiles = dir.listFiles();
    // for loop to filter out all the .class files
    for (int k=0; k < allfiles.length; k++) {
    if (allfiles[k].getName().endsWith(".class")) {
    try {
    System.out.println("File name: " + allfiles[k].getName()); // used for debugging
    FileClassLoader loader = new FileClassLoader(allfiles[k]);
    Class cl = loader.loadClass();
    //Class cl = null;
    Class[] interfaces = cl.getInterfaces();
    java.lang.reflect.Method[] methods = cl.getDeclaredMethods();
    java.lang.reflect.Field[] fields = cl.getDeclaredFields();
    System.out.println("Class Name: " + cl.getName());
    //print out methods
    for (int m=0; m < methods.length; m++) {
    System.out.println("Method: " + methods[m].getName());
    // print out fields
    for (int fld=0; fld < fields.length; fld++) {
    System.out.println("Field: " + fields[fld].getName());
    } catch (Exception e) {
    e.printStackTrace();
    } // end of if loop
    } // end of for loop
    packageName2.setText(dir.getPath());
    }

    It's throwing the exeption on the line:
    FileClassLoader loader = new FileClassLoader(allfiles[k]);
    I'm sure its something to do with the extended class i've created. but i cant seem to figure it out..
    Thanks if you can figure it out

  • Sotring an array of BPM Objects

    Hi
    I need to sort an array of BPM objects in my PBL code. I tried using Java.Util.Comparator class for this but somehow, it is not working.
    Here is what I tried,
    I created a subclass of Java.Util.Comparator class (Type inheritance) called MyComparator and created the compare method under it for comparing MyObject objects.
    I use following code,
    MyObject[] ttt;
    ttt[0] = new MyObject();
    ttt.clear();// this I use to initialize otherwise the extend method throws error.
    ttt.extend(arg1: "abcd", arg2=23.2);
    ttt.extend(arg1: "xyz", arg2=13.2);
    Arrays.sort(arg1 : ttt, arg2 : new MyComparator());
    I would expect this code should sort the arra ttt as per the comparison logic in the MyComparator. The code executes the compare method properly, but somehow the ttt arra remains unchanged.
    Has anyone faced similar issue? any help would be appreciated.

    Thanks Dan for the solution.
    But my requirement is bit more complicated.
    I need to sort the array dynamically based on different fields.
    e.g. Lets say the object contains 4 attributes - att1,att2,att3,att4.
    I need to sort the same array dynamically on any of these attributes. at one place I may want to sort on att1, while at other place I may need the array sorted on att3.
    The Java.Util.Comparator provides me this flexibility, but somehow it doesnt work.
    Is there any other alternative?
    Setting the primary key for the BPM object would not help this dynamic behaviour. Can we change the primary key settings at runtime and then call the sort method?
    I feel the reaso for Java.Util.Comparator not working may be because the PBL does not pass parameters by reference, instead it passes parameter by value, thats why the code "Arrays.sort(arg1 : ttt, arg2 : new MyComparator());" does not change the contents/order of the input array ttt. Is there any way we can eforce parameter passing by reference in PBL?

  • I can't seem to get individual elements when comparing 2 arrays using Compare-Object

    My backup software keeps track of servers with issues using a 30 day rolling log, which it emails to me once a week in CSV format. What I want to do is create a master list of servers, then compare that master list against the new weekly lists to identify
    servers that are not in the master list, and vice versa. That way I know what servers are new problem and which ones are pre-existing and which ones dropped off the master list. At the bottom is the entire code for the project. I know it's a bit much
    but I want to provide all the information, hopefully making it easier for you to help me :)
    Right now the part I am working on is in the Compare-NewAgainstMaster function, beginning on line 93. After putting one more (fake) server in the master file, the output I get looks like this
    Total entries (arrMasterServers): 245
    Total entries (arrNewServers): 244
    Comparing new against master
    There are 1 differences.
    InputObject SideIndicator
    @{Agent= Virtual Server in vCenterServer; Backupse... <=
    What I am trying to get is just the name of the server, which should be $arrDifferent[0] or possibly $arrDifferent.Client. Once I have the name(s) of the servers that are different, then I can do stuff with that. So either I am not accessing the array
    right, building the array right, or using Compare-Object correctly.
    Thank you!
    Sample opening lines from the report
    " CommCells > myComCellServer (Reports) >"
    " myComCellServer -"
    " 30 day SLA"
    CommCell Details
    " Client"," Agent"," Instance"," Backupset"," Subclient"," Reason"," Last Job Id"," Last Job End"," Last Job Status"
    " myServerA"," vCenterServer"," VMware"," defaultBackupSet"," default"," No Job within SLA Period"," 496223"," Nov 17, 2014"," Killed"
    " myServerB"," Oracle Database"," myDataBase"," default"," default"," No Job within SLA Period"," 0"," N/A"," N/A"
    Entire script
    # things to add
    # what date was server entered in list
    # how many days has server been on list
    # add temp.status = pre-existing, new, removed from list
    # copy sla_master before making changes. Copy to archive folder, automate rolling 90 days?
    ## 20150114 Created script ##
    #declare global variables
    $global:arrNewServers = @()
    $global:arrMasterServers = @()
    $global:countNewServers = 1
    function Get-NewServers
    Param($path)
    Write-Host "Since we're skipping the 1st 6 lines, create test to check for opening lines of report from CommVault."
    write-host "If not original report, break out of script"
    Write-Host ""
    #skip 5 to include headers, 6 for no headers
    (Get-Content -path $path | Select-Object -Skip 6) | Set-Content $path
    $sourceNewServers = get-content -path $path
    $global:countNewServers = 1
    foreach ($line in $sourceNewServers)
    #declare array to hold object temporarily
    $temp = @{}
    $tempLine = $line.Split(",")
    #get and assign values
    $temp.Client = $tempLine[0].Substring(2, $tempLine[0].Length-3)
    $temp.Agent = $tempLine[1].Substring(2, $tempLine[1].Length-3)
    $temp.Backupset = $tempLine[3].Substring(2, $tempLine[3].Length-3)
    $temp.Reason = $tempLine[5].Substring(2, $tempLine[5].Length-3)
    #write temp object to array
    $global:arrNewServers += New-Object -TypeName psobject -Property $temp
    #increment counter
    $global:countNewServers ++
    Write-Host ""
    $exportYN = Read-Host "Do you want to export new servers to new master list?"
    $exportYN = $exportYN.ToUpper()
    if ($exportYN -eq "Y")
    $exportPath = Read-Host "Enter full path to export to"
    Write-Host "Exporting to $($exportPath)"
    foreach ($server in $arrNewServers)
    $newtext = $Server.Client + ", " + $Server.Agent + ", " + $Server.Backupset + ", " + $Server.Reason
    Add-Content -Path $exportPath -Value $newtext
    function Get-MasterServers
    Param($path)
    $sourceMaster = get-content -path $path
    $global:countMasterServers = 1
    foreach ($line in $sourceMaster)
    #declare array to hold object temporarily
    $temp = @{}
    $tempLine = $line.Split(",")
    #get and assign values
    $temp.Client = $tempLine[0]
    $temp.Agent = $tempLine[1]
    $temp.Backupset = $tempLine[2]
    $temp.Reason = $tempLine[3]
    #write temp object to array
    $global:arrMasterServers += New-Object -TypeName psobject -Property $temp
    #increment counter
    $global:countMasterServers ++
    function Compare-NewAgainstMaster
    Write-Host "Total entries (arrMasterServers): $($countMasterServers)"
    Write-Host "Total entries (arrNewServers): $($countNewServers)"
    Write-Host "Comparing new against master"
    #Compare-Object $arrMasterServers $arrNewServers
    $arrDifferent = @(Compare-Object $arrMasterServers $arrNewServers)
    Write-Host "There are $($arrDifferent.Count) differences."
    foreach ($item in $arrDifferent)
    $item
    ## BEGIN CODE ##
    cls
    $getMasterServersYN = Read-Host "Do you want to get master servers?"
    $getMasterServersYN = $getMasterServersYN.ToUpper()
    if ($getMasterServersYN -eq "Y")
    $filePathMaster = Read-Host "Enter full path and file name to master server list"
    $temp = Test-Path $filePathMaster
    if ($temp -eq $false)
    Read-Host "File not found ($($filePathMaster)), press any key to exit script"
    exit
    Get-MasterServers -path $filePathMaster
    $getNewServersYN = Read-Host "Do you want to get new servers?"
    $getNewServersYN = $getNewServersYN.ToUpper()
    if ($getNewServersYN -eq "Y")
    $filePathNewServers = Read-Host "Enter full path and file name to new server list"
    $temp = Test-Path $filePathNewServers
    if ($temp -eq $false)
    Read-Host "File not found ($($filePath)), press any key to exit script"
    exit
    Get-NewServers -path $filePathNewServers
    #$global:arrNewServers | format-table client, agent, backupset, reason -AutoSize
    #Write-Host ""
    #Write-Host "Total entries (arrNewServers): $($countNewServers)"
    #Write-Host ""
    #$global:arrMasterServers | format-table client, agent, backupset, reason -AutoSize
    #Write-Host ""
    #Write-Host "Total entries (arrMasterServers): $($countMasterServers)"
    #Write-Host ""
    Compare-NewAgainstMaster

    do not do this:
    $arrDifferent = @(Compare-Object $arrMasterServers $arrNewServers)
    Try this:
    $arrDifferent = Compare-Object $arrMasterServers $arrNewServers -PassThru
    ¯\_(ツ)_/¯
    This is what made the difference. I guess you don't have to declare arrDifferent as an array, it is automatically created as an array when Compare-Object runs and fills it with the results of the compare operation. I'll look at that "pass thru" option
    in a little more detail. Thank you very much!
    Yes - this is the way PowerShell works.  You do not need to write so much code once you understand what PS can and is doing.
    ¯\_(ツ)_/¯

  • How to pass Array of Java objects to Callable statement

    Hi ,
    I need to know how can I pass an array of objects to PL/SQL stored procedure using callable statement.
    So I am having and array list of some object say xyz which has two attributes string and double type.
    Now I need to pass this to a PL/SQL Procedure as IN parameter.
    Now I have gone through some documentation for the same and found that we can use ArrayDescriptor tp create array (java.sql.ARRAY).
    And we will use a record type from SQL to map this to our array of java objects.
    So my question is how this mapping of java object's two attribute will be done to the TYPE in SQL? can we also pass this array as a package Table?
    Please help
    Thanks

    I seem to remember that that is in one of Oracle's online sample programs.
    http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html

  • Array of class objects

    I was wondering how would you declare an array of class objects. Here is my situation:
    I'm working on a project dealing with bank accounts. Each customer has a specific ID and a balance. I have to handle transactions for each customer at different times, so I was thinking that I need an array of class objects; however, I dont know how to initialize them.
    Here's what I did:
    BankAccount [ ] myAccount = new BankAccount[10];
    // 10 = 10 customers
    How do I initialize the objects?
    Thankz

    I was wondering how would you declare an array of
    class objects. Here is my situation:
    I'm working on a project dealing with bank accounts.
    Each customer has a specific ID and a balance. I have
    to handle transactions for each customer at different
    times, so I was thinking that I need an array of
    class objects; however, I dont know how to initialize
    them.
    Here's what I did:
    BankAccount [ ] myAccount = new BankAccount[10];
    // 10 = 10 customers
    How do I initialize the objects?
    Thankz
    HAI
    Use the hashtable
    and store the classObject of each customer with the corresponding Id in it
    and whenever u want to recover a class match the Id and get the corresponding class
    that is the best way to solve ur problem
    Regards
    kamal

  • How to decide if Object is an array or single object

    Hi ,
    I have a function which can return an Array of objects or a single Object...how can I decided what function has returned to me.?...
    I am looking for some way by which I can decided if it is an Array or a Object....
    Thanks

    How about:
    yourObject.getClass().isArray();  // returns boolean

  • How to create an array of an object,

    Hi,
    Trying this in Oracle 10.3 studio, I have to use a web service, I have re-catalogued the web service succesfully,
    I am getting compilation error whenI try to create an array of a object,
    Services.PackageTrackingService.PackageTrackingItem[] pkgTrackingItem = new Services.PackageTrackingService.PackageTrackingItem[2];
    I am giving the array size as 2,
    The comilation error is showing as
    Multiple markers at this line
    - statement is expected
    - Expecting ';' but 'pkgTrackingItem' was found
    - expression is expected
    Is there any other way to create the array?
    Thanks in advance.
    -Sree

    Hi,
    Please declare the array in following manner.
    Services.PackageTrackingService.PackageTrackingItem[] pkgTrackingItem;
    Now you can insert the element into the array by pkgTrackingItem[0], pkgTrackingItem[1] etc.
    Bibhu

  • Array of cfc object help

    I just picked up coldfusion about a month ago, so my
    coldfusion lingo sucks. I have been programming in C++ for over 5
    years now and will be using a lot of C++ terminology to help avoid
    any confusion. I am writing a cfc function that preforms web
    servicing. This function needs to return an object/class that is
    defined in another coldfusion function. I can do this without a
    problem if I only need to return one instance of this object.
    However, I cannot seem to return an array of this object (I need to
    return multiple instances of this object, kind of like a query, but
    for programming purposes it needs to stay as an object).
    It seems that the webservicing function hates my return type.
    If I try to make an array of the object, it does not like array or
    the object as the return type. However, when I take this function
    out of the cfc, and make it a cfm, it gets the array of objects
    just fine. So, I think I am having issues with the return type on
    the <cffunction> tag. So I came up with the idea of creating
    another object which will hold an array of the first object and
    using the second object as the return type. Here is some psuedo
    code of the function I am working on:
    <cffunction name="SelectGames" access="remote"
    returntype="ArrayOfGames" output="false">
    <!-- arguments --->
    <!--- query --->
    <cfobject component = "myArray" name>
    <cfobject component="games" name="test">
    <cfset counter = 0>
    <cfloop query="getevents">
    <cfset counter = counter + 1>
    <cfset test.Game_id = event_id>
    <cfset test.gameDate = eventdate>
    <cfset test.Starttime = starttime>
    <cfset test.Place = place>
    <cfset test.Level = level>
    <cfset test.Sport = sport>
    <cfset test.Gender = division>
    <cfset test.Opponent = opponent_id>
    <cfset test.Type = type>
    <cfset test.Link = spec_name>
    <cfset myArray.gamesArray[counter] = test>
    </cfloop>
    <cfreturn myArray>
    </cffunction>
    It keeps telling me that it does not recognize the return
    type.
    Here are examples of the two objects I am using from the 2
    dif. cfc files:
    <cfcomponent>
    <cfproperty name="gamesArray" type="array">
    </cfcomponent>
    <cfcomponent>
    <cfproperty name="Game_id" type="numeric">
    <cfproperty name="gameDate" type="date">
    <cfproperty name="Starttime" type="string">
    <cfproperty name="Place" type="string">
    <cfproperty name="Level" type="string">
    <cfproperty name="Sport" type="string">
    <cfproperty name="Gender" type="string">
    <cfproperty name="Opponent" type="string">
    <cfproperty name="Type" type="string">
    <cfproperty name="Link" type="string">
    </cfcomponent>
    Feel free to post any questions to clear anything up, I know
    this is confusing and I probably did a poor job of explaining my
    problem. Also, if I throw this code into a cfm and try to make an
    array of games, it works, this is the code I got it to work with:
    <cfset myArray = newArray(1)>
    <cfloop query="getevents">
    <cfset counter = counter + 1>
    <cfset test.Game_id = event_id>
    <cfset test.gameDate = eventdate>
    <cfset test.Starttime = starttime>
    <cfset test.Place = place>
    <cfset test.Level = level>
    <cfset test.Sport = sport>
    <cfset test.Gender = division>
    <cfset test.Opponent = opponent_id>
    <cfset test.Type = type>
    <cfset test.Link = spec_name>
    <cfset myArray[counter] = test>
    </cfloop>
    I guess my problem is I do not know how to specify a type for
    an array.

    The return type of this FUNCTION would be returnType="array".
    No matter
    what kind of data the array contained.
    That's what I get for fast proofing.
    Ian Skinner wrote:
    > I would have to play with your code more if this does
    not clear it up
    > for you, but lets start with this simple concept first.
    >
    > You mentioned "typing the array" several times.
    ColdFusion is typeless,
    > you don't type an array, it is just array. An array of
    strings is the
    > same as an array of integers which is the same as an
    array of objects.
    >
    > So if you had a function something like this.
    >
    > <cffunction returnType="array" ...>
    > <cfset theArray = arrayNew()>
    >
    > <cfloop ...>
    > <cfset arrayAppend(theArray, newObject)>
    > </cfloop>
    >
    > <cfreturn theArray>
    > </cffunction>
    >
    > The return type of this function would be
    returnType="array". No matter what
    > kind of data the array contained.
    >
    > mwiley63 wrote:
    >> I just picked up coldfusion about a month ago, so my
    coldfusion lingo
    >> sucks. I have been programming in C++ for over 5
    years now and will
    >> be using a lot of C++ terminology to help avoid any
    confusion. I am
    >> writing a cfc function that preforms web servicing.
    This function
    >> needs to return an object/class that is defined in
    another coldfusion
    >> function. I can do this without a problem if I only
    need to return
    >> one instance of this object. However, I cannot seem
    to return an
    >> array of this object (I need to return multiple
    instances of this
    >> object, kind of like a query, but for programming
    purposes it needs to
    >> stay as an object).
    >> It seems that the webservicing function hates my
    return type. If I
    >> try to make an array of the object, it does not like
    array or the
    >> object as the return type. However, when I take this
    function out of
    >> the cfc, and make it a cfm, it gets the array of
    objects just fine.
    >> So, I think I am having issues with the return type
    on the
    >> <cffunction> tag. So I came up with the idea
    of creating another
    >> object which will hold an array of the first object
    and using the
    >> second object as the return type. Here is some
    psuedo code of the
    >> function I am working on:
    >>
    >> <cffunction name="SelectGames" access="remote"
    >> returntype="ArrayOfGames" output="false">
    >> <!-- arguments --->
    >> <!--- query --->
    >> <cfobject component = "myArray" name>
    >> <cfobject component="games" name="test">
    >> <cfset counter = 0>
    >> <cfloop query="getevents">
    >> <cfset counter = counter + 1>
    >> <cfset test.Game_id = event_id>
    >> <cfset test.gameDate = eventdate>
    >> <cfset test.Starttime = starttime>
    >> <cfset test.Place = place>
    >> <cfset test.Level = level>
    >> <cfset test.Sport = sport>
    >> <cfset test.Gender = division>
    >> <cfset test.Opponent = opponent_id>
    >> <cfset test.Type = type>
    >> <cfset test.Link = spec_name>
    >> <cfset myArray.gamesArray[counter] = test>
    >> </cfloop>
    >> <cfreturn myArray>
    >> </cffunction>
    >>
    >> It keeps telling me that it does not recognize the
    return type.
    >> Here are examples of the two objects I am using from
    the 2 dif. cfc
    >> files:
    >> <cfcomponent>
    >> <cfproperty name="gamesArray" type="array">
    >> </cfcomponent>
    >> <cfcomponent>
    >> <cfproperty name="Game_id" type="numeric">
    >> <cfproperty name="gameDate" type="date">
    >> <cfproperty name="Starttime" type="string">
    >> <cfproperty name="Place" type="string">
    >> <cfproperty name="Level" type="string">
    >> <cfproperty name="Sport" type="string">
    >> <cfproperty name="Gender" type="string">
    >> <cfproperty name="Opponent" type="string">
    >> <cfproperty name="Type" type="string">
    >> <cfproperty name="Link" type="string">
    >> </cfcomponent>
    >>
    >> Feel free to post any questions to clear anything
    up, I know this is
    >> confusing and I probably did a poor job of
    explaining my problem.
    >> Also, if I throw this code into a cfm and try to
    make an array of
    >> games, it works, this is the code I got it to work
    with:
    >> <cfset myArray = newArray(1)>
    >> <cfloop query="getevents">
    >> <cfset counter = counter + 1>
    >> <cfset test.Game_id = event_id>
    >> <cfset test.gameDate = eventdate>
    >> <cfset test.Starttime = starttime>
    >> <cfset test.Place = place>
    >> <cfset test.Level = level>
    >> <cfset test.Sport = sport>
    >> <cfset test.Gender = division>
    >> <cfset test.Opponent = opponent_id>
    >> <cfset test.Type = type>
    >> <cfset test.Link = spec_name>
    >> <cfset myArray[counter] = test>
    >> </cfloop>
    >>
    >> I guess my problem is I do not know how to specify a
    type for an array.
    >>

  • How to call a method using a array of that object?

    hey, another array question
    for example i have 2 classes one name class and a driver
    inside the name class i have method that gets the name
    public Name getName1( ) {return name1;}
    my question is if i created an array of Name objects in my driver with the following line
    Name [ ] n1 = new Name [ ] ;
    and i wanna call methods inside the name class using my array of Name that i created how do i do it?
    thanks in advance

    thanks for the reply Maxx
    another question regarding arrays
    for example if im doing an array of objects Name[ ] n1 = new Name [ ]
    and i have a method that removes the name if its the same as the user input
    if (n1[ i ].getName.equals(myName))
    / / if they equal it removes it,
    else,
    / / the n[ 1 ] stays the same
    ive search the forum for previous questions on this but their examples doesnt seems to work, can anyone help? also if end up using this remove method that checks the elements in n1 if it matches it will remove it what should i do to avoid nullpointerexceptions if i wanna shift it all down?
    thanks in advance

Maybe you are looking for

  • Changing Import source

    I am running out of hard drive space which is the source for importing my images into Lightroom 4.3.  I have these images backed up on an external drive.  I now want to use the external drive as my source of import.  How do I do that.  And then how t

  • Re download of Photo Elements 10

    I need to re download photo elements 10, please give me the link to that file I can not find it in my account. Thanks

  • I am using Pattern matching using vision assistant . its able to detect the temple which created while configuration

    Hi all ,           i am using vision assistant to do patten matching . its able to find the pattern with created template in vision assistant .         if i load some other pattern is not detecting ..           i have attached my vi file  Attachments

  • My ipad wont switch on and i can not restore it...help?

    My one week old ipad Air has frozen and now wont switch on. I have tried to restore it by holding down the button but nothing happens, when connecting it to I tunes, I can not restore it as it wants me to turn off the find my ipad which I can not tur

  • Autoclearing of GR/IR accounts through SAPF124E program

    Hi , We are trying to do auto clearing of GR/IR accounts.We gave the criteria as PO(EBELN) and PO Line Item(EBELP) in OB74 configuration. We have a PO for which 2 GR's and one IR is posted.The GR quantities posted are 2 and 3 and IR quantity posted i