Run-Time Type Identification question

Let's say I have a class Chart and 2 subclasses BarChart. and LineChart. I have a method that takes in the type of chart to create as a parameter and then creates the appropriate chart. Something like:
public void createChart(int type){
Chart ch = ChartFactory.getChart(type); //type could be Chart.LINE or Chart.BAR
//Line x
Now, at Line x above, if I want to call a method that is specific to BarChart such as getBarWidth(), how would I go about it?
Thanks.

You're only going to call getBarWidth() in a context that knows it's dealing with a BarChart. The question is how to get your design in such a form so it doesn't have to say "If this is a BarChart then call getBarWidth()". I don't exactly know how you would do that but I suggest it should be your desire to do that.
Let me give a crude example that may or may not have anything to do with your project.
You display a chart and you want to give the user a panel of controls so they can tinker with the way it looks. Controls like the width of the bars in a bar chart, whether or not one of the pieces is offset from the others in a pie chart, the dottedness of the line in a line chart, and so on.
In this case the factory should have a method that takes a chart type (or maybe a chart) and returns a panel of suitable controls. This panel will have only the controls that are suitable for that chart type, and it will be given a reference to a chart that it assumes is of that type.
And similarly. Each time you feel like using instanceof, go back and see if you can't get the factory to do the work.

Similar Messages

  • Access to run time type information

    Hi,
    I am looking for some information on how I can enumerate run time type information (lists of properties and methods) from within LabVIEW.  For instance, I would like to be able to generate a list of controls on a front panel (this I figgured out), and then dynamically generate a list of properties for a selected control.  Anyone know how to do this one?
    Thanks,
    -10

    Thanks Ankita.  I might poke around a bit more.  Most languages have hooks into run-time type information for controls and components (like an activeX control) you can query it to get this information and then display it in a property-setting dialog box.  There is most likely something like this in LabVIEW too.
    -10

  • Run Time: type conflicts in field symbol

    In this statement i am getting run time error : assign component.
    type conflicts in field symbol
    FIELD-SYMBOLS:
        <fs_tab> TYPE ANY table,
         <wa_tab> TYPE ANY,
         <fs_field> type crmd_orderadm_h.
    DATA:      w_data    TYPE REF TO data.
    CREATE DATA w_data TYPE STANDARD TABLE OF (c_tabname) WITH NON-                     UNIQUE DEFAULT KEY.
        ASSIGN w_data->* TO <fs_tab>.
    SELECT * FROM (c_tabname)
              INTO CORRESPONDING FIELDS OF TABLE <fs_tab>
      LOOP AT <fs_tab> ASSIGNING <wa_tab>.
          DO.
            ASSIGN COMPONENT sy-index OF STRUCTURE <wa_tab> TO <fs_field>.
    *Writeing: fs_field here*
    Enddo.

    FIELD-SYMBOLS: <fs_field> type crmd_orderadm_h.
    <fs_field> type any.
    i cannot pass "
      lv_header_guid =    <fs_field>-guid.
    complete code as follows.
      LOOP AT <fs_tab> ASSIGNING <wa_tab>.
          DO.
            ASSIGN COMPONENT sy-index OF STRUCTURE <wa_tab> TO <fs_field>.
    *i am assining fs_field-guid here. Thats why i am taking this field symbol as type "crmd_orderadm_h"*
    *bold* * <fs_field>-guid.*bold**
            lv_header_guid =    <fs_field>-guid.
            iv_header_guid = lv_header_guid.
            REFRESH: lt_header_guid.
            INSERT iv_header_guid INTO TABLE lt_header_guid.
            REFRESH: im_orderadm_h,im_text.
            CALL FUNCTION 'CRM_ORDER_READ'
              EXPORTING
                it_header_guid       = lt_header_guid
              IMPORTING
                et_orderadm_h        = im_orderadm_h
                et_text              = im_text
              EXCEPTIONS
                document_not_found   = 1
                error_occurred       = 2
                document_locked      = 3
                no_change_authority  = 4
                no_display_authority = 5
                no_change_allowed    = 6
                OTHERS               = 7.
            IF sy-subrc <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
            ENDIF.
          ENDDO.

  • Run Time structure identification of a variable.

    Hi Experts,
    I have a requirement where i need to identify the structure type assigned to the variable at run time. i.e. if i have the variable name at run time i shold be able to find the structure type assigned in that program.
    Please help. let me know if you need any further information.
    BR,
    Raj.

    Check this:
    TYPE-POOLS: abap.
    DATA: gc_mara TYPE mara,
          gc_marc TYPE marc.
    PERFORM check_struct USING gc_mara.
    PERFORM check_struct USING gc_marc.
    *&      Form  check_struct
    *       text
    *      -->P_STRUCT   text
    FORM check_struct USING p_struct TYPE any.
      DATA: lcl_struc TYPE REF TO cl_abap_structdescr,
            lv_struc_name TYPE abap_abstypename.
      lcl_struc ?= cl_abap_structdescr=>describe_by_data( p_struct ).
      CHECK lcl_struc IS BOUND.
      * Get the DDIC structure of the formal param P_STRUC
      lv_struc_name = lcl_struc->absolute_name. "\TYPE=<DDIC Structure>
      WRITE: / lv_struc_name.
    ENDFORM.                    "check_struct
    BR,
    Suhas

  • Warning when casting object into generic type at run time.

    I am getting this message when casting an object at run time:
    Type safety: The cast from Object to Tree<V> is actually checking against the erased type TreeI'm overloading an equals(Object o) method in my class.
    Is there a way to get rid of the warning (besides turning the warning off :))

    I'm overloading an equals(Object o) method in my
    class.
    Is there a way to get rid of the warning (besides
    turning the warning off :))No. The best you can do is what is demonstrated in the previous link.

  • Can i change my contain in file at run time

    hello everybody,
    i am beginner and i am trying to write the online test,
    i display users to login and then display first question on question.html,
    now my question is can i change question and send next question at run time on same question.html
    please reply me,
    waiting for answer

    hello,
    but how i open that html files and change the contain within control (say textbox) as i change the question in text box.
    please reply me

  • RE:Placing a file in one of many directories at run time

    Hi all,I posted a question yesterday evening with subject name as "Placing a file in one of many directories at run time".
    The link for that qestion is as follows:
    [Placing a file in one of many directories at run time;
    For that question I got a UDF as a reply.The UDF is as follows
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
    String strDirectory = "Dir1"
    // here write your condition for dynamic Directory
    conf.put(key,strDirectory);
    return  strDirectory;
    Im having an double if condition in my scenario as follows:
    if (Integer.parseInt(TableName[0])==8 || Integer.parseInt(TableName[0])==10 || Integer.parseInt(TableName[0])==12 )
    if(CountryCode.equals("SG") || CountryCode.equals("MY") || CountryCode.equals("PH") || CountryCode.equals("TH") || CountryCode.equals("ID"))
    Now my question is  where to insert last two statements of UDF(conf.put(key,strDirectory);
    return  strDirectory;).
    Should I use both in if condition or any one in if condition.
    Can any one help me out in this case.
    Thanks in advance,
    Regards,
    Prajwal Kumar

    Hi Naluvala
    You can do this. It is pretty simple
    bstractTrace trace = container.getTrace();
    trace.addInfo("In Dynamic Configuration...............................:");
    DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
    DynamicConfigurationKey key1 = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");
    String ourSourceFileName = conf.get(key);
    trace.addInfo("Key Filename:"+ourSourceFileName);
    String valueOld = "/XD1_interfaces/messages/inbound/ref_payments";
    trace.addInfo("Key valueOld:"+valueOld);
    conf.put(key1,valueOld);
    return  ourSourceFileName; 
    Regards
    Abhishek
    *Please reward points if helpful***

  • Validation at run time

    Hi,
      i am trying to use the keyword "order_time" in for/next.
      it says on the admin guide on page 111 that, "you can use the passed members of a dimension in a for/next loop, when the validation is performed at run time".
      my question is:
    1) what is validation performed at run time?
    2) how does one perform validation at run time?
      thanks for your help in advance
    cheers

    Are you handling it in valueChangeListener? Have you set the properties
    AutoSubmit to true
    Immediate to true
    for the drop down? On top of that as Timo has mentioned you need to set the partialTrigger property of the inputText to the dropdown.
    Regards,
    ~K

  • Run-time error '13':  Type mismatch

    There are A and B excel files.
    And two different POV-dimension in two excel files
    VBA code below:
    Dim vtGrid As Variant
    Dim vtDimNames As Variant
    Dim vtPOVNames As Variant
    x = HypRetrieve("sheet1")
    x = HypUseLinkMacro(True)
    Range("b10").Select
    x = HypGetSourceGrid("sheet1", vtGrid)
    ref = HypMenuVRefresh()
    x = HypGetPOVItems(vtDimNames, vtPOVNames)
    MsgBox (vtPOVNames(6))
    Range("a3").Value = "date: " & vtPOVNames(6) & " - " & vtPOVNames(3)
    Range("a4").Value = "dep : " & vtPOVNames(0)
    There is not any attribute dimension in pov A excel file.
    There is one attribute dimension in pov B excel file.
    The same VBA code excute is normal in A excel file.
    But the same VBA code excute is "run-time error '13': Type mismatch " in B excel file.
    The error '13' in the row of MsgBox (vtPOVNames(6)).
    Is attribute dimension in pov cause this question?
    And how did I solve this question?

    Based on where the error is occurring, it looks like the value returned by vtPOVNames(6) is not defaulting to a string datatype for the msgbox.
    Try 'cstr(vtPOVNames(6))' to force conversion of the value into a string. Also, you may want to test for nulls using IsNull() and empty variant values using IsEmpty().
    It doesn't look like the code you posted shows vtPOVNames being populated. If you're populating the names yourself, you could always use a string array instead of a variant array. Just dim the string array using a statement such as, "Dim strPOVNames(6) as String" or "Dim strPOVNames() as String" in case you need to ReDim the array later to size it for a non-fixed set of POV names.
    Hope this helps.

  • SBO Run-time error '13' Type mismatch

    Hello,
    I'm currently using SBO 2005 SP1 (PL11)
    After installing SBO DTW (2005A PL11 as well), i'm facing this issue : Run-time Error '13' Type mismatch
    I've been trying to modify my regional settings as per the previous discussions but this didn't work (first of all, i'm located in France, and try to apply the french regional settings).
    I've uninstalled and reinstalled DTW and my DI API but unfortunately, this didn't"t work either.
    Any other advise on this problem ?
    Thanks,
    Stephane

    Stephane,
    Here are some links to SAP Notes on the SAP PartnerEdge Portal that may help.  Please read the note carefully as the first note has your remove the Windows User Profile.
    https://websmp230.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/smb_searchnotes/display.htm?note_langu=E&note_numm=0000873864
    https://websmp230.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/smb_searchnotes/display.htm?note_langu=E&note_numm=0000884234
    If these do not help I recommend that you log a message with SAP Technical Support as the forum you have posted your question in is for questions related to the SAP Business One SDK and your question is application related to the DTW.
    HTH,
    Eddy

  • How To... Change the Data Type for a SELECT-OPTIONS at run time.

    Hello,
    I am trying to restrict the values available for entry into a SELECT-OPTIONS at run time depending on user input.
    The logic is as follows. The user has two input fields. A PARAMETER field which has the type RSDIOBJNM and allows them to choose an InfoObject. And the user has a SELECT-OPTIONS field to allow them to select the Characteristic values for that InfoObject.
    I would like the following example to be possible:
    The user enters 0MATERIAL into the PARAMETER. When the user clicks on the SELECT-OPTIONS control code will derive a list of possible options the user can enter in the SELECT-OPTIONS. In this case only values found in the master data or at least no values greater than 18 characters.
    I have looked at the following function module SELECT_OPTIONS_RESTRICT and this do not appear to be helpful as they only restrict on the signs allowed for the values (unless I misunderstand, it is a complex function module!).
    The code I have so far is (thus the user enters a InfoObject into p_char1 and the select options so_char1 should only accept active values of that InfoObject):
    declaration of variables for user interface
      DATA c_char(32) TYPE c.
    declaration of count variable
      DATA i_count TYPE i.
    declaration of user interface
      SELECTION-SCREEN BEGIN OF BLOCK a1 WITH FRAME TITLE text-001.
        PARAMETERS: p_ipack TYPE RSLOGDPID.
      SELECTION-SCREEN END OF BLOCK a1.
      SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-002.
        PARAMETERS: p_char1 TYPE RSDIOBJNM.
        SELECT-OPTIONS: so_char1  for c_char NO INTERVALS.
        PARAMETERS: p_char2 TYPE RSDIOBJNM.
        SELECT-OPTIONS: so_char2  for c_char NO INTERVALS.
        PARAMETERS: p_char3 TYPE RSDIOBJNM.
        SELECT-OPTIONS: so_char3  for c_char NO INTERVALS.
      SELECTION-SCREEN END OF BLOCK b1.
    Is what I am trying to do possible???
    Thanks for any help. Ross.

    You really want to restrict possible values of a select-option based on another field, not change the length of type of the select-option field, right?
    Here is what you do:  Code a custom F4 value help for the select-option at event AT SELECTION-SCREEN ON VALUE REQUEST FOR..  The first thing you do here is read the value of the parameter field (p_ipack in your example).  You can use function module DYNP_VALUES_READ.  Based on this value, you can propose values for the select-option fields.  Note that the use can still enter whatever s(he) wishes in to the select-option field without pressing F4. In this case, you will have to code some input validations taking into account the value in the p_ipack field.

  • My imac is running mountain lion and last night i downloaded maverick. in midst of installing it it said a powerPC app microsoft word would not work so i canceled the install for the time being. my questions is  if i choose to finish installing maverick

    my imac is running mountain lion and last night i downloaded maverick. in midst of installing it, it said a powerPC app microsoft word would not work so i canceled the install for the time being. my questions is  if i choose to finish installing maverick does that mean i will nevver be able to access word documents stored on my desktop? or do the word docs automatically convert to pages or what? i am so confused. would i be better off just sticking with mountain lion and send the maverick install to the trash? hoping someone will be able to answer my question though i am afraid the response is likely to be just stick with mountain lion so you can keep using word. i had been looking forward to maverick but it seems pretty drastic to not have access to microsoft word anymore by switching to maverick. hope someone has an answer so i can have the best of both worlds so to speak!

    thanks for your response Csound1 on the peninsula ... if i go ahead and install maverick and then download LibreOffice or OpenOffice will i then be able to access old microsoft word saved documents on my deskstop through those two free alternatives? i am not that knowledgeable about these things so i am not sure if you are saying i will just be able to use libreoffice or openoffice for creating new documents or whether i can access the saved microsoft docs? are they transferred to OO or LO or what and if editing of the old word docs is needed can i do that through the OO and LO programs or apps (see i am not even sure if i am using the correct vocabulary!) hope you can answer this as quick as the first question, so i can decide to stick with mountain lion and trash the maverick install or proceed with maverick install and hoppe that my microsoft word docs are still accessible through OO or LO or adding to myquestion will pages on maverick be able to open the old word documents? thanks again!

  • How to determine itab type at run time

    I need to write a subroutine that organizes data in internal tables for presentation by a smartform. There are a few similarly structured internal tables all with the same field name ("recipe_type") by which the data is sorted. My problem is that how I can determine the type of the itab inside my subroutine at run time? Is it ever possible in ABAP?
    The subroutine code is attached below. Thanks for any help.
    FORM beautify_itab    TABLES itab_in TYPE table
                                     USING v_type TYPE any
                                     CHANGING itab_out TYPE table.
    Data declaration
      DATA: v_data_row LIKE LINE OF itab_in,                " THIS WON'T COMPILE!
                 v_blank_row LIKE LINE OF itab_in.              " blank row
    Organize the display of the table data
      LOOP AT itab_in INTO v_data_row.
        IF v_type <> itab_in-recipe_type.                     " 'recipe_type' is the sort key for the incoming itabs
          v_type = itab_in-recipe_type.
          IF sy-tabix > 1.
            APPEND v_blank_row TO itab_out.
          ENDIF.
          APPEND v_data_row TO itab_out.
        ELSE.
          CLEAR v_data_row-recipe_type.
          APPEND v_data_row TO itab_out.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    "beautify_itab

    The following code does what I want, but only if the input itab structure is declared first in the program. It won't work if the itab is declared as itab_in TYPE TABLE OF sflight. This is because the function 'GET_COMPONENTS_LIST'  only can load the structure of a field declared explicitly in the program.  Does anybody know of any method to load the structure of an itab based off a dtab? 
    Thanks you guys for answers. Points have been rewarded.
    *& Report  Z_GET_ITAB_TYPE_AT_RUN_TIME
    REPORT  z_get_itab_type_at_run_time.
    DATA: BEGIN OF itab_in OCCURS 0,
             seatsocc_b LIKE sflight-seatsocc,
             fldate LIKE sflight-fldate,
          END OF itab_in,
          itab_out TYPE TABLE OF string,
          wa_itab_out TYPE string.
    SELECT seatsocc_b fldate
    INTO TABLE itab_in
    FROM sflight
    WHERE carrid = 'AA' AND
          connid = '0017'
    ORDER BY seatsocc_b.
    PERFORM beautify_itab
                TABLES
                   itab_in
                USING
                   sy-repid
                   'itab_in'
                   'SEATSOCC_B'
                CHANGING
                   itab_out.
    LOOP AT itab_out INTO wa_itab_out.
      WRITE: / wa_itab_out.
    ENDLOOP.
    *&      Form  beautify_itab
          text
         -->ITAB_IN    text
         -->V_KET_FIELD   text
         -->ITAB_OUT   text
    FORM beautify_itab TABLES itab_in TYPE table
                       USING  v_prog_name LIKE sy-repid
                              v_itab_in_name TYPE any
                              v_key_field_name TYPE rstrucinfo-compname
                       CHANGING  itab_out TYPE table.
      DATA: itab_fields TYPE TABLE OF rstrucinfo,
            v_field_name LIKE rstrucinfo-compname,
            v_old_key TYPE string,
            v_field_value TYPE string,
            v_data_line TYPE string,
            v_tabix LIKE sy-tabix,
            c_blank_row TYPE string VALUE ''.
      FIELD-SYMBOLS: <fs_field>,
                     <fs_data_line>,
                     <fs_field_list> TYPE  rstrucinfo.
    gets all of the components of a structure
      CALL FUNCTION 'GET_COMPONENT_LIST'
        EXPORTING
          program    = v_prog_name
          fieldname  = v_itab_in_name
        TABLES
          components = itab_fields.
      LOOP AT itab_in ASSIGNING <fs_data_line>.
        v_tabix = sy-tabix.
        LOOP AT itab_fields ASSIGNING <fs_field_list>.
          v_field_name =  <fs_field_list>-compname.
          ASSIGN COMPONENT v_field_name OF STRUCTURE
                        <fs_data_line> TO <fs_field>.
          v_field_value = <fs_field>.
          IF v_key_field_name = v_field_name.
            IF v_old_key <> v_field_value.
              v_old_key = v_field_value.
              IF v_tabix > 1.
                APPEND c_blank_row TO itab_out.
              ENDIF.
            ELSE.
              CLEAR v_field_value.
            ENDIF.
          ENDIF.
          CONCATENATE v_data_line v_field_value INTO v_data_line
                      SEPARATED BY space.
        ENDLOOP.
        APPEND v_data_line TO itab_out.
        CLEAR v_data_line.
      ENDLOOP.
    ENDFORM.                    "beautify_itab

  • How to change at run-time the type of a step?

    Hi,
    How topic title, i need to know how change at run-time the type of a step. I have, i my sub-sequence, a step whose type must change at run-time based upon the occurrence of a condition. How can do it?
    Thanks.

    I need to do this: At verify of a condition, one specific step at the end of sequence must change from statement to numeric limit test and viceversa.
    However, is right to no writing self-modifyinf sequence  unless handle rece condition on step that i want change at run-time.
    Moreover i ask myself: If for change the type of a step i need first delete the substep and later create a new one relative to the step that I want, then it is better and make more sense to create dynamically the step that i would like to have depending on the condition that occurs, right?
    Thanks

  • Read Data's from the Form step type at run time

    Hi Experts,
    I have the 'Form' step type in my workflow and it will displays some values at the Run time. In this form I have one IO field called 'Comments'. So at the runtime manager can Enter the comments on it.
    Now my need is I need to get the 'Comments' data from that form. How can I get this value?
    Thanks in Advance,
    Helps will be Appreciated..

    I got the solution.
    Thanks All..

Maybe you are looking for

  • "CoreServicesUIAgent.app" would like to access your calendar. What do I do with THAT?

    This morning I see a pop-up that says, "CoreServicesUIAgent.app" would like to access your calendar" with choices of "Don't Allow" or "OK." I have no idea how to choose since I don't know what that is and where it came from. Now I feel forced to leav

  • Transfer from MBP to MBA?

    Hi guys, I've just replaced by MBP with an MBA & understand that I can transfer data from one to another via Ethernet. Seeing as the MPA doesn't have an Ethernet port, I was wondering on the following: I will possibly never use an Ethernet - USB or T

  • Asian characters pop into text bubbles when I chat...

    Hi. I am having issues with iChat. When I type into the message field in iChat my text is in English. When I hit return, when the message is displayed into the bubbles, my text turns into Asian characters, which, of course, I am unable to read. Howev

  • DW CS3 upload

    I had to leave yesterday, just as we were getting to my problem. I re-contacted the hosting service and this is the reply "our servers do not support the FTP client in Dreamweaver. This does not mean that you can't use Dreamweaver. You can continue t

  • FM to check the correctness of a timestamp.

    Hello, Can any one tell me how to check if the incomming timestamp is in correct format or not? Lets say if the incomming timestamp is not in the standard format 'YYYYMMDDHHMMSS'  i should rise a error. there are cases where the input format is commi