?
Solved

Program in main

Posted on 2003-03-14
32
Medium Priority
?
294 Views
Last Modified: 2007-12-19


How do I write the prog in main to receive the calandar value from getCalandar in com.tr.IXCalandar  and then
pass the calandar value to getCycleRunDate (ISCObject oCalendar) in my Main prog in my class to test the method.

The method to test is  public Date getCycleRunDate (ISCObject oCalendar) which is in com.tr.xscmds.test  

Now I need to pass  oClalandar value to  getCycleRunDate (ISCObject oCalendar) in my class TestHierarchy.
I can get oClalandar value  from a  method public IXCalendar getCalendar()  which is in com.tr.IXCalandar .


Initially I am registering the manager and to connect to the database through local properties file. This
is what I am doing in public TestHierarchy() . Now how do I write my main prog to import the methods and test it ?


import java.util.*;
import ....etc..;
import ...etc.;

public class TestHierarchy
{
    static ISCManager mgr;

}

public TestHierarchy()
    {
         try
         
         {
             Properties props = new Properties();
              String propFile = "C:\\Trilogy\\SCBBJava\\doc\\methods\\local.properties";
              props.load(new FileInputStream(propFile));
              mgr = new SCManager(props);
              System.out.println("Registering manager");
              mgr.register();
              System.out.println("Manager registered");
         }
         catch (IOException e)
         {
              System.err.println(e);
         }

    }


    public static void main(String[] args)
    {
         IXCalendar calendar;
         try
         {
              TestHierarchy first = new TestHierarchy();
                   
              System.out.println("Update Hierarchy is done...");
                               
                   }
         catch (Exception e)
         {
              System.err.println(e);
         }
         System.exit(30);
    }

0
Comment
Question by:Richards
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 16
  • 15
32 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 8135358
> How do I write the prog in main to receive the calandar value from getCalandar in com.tr.IXCalandar

 IXCalendar calendar = new IXCalendar((; // use whatever constructro.

  <return type of getCalendar> cal = calendar.getCalendar();

> pass the calandar value to getCycleRunDate (ISCObject oCalendar)

  Date d = getCycleRunDate(cal); // I guess the "cal" variable is of type "ISCObject"

  Hope it helps. If you are still uncertain ask :-)
0
 
LVL 6

Expert Comment

by:expertmb
ID: 8135407
the above code looks like c++ code.


 public class TestHierarchy
{
   static ISCManager mgr;


public TestHierarchy()
   {
        try
       
        {
            Properties props = new Properties();
             String propFile = "C:\\Trilogy\\SCBBJava\\doc\\methods\\local.properties";
             props.load(new FileInputStream(propFile));
             mgr = new SCManager(props);
             System.out.println("Registering manager");
             mgr.register();
             System.out.println("Manager registered");
        }
        catch (IOException e)
        {
             System.err.println(e);
        }

   }


   public static void main(String[] args)
   {
        IXCalendar calendar;
        try
        {
             TestHierarchy first = new TestHierarchy();
                 
             System.out.println("Update Hierarchy is done...");
                               
                  }
        catch (Exception e)
        {
             System.err.println(e);
        }
        System.exit(30);
   }
}
0
 

Author Comment

by:Richards
ID: 8136436
Thanks! Girionis Can you put the exact code in this main.
For each of you information its Java code only .Please let
me know how to import those methods into my class.

The method public IXCalendar getCalendar() is in com.tr.IXCalandar  and

getCycleRunDate (ISCObject oCalendar)  is in com.tr.xscmds.test  


public static void main(String[] args)
   {
        IXCalendar calendar;
        try
        {
             TestHierarchy first = new TestHierarchy();
                 
             System.out.println("Update Hierarchy is done...");
                               
                  }
        catch (Exception e)
        {
             System.err.println(e);
        }
        System.exit(30);
   }
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 35

Expert Comment

by:girionis
ID: 8136715
 I need to clarify some thigns first:

1) Does the "getCalendar" method in the IXCalendar class return an object of type "ISCObject"
2) What is the/a constructor of the "IXCalendar" class?
0
 

Author Comment

by:Richards
ID: 8137257
This is the Cal method which in Utility Class and not XCalandar class.Sorry ! and the method to test is below which is in com.tr.test.xscmtd (getCycleRunDate (ISCObject oCalendar)). Please let me know if you any more info
public IXCalendar getCalendar()
     throws Exception
{
     IXCalendar cal = null;
     try
     {
          String query = new String (" select p from xcalendar p " ) ;
          ISCRecordset result = model.getSCManager().newQuery().execute(query);

          int resCount = 0;
          while (result.moveNext())
          {
               resCount++ ;
               if (resCount > 1)
                    throw new Exception (" There is more than one calendar object " );
     
               cal = (IXCalendar) model.getSCManager().objectFromGID(model.getSCManager().newGID(result.valueFromIndex(0).toString()));
          }

          return cal ;
     }

     catch (Exception e)
     {
          throw e;
     }
}



 public Date getCycleRunDate (ISCObject oCalendar)
{

String methodName = "CalendarMethods.getCycleRunDate(calendar, " + cycle + "," + channel + ")";

try
     {
          IXCalendar calendar = (IXCalendar) oCalendar;
          IXWeeklyCalendar weeklyCalendar = getWeeklyCalendarObject(calendar, cycle);
          //Returns a SATURDAY
          return CommonFunctions.addToDate(Calendar.DATE, 5, weeklyCalendar.getx_cycleWeekStart());
         
     }
     catch (Exception e)
     {
     
          if (!(e instanceof PaceException))
          {
               PaceException pE = new PaceException(methodName);
               pE.add(e.toString());
               throw pE;
          }
          return null;
     }
}
0
 
LVL 35

Expert Comment

by:girionis
ID: 8137332
 Ok, given the fact that you have imported the necessary classes (Utility, IXCalendar etc) you can do:

  To get a IXCalendar object do:

  Utility utility = new Utility();
  IXCalendar calendar = utility.getCalendar();

  Now you have an object of type "IXCalendar". Where do you want to use this object? You cannot use it with the "getCycleRunDate" since it expects an "ISCObject" as parameter and you cannot pass one of type "IXCalendar".
0
 

Author Comment

by:Richards
ID: 8137353
Thanks ! OK then I want to test getCycleRunDate (ISCObject oCalendar how do I do it ?
0
 
LVL 35

Expert Comment

by:girionis
ID: 8137387
 Actually you can... sorry, I just noticed that oCalendar is a super class of IXCalendar.

  Your main method can be:

public static void main(String[] args)
  {
       IXCalendar calendar;
       Utility utility = new Utility();
       calendar = utility.getCalendar();

       Date d = utility. getCycleRunDate(calendar);

       try
       {
            TestHierarchy first = new TestHierarchy();
                 
            System.out.println("Update Hierarchy is done...");
                              
                 }
       catch (Exception e)
       {
            System.err.println(e);
       }
       System.exit(30);
  }

0
 

Author Comment

by:Richards
ID: 8137507
Thanks ! I am getting this error

The type name Utility is not visible

The utility class extends EngineInput
import java.text.*;
import java.util.*;
import java.io.*;
import com.trilogy.cm.*;
import com.trilogy.sc.*;
import com.trilogy.sc.core.*;
import com.prudential.pace.xscmethods.*;
/**
 * This class is used to host common methods like getting specified object from the
 * database, reading the file contents, parsing the strings etc., which are mostly
 * used by other utility classes.
 */
public class Utility extends EngineInput {

}
0
 
LVL 35

Expert Comment

by:girionis
ID: 8137550
 Can you please post the Utility's constructor? And could you post the whole error message and the line it occurs?
0
 

Author Comment

by:Richards
ID: 8137692
Thanks !
public Utility(String fileName)
     throws Exception
{
     super(fileName);
}


public Utility(String fileName, String fileName1)
     throws Exception
{
     super(fileName, fileName1);
     System.out.println ( " Called engineinput constructor for " + fileName + " ," + fileName1 );
}

The error is near

Utility utility = new Utility();


     
public static void main(String[] args)
 {

      try
      {
           TestHierarchy first = new TestHierarchy();

                      System.out.println("Update Hierarchy is done...");

         
      IXCalendar calendar;
      Utility utility = new Utility();
      calendar = utility.getCalendar();

      Date d = utility. getCycleRunDate(calendar);
      }
      catch (Exception e)
      {
           System.err.println(e);
      }
      System.exit(30);
 }

0
 

Author Comment

by:Richards
ID: 8137718
The class Hierarchy is as follows
 Object is the main
    then EngineInput
         then  Utiltiy


Do I need add any more to import I am having the following

import java.io.*;
import java.util.*;
import java.text.SimpleDateFormat;
import com.trilogy.sc.*;
import com.trilogy.sc.core.*;
import com.trilogy.util.*;
import java.text.MessageFormat;
import java.util.GregorianCalendar;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import com.prudential.pace.exceptions.*;
import java.text.*;
import com.prudential.pace.xscmethods.*;
0
 
LVL 35

Expert Comment

by:girionis
ID: 8137906
> Do I need add any more to import I am having the following

  No, not for the moment.

  The problem is that the "Utility" class takes either one filename or two as argument, so when you create it you need to pass a filename. If your filename is:

  String fileName = "c:\files\myfile.txt";

  you need to do:

  Utility utility = new Utility(fileName);
0
 

Author Comment

by:Richards
ID: 8137948
Thanks ! I am still gettin the error

The type name Utility is not visible
I had added
 String fileName = "C:\\Trilogy\\SCBBJava\\doc\\methods\\local.properties";

0
 

Author Comment

by:Richards
ID: 8137952
Just curious will you be there for somemore time on the net with EE?
0
 
LVL 35

Expert Comment

by:girionis
ID: 8137963
> Just curious will you be there for somemore time on the net with EE?

  Yes probably...

  Meanwhile the error yor are getting is really weird. Do you import Uitilty properly?
0
 
LVL 35

Expert Comment

by:girionis
ID: 8137979
 The error you are getting "The type name Utility is not visible" is it the *exact* error message?
0
 

Author Comment

by:Richards
ID: 8138001
How do I check to see if I am importing the Utility class properly .
0
 
LVL 35

Expert Comment

by:girionis
ID: 8138024
 Check he package. The error you are getting, is it during compile time or during run time?
0
 

Author Comment

by:Richards
ID: 8138072
I am getting the error when I am saving and where to check for the package .
0
 
LVL 35

Expert Comment

by:girionis
ID: 8138112
 Check the first line of your Utility class. If it is a package (package ...) then you need to import it. Check the first line and let me know.

> I am getting the error when I am savin

  So you mean when you save the file and you try to compile it?
0
 

Author Comment

by:Richards
ID: 8138199
OK the Utility prog is in
com.pace.loader and so I imported it now I am getting a error near

Date d = utility.getCycleRunDate(calendar);

The error  is

The method getCycleRunDate invoked for type
 com.pace.loader.Utility with arguments(com.tri.sc.IXCalandar) is not defined
0
 
LVL 35

Expert Comment

by:girionis
ID: 8138248
 Ok we get will get it eventually.

  Look at the method:

  public Date getCycleRunDate (ISCObject oCalendar)

  it takes an "ISCObject" type argument. But later in the method you wil notice the:

  IXCalendar calendar = (IXCalendar) oCalendar;

  which casts the "ISCObject" type into "IXCalendar" type. This means that "ISCObject" type is a superclass of the "IXCalendar" class and you shouldn't have any problems.

  Do you have any more getCycleRunDate methods defined that take different arguments?
0
 
LVL 35

Expert Comment

by:girionis
ID: 8138259
 And can you also tell me where the IXCalandar class is. Is it within the com.tr package or within the com.tri.sc package?
0
 

Author Comment

by:Richards
ID: 8138308
It is in com.trilogy.sc.IXCalendar--

tr is trilogy fullform so I was typing it in shortform here
0
 
LVL 35

Expert Comment

by:girionis
ID: 8138387
 Do you get the error during run time or during compile time? And can you also check if "IXCalendar" extends "ISCObject"?
0
 

Author Comment

by:Richards
ID: 8138468
In visual age when we save more or less compiles and that is the time I am getting the error when I click save and here is the IXCalendar extends ISCCMBasic and ISCCMBasic extends ISCObject

public interface IXCalendar extends com.trilogy.sc.ISCCMBasic {
     public static final int typeID;
}

public interface ISCCMBasic extends com.trilogy.sc.ISCObject {
     public static final int typeID;
}
0
 
LVL 35

Expert Comment

by:girionis
ID: 8138578
 This is really weird. It is obvious that the IXCalendar is a subclass of the ISCObject but for some weird reason it throws an error. Two things I suggest:

1) Make sure that we have the getCycleRunDate method properly defined and there are no spelling errors, case sensitive problem, etc.
2) Make sure that you do not have any other getCycleRunDate methods somewhere else in your programme, or if you have, that we are not calling the wrong one.

  Check them and let me know so we know what is going wrong.

 
0
 

Author Comment

by:Richards
ID: 8138703
Thanks !
This is what I have in main I am doing a copy and paste for both the methods


     
public static void main(String[] args)
 {
      String fileName = "C:\\Trilogy\\SCBBJava\\doc\\methods\\local.properties";



      try
      {
         TestHierarchy first = new TestHierarchy();

                      System.out.println("Update Hierarchy is done...");
         
      IXCalendar calendar;
     
           Utility utility = new Utility(fileName);
      calendar = utility.getCalendar();

      Date d = utility.getCycleRunDate(calendar);
      }
      catch (Exception e)
      {
           System.err.println(e);
      }
      System.exit(30);
 }


This is the  getCycleRunDate


public Date getCycleRunDate (ISCObject oCalendar)
{
//GregorianCalendar cal = new GregorianCalendar();    
     
String methodName = "CalendarMethods.getCycleRunDate(calendar)";

try
     {
          IXCalendar calendar = (IXCalendar) oCalendar;
          IXWeeklyCalendar weeklyCalendar = getWeeklyCalendarObject(calendar);
          //Returns a SATURDAY
          return CommonFunctions.addToDate(Calendar.DATE, 5, weeklyCalendar.getx_cycleWeekStart());
         
     }
     catch (Exception e)
     {
          //if it's a pace exception we've already logged it.
          if (!(e instanceof PaceException))
          {
               PaceException pE = new PaceException(methodName);
               pE.add(e.toString());
               throw pE;
          }
          return null;
     }
}
0
 
LVL 35

Accepted Solution

by:
girionis earned 1000 total points
ID: 8139046
 Hmm.. I am stuck now... Everything seems fine in your source code.

  So it is a compile time error sin't it? Do you get any more error messages? Is this "The method getCycleRunDate invoked for type
com.pace.loader.Utility with arguments(com.tri.sc.IXCalandar) is not defined " the exact error message you are getting?
0
 

Author Comment

by:Richards
ID: 8158099
Yes i am getting the same error still
0
 
LVL 35

Expert Comment

by:girionis
ID: 8158124
 Can you copy/paste the error message?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month14 days, 14 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question