Dynamic object call

hi i have following code:
     switch (type) {
               default:
               case 1:
                    objSquare sq = new objSquare(positionX, positionY, positionX1,
                              positionY1);
                    sq.color = color;
                    sq.paint(g);
                    break;
               case 2:
                    objArc ac = new objArc(positionX, positionY, positionX1,
                              positionY1);
                    ac.color = color;
                    ac.paint(g);
                    break;
}it is possible to create Java object dynamicaly? So there will be no switch, but i will load object name to call from database...for example, this "objSquare sq = new objSquare" will be called depending on object requested, so i dont need many switch cases, just one object call..
more details:
i have DB table with:
id object_id object_name etc....
and i want to load object in java that corresponds with object_name variable i will get from DB...it is possible?

You can use reflection for this, or use a map of names to factory pattern. I'd go with a factory, as it's not as open to insecurities. So have a HashMap<String, Class> or HashMap<String, Factory> where Factory is an interface with an appropriate method to create your objects, and Class is java.lang.Class and you create your objects using the newInstance method.

Similar Messages

  • Dynamic object called in Procedure

    Hi ,
    Let me first explain the requirment of my prj.its telecom based prj.There are various types of network equipment.So i have created the object for those equipment.
    for ex
    CREATE TYPE 16x AS OBJECT (...._);
    CREATE TYPE 4x AS OBJECT (...._);
    Now I have to write a procedure in which we just pass the eqipment name .
    for ex 16x
    Now as soon as I pass the eqipment name the procedure should direclty select the varaible of object 16x.
    SO how is possible to select the variable along with associated objectstype of the equiment at runtime only.
    Hope someone can answer my question.
    Thanks in advance.

    .So i have created the object for those equipment.Why are you using objects? The Oracle o-o implementation is not complete, and (in my opinion) not very useful outside of some rather unusual scenarions. Find out more.
    Anyway, let's assume your motives are good. It's also not clear precisely what you have done, so it's difficult to be sure what your problem is. What I would do woyuld be to create a master type of NETWORK_EQPT and then extend that to specific types - 16x, 4x. You can then write a function to instantiate a NETWORK_EQPT object which will figure it all out and return the appropriate subtype....
    SQL> create type network_eqpt as object (type varchar2(3), name varchar2(30))
      2  not final
      3  /
    Type created.
    SQL> create type net_16X under network_eqpt (capacity number)
      2  /
    Type created.
    SQL> create type net_4X under network_eqpt (start_date date)
      2  /
    Type created.
    SQL> create or replace function new_nw
      2      (p_type varchar2, p_name varchar2
      3          , p_capacity number := null, p_start date := null)
      4  return network_eqpt
      5  is
      6      return_value network_eqpt;
      7  begin
      8      if p_type = '16X' then
      9          return_value := net_16X(p_type,p_name, p_capacity);
    10      elsif  p_type = '4X' then
    11         return_value := net_4X(p_type,p_name, p_start);
    12      else
    13         return_value := network_eqpt(p_type,p_name);
    14      end if;
    15      return return_value;
    16  end new_nw;
    17  /
    Function created.
    SQL> select new_nw('APC', 'Not a network') from dual
      2  /
    NEW_NW('APC','NOTANETWORK')(TYPE, NAME)
    NETWORK_EQPT('APC', 'Not a network')
    SQL> select new_nw('16X', 'Recognised type', 89) from dual
      2  /
    NEW_NW('16X','RECOGNISEDTYPE',89)(TYPE, NAME)
    NET_16X('16X', 'Recognised type', 89)
    SQL> Be aware that the above is just a sample of what can be done rather than a indication of the correct way to program it.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • Daisy-chaining remote object calls

    If you want to get data from a series of CFCs using remote
    object, and each call depends on data received from the previous
    call, you have to daisy-chain the functions making the calls,
    otherwise there is no way to guarantee that the data is available
    in time (in practice it is never available in time) because the
    main thread races on regardless.
    Now if you want to refresh parts of the data, or you want to
    get a different set of data from one or more of the same CFCs, you
    either can use the same functions and set up a different set of
    daisy-chains with multiple boolean tests to see which chain of
    links should be being followed ( and this ends up something akin to
    a four-dimensional Hampton Court maze), or you have to duplicate
    the remote calls over and over again in different sets of functions
    and resultHandlers. Either way you end up with a horrible mess.
    Is there any way to write a class that can suspend the main
    thread, pending a remote call listener sending a resume main thread
    event.
    The other way that would work (though this would not be as
    good) is to change addEventListener, so that you can pass arguments
    into the resultHandler.
    Does anyone have any ideas that could lead to a solution to
    this problem? It's giving me gray hair.
    Doug

    "suspend the main thread, pending a remote call.." No. Can't
    be done.
    ..."pass arguments into the resultHandler..." Yes, this is
    done using the AsyncToken. (ACT pattern)
    The send() methods returns an AsyncToken object. You can use
    this dynamic object to add almost anything you want to the token,
    including strings, and functions (google the term "closure").
    As I am still not comfortable with anonymous functions, I
    like to pass strings. I pass an identifier, which I can use in a
    switch statement to determine the next step. Sometimes I pass a
    "nextStep" string to define finer grain conditionality.
    I use a single dataService object and result handler function
    for all calls.
    Tracy

  • How to use reflection package for dynamic object creation

    I want to convert a "DataObject (SDO) " into "Pure java object".
    For this i want to create a java object with the fields in Dataobject, and this should be in generic way.

    Use Java reflection if you have the java class already created.
    Otherwise use Java IO API for creating the .java file and compile it dynamically by calling javac exe from java code and executing using reflection

  • Type conflict during dynamic method call.

    While executing the following program I get the error "Type conflict during dynamic method call.":
    DATA: container_r  TYPE REF TO object,
          grid_r       TYPE REF TO object,
          itab_saplane TYPE TABLE OF saplane.
    * IMPORTANT NOTE: class names must be in UPPER CASE
    DATA: str_cnt TYPE seoclsname VALUE 'CL_GUI_CUSTOM_CONTAINER',
          str_gui TYPE seoclsname VALUE 'CL_GUI_ALV_GRID',
          meth_name TYPE STRING VALUE 'SET_TABLE_FOR_FIRST_DISPLAY'.
    TYPE-POOLS abap.
    DATA: ptab    TYPE abap_parmbind_tab,
          wa_ptab LIKE LINE OF ptab,
          ref     TYPE REF TO data.
    CREATE OBJECT container_r TYPE (str_cnt)
      EXPORTING container_name = 'CUSTOM_CONTROL1'. " Name of the custom control area (UC!)
    * Construct parameter itab
    GET REFERENCE OF container_r INTO ref.
    wa_ptab-name  = 'I_PARENT'.  " Must be upper-case
    wa_ptab-value = ref.
    INSERT wa_ptab INTO TABLE ptab.
    *   EXPORTING i_parent = container_r.
    CREATE OBJECT grid_r TYPE (str_gui)
      PARAMETER-TABLE ptab.
    SELECT * FROM saplane INTO CORRESPONDING FIELDS OF TABLE itab_saplane.
    * Cannot call set_table_for_first_display directly...
    CALL METHOD grid_r->(meth_name)
      EXPORTING I_STRUCTURE_NAME = 'SAPLANE'  " Type of the rows in the internal table  (UC!)
      CHANGING  IT_OUTTAB = itab_saplane.     " The internal table itself
    CALL SCREEN 100.
    Any help would be appreciated!

    Hi ...
    Apologies ... for confusion ... actually both are required ...
    the type 'E' as well as CL_GUI_CONTAINER.
    The below code worked for me ...
    check out how I cast it to the parent class type ...
      DATA : lv_container   TYPE seoclsname VALUE 'CL_GUI_CUSTOM_CONTAINER',
             lv_control     TYPE seoclsname VALUE 'CL_GUI_ALV_GRID',
             lv_method      TYPE string VALUE 'SET_TABLE_FOR_FIRST_DISPLAY',
             lt_par_tab     TYPE abap_parmbind_tab,
             ls_param       LIKE LINE OF lt_par_tab,
             lref_cont      TYPE REF TO cl_gui_container,
             lv_data        TYPE REF TO data.
    CREATE OBJECT lref_container
          TYPE
            (lv_container)
          EXPORTING
            container_name = 'ALV_AREA'.
        ls_param-name = 'I_PARENT'.
        ls_param-kind = 'E'.
        lref_cont ?= lref_container.
        GET REFERENCE OF lref_cont INTO lv_data.
        ls_param-value = lv_data.
        INSERT ls_param INTO TABLE lt_par_tab.
    **  Now create ALV Control.
        CREATE OBJECT lref_alv_ctrl
          TYPE
            (lv_control)
          PARAMETER-TABLE
            lt_par_tab.
    **  Set table for 1st display
        DATA : lv.
        lv = lref_alv_ctrl->mc_fc_print.
        CALL METHOD lref_alv_ctrl->(lv_method)
          EXPORTING
            i_structure_name = 'T001'
          CHANGING
            it_outtab        = lt_company.
    Cheers
    Edited by: Varun Verma on Aug 12, 2008 4:19 PM

  • Simultaneous remote object calls in one http request?

    I am noticing when I have two remote object calls happen at the same time they are being bundled into one http request.  This is causing problems in my application becuase the result is not coming back until both have finished.
    So basically I have to calls that happen at the sametime.  One does not take anytime and the other is a long running task.  I will not get the result for the first until the long running task completes.
    Has anyone else seen this?
    Any help would be appreciated.

    "suspend the main thread, pending a remote call.." No. Can't
    be done.
    ..."pass arguments into the resultHandler..." Yes, this is
    done using the AsyncToken. (ACT pattern)
    The send() methods returns an AsyncToken object. You can use
    this dynamic object to add almost anything you want to the token,
    including strings, and functions (google the term "closure").
    As I am still not comfortable with anonymous functions, I
    like to pass strings. I pass an identifier, which I can use in a
    switch statement to determine the next step. Sometimes I pass a
    "nextStep" string to define finer grain conditionality.
    I use a single dataService object and result handler function
    for all calls.
    Tracy

  • Concurrent / Parallel remote object calls from same browser app

    Hello Everyone,
    I was wondering how remote requests made to blazeds get served by application servers, when it comes to serving multiple (parallel) remote requests coming from the same application in the same browser.
    Let us say that once you land on an application, you can fire-off 10 independent remote calls.
    Will they all be served by the same request thread in the application server one after another?
    I suspect this because the browser will really only maintain one duplex tcp/ip channel with the blazeds and therefore multiple requests should really just race to the server and get served one after another sequentially based on whichever gets their first.
    This is just what I suspect but I would like to find out from experts on the forum.
    Thanks,
    - Pulkit

    "suspend the main thread, pending a remote call.." No. Can't
    be done.
    ..."pass arguments into the resultHandler..." Yes, this is
    done using the AsyncToken. (ACT pattern)
    The send() methods returns an AsyncToken object. You can use
    this dynamic object to add almost anything you want to the token,
    including strings, and functions (google the term "closure").
    As I am still not comfortable with anonymous functions, I
    like to pass strings. I pass an identifier, which I can use in a
    switch statement to determine the next step. Sometimes I pass a
    "nextStep" string to define finer grain conditionality.
    I use a single dataService object and result handler function
    for all calls.
    Tracy

  • Java Core Program :: Dynamic Object Creation for Classe & Invoking the same

    Hi,
    I need to create a dynamic object for a class & invoke it.
    For eg: I have a table in my DB where all the names of my java classes are stored. I need to call name from the table of the DB and call that class dynamically in my java program.
    ResultSet_01 = executeQuery("select classname from class_table where class_descrip = 'Sales Invoice' ");
                   while(ResultSet_01.next())
                        String class_name = ResultSet_01.getDouble("classname");
                   }Now using the string in class_name that is fetched from ResultSet_01, I need to create an object for the class_name & invoke the class that is been created with the same name.
    Thank in advance.
    Regards,
    Haider Imani

    Well for a start since a class name is a String, not a number you'd better start by getting the name with getString() not getDouble().
    You need to work with fully qualified names, (FQNs) like "com.acme.myproject.MyDynamicClass", not just the bare MyDynamicClass.
    The next question is where the .class files for the dynamically loaded classes are stored. If they are part of your normal program code, on the class path, then you can use Class.forName to load the class and return a Class object. If they are in some special place you'll need to create a URLClassLoader and get the Class from that.
    Generally, when you load a class this way, it should implement some known interface, or extend some know abstract class. By placing objects of the dynamic class in a reference to that interface you can use the methods defined in the interface.
    The usual way of getting an instance of a dynamic class is to call newInstance() on the Class object.

  • Static verse dynamic dispatch call

    I'm just getting started with creating my own lab view classes using the class object but I'm having trouble with some of the basic concepts. Are there any good tutorials or knowledge base articles which talk about how to create and use LabVIEW classes? I'm getting hung on static verses dynamic dispatch calls specifically.
    Any help would be appreciated!
    Thank you,
    Craig

    I'm still getting a handle on LVOOP myself.
    Those two different methods control which VI actually gets called when your app is running.
    THe static method is very similar to calling a normal sub-VI in LV except you are passing LVOOP data.
    The dynamic comes into play when you have more than one class and one is a child of the other. In that case you can create a VI for the child that has the same name as a VI in the parent, but because it has different data, the data it accepts and return is different. This OTHER VI in the child will under the right condition be called instead of the VI in the parent. I understand this to be concidered over-riding. Which versino will be called? It is dicated by the data you pass to the sub_VI call. If you pass the parent data, the parent versino will be called and vise versa.
    So the VI to call is determined at run-time depending on the data.
    I hope I got that right!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • Two remote objects calls on the same php class

    Hi to all,
           I've encountered a strange issue while developing with remote objects.
    I've a mxml component with an init() method inside which is called by a menu.
    When the init() method is called it makes 7 remote object calls which are bound to some components' dataprovider.
    Among this calls I've got 2 remote object which refer to the same remote class. This because I have to call the class twice and the bind the result to two different combobox. Below you find the code:
    <mx:RemoteObject id="myFile" source="myRemoteClass" destination="amfphp"  showBusyCursor="true" makeObjectsBindable="true" fault="traceFault(event)"/>
    <mx:RemoteObject id="myXls"  source="myRemoteClass" destination="amfphp"  showBusyCursor="true" makeObjectsBindable="true" fault="traceFault(event)"/>
    in the init function I make this calls:
    myFile.listDir("dir_1")
    myXls.listDir("dir_2")
    then in the mxml code I bound the result of myFile to combobox1 and the result of myXls on combobox2.
    The problem arise when I call the myXls' listDir method. When I call it I receive the following error:
    code:
    Client.Error.DeliveryInDoubt
    Message:
    Channel disconnected
    Detail:
    Channel disconnected before an acknowledgement was received
    The strange thing is that not only the myXls object returns this error, but also all the other 6 remote object return the same error above.
    I'm not sure, but I guess that the error could be caused by the two remote object which call the same php remote class. If I comment one of the two calls everything works fine.
    Do you have any suggestion about?
    Thanks!!
    Bye
    Luke

    Hi Jan.
    1) We have the 2 VO, each with 3 rows to fill in data. What I mean is that when i just fill in all the fields for the first row of the first VO, and the value of one of these fields is bigger than 50, then after the exception is thrown and the message is displayed, the fields for the first VO are duplicated and shown in the second VO as if the user had inserted them.
    2) We tried yesterday the validateEntity and a Method and Atributte Validator approaches after reading that white paper with the same results.
    The validation is correctly done using any of the those methods.
    I will try to reproduce this issue with the HR schema.
    Thanks in advance once again.

  • Fetching Dynamic Object issue

    Hi all,
    Instead of define an variable as external (due to size limitation), I decided to use session.getInstanceData to obtain the value in an instance variable. While things works well on my environment, it does not work out in the QA environment. The following is how I do it:
    DynamicObject instanceData =
    session.getInstanceData(instanceInfo.getId());
    Map dataMap = instanceData.asMap();               
    //Get screening result
    String resultStr = "";
    boolean hasResult =
    dataMap.containsKey("screeningResults");
    if (hasResult){
    Object resultValue =
    dataMap.get("screeningResults");
         resultStr = resultValue.toString();
    I have also log the content of screen result inside the activity:
    logMessage("leaving ... "+this.activity.name +" with screening results="+ this.screeningResults);
    At my environment, I can see the content pass from the engine back to PAPI. However, on QA environment, I see the content show on the engine log (due to the logMessage) but PAPI gets empty string back.
    At first I thought it is due to the "Max Instnace Size limitation", so I upped the limit to 2000kb, but it still doesn't solve the issue. So anyone got any idea what did I do wrong or forgot to handle? Thanks!
    Matthew

    Can I create dynamic object?Depends what you mean by "dynamic object." That term is not part of standard Java parlance, AFAIK.

  • Error #1056, creating dynamic object

    Hi,
    I am simultaneously creating an object and adding it to an array, perhaps ill-advisedly. The following code worked on the main timeline, but not when I moved it to the constructor of a document class:
    package {
         import flash.geom.Point;
        import flash.display.MovieClip;
        public class IconTour extends MovieClip {
            var thePoint:Point = new Point();
            var defaultColor:Number;
            var overColor:Number;
            var iconCreationList:Array = new Array();
            //var xx:MyIcon;
            public function IconTour(){
                thePoint.x=50;
                thePoint.y=300;
                defaultColor=0x7dc2df;
                overColor=0x788dec;
                iconCreationList.push(this["xx"+iconCreationList.length] = new MyIcon(thePoint,"folder","Text for the folder", "Folder", defaultColor, overColor));
                for each (var iconObject:MyIcon in iconCreationList) {
                    addChild(iconObject);
    The following error is generated:
    >ReferenceError: Error #1056: Cannot create property xx0 on IconTour.
        at IconTour()
    I guess this is because xx0 isn't declared? How does one declare a dynamic object/variable?

    Nope. No mention. However, I guess I don't need to dynamically create a variable as this works:
    iconCreationList.push(xx = new MyIcon(thePoint,"folder","Text for the folder", "Folder", defaultColor, overColor));
    iconCreationList.push(xx = new MyIcon(thePoint,"assignments","Text for the assignment", "Assignments", defaultColor, overColor));
    where this does not:
    iconCreationList.push(this["xx"+iconCreationList.length] = new MyIcon(thePoint,"quiz","Text for the quiz", "Quiz", defaultColor, overColor));
    iconCreationList.push(this["xx"+iconCreationList.length] = new MyIcon(thePoint,"assignments","Text for the assignment", "Assignments", defaultColor, overColor));
    AS doesn't care if I add more than one object to the array that is named xx. I probably won't be referencing xx by that name anyway, just by iconCreationList[1].

  • Weblogic 10.3.0 issues with remote object calls.

    All:
    I was wondering if anyone has experienced any issues with Weblogic 10.3.0 dropping initial remote object calls over AMF Secure Channel. Here are the issues we are experiencing.
    1.     FLEX applications fail consistently on the first remote object call made across the AMF Secure Channel. Resulting in the request not returning from the application server; which has had varying affects on the different applications including missing data, application freeze and general degrading of the user experience.
    2.     FLEX applications require a browser/application refresh once the application has been inactive for a certain period of time. In our experiences the behavior occurs after 30 minutes of inactivity.
    I've deployed this same code to Weblogic 10.3.3 and the behaviors go away. Are there any patches to 10.3.0 that might take care of this issue that we are not aware of?
    Thanks for you help,
    Mike

    Hello,
    I found the problem. But I needed change the target of all my datasources until discover that one of my datasource didn´t answer and no errors was trigged.
    My server was waiting this datasource, and not get started.

  • Dynamic objects in component

    I be trying insert dynamic objects in my JSF component by JavaScript,
    but it don't see this objects in the Servlet.
    for e.g., i have a datatable with 3 rows(from Database), each row with a
    input text(HTML), and insert a dynamic input text(HTML) in my structure(4 rows),
    after execute submit to a ActionListener, the input text included in the
    fourth row dont exists in the Collection return by JSF.
    How can i get the fourth object value?

    Simply you can't.
    JavaScript can't affect the structure of the JSF component tree.

  • Change Value based on Dynamical Object

    Goal:
    The goal is to make the variable with value '2014-06-14 09:00:00.000'
    Problem:
    The syntax code is created as a dynamical object how do you make it from '2014-06-14 16:20:10.000' into value '2014-06-14 09:00:00.000'?
    DECLARE @a datetime = '2014-06-14 16:20:10.000'

    Are you looking for this?
    DECLARE @a datetime = '2014-06-14 16:20:10.000'
    select dateadd(hour,9,convert(datetime,convert(date,@a)))
    set @a = '2014-06-14 08:20:10.000'
    select dateadd(hour,9,convert(datetime,convert(date,@a)))
    Satheesh
    My Blog |
    How to ask questions in technical forum

Maybe you are looking for

  • Cannot get the value after space

    i am doing my double module project for my degree course and i am also a newbie in JSP. Hope there is someone can help me to solve this problem. Now, i set the value of a radio button to "don't smoke", "smoke lightly", and "smoke heavily". Then i use

  • Follow Up to iMac G5 Crash n Burn

    If you go here you will read of an issue my wife was having. We thought it was resolved and this is a follow up to that/those issues. In the end it was a defective hard drive. Which Apple replaced after confirming what Diskwarrior® had identified aft

  • Save for web freezes (Both CS3 and CS4)

    Hello all, A small problem that I've endured with CS3 seems to be happening in CS4 as well, so thought I'd ask about it. Whenever I try saving for the web, the save for web window often freezes, leaving Photoshop unusable for a few minutes. The beach

  • 1. Twitter / Uber Social | 2. My Bberry Menu

    Hi folks... Good Tuesday Moning to you all... I have a Curve 8530 here and just downloaded Uber Social... Being new to Bberry and twitter, I need to know if I have Uber Social, can I delete Twitter?????? I mean they are both the same thing aren't the

  • Function Module for book Training Program for an employee

    Hi All, As we are having the Standard function module "HR_INFOTYPE_OPERATION" for PA infotypes. So is there any function module by using that function module in program we can Book,Cancel, Rebook , Prebook a training program for an employee as we can