Passing polymorphic ArrayLists to a method expecting ArrayList superclass

In short, is it possible? In keeping in line with my other threads and a program using cats, I give you this example using Cats and Animals (a cat is an animal):
public void go()
     ArrayList<Cat> lotsOfCats = new ArrayList<Cat>();
     feed(lotsOfCats);
void feed(ArrayList<Animal> animals)
     //feed the animals
}So an error is thrown because the function is expecting an ArrayList of Animals and I'm trying to pass in an ArrayList of Cats. The function shouldn't have any problem dealing with the cats though because a cat IS AN Animal, so anything you can do to/find out about the superclass animal you can certainly apply to a cat. I've tried casting the lotsOfCats ArrayList like so:
ArrayList<Animal> myAnimals = (ArrayList<Animal>)lotsOfCats;But it didn't work. So is there any way for me to reference the ArrayList as type Animal without necessarily having to originally declare it that type? Or do I just have to suck it up and declare it type Animal from the get go?

Thank you both for the responses. I gave you both helpful ratings because I think you both answered the question, just in different ways. fredrikl, your solution certainly works well. I'm sure I have seen that notation in documentation and such but haven't had experience using it yet. Your solution works out perfectly for my method since all I am trying to do is print out array components with it. I see you said you can't add components, that makes sense since the ArrayList doesn't really know what it is, but I figure you can still modify existing things in the list, right? Didn't actually try it yet but I have been using some casts to get out various things for display and that's working fine.
morgalr, that's a complicated piece of code you have there. I don't fully understand it yet but I'll go through it again if I get this problem. From what I gather, it looks like you actually tried to solve my original problem and successfully did it?

Similar Messages

  • Pass an arrayList into a method

    I am looking to pass and  arraylist into a method and I am wondering how this is done...

    I figured it out:
    public function someMethod(someArray:ArrayList){}
    I figured it was the same.
    This is dealing with flex, How ever on the AS side, so its a pure AS question

  • How can I move an ArrayList from one method to another?

    As the subject reveals, I want to know how I move an ArrayList. In one method, I fill my ArrayList with objects, and in the next I want to pick an arbitrary object out of the ArrayList.
    How do I make this work??

    You pass the same array list to both the method. Both method are getting the same thing.
    void main(){
    //create array list here
    ArrayList aList = new ArrayList();
    //pass it to a method to fill items
    fillArrayList(aList);
    //pass the same arraylist to another method
    printArrayList(aList);
    void fillArrayList(ArrayList list){
      list.add("A");
    void printArrayList(ArrayList list){
    //The array list will contain A added by the previos method
    System.out.println(list);
    FeedFeeds : http://www.feedfeeds.com                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Arraylist issue: pass all the arrayList `s object to other arrayList ...

    hi all...i hope somebody could show me some direction on my problem...i want to pass a arraylist `s cd information to an other arraylist
    and save the new arraylist `s object to a file...i try to solve for a long ..pls help...
    import java.text.*;
    import java.util.*;
    import java.io.*;
    public class Demo{
         readOperation theRo = new readOperation();
         errorCheckingOperation theEco = new errorCheckingOperation();
         ArrayList<MusicCd>  MusicCdList;
         private void heading()
              System.out.println("\tTesting read data from console, save to file, reopen that file\t");
         private void readDataFromConsole()
         //private void insertCd()
            MusicCdList = new ArrayList<MusicCd>( ); 
            MusicCd theCd;
            int muiseCdsYearOfRelease;
            int validMuiseCdsYearOfRelease;
            String muiseCdsTitle;
              while(true)
                    String continueInsertCd = "Y";
                   do
                        muiseCdsTitle = theRo.readString("Please enter your CD`s title : ");
                        muiseCdsYearOfRelease = theRo.readInt("Please enter your CD`s year of release : ");
                        validMuiseCdsYearOfRelease = theEco.errorCheckingInteger(muiseCdsYearOfRelease, 1000, 9999);
                        MusicCdList.add(new MusicCd(muiseCdsTitle, validMuiseCdsYearOfRelease));//i try add the cd`s information to the arrayList
                        MusicCdList.trimToSize();
                        //saveToFile(MusicCdList);
                        continueInsertCd = theRo.readString("Do you have another Cd ? (Y/N) : ");
                   }while(continueInsertCd.equals("Y") || continueInsertCd.equals("y") );
                   if(continueInsertCd.equals("N") || continueInsertCd.equals("n"));
                                                    //MusicCdList.add(new MusicCd(muiseCdsTitle, muiseCdsYearOfRelease));                              
                        break;
                      //System.out.println("You `ve an invalid input " + continueInsertCd + " Please enter (Y/N) only!!");
         //i want to pass those information that i just add to the arrayList to file
         //I am going to pass the arraylist that contains my cd`s information to new arraylist "saveitems and save it to a file...
         //i stuck on this problem
         //how do i pass all the arrayList `s object to another arraylist ..pls help
         //it is better show me some example how to solve thx a lot
         private void saveToFile(ArrayList<MusicCd> tempItems)
              ArrayList<MusicCd> saveItems;
              saveItems = new ArrayList<MusicCd>();
              try
                   File f = new File("cdData.txt");
                   FileOutputStream fos = new FileOutputStream(f);
                   ObjectOutputStream oos = new ObjectOutputStream(fos);
                   saveItems.add(ArrayList<MusicCd> tempItems);
                   //items.add("Second item.");
                   //items.add("Third item.");
                   //items.add("Blah Blah.");
                   oos.writeObject(items);
                   oos.close();
              catch (IOException ioe)
                   ioe.printStackTrace();
              try
                   File g = new File("test.fil");
                   FileInputStream fis = new FileInputStream(g);
                   ObjectInputStream ois = new ObjectInputStream(fis);
                   ArrayList<String> stuff = (ArrayList<String>)ois.readObject();
                   for( String s : stuff ) System.out.println(s);
                   ois.close();
              catch (Exception ioe)
                   ioe.printStackTrace();
         public static void main(String[] args)
              Demo one = new Demo();
              one.readDataFromConsole();
              //one.saveToFile();
              //the followring code for better understang
    import java.io.Serializable;
    public class MusicCd implements Serializable
         private String musicCdsTitle;
            private int yearOfRelease;
         public MusicCd()
              musicCdsTitle = "";
              yearOfRelease = 1000;
         public MusicCd(String newMusicCdsTitle, int newYearOfRelease)
              musicCdsTitle = newMusicCdsTitle;
              yearOfRelease = newYearOfRelease;
         public String getTitle()
              return musicCdsTitle;
         public int getYearOfRelease()
              return yearOfRelease;
         public void setTitle(String newMusicCdsTitle)
              musicCdsTitle = newMusicCdsTitle;
         public void setYearOfRelease(int newYearOfRelease)
              yearOfRelease = newYearOfRelease;
         public boolean equalsName(MusicCd otherCd)
              if(otherCd == null)
                   return false;
              else
                   return (musicCdsTitle.equals(otherCd.musicCdsTitle));
         public String toString()
              return("Music Cd`s Title: " + musicCdsTitle + "\t"
                     + "Year of release: " + yearOfRelease + "\t");
         public ArrayList<MusicCd> getMusicCd(ArrayList<MusicCd> tempList)
              return new ArrayList<MusicCd>(ArrayList<MusicCd> tempList);
    import java.util.Scanner;
    import java.util.InputMismatchException;
    import java.util.NoSuchElementException;
    public class errorCheckingOperation
         public int errorCheckingInteger(int checkThing, int lowerBound, int upperBound)
               int aInt = checkThing;
               try
                    while((checkThing < lowerBound ) || (checkThing > upperBound) )
                         throw new Exception("Invaild value....Please enter the value between  " +  lowerBound + " & " +  upperBound );
               catch (Exception e)
                 String message = e.getMessage();
                 System.out.println(message);
               return aInt;
           public int errorCheckingSelectionValue(String userInstruction)
                int validSelectionValue = 0;
                try
                     int selectionValue;
                     Scanner scan = new Scanner(System.in);
                     System.out.print(userInstruction);
                     selectionValue = scan.nextInt();
                     validSelectionValue = errorCheckingInteger(selectionValue , 1, 5);
               catch (NoSuchElementException e)
                   //if no line was found
                   System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
              catch (IllegalStateException e)
                   // if this scanner is closed
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return validSelectionValue;
    import java.util.*;
    public class readOperation{
         public String readString(String userInstruction)
              String aString = null;
              try
                         Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   aString = scan.nextLine();
              catch (NoSuchElementException e)
                   //if no line was found
                   System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
              catch (IllegalStateException e)
                   // if this scanner is closed
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aString;
         public char readTheFirstChar(String userInstruction)
              char aChar = ' ';
              String strSelection = null;
              try
                   //char charSelection;
                         Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   strSelection = scan.next();
                   aChar =  strSelection.charAt(0);
              catch (NoSuchElementException e)
                   //if no line was found
                   System.out.println("\nNoSuchElementException error occurred (no line was found) " + e);
              catch (IllegalStateException e)
                   // if this scanner is closed
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aChar;
         public int readInt(String userInstruction) {
              int aInt = 0;
              try {
                   Scanner scan = new Scanner(System.in);
                   System.out.print(userInstruction);
                   aInt = scan.nextInt();
              } catch (InputMismatchException e) {
                   System.out.println("\nInputMismatchException error occurred (the next token does not match the Integer regular expression, or is out of range) " + e);
              } catch (NoSuchElementException e) {
                   System.out.println("\nNoSuchElementException error occurred (input is exhausted)" + e);
              } catch (IllegalStateException e) {
                   System.out.println("\nIllegalStateException error occurred (scanner is closed)" + e);
              return aInt;
    }

    sorry for my not-clear descprtion...thc for your help....i got a problem on store some data to a file ....u can see my from demo..
    Step1: i try to prompt the user to enter his/her cd `s information
    and i pass those cd `s information to an object "MuiscCd" ..and i am going to add this "MuiscCd" to the arrayList " MusicCdList ". i am fine here..
    Step2: and i want to save the object that `s in my arrayList " MusicCdList " to a file....i got stuck here..<_> ..(confused).
    Step3:
    i will reopen the file and print it out..(here i am alright )

  • Where to find info on ArrayList or other methods?

    Hi,
    Can someone tell me how to find any resourses if I want to know how to use a method like ArrayList?
    I can't find what I want in FORUMS, but I know it's there, somewhere....
    could you please tell me how to search for that ?
    Thanks

    The most useful resource for Java coding is the Javadoc API ( http://java.sun.com/j2se/1.3/docs/api/index.html ).
    You can browse on the Web or download it to your own PC for more frequent use.
    I find the the Index function useful when I'm not sure exactly what I'm looking for.
    Good Luck.

  • Passing JAVA objects to different methods

    As you can see that
    "public static IntervalCategoryDataset createDataset()" want to get the data and attributes from storeStartDate and storeEndDate methods. i have class files, StartDate and EndDate that contains all the accessor methods. after i have store the relevant attributes, i want to call it out in the "public static IntervalCategoryDataset createDataset()" method to manipulate it.
    i hope that my question doesn't confuse you all. hope that you all can guide me on this. Thank you
    package ericTest;
    import java.io.BufferedReader;
    import java.io.DataInputStream;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;
    import java.text.ParseException;
    import java.util.StringTokenizer;
    import java.util.ArrayList;
    import java.util.Iterator;
    import java.util.Calendar;
    import java.util.Date;
    import org.jfree.chart.ChartFactory;
    import org.jfree.chart.ChartPanel;
    import org.jfree.chart.JFreeChart;
    import org.jfree.data.category.IntervalCategoryDataset;
    import org.jfree.data.gantt.Task;
    import org.jfree.data.gantt.TaskSeries;
    import org.jfree.data.gantt.TaskSeriesCollection;
    import org.jfree.data.time.SimpleTimePeriod;
    import org.jfree.ui.ApplicationFrame;
    import org.jfree.ui.RefineryUtilities;
    import Gantt.Chart;
    import com.db4o.Db4o;
    import com.db4o.ObjectContainer;
    import com.db4o.ObjectSet;
    public class GanttDemo3 extends ApplicationFrame {
         private static ObjectContainer db;
         private static String day;
         private static String month;
         private static String year;
         private static String task;
         private static String startDate;
         private static String endDate;
         private static String startDay;
         private static String startMonth;
         private static String startYear;
         public static int startDay1;
         public static int startMonth1;
         public static int startYear1;
         public static int startDay2;
         public static int startMonth2;
         public static int startYear2;
         public static String endDay;
         public static String endMonth;
         public static String endYear;
         public static int endDay1;
         public static int endMonth1;
         public static int endYear1;
         public static int endDay2;
         public static int endMonth2;
         public static int endYear2;
         DataInputStream dis = null;
         String fileRecord = null;
       public GanttDemo3(final String title) {
            super(title);
            final IntervalCategoryDataset dataset = createDataset();
            final JFreeChart chart = createChart(dataset);
            // add the chart to a panel...
            final ChartPanel chartPanel = new ChartPanel(chart);
            chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
            setContentPane(chartPanel);
             public final static String filename = "C:\\KLGCC Mock Up.yap";
             public void storeData() throws IOException{
                  new File(filename).delete();
                  db = Db4o.openFile(filename);
                       File f = new File("C:\\KLGCC Mock Up.txt");
                       FileReader fis = new FileReader(f);
                       BufferedReader bis = new BufferedReader(fis);
                       while((fileRecord = bis.readLine()) != null){
                                 StringTokenizer st = new StringTokenizer(fileRecord,",");
                                 task = st.nextToken();
                                 startDate = st.nextToken();
                                 endDate = st.nextToken();
                                 Country c = new Country(task, startDate, endDate);
                                 db.set(c);               
                       db.close();
             public void storeStartDate() throws ParseException{
                  db = Db4o.openFile(filename);
                  Country c = new Country();
                  ObjectSet result = db.get(c);
                  while(result.hasNext()){
                       Country obj = (Country)result.next();
                       String sDate = obj.getStartDate();
                       StringTokenizer str = new StringTokenizer(sDate, "/");
                       startMonth = str.nextToken();
                       startDay = str.nextToken();
                       startYear = str.nextToken();
                       int startMonth1 = Integer.parseInt(startMonth);
                       int startDay1 = Integer.parseInt(startDay);
                       int startYear1 = Integer.parseInt(startYear);
                       StartDate sd = new StartDate(startDay1, startMonth1, startYear1);
                       ArrayList<Integer> startDay2 = new ArrayList<Integer>();
                       startDay2.add(startDay1);
                       ArrayList<Integer> startMonth2 = new ArrayList<Integer>();
                       startMonth2.add(startMonth1);
                       ArrayList<Integer> startYear2 = new ArrayList<Integer>();
                       startYear2.add(startYear1);                 
                  db.close();          
        public void storeEndDate() throws ParseException{
                  db = Db4o.openFile(filename);
                  Country c = new Country();
                  ObjectSet result = db.get(c);
                  while(result.hasNext()){
                       Country obj = (Country)result.next();
                       String sEndDate = obj.getEndDate();
                       StringTokenizer str1 = new StringTokenizer(sEndDate, "/");
                       endMonth = str1.nextToken();
                       endDay = str1.nextToken();
                       endYear = str1.nextToken();
                       int endMonth1 = Integer.parseInt(endMonth);
                       int endDay1 = Integer.parseInt(endDay);
                       int endYear1 = Integer.parseInt(endYear);
                       EndDate ed = new EndDate(endDay1, endMonth1, endYear1);
                       ArrayList<Integer> endDay2 = new ArrayList<Integer>();
                       endDay2.add(startDay1);
                       ArrayList<Integer> endMonth2 = new ArrayList<Integer>();
                       endMonth2.add(endMonth1);
                       ArrayList<Integer> endYear2 = new ArrayList<Integer>();
                       endYear2.add(endYear1);
                  db.close();
    public static IntervalCategoryDataset createDataset() {
             final TaskSeries s1 = new TaskSeries("Scheduled");
             StartDate sd = new StartDate(startDay1, startMonth1, startYear1);
             EndDate ed = new EndDate(endDay1, endMonth1, endYear1);
            s1.add(new Task(task,
                   new SimpleTimePeriod(date(sd.getStartDay1(),sd.getStartDay1(), sd.getStartYear1()),
                                        date(ed.getEndDay1(), ed.getEndMonth1(), ed.getendYear1()))));
            System.out.println("dumb");
                    final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            return collection;
         * Utility method for creating <code>Date</code> objects.
         * @param day  the date.
         * @param month  the month.
         * @param year  the year.
         * @return a date.
        private static Date date(final int startDay2, final int startMonth2, final int startYear2) {
            System.out.println("sdojsodj");
             final Calendar calendar = Calendar.getInstance();
            calendar.set(startYear2, startMonth2, startDay2);
            final Date result = calendar.getTime();
            return result;
         * Creates a chart.
         * @param dataset  the dataset.
         * @return The chart.
        private JFreeChart createChart(final IntervalCategoryDataset dataset) {
            final JFreeChart chart = ChartFactory.createGanttChart(
                "Gantt Chart Demo",  // chart title
                "Task",              // domain axis label
                "Date",              // range axis label
                dataset,             // data
                true,                // include legend
                true,                // tooltips
                false                // urls
    //        chart.getCategoryPlot().getDomainAxis().setMaxCategoryLabelWidthRatio(10.0f);
            return chart;   
        public static void main(final String[] args) throws IOException, ParseException
            final GanttDemo3 demo = new GanttDemo3("Gantt Chart Demo 1");
            demo.storeData();
            demo.storeStartDate();
            //demo.storeEndDate();
            //demo.pack();
            //RefineryUtilities.centerFrameOnScreen(demo);
            //demo.setVisible(true);
    }

    the error that came out in eclipse is
    Exception in thread "main" java.lang.IllegalArgumentException: Null 'description' argument.
         at org.jfree.data.gantt.Task.<init>(Task.java:87)
         at ericTest.GanttDemo3.createDataset(GanttDemo3.java:191)
         at ericTest.GanttDemo3.<init>(GanttDemo3.java:78)
         at ericTest.GanttDemo3.main(GanttDemo3.java:248)and if i replace this
    public static IntervalCategoryDataset createDataset() {
             final TaskSeries s1 = new TaskSeries("Scheduled");
             StartDate sd = new StartDate(startDay1, startMonth1, startYear1);
             EndDate ed = new EndDate(endDay1, endMonth1, endYear1);
            s1.add(new Task(task,
                   new SimpleTimePeriod(date(sd.getStartDay1(),sd.getStartDay1(), sd.getStartYear1()),
                                        date(ed.getEndDay1(), ed.getEndMonth1(), ed.getendYear1()))));
            System.out.println("dumb");
                    final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            return collection;
        }with
    public static IntervalCategoryDataset createDataset() {
             final TaskSeries s1 = new TaskSeries("Scheduled");
             Chart chart = new Chart();
            s1.add(new Task(chart.getTitle(),
                   new SimpleTimePeriod(date(chart.getStartDay(), chart.getStartMonth(), chart.getStartYear()),
                                        date(chart.getEndDay(), chart.getEndMonth(), chart.getEndYear()))));
    System.out.println("dumb");
                    final TaskSeriesCollection collection = new TaskSeriesCollection();
            collection.add(s1);
            return collection;
        }the chart class file has all the accessor methods and all the values is hard code. so the graph can be generated. the problem now is if i want to get the values from the StartDate and EndDate methods to get the dates so that i can put it into the createDataset method to add the values needed for the graph.
    can anyone help me on this? thanks alot

  • In BADi , How to pass the values between two Method

    Hi Experts,
    We have two methods in BADis. How to pass the value  between two Methods. Can you guys explain me out with one example...
    Thanks & Regards,
    Sivakumar S

    Hi Sivakumar!
    Create a function group.
    Define global data (there is a similiar menu point to jump to the top include).
    Create one or two function modules, with which you can read and write the global data.
    In your BADI methods you can access the global data with help of your function modules. It will stay in memory through the whole transaction.
    Regards,
    Christian

  • How to call a java method so I can pass a file into the method

    I want to pass a file into a java method method from the main method. Can anyone give me some help as to how I pass the file into the method - do I pass the file name ? are there any special points I need to put in the methods signature etc ?
    FileReader file = new FileReader("Scores");
    BufferedReader infile = new BufferedReader(file);
    Where am I supposed to put the above text - in the main method or the one I want to pass the file into to?
    Thanks

    It's a matter of personal preference really. I would encapsulate all of the file-parsing logic in a separate class that implements an interface so that if in the future you want to start taking the integers from another source, e.g. a db, you wouldn't need to drastically alter your main application code. Probably something like this, (with an assumption that the numbers are delimited by a comma and a realisation that my file-handling routine sucks):
    public class MyApp{
    public static void main(String[] args){
    IntegerGather g = new FileIntegerGatherer();
    Integer[] result = g.getIntegers(args[0]);
    public interface IntegerGatherer{
    public Integer[] getIntegers(String location);
    import java.io.*;
    public class FileIntegerGatherer implements IntegerGatherer{
    public Integer[] getIntegers(String location){
    FileInputStream fs=null;
    try{
    File f = new File(location);
    fs = new FileInputStream(f);
    byte[] in = new byte[1024];
    StringBuffer sb = new StringBuffer();
    while((fs.read(in))!=-1){
    sb.append(new String(in));
    StringTokenizer st = new StringTokenizer(sb.toString(),",");
    Integer[] result = new Integer[st.countTokens()];
    int count = 0;
    while(st.hasMoreTokens()){
    result[count]=Integer.valueOf(st.nextToken());
    count++;
    catch(IOException e){
    //something sensible here
    finally{
    if(fs!=null){
    try{
    fs.close();
    catch(IOException f){
    return result;
    Once compiled you could invoke it as java MyApp c:\myInts.txt
    Sorry if there are typos in there, I don't have an ide open ;->

  • How to pass table to in a method as a parameter

    Hi
    I need to pass one table in one method to another method as a parameter.
    ex: it_tab type zvalue(DDIC).
         send_mail( it_tab)like this i need to pass. How to do this.
    Please help me.
    Thanks & Regards
    SUN

    Hello,
    You'll need a table category that has the same structure of your internal table. Suppose you need to pass an internal table of type SCARR: you'll actually pass a parameter of type SCARR_TAB (look for it into tcode SE11).
    Remember that in a OOP scope, you cannot have header line in your internal tables.
    Regards,
    Andre

  • What is the use of passing String[] args in main() method?

    what is the use of passing String[] args in main() method?
    Is there any specific use for this ?

    actually my sir asked me the same question & I gave
    the same reply as given by you........but he further
    asked what is the use of this also??
    ie accepting cmd line args at runtime??is there any
    specific purpose ??Apart from the one you just mentioned? No

  • Passing select-options value in method

    How to pass select-options value in method ?
    Example:
    Select-options: carrid for spfli-carrid.
    class cl_myclass implementation.
    select  carrid connid from
    spfli where carrid in carrid.
    endclass.
    Thanks

    Hello Anee
    The coding of this functionality is quite simple:
    REPORT zmy_report.
    DATA:  go_myclass   TYPE REF TO zcl_myclass,
               gd_repid         TYPE syst-repid.
    PARAMETERS:
      p_bukrs   ...
    SELECT-OPTIONS:
      o_kunnr  ...
    START-OF-SELECTION.
      gd_repid = syst-repid.
      CREATE OBJECT go_myclass
        EXPORTING
          id_calling_program = gd_repid.
    And that's how your CONSTRUCTOR method should look like:
    METHOD constructor.  " IMPORTING parameter id_calling_program
    CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'
      EXPORTING
        CURR_REPORT = id_calling_report
      TABLES
        SELECTION_TABLE = me->mt_selopts.
    " NOTE: define mt_selopts as instance attribute of table type RSPARAMS_TT
    ENDMETHOD.
    Finally you have to extract the parameter and select-options from MT_SELOPTS.
    Regards
      Uwe

  • Passing custom DTO to input method...

    Hi,
    Im attempting to create a workshop web service that accesses an EJB control. The
    method's input params require the passing of a custom built data transfer object
    (bean) that contains itself other objects. is there any way to do this via a web
    service thru workshop?

    John,
    A workshop web service (i.e. a JWS file) is analogous to a JSP/servlet. Any
    class (bean) that needs to be passed to an EJB Control method should be
    accessible to the contaning JWS.
    So the bean and all the objects contained/referenced by the bean should be
    available in any one of the following 3 ways:
    1. System CLASSPATH
    2. In the WEB-INF/lib or WEB-INF/classes directory of the Workshop project
    3. As a Java file in the Workshop project directory.
    I hope this answers your question. Do let me know if I can help further.
    Regards,
    Anurag
    "John Bonham" <[email protected]> wrote in message
    news:3e0f058e$[email protected]..
    >
    Hi,
    Im attempting to create a workshop web service that accesses an EJBcontrol. The
    method's input params require the passing of a custom built data transferobject
    (bean) that contains itself other objects. is there any way to do this viaa web
    service thru workshop?

  • Passing an array from one method to another

    I am passing an array from my "load" method and passing it to be displayed in my "display" method in an applet .
    I made the array a class variable (to be able to pass it to the "display" method).
    The applet runs, but nothing seems to be in the array.The screen says applet started, but nothing else. There does not seem to be any CPU activity.
    Trying to debug this, I have tried to paint the screen during the array build. I never figured out how to do this. So I made this a non applet class, put it in debug, and the array seems to load okay.
    Any help is appreciated.
    This is the applet code:
    import java.applet.Applet;
    import java.awt.*;
    import java.io.*;
    import java.util.*;
    import java.net.*;
    public class urla extends java.applet.Applet
    int par1;
    int i = 1;
    int j = 20;
    int m = 0;
    int k = 0;
    String arr[] = new String[1000];
    String inputLine;
        public void load() throws Exception
          try
            URL mysite = new URL("http://www.xxxxxxxxxxxxxx.html");
           URLConnection ms = mysite.openConnection();
           BufferedReader in = new BufferedReader(
           new InputStreamReader(
           ms.getInputStream()));
             while ((inputLine = in.readLine()) != null)
               arr[m] = inputLine;
               m++;
           in.close();
          catch (MalformedURLException e)
            k++;
        public void display(Graphics screen)
          screen.drawString("THE FOLLOWING HAVE ADDED THEIR BIOS:",5 ,5);
          for (int i = 0; i < 20; i++);
            j = j + 20;
            screen.drawString("output - "
            + arr, 5, j);
            repaint() ;
    }

    String arr[] = new String[1000];is this typing mistake????? because if u did it in
    program as well i don think it will work.. the tag is
    innnside array lenght... hope iam saying this right!!no, he had the bold form tags (b and /b inside square brackets) in his previous non-code tagged post. He carried it over to this post and they caused an error. I highly doubt that they were in his actual program. Just delete them.
    Message was edited by:
    petes1234

  • Passing argstrings[1] to another method

    Hello I want to pass argstrings[1] to another method. Other stuff is being passed there to. Before I passed argstrings[1] the other stuff worked, now it does not.
    Please tell me why I am getting compilation errors.
    Thanks
    public static void main(String[] argStrings)
            String filePath = null;
            if(argStrings.length != 0)
                 filePath = argStrings[0];
            else
                 System.out.println("Enter a directory please");// Else you have to enter a directory
                 Scanner scan = new Scanner(System.in);
                    filePath = scan.nextLine();
            String copyDate = argStrings[1];
            Date dateToLookFor = new Date(copyDate);
            listFiles(filePath);// this no longer works as of the new log(datetolookfor)
            log(dateToLookFor);// just wanna pass this to the next method
       private static void log(File[] files, Date dateToLookFor)
       {

    Well i only get one compile error, cheers.
    So please could you help me what i have to do to this mess in order for it to work:
    Or just edit the code as I dont think there is much to do:
    Thanks
    import java.lang.*;
    import java.io.*;
    import java.util.*;
    * This application identifies files which could potentially be archived
    * and copied. A file is to be archived if the last modified date is more
    * than 100 days ago. A file is to be copied if it has been modified since
    * a given time. Only nominated extensions are to be considered. The java.
    * util.Calendar class contains relevant methods for comparing times and dates.
    * For instance, a command line of: java CrawlerApp Knuth 2005-12-28 php html
    * Will nominate for archiving or copying only php or html files in the Knuth
    * directory tree. It will only nominate for copying files modified after
    * midnight on the 28th of December, 2005.
    * The output from this application is two files (called archive.txt and copy.txt)
    * containing the names of files to be archived, and those which may be copied.
    * The names will follow the convention specified in the create application.
    * These two text files must appear in the root directory (Knuth, in this example).
    public class Crawler
       public static void main(String[] argStrings)
            String name = null;
            if(argStrings.length != 0)
                 name = argStrings[0];
            else
                 System.out.println("Enter a directory please");// Else you have to enter a directory
                 Scanner scan = new Scanner(System.in);
                    name = scan.nextLine();
            String copyDate = argStrings[1];
            listFiles(name, copyDate);
       private static void log(String copyDate, File[] files)
            PrintStream archivePS = null;
            PrintStream copyPS = null;
            try
                 archivePS = new PrintStream("archive.txt");
                 copyPS = new PrintStream("copy.txt");
                 // instantiate cutoff Calendar instance to test files with
                   Calendar cutoff = Calendar.getInstance();
                   // time now
               Date now = new Date();
                   // set cutoff time with current time
                   cutoff.setTime(now);
                   // subtract 100 days from current time
                   cutoff.add(Calendar.DAY_OF_YEAR, -100);//
                 Calendar calendar = Calendar.getInstance();
                 for(int j = 0; j < files.length; j++)
                      // get last modified time of file
                      long lastModified = files[j].lastModified();
                      // convert lastModified to a date
                      Date lastMod = new Date(lastModified);
                      // set the time for the Calendar instance with lastMod
                      calendar.setTime(lastMod);
                      // test against cutoff Calendar instance variable
                     if(lastMod.before(cutoff.getTime()))
                           archivePS.println(files[j]);
                         if(lastMod.before(cutoff.getTime()))
                              copyPS.println(files[j]);
                         // I will do copy later, just want to see if this works
            catch(FileNotFoundException fnfe)
                 System.err.println("Log error: " + fnfe.getMessage());
            catch(IOException ioe)
                 System.err.println("I/O exception: " + ioe.getMessage());
       private static void listFiles(String name, String copyDate)
           File f = new File(name);// Try to get a list of files in the directory
           File[] files = f.listFiles();// Make array of all the files in that directory
           log(files, copyDate);
           if(f.isDirectory())// If the argStrings[0] is a directory then do the following
               File[] children = f.listFiles(HTMLfilter);// Make an array of html files
               System.out.println("HTML files in " + name + " directory = " + children.length);
               File[] phpFiles = f.listFiles(PHPFilter);// Make an array of php files
               System.out.println("PHP files in " + name + " directory = " + phpFiles.length);
       private static FileFilter HTMLfilter = new FileFilter()
           public boolean accept(File f)// Accept directory Knuth
               //if(f.isDirectory()) return true;
               String name = f.getName().toLowerCase();
               return name.endsWith("html");
               //if(file is 100 days old)
       private static FileFilter PHPFilter = new FileFilter()
            public boolean accept(File f)
                 //if(f.isDirectory()) return true;
                 String name = f.getName().toLowerCase();
                 return name.endsWith("php");
    }

  • I am passing range table from the method of ODATA Service to FM but In FM range table is becoming initial.What would be the reason for the same?

    I am passing range table from the method of ODATA Service to FM but In FM range table is becoming initial.What would be the reason for the same?

    Vinod, Can you share detail on how are you sending and how are you reading.

Maybe you are looking for