Calling abstract method from method, where is functional code

HI All
I'm trying to find the actual code that is responsible for the play() method to play sound of Applet or of AudioClip. I looked in the source files and found that the two are circle-refering to each other. Audio clip is an interface so it doesnt specify any code for how the method play() should work. That should be left to the classes that implement it. But the play(URL) method of Applet refers to the the AudioClips method:public void play(URL url) {
AudioClip clip = getAudioClip(url);
if (clip != null) {
clip.play();
So where is the real code for the method?
This seems to be very normal because almost all methods in Applet where refering to interfaces like AppletContext an AppletStub.
How does this work? Can anybody explain?

This is a design-pattern called "factory-method". The factory-method (here getAudioClip(URL)) has a return value of an interface but really returns an object of a class implementing this interface. The user can call this factory-method and then call the methods of the returned object without knowing wich class this methods implements. If you want to change the implementing class later, you only have to build a new class and to change the factory-method - but the code of the "user" will not change.

Similar Messages

  • Calling abstract method inside constructor

    what will happen if you call abstract method inside a constructor ?

    AMARSHI wrote:
    Then wat is the purpose of that object then.
    When u create an object then the control will move to the default constructor,If there is one. Not all classes have default constructors. Some c'tor will be called though.
    inside the constructor u r having an abstract method.
    But theere are 2 cases now:
    1 the top-level class is an abstract class
    2 the abstract class is an inner class.
    1. for case 1 , u cannot create an object ,so no need of having the constructor.Yes, you can create an object. You can instantiate a concrete subclass. The abstract parent's constructor is still called, and that c'tor may call an abstract method, which will be implemented in the concrete subclass, or some class between it and the parent.
    2.for case 2 u cannot have an object like:
    outerClass obj = new innerAbstractClass()I have no idea what you're talking about here.

  • Parent constructor calls abstract method

    Hi everybody!
    I'm wondering if there is something wrong with java or if the idea is just too ill?
    Anyway, I think it would be great if this hierachy would work...
    Two classes A and B.
    Class A defines an astract method.
    In A's constructor this abstract method is called.
    Class B extends A and provides an implementation for the abstract method in A.
    Class B also defines a member variable that is set in B's implementation of the abstract method.
    In class' B constructor the parent constructor A() is called.
    example:
    public abstract class A {
      public A() {
        createComponents();
      public abstract void createComponents();
    public class B extends A {
      private String string = null;
      public B() {
        super();
        System.out.println("B::B() " + string);
      public void createComponents() {
        System.out.println("B::createComponents() begin");
        string = new String("test");
        System.out.println("B::createComponents() " + string);
      public void describe() {
        System.out.println("B::describe() " + string);
      public static void main(String[] args) {
        B b = new B();
        b.describe();
    }running the code above produces the following output:
    B::createComponents() begin
    B::createComponents() test
    B::B() null
    B::describe() null
    why is the string member variable null in B's constructor??
    thanks in advance
    Peter Bachl
    Polytechnic University of Upper Austria, Hagenberg
    [email protected]

    The answer is that the call of the super-constructor
    is allways done before the initialization
    of the member variable. That's all and that's the
    normal behavior.
    order :
    - initialization of static variables
    - call to the super-constructor
    - initialization of the instance variables
    - execution of the constructor
    Since this is the advanced forum it is relevant to point out that that is not exactly true.
    There is a step in java that 'initializes' member variables before any constructors are called, super or other wise.
    From the JLS 12.5...
    Otherwise, all the instance variables in the new object, including those declared in superclasses, are initialized to their default values (4.5.5)
    Using the following code as an example
      class MyClass
         int i1;
         int i2 = 1;
    .When creating an instance of the above there will be three 'initializations'
    // Part of object creation...
    i1 = 0; // The default value
    i2 = 0; // The default value
    // Part of construction...after super ctors called.
    i2 = 1; // The variable initializer (see step 4 of JLS 12.5)
    Unfortunately the descriptions are rather similar and so confusion can result as to when the assignment actually occurs.

  • Multiple dispatch and Symmetric methods - Where Does That Code Live?

    Hi all.
    I am stuck with the above problem, which looks to be a very common and fundamental one. Supposing I have some sort of relation or operation to be performed on various different pairs (or n-tuples) of classes of object. Where does this code belong, given that it is not sole property of any one of the classes, but a kind of property of the collection of classes?
    An bad example for me to bring up, but one that neatly illustrates the point, is the equals method. In order to retain the symmetric and transitive properties of the equals method, and object can only make judgement calls about it being equal to another object of it's own type. This prevents the concept of equivalency from crossing between types.
    In order to compare a with b (if a and b are of different types), b must supply some sort of representation of itself as an a, then the comparison statement a.equals(b.asA()); must be called.
    This of course means b must supply an 'asXXX()' method for each class XXX it wishes to equate itself to. Furthermore, by an extension of the equals contract for symmetricality, the method AsB() in class A (if it exists) must be such that, if a.AsB() .equals (b), then b.AsA.equals( a ).
    This sort of design is unfeasible for obvious reasons, the main reason being that it is impossible to anticipate evey case where an instance of class A could reasonably be compared to an instance of some other class X.
    The other annoyance is all that hard work of providing methods to equate A with something else, would go unused for 99% of the time.
    With this in mind, I was thinking. Suppose in some program environment, we have only 3 classes, A, B, and C, such that:
    {A,B} can be meaningfully compared
    {B, C} and {A, C} cannot.
    It would be OK to supply code (somewhere) for comparing A's with B's. We also know that under no circumstances will an A or a B, and a C, ever need to be compared for equality.
    Supposing an extension of this environment were created, introducing class D.
    {D, A} and {D, B} can be meaningfully compared.
    Now, neither A nor C knows what a D is, or how to compare themselves to it. But D was developed with A, B and C in mind, and contains logic for the various comparisons (with A and with B). An obvious idea for this is to let D bring it's new code into play, by registering these new comparison functions in the environment somehow.
    Supposing instead that equality comparison was delegated to some third party, instead. This third party contains a table of pairs of classes, which act as keys to look up a comparison object.
    So, when class A is loaded, something of the sort happens:
    public class A {
        static {
            Equals.comparer.addEntry(A.class, B.class, new EqualsMethod() {
               // details of the EqualsMethod interface implementation go here
    public class B {
        static {
            // since equals is symmetric, this method clashes with the above in A
            // This could happen...
            Equals.comparer.addEntry(B.class, A.class, new EqualsMethod() {
               // ... different approach to the above
    public class D {
        static {
            Equals.comparer.addEntry(D.class, A.class, new EqualsMethod() {
            Equals.comparer.addEntry(D.class, B.class, new EqualsMethod() {
        } // Ds can now be compared with Bs and As. They can now be compared with Ds
    }There is a problem with the above. As can clearly be seen, there are 3 unique situations that might occur between two classes (call them X and Y).
    o One of X or Y contains code to compare them both.
    o Neither X nor Y contain code to compare the two. X equals Y is always false
    o Both X and Y contain code to compare the two.
    The third causes the problem. What if X and Y disagree on how to compare themselves? Which method gets chosen? The only solution would be to let whosever static initialiser gets called first be the one to supply the code.
    I said before that equals was a bad example to bring up. this is because the usage of equals and the concept of equality in java is already well defined, and works just fine. However, in my own pet project at the moment, I have run into the same problems as outlined above.
    I am currently assembling a generic pattern API for use in various other applications I am writing (I was finding that I was writing code for matching objects to patterns, in different guises, quite frequently, so I made the decision to refactor it into its own package). An important part of the API is the section that handles the logic for combining patterns, ie with AND, OR and NOT operations.
    The Pattern interface is this:
    interface Pattern<E> {
         public boolean match(E toMatch);
         public Pattern<E> not();
         public Pattern<E> or(Pattern<E> other);
         public Pattern<E> and(Pattern<E> other);
    }There are a few basic Patterns:
    TruePattern<E> - a pattern that always returns true no matter what E is passed for it toMatch
    FalsePattern<E> - self-explanatory.
    ExactValuePattern<E> - true if and only if the E that it is passed toMatch is .equal to the E that this pattern was constructed with.
    NotPattern<E> - a pattern that contains another pattern, and returns true for any E that returns does not match it's contained pattern. Used for when the contained pattern cannot be logically reduced to one pattern under the NOT method in the Pattern interface
    AndPattern<E> - a pattern that contains 2 other patterns, and returns true for some E iff both contained patterns return true for that E. Used for when the 2 patterns cannot be logically reduced into one pattern via the AND method in the Pattern interface
    OrPattern<E> - self explanatory
    RangePattern<E extends Comparable <E>> - a pattern for comparing if some Comparable lies between two other comparables.
    Every pattern has the opportunity to provide a reduction, when combined with another pattern through And or Or. For example, any pattern AND a FalsePattern can be reduced just the FalsePattern. any pattern OR a TruePattern can be reduced to just the TruePattern.
    The methods AND and OR from the Pattern interface present the same problems as the .equals() example I was using before.
    o AND and OR are symmetric operations
    o There exist situations where two patterns of unrelated class could be meaningfully combined (and reduced) under these two operations.
    Example: The pattern on Integers '0 < X < 3' and 'X is 5' can be reduce to the FalsePattern
    Example: The pattern on Doubles '0 < X <= 10' or 'X is 5.5' or 'X is 7.2' can be reduced to '0 < X <= 10'.
    Example: The pattern on Integers ('0 <= X <= 5' and 'X is not 0') or ('X is 6') or ('x is 7') can be reduced to '1<=X<=7'.
    So the question is, where does the code belong? a.and(b) should return the same as b.and(a), but both b and a may well disagree as to what happens when they are combined under and. At present, both a and b need to supply their own separate implementations. Clearly though, the code for combining patterns A and B belongs to neither A alone, not B alone, but to A and B as a whole.
    Thanks in advance, and sorry for this overlong post.

    So the equivalent thing in my scenario would be an
    AndAnator, and an OrAnator? :)
    The thing is, it would be nice for comparison between
    A and B to take place automatically, without the poor
    coder having to maintain a reference to a Comparator
    and invoke the comparison method each time. Likewise
    in my situation, it'd be nice to say A.or(B) instead
    of andAnator.and(A,B), yet have all the goodness of a
    third party doing the comparison (or in this case,
    the anding).
    I am going to go and test this all out, but do you
    have any suggestions on a good structure? I think it
    would involve pulling the and/or/not methods from the
    interface (this appeals, as many implementors may not
    wish to supply logic for running these methods
    anyhow), and then putting them... somewhere else.I didn't consider your speicifc problem very deeply because after such a long detailed explanation I figured you'd be up for kicking around the idea for a while.
    In your case, I see that you would want to be able to call the and and or methods on the Objects themselves. Luckily, in this case, I think you can have your cake and eat it too.
    You can make your and and or methods fa�ades to the third party 'referee'. This way you can enfore symmetry. It's difficult (if not impossible) to enoforce transitivity with this design but I think you don't even need that in this case. That is if a == b and b == c then a == c should be true but if a and b and b and c then a and c is not necessarily true. In your case, it may not even make sense.

  • Help: Calling C++ method in Java source code?

    I found a method very useful, but it is written in C++, really hate to translate it into Java. My questions are:
    1. Is it possible to call it in my java source code?
    2. If so, how to call the C++ method in my Java program?

    To answer your first question, yes it is possible to call your C++ method from Java. There are several answers to your second question, however. You can use the raw procedural JNI and code your own layer that maps your Java proxy object instances to C++ peer instances. Another option is to generate the code for that mapping automatically. How? Download JNI++ (http://jnipp.sf.net or http://www.sf.net/projects/jnipp). JNI++ is a free, open-source toolkit that makes easy work of bi-directional Java <---> C++ integration -- it will even generate your makefile. Comes complete with a 100-page printable PDF User Guide and plenty of examples to get you started.
    Good luck with your project.
    I found a method very useful, but it is written in
    C++, really hate to translate it into Java. My
    questions are:
    1. Is it possible to call it in my java source code?
    2. If so, how to call the C++ method in my Java
    program?

  • Set_block_property does not called the query from the where clause

    Hi all,
    I have two blocks in the Oracle form 6i. Master link with the detail. Because of the data is quite huge if I have the auto query when the form is loaded hence I have two enter parameter created of From_date and To_date together with button to execute the query when that two parameter is being filled.
    I have the following quotes in the button of when-button-pressed :-
    BEGIN
    set_block_property('act_vw_sale_comm', default_where, 'invh_dt >='''|| to_date(:act_vw_sale_comm.fdate,'dd/mm/yyyy') ||''' and invh_dt <= ''' || to_date(:act_vw_sale_comm.tdate,'dd/mm/yyyy')||'');
    go_block('act_vw_sale_comm');
    execute_query;
    set_block_property('act_vw_sale_comm', default_where, '');
    END;
    However, nothing being displayed when I click on the button. Anything wrong on the above statement ? Please help me. thanks.
    Rgds
    Lim

    BEGIN
    go_block('act_vw_sale_comm');
    set_block_property('act_vw_sale_comm', default_where, 'invh_dt >= '''|| :FDATE ||''''' AND invh_dt <= '''|| :TDATE ||'''');
    execute_query;
    --set_block_property('act_vw_sale_comm', default_where, '');
    END;
    Now, I have the above statement, but still the same when try to execute the query, this time, the screen execute but does not show anything and close my form straight away. Why!
    Anyone can help me?
    Thanks
    Lim

  • Calling shell scripts from within Oracle PL/SQL codes

    Hello,
    We are migrating from informix to Oracle. In our Informix Stored Procedure we
    were able to call Unix Shell Script by executing a 'SYSTEM' command, such as:
    CREATE PROCEDURE magazine(flag1, flag2)
    SYSTEM '/pics2/informix/mag.sh' || flag1 || flag2;
    END PROCEDURE;
    How can I write this in PL/SQL? Is there a simillar command for 'SYSTEM' in PL/SQL?
    Thanks

    Mike,
    Wrong forum, for this question, suggest you ask it in the PL/SQL forum.
    Jim Stern

  • Abstract classes and constructors - cannot call abs. methods in CONSTRUCTOR

    Let me explain the scenario:
    I'm building a program in which I need to read a file (among other things) and I intend to use object orientation to it's fullest in doing so. I thought of creating an abstract FILE class which has the commonalities, and two subclasses SERVER_FILE and PC_FILE, which implement the abstract method GET_CONTENTS in different ways (OPEN DATASET / GUI_UPLOAD), same for the CHOOSE method which allows to select the file from it's corresponding source.
    Initially I've used an interface but since another tasks like setting the file path are common for both, switched to an ABSTRACT class.
    Now, the problem is, from the main code I intend to use a FILE reference to handle either type of file. At the instantiation moment I'd like the path attribute to be set; if it was not set by parameter, i'd like to call the CHOOSE method which is abstract for the superclass. Since this is common for either subclass, I need a way to code it once in the superclass. But I get an error because the CHOOSE method is abstract.
    This is the problem code (extracts):
    *       CLASS lcl_file DEFINITION
    CLASS lcl_file DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS:
          constructor
            IMPORTING
              i_path  TYPE string OPTIONAL
            EXCEPTIONS
              no_path_chosen,
          get_contents ABSTRACT
            RETURNING
              value(rt_contents) TYPE string_table
            EXCEPTIONS
              read_error.
      PROTECTED SECTION.
        DATA:
          _v_path        TYPE string.
        METHODS:
          choose ABSTRACT
            EXCEPTIONS
              no_path_chosen,
          set_path
            IMPORTING
              i_path  TYPE string.
    ENDCLASS.                    "lcl_file DEFINITION
    *       CLASS lcl_file IMPLEMENTATION
    CLASS lcl_file IMPLEMENTATION.
      METHOD constructor.
        IF i_path IS SUPPLIED.
          CALL METHOD set_path
            EXPORTING
              i_path = i_path.
        ELSE.
    *---->>>> PROBLEM CALL - CAN'T BE DONE!!
          CALL METHOD choose
            EXCEPTIONS
              no_path_chosen = 1.
          IF sy-subrc = 1.
            RAISE no_path_chosen.
          ENDIF.
        ENDIF.
      ENDMETHOD.                    "constructor
      METHOD set_path.
        _v_path = i_path.
      ENDMETHOD.                    "set_path
    ENDCLASS.                    "lcl_file IMPLEMENTATION
    *       CLASS lcl_server_file DEFINITION
    CLASS lcl_server_file DEFINITION
                          INHERITING FROM lcl_file.
      PUBLIC SECTION.
        METHODS:
          get_contents REDEFINITION.
      PROTECTED SECTION.
        METHODS:
          choose       REDEFINITION.
    ENDCLASS.                    "lcl_server_file  DEFINITIO
    *       CLASS lcl_server_file IMPLEMENTATION
    CLASS lcl_server_file IMPLEMENTATION.
      METHOD choose.
        DATA:
          l_i_path     TYPE dxfields-longpath,
          l_o_path     TYPE dxfields-longpath.
        CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
          EXPORTING
            i_location_flag = 'A'  " Application server
            i_path          = l_i_path
            fileoperation   = 'R'  " Lectura
          IMPORTING
            o_path          = l_o_path
          EXCEPTIONS
            rfc_error       = 1
            OTHERS          = 2.
        IF sy-subrc = 0 AND l_o_path <> l_i_path.
          MOVE l_o_path TO _v_path.
        ELSE.
          RAISE no_path_chosen.
        ENDIF.
      ENDMETHOD.                    "choose
      METHOD get_contents.
        DATA: l_line   LIKE LINE OF rt_contents,
              l_osmsg  TYPE string.
        CHECK NOT _v_path IS INITIAL.
        OPEN DATASET _v_path FOR INPUT
                                 IN TEXT MODE
                                 MESSAGE l_osmsg.
        IF sy-subrc <> 0.
          MESSAGE e000(oo) WITH l_osmsg
                           RAISING read_error.
        ELSE.
          DO.
            READ DATASET _v_path INTO l_line.
            IF sy-subrc = 0.
              APPEND l_line TO rt_contents.
            ELSE.
              EXIT.
            ENDIF.
          ENDDO.
          CLOSE DATASET _v_path.
        ENDIF.
      ENDMETHOD.                    "get_contents
    ENDCLASS.                    "lcl_server_file IMPLEMENTATION
    *       CLASS lcl_pc_file DEFINITION
    CLASS lcl_pc_file  DEFINITION
                       INHERITING FROM lcl_file.
      PUBLIC SECTION.
        METHODS:
          get_contents REDEFINITION.
      PROTECTED SECTION.
        METHODS:
          choose       REDEFINITION.
    ENDCLASS.                    "lcl_pc_file  DEFINITIO
    *       CLASS lcl_pc_file IMPLEMENTATION
    CLASS lcl_pc_file IMPLEMENTATION.
      METHOD choose.
        DATA:
          l_i_path     TYPE dxfields-longpath VALUE 'C:\',
          l_o_path     TYPE dxfields-longpath.
        CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
          EXPORTING
            i_location_flag = 'P'  " PC
            i_path          = l_i_path
            fileoperation   = 'R'  " Lectura
          IMPORTING
            o_path          = l_o_path
          EXCEPTIONS
            rfc_error       = 1
            OTHERS          = 2.
        IF sy-subrc = 0 AND l_o_path <> l_i_path.
          MOVE l_o_path TO _v_path.
        ELSE.
          RAISE no_path_chosen.
        ENDIF.
      ENDMETHOD.                    "choose
      METHOD get_contents.
        CHECK NOT _v_path IS INITIAL.
        CALL METHOD cl_gui_frontend_services=>gui_upload
          EXPORTING
            filename                = _v_path
          CHANGING
            data_tab                = rt_contents
          EXCEPTIONS
            file_open_error         = 1
            file_read_error         = 2
            no_batch                = 3
            gui_refuse_filetransfer = 4
            invalid_type            = 5
            no_authority            = 6
            unknown_error           = 7
            bad_data_format         = 8
            header_not_allowed      = 9
            separator_not_allowed   = 10
            header_too_long         = 11
            unknown_dp_error        = 12
            access_denied           = 13
            dp_out_of_memory        = 14
            disk_full               = 15
            dp_timeout              = 16
            OTHERS                  = 17.
        IF sy-subrc <> 0.
          RAISE read_error.
        ENDIF.
      ENDMETHOD.                    "get_contents
    ENDCLASS.                    "lcl_pc_file IMPLEMENTATION
    * Data
    DATA: gr_file          TYPE REF TO lcl_file.
    * Main Program
    START-OF-SELECTION.
    *   Get text lines from file
        IF p_srv = abap_true.
          CREATE OBJECT gr_file
            TYPE
              lcl_server_file
            EXCEPTIONS
              no_path_chosen  = 1.
        ELSE.
          CREATE OBJECT gr_file
            TYPE
              lcl_pc_file
            EXCEPTIONS
              no_path_chosen = 1.
        ENDIF.
    On a 4.6c system this code gave me a dump, while on my NW7.0 SP it doesn't even activate with the following error:
    You cannot call abstract methods in the "CONSTRUCTOR" method.
    - Following some suggestions from Java forums i've tried to define the constructor in the base class as PROTECTED or PRIVATE instead, then calling super->constructor from the subclasses, but I get this error in german:
    Sichtbarkeit des Konstruktors darf nicht spezieller als die Sichtbarkeit der Instanzerzeugung (CREATE-Zuzatz) sein.
    which Altavista translates like:
    Visibility of the constructor may not be more special than the
    visibility of the instance production (CREATE Zuzatz).
    - I've also thought of defining the CHOOSE method as a class (not instance) one, then calling it before creating the file object which maybe solves the problem, but I see that approach more "procedural oriented" which i'm trying to avoid.
    - Of course I could define a constructor for each subclass, but both would have exactly the same code.
    I'm really lost on how should I code this. My main focus is on avoiding code dupplication.
    I hope someone with more OO experience can see what I'm trying to do and sheds some light.
    Many thanks for reading all this!

    Dear Alejandro,
        When i saw your code, you are trying to access an astract method CHOOSE(which is actually implemented in sub class) from the constructor of the base class which is not possible.  By this time, we don't know which sub class it is refering to, so it gives an error.   I see two solutions for this..
    1.  To define constructor in sub class and call the choose method from the consturctor of the sub class(which in this case is reputation of the same again for each sub class)
    2.  Remove the calling of choose method from the constructor of the main class and call it separately(after creating the object).   By now we know which sub class we are refering to.   I would have designed the program in the following way.
    *       CLASS lcl_file DEFINITION
    CLASS lcl_file DEFINITION ABSTRACT.
      PUBLIC SECTION.
        METHODS:
          constructor
            IMPORTING
              i_path  TYPE string OPTIONAL
            EXCEPTIONS
              no_path_chosen,
          get_contents ABSTRACT
            RETURNING
              value(rt_contents) TYPE string_table
            EXCEPTIONS
              read_errorm,
          set_path ABSTRACT
            EXCEPTIONS
              no_path_chosen.
      PROTECTED SECTION.
        DATA:
          _v_path        TYPE string.
    *    METHODS:
    *      choose ABSTRACT
    *        EXCEPTIONS
    *          no_path_chosen,
    *      set_path ABSTRACT
    *        IMPORTING
    *          i_path  TYPE string.
    ENDCLASS.                    "lcl_file DEFINITION
    *       CLASS lcl_file IMPLEMENTATION
    CLASS lcl_file IMPLEMENTATION.
      METHOD constructor.
        IF i_path IS SUPPLIED.
          _v_path = i_path.
    *      CALL METHOD set_path
    *        EXPORTING
    *          i_path = i_path.
    *    ELSE.
    **---->>>> PROBLEM CALL - CAN'T BE DONE!!
    *      CALL METHOD choose
    *        EXCEPTIONS
    *          no_path_chosen = 1.
    *      IF sy-subrc = 1.
    *        RAISE no_path_chosen.
    *      ENDIF.
        ENDIF.
      ENDMETHOD.                    "constructor
    * METHOD set_path.
    *    _v_path = i_path.
    * ENDMETHOD.                    "set_path
    ENDCLASS.                    "lcl_file IMPLEMENTATION
    *       CLASS lcl_server_file DEFINITION
    CLASS lcl_server_file DEFINITION
                          INHERITING FROM lcl_file.
      PUBLIC SECTION.
        METHODS:
          get_contents REDEFINITION,
          set_path     REDEFINITION.
    *  PROTECTED SECTION.
    *    METHODS:
    *      choose       REDEFINITION.
    ENDCLASS.                    "lcl_server_file  DEFINITIO
    *       CLASS lcl_server_file IMPLEMENTATION
    CLASS lcl_server_file IMPLEMENTATION.
      METHOD set_path.
        DATA:
          l_i_path     TYPE dxfields-longpath,
          l_o_path     TYPE dxfields-longpath.
        CHECK _v_path IS INITIAL.
        CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
          EXPORTING
            i_location_flag = 'A'  " Application server
            i_path          = l_i_path
            fileoperation   = 'R'  " Lectura
          IMPORTING
            o_path          = l_o_path
          EXCEPTIONS
            rfc_error       = 1
            OTHERS          = 2.
        IF sy-subrc = 0 AND l_o_path  = l_i_path.
          MOVE l_o_path TO _v_path.
        ELSE.
          RAISE no_path_chosen.
        ENDIF.
      ENDMETHOD.                    "set_path
      METHOD get_contents.
        DATA: l_line   LIKE LINE OF rt_contents,
              l_osmsg  TYPE string.
        CHECK NOT _v_path IS INITIAL.
    *    OPEN DATASET _v_path FOR INPUT
    *                             IN TEXT MODE
    *                             MESSAGE l_osmsg.
        IF sy-subrc  = 0.
    *      MESSAGE e000(oo) WITH l_osmsg
    *                       RAISING read_error.
        ELSE.
          DO.
            READ DATASET _v_path INTO l_line.
            IF sy-subrc = 0.
              APPEND l_line TO rt_contents.
            ELSE.
              EXIT.
            ENDIF.
          ENDDO.
          CLOSE DATASET _v_path.
        ENDIF.
      ENDMETHOD.                    "get_contents
    ENDCLASS.                    "lcl_server_file IMPLEMENTATION
    *       CLASS lcl_pc_file DEFINITION
    CLASS lcl_pc_file  DEFINITION
                       INHERITING FROM lcl_file.
      PUBLIC SECTION.
        METHODS:
          get_contents REDEFINITION,
          set_path     REDEFINITION.
    *  PROTECTED SECTION.
    *    METHODS:
    *      choose       REDEFINITION.
    ENDCLASS.                    "lcl_pc_file  DEFINITIO
    *       CLASS lcl_pc_file IMPLEMENTATION
    CLASS lcl_pc_file IMPLEMENTATION.
      METHOD set_path.
        DATA:
          l_i_path     TYPE dxfields-longpath VALUE 'C:\',
          l_o_path     TYPE dxfields-longpath.
        CHECK _v_path IS INITIAL.
        CALL FUNCTION 'F4_DXFILENAME_TOPRECURSION'
          EXPORTING
            i_location_flag = 'P'  " PC
            i_path          = l_i_path
            fileoperation   = 'R'  " Lectura
          IMPORTING
            o_path          = l_o_path
          EXCEPTIONS
            rfc_error       = 1
            OTHERS          = 2.
        IF sy-subrc = 0 AND l_o_path  = l_i_path.
          MOVE l_o_path TO _v_path.
        ELSE.
          RAISE no_path_chosen.
        ENDIF.
      ENDMETHOD.                    "set_path
      METHOD get_contents.
        CHECK NOT _v_path IS INITIAL.
        CALL METHOD cl_gui_frontend_services=>gui_upload
          EXPORTING
            filename                = _v_path
          CHANGING
            data_tab                = rt_contents
          EXCEPTIONS
            file_open_error         = 1
            file_read_error         = 2
            no_batch                = 3
            gui_refuse_filetransfer = 4
            invalid_type            = 5
            no_authority            = 6
            unknown_error           = 7
            bad_data_format         = 8
            header_not_allowed      = 9
            separator_not_allowed   = 10
            header_too_long         = 11
            unknown_dp_error        = 12
            access_denied           = 13
            dp_out_of_memory        = 14
            disk_full               = 15
            dp_timeout              = 16
            OTHERS                  = 17.
        IF sy-subrc  = 0.
    *      RAISE read_error.
        ENDIF.
      ENDMETHOD.                    "get_contents
    ENDCLASS.                    "lcl_pc_file IMPLEMENTATION
    * Data
    DATA: gr_file          TYPE REF TO lcl_file.
    * Main Program
    START-OF-SELECTION.
    *   Get text lines from file
      IF abap_true = abap_true.
        CREATE OBJECT gr_file
          TYPE
            lcl_server_file
          EXCEPTIONS
            no_path_chosen  = 1.
      ELSE.
        CREATE OBJECT gr_file
          TYPE
            lcl_pc_file
          EXCEPTIONS
            no_path_chosen = 1.
      ENDIF.
      gr_file->set_path( ).
    Regards
    Kesava
    Edited by: Kesava Chandra Rao on Mar 19, 2008 11:44 AM

  • BDC ( Call Session Method)

    how to make bdc using call session method.

    Hi,
    Use this code,you can easily understand which u want to know
    DATA: BEGIN OF itab OCCURS 0,
          str(255),
          END OF itab.
    DATA: BEGIN OF itab1 OCCURS 0,
          lifnr LIKE lfa1-lifnr,
          name1 LIKE lfa1-name1,
          ort01 LIKE lfa1-ort01,
          END OF itab1.
    DATA: jtab LIKE bdcdata OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'WS_UPLOAD'
      EXPORTING
        filename                = 'D:\ABAP EVE\ffile5.txt'
        filetype                = 'ASC'
      TABLES
        data_tab                = itab
      EXCEPTIONS
        conversion_error        = 1
        file_open_error         = 2
        file_read_error         = 3
        invalid_type            = 4
        no_batch                = 5
        unknown_error           = 6
        invalid_table_width     = 7
        gui_refuse_filetransfer = 8
        customer_error          = 9
        no_authority            = 10
        OTHERS                  = 11.
    IF sy-subrc <> 0.
      WRITE:/ 'no file exist'.
    ENDIF.
    LOOP AT itab.
      SPLIT itab-str AT ',' INTO itab1-lifnr itab1-name1 itab1-ort01.
      APPEND itab1.
    ENDLOOP.
    CALL FUNCTION 'BDC_OPEN_GROUP'
    EXPORTING
       client                    = sy-mandt
      DEST                      = FILLER8
       group                     = 'ZCSSESSIONM1'
      HOLDDATE                  = FILLER8
       keep                      = 'X'
       user                      = sy-uname
      RECORD                    = FILLER1
      PROG                      = SY-CPROG
    IMPORTING
      QID                       =
    EXCEPTIONS
       client_invalid            = 1
       destination_invalid       = 2
       group_invalid             = 3
       group_is_locked           = 4
       holddate_invalid          = 5
       internal_error            = 6
       queue_error               = 7
       running                   = 8
       system_lock_error         = 9
       user_invalid              = 10
       OTHERS                    = 11.
    LOOP AT itab1.
      PERFORM prginfo USING 'SAPMZBDCCT' '123'.
      PERFORM fldinfo USING 'i01' itab1-lifnr.
      PERFORM fldinfo USING 'i02' itab1-name1.
      PERFORM fldinfo USING 'i03' itab1-ort01.
    CALL TRANSACTION 'ZCSBDCCT' USING jtab.
      CALL FUNCTION 'BDC_INSERT'
       EXPORTING
         tcode                  = 'ZCSBDCCT'
        POST_LOCAL             = NOVBLOCAL
        PRINTING               = NOPRINT
        SIMUBATCH              = ' '
        CTUPARAMS              = ' '
        TABLES
          dynprotab              = jtab
       EXCEPTIONS
         internal_error         = 1
         not_open               = 2
         queue_error            = 3
         tcode_invalid          = 4
         printing_invalid       = 5
         posting_invalid        = 6
         OTHERS                 = 7.
    ENDLOOP.
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
    *&      Form  prginfo
          text
         -->PRGNAME    text
         -->SCRNUMBER  text
    FORM prginfo USING prgname scrnumber.
      CLEAR jtab.
      REFRESH jtab.
      jtab-program = prgname.
      jtab-dynpro = scrnumber.
      jtab-dynbegin = 'X'.
      APPEND jtab.
    ENDFORM.                    "prginfo
    *&      Form  fldinfo
          text
         -->FLDNM      text
         -->FLDVAL     text
    FORM fldinfo USING fldnm fldval.
      CLEAR jtab.
      jtab-fnam = fldnm.
      jtab-fval = fldval.
      APPEND jtab.
    ENDFORM.                    "fldinfo
    MPP CODE.
    TOP-INCLUDE.
    DATA: OK_CODE TYPE SY-UCOMM.
    DATA: I01(10),I02(20),I03(26).
    DATA: WA TYPE LFA1.
    PAI
    CASE OK_CODE.
       WHEN 'INSERT'.
         MOVE I01 TO WA-LIFNR.
         MOVE I02 TO WA-NAME1.
         MOVE I03 TO WA-ORT01.
         INSERT INTO LFA1 VALUES WA.
         IF SY-SUBRC = 0.
           MESSAGE I001(ZCSMSG).
         ELSE.
           MESSAGE I002(ZCSMSG).
         ENDIF.
       WHEN 'EXIT'.
         LEAVE PROGRAM.
    ENDCASE.
    Create the 3 io's in layout and 2 pushbuttons(exit,insert).
    Open SM35 TCode -> select the session -> Click on "Process" from application toolbar
    -> select mode of execution(foreground/background) -> click on "process".
    Flatfile data:
    300001,Yogesh,Secundrabad
    320003,Wreline,Mexico
    320004,Alexme,New York
    And store this in "D:\ABAP EVE\ffile5.txt" path
    Reward,if it is useful.
    Thanks,
    Chandu.

  • Add a column and I can't call a method

    I'm trying to make a small portal app with IBM RAD 6.0 but I'm having a wierd problem calling a method in my page code. Any help would be great.
    Here's the cod I'm using, I've got a bunch of system.outs in it to help me track down what's happening as well as some commented code of some things I'm trying. Any why here goes:
    I start a data table in the jsp like this
    <h:dataTable value="#{pc_MaintainBasisFormView.memberBasisComponents}" var="results"
                             border="0" cellpadding="2" cellspacing="0"
                             columnClasses="columnClass1" headerClass="headerClass"
                             footerClass="footerClass" rowClasses="rowClass1"
                             styleClass="dataTable" id="table1">
    later I build these two columns
    <h:column id="startdatecolumn">
                                  <f:facet name="header">
                                       <h:outputText styleClass="outputText" value="Start Date" id="startdateheader" />
                                  </f:facet>
                                  <h:inputText styleClass="inputText" id="startdate" value="#{results.effectiveDates.effectiveStartDate}"></h:inputText>
                             </h:column>
                             <h:column id="column7">
                                  <f:facet name="header">
                                       <h:outputText styleClass="outputText" value="Remove" id="remove"></h:outputText>
                                  </f:facet>
                                  <h:commandLink styleClass="commandLink" id="removelink" action="#{pc_MaintainBasisFormView.removeBasisComponent}">
                                  <h:outputText id="text6" styleClass="outputText" value=">>"></h:outputText>
                                       <f:param name="krusty" value="#{results.id}"></f:param>
                                  </h:commandLink>
                             </h:column>
    so column startdate calls does this "results.effectiveDates.effectiveStartDate"
    so results has this method
    public EffectiveDates getEffectiveDates() {
              System.out.println("in getEffectiveDates " + effectiveDates);
              //effectiveDates = (effectiveDates == null) ? new EffectiveDates():effectiveDates;
              return effectiveDates;
    and EffectiveDates has this method
    public String getEffectiveStartDate() {
              System.out.println("in getEffectiveStartDate " + effectiveStartDate);
              effectiveStartDate = (effectiveStartDate == null) ? new Date() :effectiveStartDate;
              return "dfgdfG";
    (it's supposed to return a date but I've set it to a string just to try to get it working)
    and that all works fine.
    Now the second column calls "pc_MaintainBasisFormView.removeBasisComponent" with a parameter <f:param name="krusty" value="#{results.id}">
    and removeBasisComponent is defined as
         public String removeBasisComponent() {
              System.out.println("in removeBasisComponent");
              String id = getPortletRequest().getParameter("krusty");
              System.out.println("in krusty " + id);
              return "removeBasisComponent";
    so whats the probelm? When I click the link in the second column, the method that it is tied to is never called. BUT, when I don't have the first column, the link works as I expect it to.
    can anyone point me in the right direction to solve this problem?
    Thanks in advance
    JohnL

    Hi Ruhi
    I hope this answer doesn't come too late, for some reason the forum does not let me in w/ my username & password, and won't allow me to follow the "Forgot password" procedures.
    Anyway:
    I don't have the code but I'll try to explain the problem using the info I posted originally.
    my problems start here:
    <h:inputText styleClass="inputText" id="startdate" value="#{results.effectiveDates.effectiveStartDate}"></h:inputText>
    It generates an input box with the value results.effectiveDates.effectiveStartDate. What I didn't know was that when I tried to submit the form from the link the application was silently failing. By silently I mean there was no error in the log, nothing, not a clue as to what the problem was.
    The problem turned out to be pretty simple. When the form is generated with results.effectiveDates.effectiveStartDate
    it was essentially running results.getEffectiveDates().getEffectiveStartDate() which, from my example, returned a string. That's great, no problem.
    When the form is submitted it was trying to call results.getEffectiveDates().setEffectiveStartDate(), where the method setEffectiveStartDate must take a String argument, setEffectiveStartDate(String EffectiveDate). Remember that in my example I was returning a string to the from...so I needed to accept a string as an argument to the set method.
    I hope this helps.

  • Calling Web Service From Oracle PL/SQL do not invoke the webservice in SOA Server

    Hi ,
    Trying to call the webservice from oralce pl/sql Function
    created a Function
    Not able to invoke the web service of SOA Server .
    CREATE OR REPLACE FUNCTION HelloWorld_WebServices(S_STRING Varchar2) RETURN VARCHAR2 AS 
        service_ sys.utl_dbws.SERVICE; 
        call_ sys.utl_dbws.CALL; 
        service_qname sys.utl_dbws.QNAME; 
        port_qname sys.utl_dbws.QNAME; 
        response sys.XMLTYPE; 
        request sys.XMLTYPE; 
        BEGIN 
         sys.utl_dbws.set_http_proxy('Host name : Port'); 
          service_qname := sys.utl_dbws.to_qname('ns1', 'process'); 
           service_      := sys.utl_dbws.create_service(service_qname); 
           call_         := sys.utl_dbws.create_call(service_); 
            sys.utl_dbws.set_target_endpoint_address(call_, 'http:/host name : port/soa-infra/services/OFS/HelloWorld/helloworld_client_ep'); 
            sys.utl_dbws.set_property( call_, 'OPERATION_STYLE', 'process'); 
            request       := sys.XMLTYPE('<ns1:process xmlns:ns1="http://xmlns.oracle.com/OFSOrderServices/HelloWorld/HelloWorld"><ns1:input></ns1:input></ns1:process>'); 
         response      := sys.utl_dbws.invoke(call_, request); 
         return response.extract('//HelloWorld/child::text()', 'http://xmlns.oracle.com/OFSOrderServices/HelloWorld/HelloWorld').getstringval(); 
         DBMS_OUTPUT.PUT_LINE ('Values of OutputsVariables8');
    --  Return 'S';
       END;
    Execute----the below code:
      Select HelloWorld_WebServices('Hi') from dual;
    Error:
    ORA-29532: Java call terminated by uncaught Java exception: java.lang.NoClassDefFoundError
    ORA-06512: at "SYS.UTL_DBWS", line 403
    ORA-06512: at "SYS.UTL_DBWS", line 400
    ORA-06512: at "APPS.HELLOWORLD_WEBSERVICES", line 74
    29532. 00000 -  "Java call terminated by uncaught Java exception: %s"
    *Cause:    A Java exception or error was signaled and could not be
               resolved by the Java code.
    *Action:   Modify Java code, if this behavior is not intended.

    Well, you should first test if your webservice is reachable with a simple WS - Client or a Browser - Plugin, then verify the respones of the web service and after that you can take further investigations on your problem domain. The error - message refers to a line in your function, obviously, but I can't see which line and because there is more than one call to sys.utl_dbws I don't see at what point the script fails. NULL - Pointer - Execptions usually indicate that a method was invoked on a variable which should contain an object reference but is NULL.

  • How to distinguish the User-Defined-Function from Oracle Build-In function

    Hi Friends,
    I could get the function list form all_objects table by the SQL:
    select * from all_objects where object_type = 'FUNCTION'
    but there is no column in all_objects specify the function is build-in or user-defined.
    But I found in SQL Server there is a column "is_ms_shipped" in the sys.all_objects table. This column will specify the object is build-in or user-defined. I want to get the equivalent column in Oracle but failed.
    Could anyone tell me how to solve this problem?
    Thanks,
    Ricky

    Thanks Pavan.
    But if an user connects to database using "conn /as sysdba" syntax and creates a function. This user-defined funtion goes into the "SYS" schema also. I know it is not the best practise to create objects using sys user so I think your solution is right.
    Regards,
    Ricky

  • Calling javaFX script from Java program

    I am trying to call JavaFX script from a simple Java program. code as follows:
    import java.io.*;
    import javax.script.ScriptEngine;
    import javax.script.ScriptEngineManager;
    public class My{
    public static void main(String[] args) {
    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByExtension("fx");
    try {  
    InputStreamReader reader = new InputStreamReader(My.class.getResourceAsStream("first.fx"));
    engine.eval(reader);
    reader.close();
    } catch (Exception e) {
    e.printStackTrace();
    my first.fx file code is here:
    import javafx.stage.Stage;
    import javafx.scene.Scene;
    import javafx.scene.text.Text;
    import javafx.scene.text.Font;
    import javafx.scene.text.TextAlignment;
    Stage {
    title: "My First JavaFX Sphere"
    scene: Scene {
    width: 250
    height: 250
    content: [
    Text {
    font: Font { size: 24 }
    x: 20, y: 90
    textAlignment: TextAlignment.CENTER
    content:"Welcome to \nJavaFX World"
    } //Text
    ] // content
    } // Scene
    } // Stage
    I am not able to run My.java. runtime error as follows:
    java.lang.NullpointerException
    Kindly correct me, where I am wrong

    I am able to call .fx file from Java. Thank you all for helping me to resolve this problem
    Regards,
    Ritu

  • Calling java method from c function

    Hi,
    I have been through some forums and tutorials, but nothing helps me yet.
    Here's my problem : I want to access java funtion from c function.
    <code java>
    public class MyClass {
    public int oneMethod() {
    return 5;
    </code java>
    <code c++>
    void main(int argc, char *argv[]) {
    // creation of JVM -> no problem
    cls = (env)->FindClass("MyClass");
    if (cls != 0) {
    // it finds the class
    mid = (env)->GetMethodID(cls, "oneMethod", "()I");
    if (mid != 0) {
    // it finds the method
    intReturn = (env)->CallIntMethod(cls, mid);
    printf("Result of oneMethod: %d \n", initReturn);
    </code c++>
    the initReturn gives me 0, and not 5. So what do you think the mistake is ?
    Should I pass by the GetClassObject() funtion, but in this case, what object would I pass in reference since I'm using a call from c to java.
    Thanks a lot for your response, and Happy new Year to all the comunity.

    1. You are - apparently - trying to call a method of a java object.
    2. But you are instead making the call on a class.
    3. You can do one of the following:
    o Pass a reference to the object as you call C.
    o Call some other java method (maybe static) that gets you a reference to a java object.
    o Use JNI to call a java constructor to create a java object.
    o Change your code to get the class object and call a static method.

  • Call Java Method from Callback function

    I am writing a JNI wrapper in c++ for a particular event driven DLL. The DLL makes a network connection to another device and then calls a callback function when events are raised on the device. The DLL has 3 basic functions: connect, disconnect, and registerEventListener. RegisterEventListener takes a function pointer which is called each time an event is raised on the device.
    My wrapper DLL exposes connect and disconnect functions via JNI. I can call these functions just fine from my Java code. Now the question... How do I call a Java method from my c++ callback function? I can call a Java method using env->CallXXXMethod(...) from within a function that is accessible to Java but I don't have access to the JNI parameters in my Callback function.
    So how do I call a Java method from a callback function? If this cannot be done then what is the "right way" to handle native event notification with JNI?

    jschell wrote:
    JNI parameters? Meaning what exactly?
    General outline of a callback
    1. Entry
    2. Get the VM, env - there are methods for this
    3. Attach the thread
    4. Get a java object - how depends on what you are doing, but create it or a static reference.
    5. Get the java method
    6. Call the java method.That is exactly correct. The callback function is called from a separate thread so using a cached pointer to JNIEnv, obtained from the original native method, crashes the JVM. The jmethodID and jclass objects (which are needed to call the static Java method) can be cached without problem. The following is the code I used to attach the current thread and call my static method.
    void MyClass::onEvent(int system_id, char* data)
         //get a pointer to the Java Environment
         JNIEnv *env;
         jvm->AttachCurrentThread((void **)&env, NULL);
         //Call the Java method with the newly aquired data
         jstring js = env->NewStringUTF(data);
         env->CallStaticVoidMethod(cls, mid, system_id, js);
    }My last question is about cleanup in this function. When I use NewStringUTF to "convert" my char* to jstring do I need to do anything special to clean up or will the Java garbage collector take care of it since the jstring is being passed to a Java method?
    Thanks for you help

Maybe you are looking for