Plugins using Parent (calling object or Class)'s Methods

I would like to know if this design makes sense (or if im abusing the inheritance concept of java)
This comes about because :: Plugins, that are only known about at runtime, know of each others existance. But the core application does not know about plugins until runtime. The plugins might be reused so the core calling class may not be known till runtime either. So
Public Static Class PluginContainer {
Main() {
doSearchofDirectoryForUseablePlugins()
while pluginsLeft {
Load plugin so it can be referenced by name();
plugin[x].runmain()
SendMessage( String pluginName, Object message) {
doBlahToFindCorrectPlugin();
plugin[x].doSomethingWithMessage( Object message);
public Class plugin { // in a far off directory
public plugin() { //setup myself blah}
public runmain( ) { //do stuff
// ohh lets find out if my plugin friends are here
Class myParent = this.getSuperClass(); // does this give me my parent given that my parent is static??
myParent.sendMessage("Friend", aLittleSomethingiMadeEarlier);
Is this the correct way of doing this? Im new to this type of java programming. This comes late in the night - so i may be completely loopy over this apparent problem that seems so easy!
Thanks in Advance
Gary

1. You cannot declare a static top level class. Only nested classes (classes that are members of the surrounding class) can be declared static.
2. The Plugin class does not extend PluginContainer so PluginContainer is not the parent class, the Object class is.
What you probably want to do is declare a Plugin interface and have all you plugins implement that interface.

Similar Messages

  • How to get caller object reference from a method

    Hi,
    I am working a already existing Java Swing project, now I got a problem, in a method I need to get the caller object reference otherwise, I can't succeed this operation. So please tell me a way how to get the caller object reference from a method. that method would be static or regular method anything will do for me.
    Edited by: navaneeth.j on Jan 29, 2010 11:20 PM

    navaneeth.j wrote:
    Actually my doubt is, I have a method "addition" method, which is using by many classes so my requirement is in the addition method I want to write a code snippet which will identify and get the the caller object. Actually I tried Reflection.getcallerclass but there I am getting "CLASS" object not the actual object reference, but I want object reference.
    Actually we have a huge project which is writen plain JAVA, so in this project the authors written the Database connection package for single database transaction. so now we are using this project source code for JSF application in this web application the DB package has serve based on the dynamic db connection parameters, so if we want to change this package fully means need to solve the dependency problem in hundreds of classes, so my point is if I can access the caller object in the DB package when ever it gets called by any class from any where of the project. So actually I liked Reflection.getcallerclass, the way of implementation perfectly works for me but it is not giving caller object reference, if something gives the caller object then I can get the DB connection parameters then there is no need to pass the parameters in the hierarchy.You can add a parameter (of type Object) to your addition() method
    and everywhere you call the addition() method also pass this (which from the POW of the addition() method will be a reference to the calling class instance).
    There may be alternative solutions
    but none that require less effort.

  • Getting the calling object reference / class?

    Dear forum members,
    Is it possible for A in the below example to get that B was the "caller"?
    class A {
      A() {
      public void someMethod(String text) {
        System.out.println("I was called with: " + text);
        System.out.println("I was called by: " + thatMagicWayToGetCallerClassOrReference());
    class B {
      public static void main(String[] args) {
        A a = new A();
        a.someMethod("HOLA HOLA");
    }

    Another way of getting the class of your caller is to use a SecurityManager object. getClassContext() is protected but you can get at it by subclassing SecurityManager (it works if you just instanciate the manager without installing it). This gives you a reference to the Class object itself where the stack trace returns only the class name. Bear in mind that the class in question will be several items up the array, the first entry is the SecurityManager itself, the second the called class.
    However, I agree with others it doesn't sound like the best design. If you're having trouble with not being able to change the interface specifications to pass the extra information then consider using a static reference, if necessary a ThreadLocal. What happens if you want to call the offending method indirectly through some central method at some future time? You've lost the call origin data.
    Why can't you simply add a parameter to the offending call?

  • Error while calling a super class public method in the subclass constructor

    Hi ,
    I have code like this:
    CLASS gacl_applog DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS:
                create_new_a
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXPORTING  pfx_log_hndl TYPE balloghndl
                   EXCEPTIONS error
    ENDCLASS.
    CLASS gacl_applog IMPLEMENTATION.
      METHOD create_new_a.
        DATA: ls_log TYPE bal_s_log.
      Header aufsetzen
        MOVE pf_extnumber TO ls_log-extnumber.
        ls_log-object     = pf_obj.
        ls_log-subobject  = pf_subobj.
        ls_log-aluser     = sy-uname.
        ls_log-alprog     = sy-repid.
        ls_log-aldate     = sy-datum.
        ls_log-altime     = sy-uzeit.
        ls_log-aldate_del = ls_log-aldate + 1.
        CALL FUNCTION 'BAL_LOG_CREATE'
             EXPORTING
                  i_s_log      = ls_log
             IMPORTING
                  e_log_handle = pfx_log_hndl
             EXCEPTIONS
                  OTHERS       = 1.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID      sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH    sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    CLASS gcl_applog_temp DEFINITION INHERITING FROM gacl_applog.
      PUBLIC SECTION.
        DATA: log_hndl   TYPE balloghndl READ-ONLY
            , t_log_hndl TYPE bal_t_logh READ-ONLY
        METHODS: constructor
                   IMPORTING  pf_obj       TYPE balobj_d
                              pf_subobj    TYPE balsubobj
                              pf_extnumber TYPE string
                   EXCEPTIONS error
               , msg_add      REDEFINITION
               , display      REDEFINITION
    ENDCLASS.
    CLASS gcl_applog_temp IMPLEMENTATION.
      METHOD constructor.
        CALL METHOD create_new_a
               EXPORTING  pf_obj       = pf_obj
                          pf_subobj    = pf_subobj
                          pf_extnumber = pf_extnumber
               IMPORTING  pfx_log_hndl = log_hndl.
        IF ( sy-subrc NE 0 ).
          MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                  WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4
                  RAISING error.
        ENDIF.
      ENDMETHOD.
    A public method of Super class has been called from the constructor of the sub class. we are getting the syntax error :
    ' In the constructor method, you can only access instance attributes, instance methods, or "ME" after calling the constructor of the superclass…'
    Can you please suggest how to change the code with out affecting the functioanlity.
    Thank you ,
    Lakshmi.

    Hi,
    Call that method by instance of Subclass.   OR
    SUPER-->method.
    Read very useful document
    Constructors
    Constructors are special methods that cannot be called using CALL METHOD. Instead, they are called automatically by the system to set the starting state of a new object or class. There are two types of constructors - instance constructors and static constructors. Constructors are methods with a predefined name. To use them, you must declare them explicitly in the class.
    The instance constructor of a class is the predefined instance method CONSTRUCTOR. You declare it in the public section as follows:
    METHODS CONSTRUCTOR
            IMPORTING.. [VALUE(]<ii>[)] TYPE type [OPTIONAL]..
            EXCEPTIONS.. <ei>.
    and implement it in the implementation section like any other method. The system calls the instance constructor once for each instance of the class, directly after the object has been created in the CREATE OBJECT statement. You can pass the input parameters of the instance constructor and handle its exceptions using the EXPORTING and EXCEPTIONS additions in the CREATE OBJECT statement.
    The static constructor of a class is the predefined static method CLASS_CONSTRUCTOR. You declare it in the public section as follows:
    CLASS-METHODS CLASS_CONSTRUCTOR.
    and implement it in the implementation section like any other method. The static constructor has no parameters. The system calls the static constructor once for each class, before the class is accessed for the first time. The static constructor cannot therefore access the components of its own class.
    Pls. reward if useful....

  • Dynamic Call to Java Class or Method

    Hi All,
    I have a requirement to call a Class or a Method Within the same class dynamically based on the user choice. I will give an example with how I do it in pl sql.
    begin
    if (choice = 1) then
    execute immediate 'package.procedure1(params)';
    elsif (choice = 2) then
    execute immediate 'package.procedure2(params)';
    else
    execute immediate 'package.procedure3(params)';
    end if;
    end;
    From the Example above, I call a program based on user choice. How Can I do the same in Java?
    Thank you.
    Edited by: Eric S. on Jul 6, 2011 9:52 AM

    I have a requirement to call a Class or a MethodYou can call a method, but not the Class where as you can instantiate the Class.
    I will give an example with how I do it in pl sql.
    begin
    if (choice = 1) then
    execute immediate 'package.procedure1(params)';
    elsif (choice = 2) then
    execute immediate 'package.procedure2(params)';
    else
    execute immediate 'package.procedure3(params)';
    end if;
    end;
    From the Example above, I call a program based on user choice. How Can I do the same in Java?The similar way. Here it takes the following structure.
    ClassA object = new ClassA();
    if(choice==1) {
          object.callMethod1();
    } else if(choice==2) {
          object.callMethod2();
    } else if(choice==3) {
          object.callMethod3();
    } Also you can switch case instead of if else. It takes the following structure.
    ClassA object = new ClassA();
    switch(choice) {
    case 1:  object.callMethod1(); break;
    case 2:  object.callMethod2(); break;
    case 3:  object.callMethod3(); break;
    }I recommend you to go with the second one which using switch.

  • Using Variables/Arrays from one class in another

    Hello all,
    First, to explain what I am attempting to create, is a program that will accept input of employee names and hours worked into an array. The first class will accept a command line argument when invoked. If the argument is correct, it will call another class that will gather information from the user via an input box. After all names and hours have been input for employees, this class will calculate the salary based upon the first letter of each employee name and print the total hours, salary, etc. for each employee.
    What I need to do now is to split the second class into two: one that will gather the data and another that will calculate and print the data. Yes, this is an assignment. However, I am trying to learn and I have gotten this far, but I am stuck on how to get a class to be able to use an array/variables from another class.
    I realize the below code isn't exactly cleaned up...yet.
    Code for AverageSalaryGather class:
    import javax.swing.JOptionPane; // uses class JOptionPane
    import java.lang.reflect.Array;     
    import java.math.*;
    public class AverageSalaryGather {
         public static void gatherData() {     
              char[] alphaArray = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','x','y','z'};
              String[][] empInfoArray = new String[100][4];
              String[] empNameArray = new String[100];
              String finalOutput = "Name - Rate - Hours - Total Pay\n";
              String averageHoursOutput = "Average Hours Worked:\n";
              String averageSalaryOutput = "Average Hourly Salary:\n";
              String averageGroupSalaryOutput = "Average Group Salary:\n";
                        String[] rateArray = new String[26];
                        char empNameChar = 'a';
              int empRate = 0;
              int payRate = 0;
                        for (int i = 0; i < 26; i++) {
                   payRate = i + 5;
                   rateArray[i] = Integer.toString(payRate);
                        int countJoo = 0;
              while (true) {
                   String namePrompt = "Please enter the employee name: ";
                   String empName = JOptionPane.showInputDialog(namePrompt);
                                  if (empName == null | empName.equals("")) {
                        break;
                   else {
                        empInfoArray[countJoo][0] = empName;
                        for (int i = 0; i < alphaArray.length; i++) {
                             empNameChar = empName.toLowerCase().charAt(0);
                                                      if (alphaArray[i] == empNameChar) {
                                  empInfoArray[countJoo][1] = rateArray;
                                  break;
                        countJoo++;
              // DecimalFormat dollarFormat = new DecimalFormat("$#0.00");
              for (int i = 0; i < empInfoArray.length; i++) {
                   if (!(empInfoArray[i][0] == null)) {
                        String hourPrompt = "Please enter hours for " + empInfoArray[i][0] + ": ";
                        String empHours = JOptionPane.showInputDialog(hourPrompt);
                        int test = 0;
                        empInfoArray[i][2] = empHours;
                        // convert type String to double
                        //double tmpPayRate = Double.parseDouble(empInfoArray[i][1]);
                        //double tmpHours = Double.parseDouble(empInfoArray[i][2]);
                        //double tmpTotalPay = tmpPayRate * tmpHours;
                        // create via a string in empInfoArray
                             BigDecimal bdRate = new BigDecimal(empInfoArray[i][1]);
                             BigDecimal bdHours = new BigDecimal(empInfoArray[i][2]);
                             BigDecimal bdTotal = bdRate.multiply(bdHours);
                             bdTotal = bdTotal.setScale(2, RoundingMode.HALF_UP);
                             String strTotal = bdTotal.toString();
                             empInfoArray[i][3] = strTotal;
                        //String strTotalPay = Double.toString(tmpTotalPay);
                        //empInfoArray[i][3] = dollarFormat.format(tmpTotalPay);
                        else {
                             break;
              AverageSalaryCalcAndPrint averageSalaryCalcAndPrint = new AverageSalaryCalcAndPrint();
              averageSalaryCalcAndprint.calcAndPrint();
    Code for AverageSalaryCalcAndPrint class (upon compiling, there are more than a few complie errors, and that is due to me cutting/pasting the code from the other class into the new class and the compiler does not know how to access the array/variables from the gatherData class):
    import javax.swing.JOptionPane; // uses class JOptionPane
    import java.lang.reflect.Array;
    import java.math.*;
    public class AverageSalaryCalcAndPrint
         public static void calcAndPrint() {     
              AverageSalaryGather averageSalaryGather = new AverageSalaryGather();
              double totalHours = 0;
              double averageHours = 0;
              double averageSalary = 0;
              double totalSalary = 0;
              double averageGroupSalary = 0;
              double totalGroupSalary = 0;
              int countOfArray = 0;
              for (int i = 0; i < empInfoArray.length; i++) {
                   if (!(empInfoArray[0] == null)) {
                        totalSalary = totalSalary + Double.parseDouble(empInfoArray[i][1]);
                        totalHours = totalHours + Double.parseDouble(empInfoArray[i][2]);
                        totalGroupSalary = totalGroupSalary + Double.parseDouble(empInfoArray[i][3]);
                        countOfArray = i;
              averageHours = totalHours / (countOfArray + 1);
              averageSalary = totalSalary / (countOfArray + 1);
              averageGroupSalary = totalGroupSalary / (countOfArray + 1);
              String strAverageHourlySalary = Double.toString(averageSalary);
              String strAverageHours = Double.toString(averageHours);
              String strAverageGroupSalary = Double.toString(averageGroupSalary);
              for (int i = 0; i < empInfoArray.length; i++) {
                   if (!(empInfoArray[i][0] == null)) {
                        finalOutput = finalOutput + empInfoArray[i][0] + " - " + "$" + empInfoArray[i][1] + "/hr" + " - " + empInfoArray[i][2] + " - " + "$" + empInfoArray[i][3] + "\n";
              averageHoursOutput = averageHoursOutput + strAverageHours + "\n";
              averageSalaryOutput = averageSalaryOutput + strAverageHourlySalary + "\n";
              averageGroupSalaryOutput = averageGroupSalaryOutput + strAverageGroupSalary + "\n";
              JOptionPane.showMessageDialog(null, finalOutput + averageHoursOutput + averageSalaryOutput + averageGroupSalaryOutput, "Totals", JOptionPane.PLAIN_MESSAGE );

    Call the other class's methods. (In general, you
    shouldn't even try to access fields from the other
    class.) Also you should be looking at an
    instance of the other class, and not the class
    itself, generally.Would I not call the other classes method's by someting similar as below?:
    AverageSalaryCalcAndPrint averageSalaryCalcAndPrint = new AverageSalaryCalcAndPrint();
              averageSalaryCalcAndprint.calcAndPrint(); Well... don't break down classes based on broad steps
    of the program. Break them down by the information
    being managed. I'm not expressing this well...Could you give an example of this? I'm not sure I'm following well.
    Anyway, you want one or more objects that represent
    the data, and operations on that data. Those
    operations include calculations on the data. Other
    classes might represent the user interface, and
    different output types (say, a file versus the
    console).Yes, the requirements is to have a separate class to gather the data, and then another class to calculate and print the data. Is this what you mean in the above?

  • Calling Objective C from C++

    Hi Guys,
    First of all forgive my ignorance I am new to Cocoa and Objective C.
    Basically I am trying to get some existing C++ code working with a Cocoa front end using Objective C.
    I can access objects in C++ from Objective C but cannot work out how to access Objective C objects from C++.
    The C++ classes are defined in standard C++ .h and .cpp files. Do I have to wrap them in .m files?
    And tips would be greatly appreciated.
    Cheers
    Andy
    Message was edited by: AndrewCapon

    Maybe I should have put it better as well as I seem to be able to access what I call "Objective C" objects from c++, maybe I am using the incorrect terminology.
    I have a test cpp file OSCLog.cpp:
    * OSCLog.cpp
    * OSCLog
    * Created by Andrew Capon on 09/04/2008.
    * Copyright 2008 CAD Ltd. All rights reserved.
    #include "OSCLog.h"
    #ifdef WIN32
    void OSCLog::Start(CADTextView *pTVLog)
    pTVLog->AppendText("Hello World");
    #else
    void OSCLog::Start(NSTextView *pTVLog)
    NSString *logStr = [NSString stringWithFormat:@"
    hello Textview"];
    NSRange endRange;
    endRange.location = [[pTVLog textStorage] length];
    endRange.length = 0;
    [pTVLog replaceCharactersInRange:endRange withString:logStr];
    endRange.length = [logStr length];
    [pTVLog scrollRangeToVisible:endRange];
    #endif
    In XCode I have set this Filetype to sourcecode.cpp.ocjcpp
    I have a Objective c controller class defined by OSCLogController.h:
    // OSCLogController.h
    // OSCLog
    // Created by Andrew Capon on 04/04/2008.
    // Copyright CAD Ltd All rights reserved.
    #import <Cocoa/Cocoa.h>
    #import "OSCLog.h"
    @interface OSCLogController : NSObject
    // controls on the form
    IBOutlet NSTextField *tfIpAddr;
    IBOutlet NSTextField *tfPort;
    IBOutlet NSTextView *tvLog;
    OSCLog *oscLog;
    // Action to start the logging
    -(IBAction)start:(id)sender;
    @end
    And implemented by OSCLogController.m:
    // OSCLogController.m
    // OSCLog
    // Created by Andrew Capon on 04/04/2008.
    // Copyright 2008 CAD Ltd All rights reserved.
    #import "OSCLogController.h"
    @implementation OSCLogController
    -(id)init
    [super init];
    oscLog = new OSCLog();
    return self;
    -(void)dealloc
    delete oscLog;
    [super dealloc];
    -(IBAction)start:(id)sender
    oscLog->Start(tvLog);
    @end
    The NSTextView tvLog is passed to the cpp code which uses it to append some test text to the TextView.
    This all works and is what I was after as the cpp code is using objective c classes (or what I call objective c classes!).
    As you can see I am just using a WIN32 define to switch between WIN32 and OSX, I am really after a define like _OBJC_ for objective c++ to use as the code needs to support more than just two platforms.
    Cheers
    Andy
    Message was edited by: AndrewCapon
    Message was edited by: AndrewCapon

  • How to create unique objects in class and store

    Hi, I have a class that opens a text file and reads in the
    lines. each line holds an ip address. i need to create x amount of
    objects, and each object is assigned a unique ip address from the file.
    and here i am stuck. the class reads in the file, then i think it should create an object for each line read in and assign that object the ip address. i want to store the objects in some sort of array or collection, and i guess each object will need a unique name, but i dont know how many objects until i read in the file and count the number of lines. can anyone give me any pointers as to how i should create/store the objects
    many thanx
    ness

    You could use your own object:
    public class Test {
      public class IPNumber {
        public int ip;
        public IPNumber(int ip) {
          this.ip = ip;
      public Test() {
        int numberOfIPs = 5; // this is your number of lines
        IPNumber[] ips = new IPNumber[numberOfIPs];
        for (int i = 0; i < numberOfIPs; i++) ips[i] = new IPNumber(i); // assign ip address from file
      public static void main(String args[]){
        new Test();
    }or you could store the ips as strings:
    public class Test {
      public Test() {
        final int numberOfIPs = 5; // this is your number of lines
        final java.util.ArrayList al = new java.util.ArrayList(numberOfIPs);
        for (int i = 0; i < numberOfIPs; i++) al.add(""+i); // assign ip address from file   
      public static void main(String args[]){
        new Test();
    }p.s Objects don't have names

  • Can I use classes and methods for a maintenance view events?

    Hello experts,
    Instead of perform/form, can I instead use classes and methods, etc for a given maintenance view event, lets say for example I want to use event '01' which is before saving records in the database. Help would be greatly appreciated. Thanks a lot guys!

    Hi viraylab,
    1. The architecture provided by maintenance view
       for using EVENTS and our own code inside it -
       It is provided using FORM/PERFORM
       concept only.
    2. At this stage,we cannot use classes.
    3. However, inside the FORM routine,
       we can write what ever we want.
       We can aswell use any abap code, including
       classes and methods.
      (But this classes and methods won't have any
       effect on the EVENT provided by maintenance view)
    regards,
    amit m.

  • Calling a object of class from other class's function with in a package

    Hello Sir,
    I have a package.package have two classes.I want to use object of one class in function of another class of this same package.
    Like that:
    one.java
    package co;
    public class one
    private String aa="Vijay";  //something like
    }main.java:
    package co;
    import java.util.Stack;
    public class main extends Stack
    public void show(one obj)
    push(obj);
    public static void main(String args[])
    main oo=new main();
    }when I compile main class, Its not compile.
    Its give error.can not resolve symbol:
    symbol: class one
    location: class co.main
    public void show(one obj)
                              ^Please help How that compile "Calling a object of class from other class's function with in a package" beacuse I want to use this funda in an application

    kumar.vijaydahiya wrote:
    .It is set in environment variable.path=C:\bea\jdk141_02\bin;.,C:\oraclexe\app\oracle\product\10.2.0\server\bin;. command is:
    c:\Core\co\javac one.javaIts compiled already.
    c:\Core\co\javac main.javaBut it give error.
    Both java classes in co package.Okay, open a command prompt and execute these two commands:
    // to compile both classes:
    javac -cp c:\Core c:\Core\co\*.java
    // to run your main-class:
    java -cp c:\Core co.main

  • Using Async calls in a Util class

    I have a Utility class that I want to put code in that I'm reusing over and over again.  This includes Async.handleEvent calls.  If I call an instance of the Util class from a [Test(async)] method, can I use the Async call in that other event?
    When I tried this in my code, it said that it "Cannot add asynchronous functionality to methods defined by Test,Before or After that are not marked async" but my [Test] is marked as async. And when I was in the same class, I was able to have non-Test methods make Async calls.
    Thanks for the help!
    Mocked up Example (please note these are two separate files):
    // Test.as
    package
        import TimerUtil;
        public class Test
            [Test(async)]
            public function waitForTimer():void
                TimerUtil.newTimer();
    // TimerUtil.as
    package
        import flash.events.TimerEvent;
        import flash.utils.Timer;
        import org.flexunit.async.Async;
        public class TimerUtil
            private static var instance:TimerUtil;
            private var timer:Timer;
            private static const TIME_OUT:int = 1000;
            public static function newTimer() : void
                if (!instance) instance = new TimerUtil();
                instance.timer = new Timer(1000, 5);
                instance.timer.start();
                instance.waitForFifthTick();
            private function waitForFifthTick() : void
                Async.handleEvent(this, instance.timer, TimerEvent.TIMER, handleTimerTick, TIME_OUT);
            private function handleTimerTick ( evt:TimerEvent, eventObject:Object) : void
                if ( timer.currentCount == 5 )
                    // We are at the Fifth click, move on.
                else
                    Async.handleEvent(this, instance.timer, TimerEvent.TIMER, handleTimerTick, TIME_OUT);
    Message was edited by: zyellowman2
    I missed a comma.  And a few "instance"s

    Yes, you can put async calls in utility classes or wherever you want. That isn't the issue here though.
    In your test you call TimerUtil.newTimer()
    That code creates a timer and then returns. Then your test returns. At that moment, FlexUnit sees that your test has finished and that there are no outstanding registered asynchronous events so it declares the test a success. Then, a second later, your other method executes and tries to register an async call. FlexUnit has no idea what test this pertains to, or why this call is being made as it is no longer in the context of the original test, hence the message you are receiving that you can only using Async calls inside of a method marked with a Async... as, in FlexUnit's opion, the method that is executing this code no longer has anything to do with a test with an async param.
    The best way to think about this is a chain that cannot be broken. As soon as a method finishes executing with, FlexUnit will declare it a success unless we are waiting on something else (an async event of some sort) That is what the Async syntax really does, it tells the framework not to declare this method a success just yet, and that there is something else we need to account for to make that decision.
    So, right now, in your newTimer() you don't let the framework know that you will be waiting for an async event. Therefore, when that method and the test method is over, so is the test.
    Mike

  • Using Reflectors To Dynamically Call Objects

    Hi,
    I have a Class that has two methods and each method takes two parameters (1st Method Takes Integers / 2nd Takes Double) and returns and Integer. I want to invoke these methods using Java.Reflectors so I could Do dynamic instantiations and method calling.
    I have generated an experimental test harness class as given below....
    *========================================================*
    public static void main(String[] args) {
            try {
                // Getting a Class available in the Pachage to Class Instance
                Class cls = Class.forName("testreflection.ClassMethods");
                // Instance of Current Class
                Main o_Obj = new Main();
                // Get the declared methods in the Class instand "cls"
                Method[] m_Methods = cls.getDeclaredMethods();
                for(int i=0; i<m_Methods.length; i++){
                    // Obtain the parameter types of each method
                    Type[] typ_MethodParameterTypes = m_Methods.getGenericParameterTypes();
    // Int array for Random Integer inputs as Parameters
    int[] i_Prameter = new int[typ_MethodParameterTypes.length];
    Random r_RandomInt = new Random();
    for(int j=0; j<typ_MethodParameterTypes.length;j++){
    // Just Display the Input Type
    System.out.println(typ_MethodParameterTypes[j].toString());
    i_Prameter[j]=r_RandomInt.nextInt();
    //Display the Input value to the above type
    System.out.println(i_Prameter[j]);
    // Trying to invke the 1st Method in the Mehtod array
    m_Methods[0].invoke(o_Obj, i_Prameter);
    } catch (IllegalArgumentException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InvocationTargetException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    //} catch (InstantiationException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (ClassNotFoundException ex) {
    Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    *==============================================================*
    THen I am getting the following error.... Can any one help me...
    int
    -1680302169
    int
    -1149051431
    Mar 30, 2011 11:02:53 AM testreflection.Main main
    SEVERE: null
    java.lang.IllegalArgumentException: object is not an instance of declaring class
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:597)
            at testreflection.Main.main(Main.java:52)
    Edited by: EJP on 30/03/2011 12:17: added the code tags. Please use them.
    Edited by: JLearner on Mar 29, 2011 6:18 PM
    Edited by: JLearner on Mar 29, 2011 6:20 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    EJP wrote:
    java.lang.IllegalArgumentException: wrong number of argumentsSo you are calling the method with the wrong number of arguments.
    The error messages are quite clear, in both cases.Here is the Method that I am Calling in the Class "ClassMethods"
    public int getAddition(int i_Number1,int i_Number2){
            int i_Total = i_Number1+i_Number2;
            return i_Total;
        }This method Takes two Integer values and returns an Integer.
    I am calling this method using java reflections as below.
    // Get the declared methods in the Class instand "cls"
                Method[] m_Methods = cls.getDeclaredMethods();
                for(int i=0; i<m_Methods.length; i++){
                    // Obtain the parameter types of each method
                    Type[] typ_MethodParameterTypes = m_Methods.getGenericParameterTypes();
    // Int array for Random Integer inputs as Parameters
    int[] i_Prameter = new int[typ_MethodParameterTypes.length];
    Random r_RandomInt = new Random();
    for(int j=0; j<typ_MethodParameterTypes.length;j++){
    // Just Display the Input Type
    System.out.println(typ_MethodParameterTypes[j].toString());
    i_Prameter[j]=r_RandomInt.nextInt();
    //Display the Input value to the above type
    // Currently hold two parameter values
    System.out.println(i_Prameter[j]);
    // Trying to invke the 1st Method in the Mehtod array
    Object obj = cls.newInstance();
    m_Methods[0].setAccessible(true);
    // invoking with instance of Method own class and parameters (two integer parameters in an array )
    m_Methods[0].invoke(obj, i_Prameter);

  • Array of objects in class private data and calling overridden VIs on these objects?

    Hello
    I am developing part of an application using the actor framework and have run into problems.
    I have a several actors and will try briefly describe them and their intended functionality. All actors are started by a Controller actor and in the actor core for the controller I have the possibility to do a lot of intiliazation etc.
    Logger:
    Has a message (Send Log Message) that other actors can use to write to the log. It is supposed to take a string input and a log level (error, warning, debug etc). This message chain sends data to the actor core with a user event.
    The Actor Core of Logger is supposed to save the incoming message to a log, but should be able to do it in several different ways (file, database, email or whatever).
    Logger Output:
    Abstract class that has a dynamic dispatch vi called "Write Output" that all it's children are supposed to overwrite.
    Logger Output File
    Child of Logger Output and overwrites "Write Output" to save the string to a file on disk.
    Problem:
    I want to be able to set up the actor core for Logger once and for all but still be able to create new children of "Logger Output" and have them be handled in the Logger actor core.
    My idea was to have Logger use an array of objects as private data and initialize this array in the Controller actor core.
    In the logger actor core I could then auto index the array and use each element (each Logger Output child) and the abstract "Write Output" vi to get the correct functionality.
    HOWEVER, I cannot get this to work properly and I think I have misunderstood something or stared myself blind on this problem. I have tried 3 different methods when it comes to private data for Logger.
    1. Labview Object
    2. Array of Labview Object
    3. Array of Logger Output Object
    Of these 3 methods, I can only get the first one to work and that doesn't accomplish what I want in the end (being able to add more classes without changing private data / actor core for Logger).
    I have included 3 screenshots that show snippets of 2 of the actor cores and the private data. File names should correspond to my description above.
    The screenshot "Logger actor core.png" shows a very fast test of the 3 different methods I described above. Each of the 3 tunnel inputs to the event structure can be wired to the "Reference" input of "To More Specific Class", but only method 1 (Labview Object) works.
    If you need additional information / screenshots or whatever please ask.
    Thanks in advance
    Attachments:
    Logger ctl.PNG ‏8 KB
    Logger actor core.PNG ‏25 KB
    Controller Actor Core.PNG ‏11 KB

    Thanks for the reply and sorry for the confusing OP. It was meant as a quick test and a way to skip making 10+ screenshots .
    I updated the actor core for the Controller and Logger to be less confusing (hopefully) and attached 2 screenshots.
    I agree with you that it would be a good idea to make a message for the controller that can launch new children of the L" abstract actor, but for these tests I have just launched it the easy way (dragging it to the controller actor core).
    Both Logger Output and Logger Output File are actors and in Logger Output there is a dynamic dispatch vi called Write Output that I want to override in all its children.
    The problem is when I run the actor core of Logger (see the screenshot) only the abstract version (the one in Logger Output) of Write Output is executed, not the overridden version from Logger Output File.
    When I did the same thing with the actor cores looking like the did in my original post, then the correct overridden version got executed when I used the method with one Labview Object in private data (not any array or an array of Logger Output objects).
     EDIT: I just tried to have the Logger private data be a single Logger Output object and writing the Logger Output File to that piece of private data in the Controller and the correct Write Output override method gets called now. So apparently I have done something stupid when it comes to creating the array of Logger Output objects and writing them in the controller? The private data is in the Logger actor so I have simply right clicked and chosen "New VI for Data Member Access" and chosen "Write" for "Element of Array of Logger Output Objects".
    Attachments:
    Controller Actor core updated.PNG ‏10 KB
    Logger actor core updated.PNG ‏24 KB

  • Use of swings- one class calling the gui class

    Hi,
    I have a class Manager and a class ManagerGUI.
    My ManagerGUI class looks somehting like this-
    public class ManagerGUI extends JFrame
    String name;
    JPanel namePanel;
    JTextField nameInput;
    JLabel nameLabel;
    Manager empAgent;
    ManagerGUI(Manager ea)
    super(ea.getLocalName());
    empAgent = ea;
    //make the name panel and add it to the topPanel.
    addListeners();
    getContentPane().add(topPanel, BorderLayout.CENTER);
    setResizable(false);
    }//end constructor.
    public void show()
    pack();
    super.setVisible(true);
    void addListeners()
    nameInput.addActionListener(new NameL());
    class NameL implements ActionListener
    public void actionPerformed(ActionEvent e)
    nameE = nameInput.getText();
    }//end class ManagerGUI.
    I have tried to seperate it out so that any changes can be easily implemented (although it perhaps is a long way of doing things).
    Now I have a class Manager that wants to call the GUI and then process the information got from the text field.
    I use the following lines to call the GUI class.
    manGui = new ManagerGUI(this);
    manGui.show();
    Is this the correct way of calling the GUI class?
    How do I get to use the variable nameE here, in the Manager?
    Thanks.

    Hi,
    I have no idea why you want to have an instance of Manager class in class ManagerGUI and an instance of ManagerGUI class in Manager class.
    I will create an instance of Manager in ManagerGUI and show the GUI there.
    In Manager you can create method that will accept the text from textfield in parameter.
    L.P.

  • Using predefined data objects classes.

    I am always trying to be a better, more efficient Flex developer and I was looking at a project by Christophe Coenraets where he created collaberative forms using Flex/BlazeDS. I saw in his application that he was using multidirectional binding to a Class Object for each form in the application. For example, this is the MortgageApplication.as
    package
        import mx.collections.ArrayCollection;
        [Bindable]
        public class MortgageApplication
            public var firstName:String;
            public var lastName:String;
            public var ssn:String;
            public var phone:String;
            public var mobilePhone:String;
            public var email:String;
            public var notify:Boolean;
            public var usCitizen:Boolean;
            public var address:String
            public var city:String
            public var state:String
            public var zip:String
            public var singleFamily:Boolean;
            public var salePrice:Number = 500000;
            public var downPayment:Number = 100000;
            public var closingDate:Date;
            public var jobList:ArrayCollection = new ArrayCollection();
    I have an application that I use multiple forms to input information into the database and then I use Objects (actually ObjectProxys) and ArrayCollections to store information to display. I use the Mate Framework and have manager classes that store predefined bindable variables (empty)  that are injected into the view as needed or requested. In the manager class I just create a new ObjectProxy (or ArrayCollection) and use the information passed in (an ArrayCollection from ColdFusion) and create/modify the ObjectProxy/ArrayCollection before having it injected.
    Is it better practice or more efficent to predefine object classes (such as above from the example) then just populate them in the manager class before the injection or just create an new blank Object or ArrayCollection on the fly. Is there any difference?
    Set up a seperate Class:
    package
        [Bindable]
        public class Person
            public var firstName:String;
            public var lastName:String;
            public var phone:String;
    and do this in the Manager:
    public function setPerson():void {
         var person = new Person();
         person.firstName = "Steve";
         person.lastName = "Smith";
         person.phone = "555.555.1212";
    OR just have this declaired in the Manager as
    [Bindable] public var person:ObjectProxy;
    public function setPerson():void {
         person = new ObjectProxy();
         person.firstName = "Steve";
         person.lastName = "Smith";
         person.phone = "555.555.1212";
    Thanks to anyone who wants to help me become a better developer!

    ObjectProxy access is significantly slower that data class access.  ObjectProxy will not tell you if you mistype the name of a property and you can spend hours trying to find some place were you typed ssm insead of ssn.

Maybe you are looking for

  • Terrible customer service after systemboard on T400 died for no apparent reason.

    So I hate for my first post to be a negative one, but here goes. I'm sorry if my actions sound rude or impatient, but I'm sure some of you understand the aggravation and worry that accompanies a computer that suddenly stops working when it is needed.

  • How do I set an exclusive password for the iCloud settings in my Mac at work?

    Here's the thing: I want to have my computer at work (MacPro) synched with iCloud (all my contacts and bookmarks). But to do and still feel safe that no one else would open System Preferences and mess up with the iCloud settings (for example, turning

  • Can I convert data inputted to Uppercase by using a EO/VO domain?

    I am running version 10.1.3.1.0.3984 of JDeveloper and Release 10.1.3.1.26 of JHeadStart. I am trying to mimic a feature that we used extensively in our previous tool so I'm not sure that it can be done this way, but was wondering if I can use an Ent

  • J2EE Application Security

    Does anyone know how to implement and propogate security interoperability between the web and ejb tiers. I have a single web application that is split by multiple GWT entry points - each an application within a single war. A user can log into 1..n GW

  • MTO requirement class

    Hi Expert, I want to confirm with expert, the standard SAP MTO requirement class is KE? Or other requirement type? By the way, I hit an error message in GL account where I am doing a MTO order with internal order. My error message is GL account is no