Accessing a parameter in subclasses

Currently I have something like this:
public abstract class AbstractData<E extends Entity> {
    protected Class<E> clazz;
    public void process()
     System.out.println("I am processing " + clazz);
public class Data extends AbstractData<Product> {
    protected Class clazz = Product.class;
}I works but there must be a more concise and less error prone way to do the same thing.
More specifically, I would rather initialize the clazz field in the AbstractData super class.
Is it possible?
Thanks.
Oscar

First of all, your code is not doing what you think it does. The 'clazz' in the subclass 'hides' the existing 'clazz' field the AbstractData class. Run this, for example:
import java.util.*;
class Entity { }
class Product extends Entity { }
abstract class AbstractData<E extends Entity> {
     protected Class<E> clazz;
     public void process1() {
          System.out.println("I am processing " + clazz);
class Data extends AbstractData<Product> {
     protected Class clazz = Product.class;
     public void process2() {
          System.out.println("I am processing " + clazz);
public class Test {
     public static void main(String[] args) {
          Data d = new Data();
          Class<Product> clazzInAbstractData = ((AbstractData<Product>)d).clazz;
          System.out.println(clazzInAbstractData);
          d.process1();
          Class clazzInData = d.clazz;
          System.out.println(clazzInData);
          d.process2();
/* outputs:
class Product
I am processing class Product
null
I am processing null
*/Perhaps instead ofclass Data extends AbstractData<Product> {
     protected Class clazz = Product.class;
}, you want class Data extends AbstractData<Product> {
     { clazz = Product.class; }
}, or if you want to extra clear and explicit about what's happening, class Data extends AbstractData<Product> {
     { super.clazz = Product.class; }
}

Similar Messages

  • How to start microsof access with parameter through runtime.exec

    Hi,
    I try to start access with parameter like this:
    String[] cmd = new String[4];
    cmd[0] = "C:\\Programme\\Microsoft Office\\OFFICE11\\MSACCESS.EXE";
    cmd[1]= "C:\\MyDB.mdb ";
    cmd[2] = "/cmd";
    cmd[3] = "parameter1 parameter2";
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd);
    However the access mdb startet but it seems not to take the parameter i want to put in to access.
    Have anyone an Idea, what is wrong here?
    Thanks

    Hi
    What do you expect Access to do?
    The /cmd command line option sets the value that is returned by VBA Command function (see http://msdn2.microsoft.com/en-us/library/aa211469(office.11).aspx).
    If you want to start a macro, you would need the /x switch (see http://office.microsoft.com/en-us/access/HA101666051033.aspx).
    Hope this helps
    Christoph

  • Access Context Parameter in Java Bean.

    Hi,
    I want to access the Context parameter set by the web.xml from a java bean or simple java class. For example, If I have database connection details in my web.xml and I want to get these in a Java Bean of a class which will pick up the values and create a Connection object and return to the guy calling it, either JSP or servlet.
    I have a idea of using InitialContext class. But I doubt it works for
    Context parameter defined in the web.xml.
    It worked if I use like this for DataSource object which is created in my application server.
    Context ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("OMSDataSource");
    return ds.DatabaseConnection.getConnection();
    So how can I access a parameter like this..
    <context-param>
    <param-name>Webmaster</param-name>
    <param-value>[email protected]</param-value>
    </context-param>
    Cheers.
    L G Goundalkar

    Greetings,
    Hi,
    I want to access the Context parameter set by the web.xml from a java bean or simple java class.The bean doesn't have direct access to the context object so that access must to supplied to it - i.e by calling getServletContext() and passing the resulting reference to the bean.
    For example, If I have database connection details in my web.xml and I want to get these in a Java
    Bean of a class which will pick up the values and create a Connection object and return to the guy
    calling it, either JSP or servlet.Why not write a DAO to handle the JSP or servlet's access needs? The DAO can be initialized at application start with a context listener and the initialized instance placed in the context where the JSP or servlet can get it directly. ;)
    I have a idea of using InitialContext class. But I doubt it works for Context parameter defined in the
    web.xml.Not for context parameters (a different "space" from the JNDI namespace ;). But, of course, it does work for "environment entries" which may also be placed in the web.xml DD (er, presuming your web container supports JNDI, of course).
    Cheers.
    L G GoundalkarRegards,
    Tony "Vee Schade" Cook

  • PL/SQL Entity Object - Accessing Out parameter values in insertRow method

    Hi,
    I have the following pl/sql code which takes 4 input parameter and 1 out parameter.
    create or replace procedure xxfwk_emp_create(p_person_id IN NUMBER, p_first_name IN VARCHAR2, p_last_name IN VARCHAR2, p_sal IN NUMBER) is
    cursor c1 is select EMPLOYEE_ID from fwk_tbx_employees;
    v_status varchar2(1) := 's';
    BEGIN
    for v_c1 in c1 loop
    if v_c1.employee_id = p_person_id then
    p_error_msg:= 'Person with this id already exist';
    v_status := 'e';
    end if;
    exit when c1%notfound OR v_status='e' ;
    end loop;
    if v_status = 'e' then
    goto error;
    end if;
    INSERT INTO FWK_TBX_EMPLOYEES(EMPLOYEE_ID,
    FIRST_NAME,
    LAST_NAME,
    FULL_NAME,
    SALARY,
    CREATION_DATE,
    CREATED_BY,
    LAST_UPDATE_DATE,
    LAST_UPDATED_BY,
    LAST_UPDATE_LOGIN)
    VALUES(p_person_id,
    p_first_name,
    p_last_name,
    P_first_name||' '||p_last_name,
    p_sal,
    sysdate,
    fnd_global.user_id,
    sysdate,
    fnd_global.user_id,
    fnd_global.login_id);
    <<error>>
    null;
    END xxfwk_emp_create;
    I have following code in EO Impl class
    public void insertRow()
    try
    OADBTransactionImpl oadbTrans = (OADBTransactionImpl)getDBTransaction();
    String s = "begin xxfwk_emp_create(p_person_id=>:1, p_first_name=>:2, p_last_name=>:3, p_sal=>:4, p_error_msg=>:5);end;";
    OracleCallableStatement oraCall = (OracleCallableStatement)oadbTrans.createCallableStatement(s,-1);
    oraCall.setNUMBER(1,getEmployeeId());
    oraCall.setString(2,getFirstName());
    oraCall.setString(3,getLastName());
    oraCall.setNUMBER(4,getSalary());
    *< How to access Out Parameter from The procedure >*
    oraCall.execute();
    catch(SQLException sqlException)
    throw OAException.wrapperException(sqlException);
    catch(Exception exception)
    throw OAException.wrapperException(exception);
    In this insertRow i want to get the error message (out param) and throw this message as exception in OA page.
    What changes i need to do in my page?
    Regards,
    Ram

    Thanks sumit..
    I changed the code as below still i am not getting the error message on the page.
    In jdeveloper i am successfully printing the error message.
    here is the code..
    try
    OADBTransactionImpl oadbTrans = (OADBTransactionImpl)getDBTransaction();
    String s = "begin xxfwk_emp_create(p_person_id=>:1, p_first_name=>:2, p_last_name=>:3, p_sal=>:4, p_error_msg=>:5);end;";
    OracleCallableStatement oraCall = (OracleCallableStatement)oadbTrans.createCallableStatement(s,-1);
    oraCall.setNUMBER(1,getEmployeeId());
    oraCall.setString(2,getFirstName());
    oraCall.setString(3,getLastName());
    oraCall.setNUMBER(4,getSalary());
    String p_error_msg = null;
    System.out.println("Error message before call "+p_error_msg);
    Types OracleTypes;
    oraCall.registerOutParameter(5,OracleTypes.VARCHAR);
    if (p_error_msg!=null)
    throw new OAException(p_error_msg,OAException.ERROR);
    oraCall.execute();
    p_error_msg = oraCall.getString(5);
    System.out.println("Error message after call "+p_error_msg);
    catch(SQLException sqlException)
    throw OAException.wrapperException(sqlException);
    catch(Exception exception)
    throw OAException.wrapperException(exception);
    Regards,
    Ram

  • Unable to access form parameter in servlet

    What could be the possible reasons, If a server side program say a servlet, cannot access the request parameters.
    I mean, i have a form and it uses get method. Now on submitting the form, I can see the query string in url but unable to access the same in servlet.
    thank you all
    Ravi

    The most obvious reason might be that the servlet's
    programmer wrote crappy code.
    Show the code where you try to read the parameters,
    please.Code is simple. To retrieve the form parameter I used the same
    request.getParameter("paramname")
    And in the form method used is get. After submission of form, I can see the form parameter appended to url
    something like this:
    http://localhost/servlets/Test?paramname=somevalue
    But for somereason in servlet i.e at request.getParameter("paramname"), is hanging here.
    I checked the paramname, no spelling mistakes as well :)
    But i am not able to find out the reason why I am not able to get the paramname in servlet.
    thanks
    Ravi

  • Stored Procedure in access with parameter name

    Hi, i'm new in JDBC.
    I came from Ado.Net.
    I want to call a stored procedure in access and set my parameters by name and not by index.
    When i try to call the SP with params by index it works as expected,
    but with param names it give me this exception:
    java.lang.UnsupportedOperationException
    Is there a way to call SP with parameter names?
    BogN,

    Well, it still doesn't work. Here is part of the code, have a look please.
    public DisplayQueryResults() {
       String studattUrl = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=D:/StudAtt/StudAtt.mdb";
       String mustbUrl = "jdbc:odbc:mustb";          
       try {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          studattConn = DriverManager.getConnection(studattUrl);
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          mustbConn = DriverManager.getConnection(mustbUrl, "sa", "");               
    private void getTable() {
       try {
          stmtStudAtt = studattConn.createStatement(resultSet.TYPE_SCROLL_SENSITIVE, resultSet.CONCUR_READ_ONLY);
          stmtMustb = mustbConn.createStatement();
          CallableStatement callSP = studattConn.prepareCall("{call mustbFaculty}");
          resultSet = callSP.executeQuery();
          displayResultSet(resultSet);
       }

  • Accessing static members of subclasses

    So here is my problem. I have two beans (one extends the other), and I have one DAO class for each to access their tables (using Hibernate). In most cases the queries will be identical so I also have an abstract DAO class (extended by the other two DAOs) which contains the majority of the queries. I had the methods returning beans of the super class which, if need be, I would cast to the subclass. To avoid this casting I want to switch to generics. I changed over the abstract class with no compiliation erros, but I've hit a bump. In the two beans I have a static String field "entityName" which I access to for the Hibernate calls (Bean.entityName). When I converted to generics the reference changed to T.entityName which now always references the super class. What I need is to access whichever class' entityName I happen to be using.
    Example:
    class AbstractBeanDAO <T extends SuperBean> {
         public T get(Integer id){
              // this where I have the problem
              Criteria criteria = session.createCriteria(T.entityName);
              // set some criteria
              return criteria.uniqueResult();
    }No matter what I set as AbstractBeanDAO <type> it always references SuperBean.entityName. There are times I need SubBean.entityName so I can access the correct table. How can I do this without having to duplicate code in the two DAO subclasses?

    ejp wrote:
    And to the OP, this is evidence of a severe design problem. Like any system there are some design flaws, and in my defense I walked into an existing project so it wasn't my design. All I can do is try to improve it bit by bit.
    ejp wrote:
    If you really have such a requirement you would need to provide an instance method that all the subclasses of SuperBean override, and an instance of T to call it on.Part of the issue I have is that I CAN'T use and instance methods since I have a static reference T. I did figure out a way around this though. I added an abstract method to the abstract class, and just implemented it in the concrete classes which will only be using their respective bean types. So now when where I need to do a T.entityName I just call the this.getEntityName():
    public String getEntityName() {
         return MyBean.entityName;
    }So now my code looks like this:
    public T get(Integer id) {
    Criteria criteria = session.createCriteria(this.getEntityName());
      // set some criteria
      return criteria.uniqueResult();
    }

  • Access VIEW parameter(IF_WD_VIEW) outside of WDDOMODIFYVIEW

    Hi all,
    Within the WDDOMODIFYVIEW event there is a parameter called VIEW which provides certain functionality such as setting focus on certain field etc. I was just wondering if anyone could provide me with the code required to access this functionality outside of the WDDOMODIFYVIEW event.
    Regards
    Mart

    Well i dont really have a requirement I have manged to do it but thought there would be a better way. Currently I have created an attribute within my view called GD_VIEW(type ref to IF_WD_VIEW) and within event WDDOMODIFYVIEW I have put the following code
    wd_this->GD_VIEW = view.
    I can then access this anywhere using the following code
    data: lv_v_elem type ref to if_wd_view_element.
      lv_v_elem = wd_this->gd_view->get_element( 'PWORD' ).
      if lv_v_elem is bound.
        wd_this->gd_view->request_focus_on_view_elem( lv_v_elem ).
      endif.
    But just thought there would be a way without having to copy it within the WDDOMODIFYVIEW event. But then again maybe not!
    Regards
    Mart

  • Accessing "changing parametes " from JCo

    Hi all,
         I would like to access a RFC having "changing" parameters (eg EMPLOYEE_READ_APPLICANTNUMBER). How do I do it? How do I build a custom repository metadata for such a RFC??
    when I check the RFC library there the new function RFCCallRecieveEx() seems to support changing parameters but not the older one RFCCallRecieve(), but when I see the trace I see that the RFCCallRecieve() is the one being and therefore I get a RFC_SYS_EXCEPTION error.
    Can somebody tell me how to solve the problem? Has somebody tried building metadata for RFC/BAPI containing changing parameters
    Thanks in Advance
    Dilip

    I'm new to JCO and java so I'm not sure how you would handle this on the java side but as a work around you could probably just create a custom ABAP function module that called the original function module.
    Just specify all the parameters of the new function module as either IMPORTING or EXPORTING, then inside the new function module call the old one with the parameters as per the interface of the original function module.
    On the java side just call the new function module and all your parameters should work ok with the JCO.
    The "CHANGING" parameter is really more of an internal ABAP designation indicating the value may be changed during execution.  You can change a parameter that is not designated as changing.  The two behave a little differently if the program is terminated before execution is completed and it adds clarity to the interface, but other than that there really aren't many benefits.

  • JSP, Crystal RAS access passing parameter issue

    I am facing some issues with Crystal Report in RAS Server. The reports works fine, when i access the URL with parameters without hiphen('-'). But the same  throws an error  when i have an hiphen in the parameter value "The syntax of the value for prompt is facilityid incorrect. Please correct the syntax and try again"
    My URL is
    http://server/businessobjects/viewrpt.cwr?id=33432&apsuser=USERID&apspassword=PASSWORD&apsauthtype=secWinAD&init=ACTX&promptex-departmentid=CMDV&promptex-facilityid=VS-1&promptex-shiftdate=04/28/2009&promptex-dummy=14.727542216333234
    The issue is with the parameter value for facilityid VS-1

    Thank you Praveen. But, I have done it in a different way.
    http://server/businessobjects/viewrpt.cwr?id=33432&apsuser=USERID&apspassword=PASSWORD&apsauthtype=secWinAD&init=ACTX&promptex-departmentid="CMDV"&promptex-facilityid="VS-1"&promptex-shiftdate="04/28/2009"&promptex-dummy=14.727542216333234
    I passed the parameter values in double quotes and it is working fine. But now the problem is that the Crystal Report is not refreshing with the latest data. This is the case, even if i uncheck the "Save data with report".

  • Access context parameter in web.xml

    Hi, all. I add a entry into Context Initialization parameter at tab Application in file web.xml with name: path and value img/product. I don't know how to get the context parameter. I want access the context by EL in file .jspx or .jsf, as #{path} but error. Can anyone help me.Thanks.

    Hi,
    have a go with
    #{initParam['param_name_here']}"
    alternatively
    #{facesContext.externalContext.initParameterMap['param_name_here']}
    Frank

  • Accessing Sender parameter attribute in event hander method implementation

    Hello knowledgeable friends.
    I would like a single event handler to manage two alv grid objects.  There is a parameter SENDER that is available in the method implementations to say which object triggered the event.  I would like to get at the attribute MT_OUTTAB but this syntax does not work:
    local_variable = sender->mt_outtab
    Any help would be greatly appreciated

    Ok, MT_OUTTAB is a protected Attribute.  I would settle for just the name of the Sender.  This code checks:
        call method sender->get_name RECEIVING name = l_name.
    but l_name is empty.  I was hoping for 'GRID1'; when I created the object I used:
        CREATE OBJECT alvgrid
          EXPORTING
            i_parent = container_top
            i_name = 'GRID1'.

  • How to access req parameter

    i have included in the request one object....
    i wud like to access that obj in my jsp
    what i am doing is
    <td><bean:message key="app.username" /></td>
    <td><input type="text" name="username" value=request.getAttribute("employees").getUsername() /> </td>
    bt i am nt getting the results
    thanks

    You would also need a cast of the request attribute to whatever type is being retrieved.
    value = "<%= ((Employee)request.getAttribute("employees")).getUsername() %>"
    of course using EL this expression would be merely
    ${employees.username}

  • Need to access a parameter in a super class method

    Hi,
    I have the following setup:
    class A{
        exceptionHandler(Throwable ex, int iNeedThis);
    class B extends A{
        execute();
        func1{};
    }When execute() fails, the ecexptionHandler method is automatically called. In func1() of class B I need to access the iNeedThis variable once excute() fails. Is it possible to do this?
    Thanks.

    wow, thats about impossible to follow.
    Let me take a stab.
    If you want to save a value for later use when an exception is thrown, throw your own exception type that stores this info in the exception.
    Or perhaps you are asking something completely different.

  • Ref Cursor - how to access through parameter name

    Hi,
    I'm using the below table and sample data. The below script named 'Script1' works well, my concern is values for the first and second parameters need to be used for the thrid and fourth one as well.
    When I try with 'Script2' it gives "ORA-01008: not all variables bound ORA-06512: at line 17" error. I know Paramterized cursor can handle this effecively, since it is a dynamic SQL, I need to use from a parameter table, I don't have any control over the number of parameteters, parameter name, type and other things. So, I cannot go for parameterized cursor.
    As of now, for my requirement, Script1 works fine, is there any way to make Script2 to work as well, I need to pass paramters by name, not by position, please give your suggestions, thank you.
    CREATE TABLE T1
    F1 NUMBER(5),
    F2 VARCHAR2(100),
    F3 DATE
    Insert into T1
    (F1, F2, F3)
    Values
    (1, 'One', TO_DATE('08/02/2012 07:43:34', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into T1
    (F1, F2, F3)
    Values
    (2, 'Two', TO_DATE('08/02/2012 08:15:24', 'MM/DD/YYYY HH24:MI:SS'));
    Insert into T1
    (F1, F2, F3)
    Values
    (3, 'Three', TO_DATE('08/02/2012 08:16:34', 'MM/DD/YYYY HH24:MI:SS'));
    COMMIT;
    Script1:
    declare
    TYPE t_ref_cursor IS REF CURSOR;
    v_cursor t_ref_cursor;
    v_query_str varchar2(3000);
    v_f1 number(5);
    v_f2 varchar2(100);
    v_f3 date;
    begin
    v_query_str := 'SELECT f1, f2, f3 from t1 where f1 = :p1 and f3 = to_date(:p2, ''DD-MON-YYYY hh24:mi:ss'') union ';
    v_query_str := v_query_str || 'select 1, ''c1'', sysdate from dual where not exists (select 1 from t1 where f1 = :p3 and f3 = to_date(:p4, ''DD-MON-YYYY hh24:mi:ss''))';
    --dbms_output.put_line(v_query_str);
    open v_cursor for v_query_str using 1, '02-AUG-2012 07:43:34', 1, '02-AUG-2012 07:43:34';
    loop
    fetch v_cursor into v_f1, v_f2, v_f3;
    exit when v_cursor%notfound;
    dbms_output.put_line(v_f1 || ' ' || v_f2 || '' || v_f3);
    end loop;
    dbms_output.put_line('rowcount ' || v_cursor%rowcount);
    close v_cursor;
    end;
    Script2:
    declare
    TYPE t_ref_cursor IS REF CURSOR;
    v_cursor t_ref_cursor;
    v_query_str varchar2(3000);
    v_f1 number(5);
    v_f2 varchar2(100);
    v_f3 date;
    begin
    v_query_str := 'SELECT f1, f2, f3 from t1 where f1 = :p1 and f3 = to_date(:p2, ''DD-MON-YYYY hh24:mi:ss'') union ';
    v_query_str := v_query_str || 'select 1, ''c1'', sysdate from dual where not exists (select 1 from t1 where f1 = :p1 and f3 = to_date(:p2, ''DD-MON-YYYY hh24:mi:ss''))';
    --dbms_output.put_line(v_query_str);
    open v_cursor for v_query_str using 1, '02-AUG-2012 07:43:34';
    loop
    fetch v_cursor into v_f1, v_f2, v_f3;
    exit when v_cursor%notfound;
    dbms_output.put_line(v_f1 || ' ' || v_f2 || '' || v_f3);
    end loop;
    dbms_output.put_line('rowcount ' || v_cursor%rowcount);
    close v_cursor;
    end;
    /

    This link shall answer your Question. PL/SQL Dynamic SQL.
    If it had been an Anonymous Block, your code would work through.
    Please see demonstration below:
    create or replace procedure emp_data (dep_id    number, sal   number, emp_id    number)
    is
      l_cnt   number;
    begin
      select count(*)
        into l_cnt
        from hr.employees
       where department_id = dep_id
         and salary >= sal
         and employee_id > emp_id;
      dbms_output.put_line('Count :: ' || l_cnt);
    end;
    declare
      l_cnt           number;
    begin
      execute immediate 'begin emp_data(:1, :2, :2); end;' using 20, 100;
    end;
    anonymous block completed
    Count :: 2
    --Trying the Similar example as in your OP.
    --Execute the same Select statement as in emp_Data with Bind Variables;
    declare
      l_cnt           number;
    begin
      --execute immediate 'begin emp_data(:1, :2, :2); end;' using 20, 100;
      execute immediate 'select count(*)
        from hr.employees
       where department_id = :1
         and salary >= :2
         and employee_id > :2' into l_cnt using 20, 100;
      dbms_output.put_line('Count :: ' || l_cnt);
    end;
    Results in error :- ORA-01008: not all variables bound

Maybe you are looking for

  • IPod Nano: Error Message "The USB device has malfunctioned and Windows does not recognise it"

    Hi everyone, I just received 2 brand new iPod Nanos for my kids for Christmas, thought I'd be smart and sync them both now before wrapping them so I don't have to be messing around with them on the day. One synced without a problem, then using the sa

  • Installing Adobe Reader error code 1328

    Installed what I thought to be Adobe Reader but it was not.  It was a paid site displaying Adobe Reader. Now when down loading and attempting to install the correct Adobe Reader I receive an error code 1328.  Error applying patch to file C:\config.Ms

  • Using iweb/MacBook and connecting wirelessly to internet in remote China

    Ok this is a long shot....... I need to be able to update my website www.greatwalltrek.info whilst in remote areas of China using a MacBook whilst I'm fundraising for charity. I have been told that with a CDMA card I will get access from most places

  • Using Imac to display other computers (PC)

    Hi I need to find out if I can use the dvi plug to connect other computers to use the 24" screen. I have a Belkin Flip but it doesn't seem to pick up the PC's and is blanked out. I have it connected to the Mini DVI plug in the back of the machine. Be

  • Lots of spinning beach balls. MBP 3,1 OSX 10.8.2

    Dear all I own a 2007 MBP 3,1 2,4 ghz core 2 duo with 6gb of RAM (recently the video card was replaced because of the dreaded nvidia problem known to these devices.. - mind you, only the video card was replaced, not the logic board (was out of warran