Remove warning: Set Listener ? element Listener T usage

Hello,
I have a class using listeners for diffent classes. I don't know how to remove the unchecked warning.
The class stores Listener for differen classes. When called with an object of a registered class the method doIt from the registered XListener should be called with the object.
Here comes the code:
public class XSupport {
    private Set<Listener<?>> listeners = new HashSet<Listener<?>>();
    public <T> void addXListener(Class<T> clazz, XListener<T> xListener) {
        listeners.add(new Listener<T>(clazz, xListener));
    @SuppressWarnings("unchecked")
    public <T> void doIt(T data) {
        Class<?> dataClass  = data.getClass();
        for (Listener listener : listeners)
            if (dataClass.equals(listener.getClazz()))
                listener.getXListener().doIt(data);
    private class Listener<T> {
        private Class<T> clazz;
        private XListener<T> xListener;
        public Listener(Class<T> clazz, XListener<T> xListener) {
            this.clazz = clazz;
            this.xListener = xListener;
        public Class<T> getClazz() {
            return clazz;
        public XListener<T> getXListener() {
            return xListener;
}Rem.: Listener also has equals and hashCode which I did not copy here
The XListener interface is definied like this:
public interface XListener<T> {
    public void doIt(T data);
}I suppose the for loop with raw Listener is the problem, but I can't use Listener<?> neither Listener<T> there.

Kurt76 wrote:
I have a class using listeners for diffent classes. I don't know how to remove the unchecked warning.Your code "anonymizes" the generic type of incoming listeners by adding them to a wildcarded Set. What you would need here is to "re-set" the type information by time of usage, which you cannot do reflectively.
I'd suggest a small redesign as follows:
public class XSupport {
    private Set<Listener<?>> listeners = new HashSet<Listener<?>>();
    public <T> void addXListener(Class<T> clazz, XListener<T> xListener) {
        listeners.add(new Listener<T>(clazz, xListener));
    public void doIt(Object data) {
        for (Listener<?> listener : listeners) {
            listener.visit(data);
    private class Listener<T> {
        private Class<T> clazz;
        private XListener<T> xListener;
        public Listener(Class<T> clazz, XListener<T> xListener) {
            this.clazz = clazz;
            this.xListener = xListener;
        public void visit(Object data) {
            if (clazz.isInstance(data)) {
             xListener.doIt(clazz.cast(data));
}Edit: Just as I missed that one: was the use of "equals" deliberate? If so, you have to change the visit() method implementation to check on "clazz.equals(data.getClass())". An equal on classes will only match if both are the same class (uses object identity). That is, you only can use concrete classes for adding listeners, no interfaces or abstract classes, nor make use of class hierarchies.
Edited by: stefan.schulz on Oct 13, 2007 11:15 AM

Similar Messages

  • Issue with setting an Action Listener for a Command Button

    Hi all,
    I'm trying to set an action listener for a CoreCommanButton in a backing bean. Here's my code:
         CoreCommandButton editBtn = new CoreCommandButton();
              MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{backBean.doButtonAct}",null);
              editBtn.setActionListener(mb);
    //Action listener method
         public void doButtonAct(ActionEvent actionEvent)
    I keep getting a javax.faces.el.MethodNotFoundException error. However when I remove the ActionEvent parameter in doButtonAct(), I get a wrong number of arguments error.
    So i'm guessing there is something wrong with the parameters i accept in my action listener method. what can be causing this issue?
    Cheers.

    I figured this out.
    Since doButtonAct() requires an ActionEvent object as a parameter, i needed to define the parameter type when I create the method binding.
    Solution:
         Class argsString[] = new Class[] { ActionEvent.class };
              MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{backBean.doButtonAct}",argsString);

  • How do I set a Phase Listener to only run for a specific page?

    How do I set a Phase Listener to only run for a specific page?
    I understand that a Phase Listener runs for ever page in the application, however I want a phase listener to only run for one page at the beginning of the application.
    I discovered I can't use a Filter, because the JSF Application instance always returns null.
    Thus, I thought a Phase Listener would be a good approach.
    Thoughts?
    Thanks,
    --Todd                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    I have moved forward with checking the requested URI...
    (shivers)
    Thanks,
    --Todd                                                                                                                                                                                   

  • Set password for listener

    hi all.
    i am using oracle database 11g R2 and Oracle Enterprise Linux 5.5 64bit.
    i have been already set password for listener but when i start and stop then its not asking for Authentication?
    plz guide me thanks in advance.

    hi
    i have been already done that what you suggested for me,current listener is listener.
    even i used netmgr to check authentication tab.
    i am already member of DBA Group.
    here is my listener settings.
    # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_2/network/admin/listener.ora
    # Generated by Oracle configuration tools.
    PASSWORDS_LISTENER = 587DE10070B3EF82
    #----ADDED BY TNSLSNR 06-MAR-2012 11:23:42---
    ADMIN_RESTRICTIONS_LISTENER = ON
    LISTENER =
      (DESCRIPTION_LIST =
        (DESCRIPTION =
          (ADDRESS = (PROTOCOL = TCP)(HOST = localhost2)(PORT = 1521))
    ADR_BASE_LISTENER = /u01/app/oracle
    SAVE_CONFIG_ON_STOP_LISTENER = TRUEEdited by: Kelly on Mar 6, 2012 3:55 AM

  • Can i set a window Listener to JApplet

    can i set a window listener to applet if yes how?
    thanks

    boss
    my problem is i have some drawing in the panel.when i minimize the window it will disappear because it is dynamically getting drawn.So, for capuring the old drawing, i store the coordinates into the vector and
    trying to redraw by calling a method when applet gets
    maximized.
    Initially the application was a stand alone , so i used
    JFrame and window listener and whenever frame gets activated , i used to redraw the line . Now we have changed to applet.
    And i tried to implement window listener, i could not able to add listener to the contenetPane.
    So i decided to call my drawing method from START(),Since start is been called whenever applet is activated.I decided to do so.
    But the problem is ,it is calling the method,identifying the
    coordinates but the lines are not appearing in the screen.
    My suspection is, it is drawing the line and once again
    repainting the screen automatically.
    If u people wants to see am ready to post the code.

  • Database configuration warning use netca for listener

    Hi,
    I am using Red Hat 5.4 AS 32 bit and want to install oracle 11gR2 32 bit.
    Problem is occurring when installation is going on last
    Warning Message is like "listener is not configure use netca"
    Thanks in advance

    After correction port in listener
    [oracle@tsh admin]$ lsnrctl start
    LSNRCTL for Linux: Version 11.2.0.1.0 - Production on 27-OCT-2012 15:06:01
    Copyright (c) 1991, 2009, Oracle. All rights reserved.
    Starting /oracle/product/11.2.0/db_1/bin/tnslsnr: please wait...
    TNSLSNR for Linux: Version 11.2.0.1.0 - Production
    System parameter file is /oracle/product/11.2.0/db_1/network/admin/listener.ora
    Log messages written to /oracle/diag/tnslsnr/tsh/listener/alert/log.xml
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
    Listening on: (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.170.200.96)(PORT=1538)))
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC0)))
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for Linux: Version 11.2.0.1.0 - Production
    Start Date 27-OCT-2012 15:06:03
    Uptime 0 days 0 hr. 0 min. 0 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Listener Parameter File /oracle/product/11.2.0/db_1/network/admin/listener.ora
    Listener Log File /oracle/diag/tnslsnr/tsh/listener/alert/log.xml
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC0)))
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=172.170.200.96)(PORT=1538)))
    Services Summary...
    Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
    Service "tsh" has 1 instance(s).
    Instance "tsh", status UNKNOWN, has 1 handler(s) for this service...
    The command completed successfully
    [oracle@tsh admin]$
    Listener.ora
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC0))
    (ADDRESS_LIST =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.170.200.96)(PORT = 1538))
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = /oracle/product/11.2.0/db_1)
    (PROGRAM = extproc)
    (SID_DESC =
    (ORACLE_HOME = /oracle/product/11.2.0/db_1)
    (SID_NAME = tsh)
    ADR_BASE_LISTENER = /oracle
    tnsanes.ora
    TSH =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 172.170.200.96)(PORT = 1538))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = tsh.ag.com)
    )

  • Set Up a listener

    Hey everyone, Could some one help me set up a listener?

    Hey
    Check the netmgr command
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14196/network002.htm
    Regards

  • Request for assistance setting up the listener. 11.2.0.2 on 64 bit Linux,

    I have installed Oracle and am able to access it locally. Unfortunately, I can't access it remotely. lsnrctl status does not list the XE instance. The following are the contents of the relevant files/command outputs:
    listener.ora
    # listener.ora Network Configuration File:
    SID_LIST_LISTENER =
    (SID_LIST =
    (SID_DESC =
    (SID_NAME = PLSExtProc)
    (ORACLE_HOME = /u01/app/oracle/product/11.2.0/xe)
    (PROGRAM = extproc)
    LISTENER =
    (DESCRIPTION_LIST =
    (DESCRIPTION =
    (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC_FOR_XE))
    (ADDRESS = (PROTOCOL = TCP)(HOST = Neon)(PORT = 1521))
    DEFAULT_SERVICE_LISTENER = (XE)
    /etc/hosts
    127.0.0.1     localhost.localdomain     localhost     Neon
    ::1     localhost.localdomain     localhost6     localhost
    lsnrctl status
    LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 04-SEP-2012 12:27:21
    Copyright (c) 1991, 2011, Oracle. All rights reserved.
    Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=EXTPROC_FOR_XE)))
    STATUS of the LISTENER
    Alias LISTENER
    Version TNSLSNR for Linux: Version 11.2.0.2.0 - Production
    Start Date 31-AUG-2012 16:49:12
    Uptime 3 days 19 hr. 38 min. 9 sec
    Trace Level off
    Security ON: Local OS Authentication
    SNMP OFF
    Default Service XE
    Listener Parameter File /u01/app/oracle/product/11.2.0/xe/network/admin/listener.ora
    Listener Log File /u01/app/oracle/product/11.2.0/xe/log/diag/tnslsnr/Neon/listener/alert/log.xml
    Listening Endpoints Summary...
    (DESCRIPTION=(ADDRESS=(PROTOCOL=ipc)(KEY=EXTPROC_FOR_XE)))
    (DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521)))
    Services Summary...
    Service "PLSExtProc" has 1 instance(s).
    Instance "PLSExtProc", status UNKNOWN, has 1 handler(s) for this service...
    The command completed successfully
    I am able to log into the database using sqlplus mkhan/password and run the following query, select * from all_users and get the following output:
    SQL> select * from all_users;
    USERNAME               USER_ID CREATED
    XS$NULL           2147483638 28-AUG-11
    MKHAN                    49 30-AUG-12
    LKEDONGA               48 23-JUL-12
    APEX_040000               47 28-AUG-11
    APEX_PUBLIC_USER          45 28-AUG-11
    FLOWS_FILES               44 28-AUG-11
    HR                    43 28-AUG-11
    MDSYS                    42 28-AUG-11
    ANONYMOUS               35 28-AUG-11
    XDB                    34 28-AUG-11
    CTXSYS                    32 28-AUG-11
    USERNAME               USER_ID CREATED
    OUTLN                         9 28-AUG-11
    SYSTEM                         5 28-AUG-11
    SYS                         0 28-AUG-11
    14 rows selected.
    SQL>
    but attempting sqlplus mkhan/password@XE or mkhan/password@Neon/XE or mkhan/password@localhost/XE results in the following:
    SQL*Plus: Release 11.2.0.2.0 Production on Tue Sep 4 13:42:36 2012
    Copyright (c) 1982, 2011, Oracle. All rights reserved.
    ERROR:
    ORA-12514: TNS:listener does not currently know of service requested in connect
    descriptor
    Enter user-name:
    Needless to say that Apex isn't working either but I'll tackle that later. I can log into the database using user oracle in group dba using "sqlplus / as sysdba". I can shutdown the database and start it back up. So I know I installed correctly.

    user11414072 wrote:
    Thanks Ed.
    On my PC, I installed the instant client 11.2. As I understand it, when I run sqlplus in a dos box as follows, I the DB server should respond and allow a connection
    sqlplus mkhan/password@XE
    In this case it should use the local tnsnames.ora to determine where the XE instance is, and initiate a connection.
    I've also tried
    sqlplus mkhan/password@Neon/XE and
    sqlplus mkhan/[email protected]/XE and
    sqlplus mkhan/[email protected]/XE
    sqlplus mkhan/[email protected]:1521/XE
    all of them give me
    ORA-12170: TNS:Connect timeout occurred
    AdThanksVance,the most common cause from ORA-12170 is a FireWall on or between client & DB server
    what is OS name & version for both client & DB server?

  • Won't show CF card, yet it gives me device removal warning when I pull it.

    This happens occasionally and I don't know why. I put in a disc and it does not show in the finder under devices or anywhere else I can find. I pull the disc, and it gives the the device removal warning. It it's reading it, then where the heck am I supposed to find it?? Thanks.

    A multi card reader that has always worked in the past (almost always). Plugged the same reader into my Macbook and worked just fine. Tried it directs as well as through hub.

  • How to close a frozen warning: I am unable to close the "charicter boarders aren't supported and were removed" warning on my pages. Untill warning is closed I can not save my document. How can I get my document saved?

    I have an unsaved document open in pages but can not save it because the, "charicter boarders aren't supported and were removed" warning is open and I can not close the warning. How can i get the warning to close so I can save my document? Can I save the document without closing the warning?

    Probably not, but as you will have been unable to make any changes to the document with that warning window open, you're not going to lose anything by quitting (or force quitting) without saving. You'll still have the original document you were trying to import.
    I would suggest attempting to open the document in one of the open source Office applications, LibreOffice, Apache OpenOffice, or NeoOffice, each available for download from the linked sites. Once open there, remove the attributes that are causing the warning, save the file (as an MS Word document), then try opening that version in Pages.
    Regards,
    Barry

  • Can I set a time limit for usage on a 5th gen ipod touch

    My daughter just got a 5th gen Ipod touch. Of course she is using it at times she shouldn't be. Is there a way to set a time limit for usage so she can be responsible for monitoring herself without us nagging all the time?

    IIt's free and here is a link https://itunes.apple.com/gb/app/parentkit-parental-controls/id600618138?mt=8

  • Version sets in Elements 12

    I have just upgraded from 8. I can load my Raw file ok (.NEF) into the raw converter and make adjustments as necessary. However, when I open the image and then save as, although the version sets option is ticked, it does not appear back in the organiser. The file is on the hard disk ok, but does not seem to be accessable from the orhganiser. I've seen some other people are having similar issues with version sets in elements 12 but I can't see what the soluton is.

    Thanks for this advice. I killed ElementsAutoanalyzer.exe as described and this has partially solved the problem. Now when I open the image from the raw converter, and then immediately Save As, I get the options for save to organiser and include in version set ticked, the file is saved but doesn't appear in the organiser. If I then Save a second time (the option Save As is disabled), I get only the option to include it in the organiser (the include in version set option is disabled). This time, after checking ok to overwrite the existing file, it is included in the organiser next to the original file. Further editing of this file does save to a version set, so you end up with the original file and then a version set of all the edits. This is ok, although not ideal as it wastes space in the organiser.

  • How to remove namespace from root-element

    Hi Gurus,
    I want one xml output from xslt transformation with no namespace. I managed to remove namespace from child elements by leveraging elementFormDefault ='unqualified' property of xsd. But not able remove namespace from root-element.
    Output that I want is :
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <inp1:Email_Mod_Root>
       <Email_Mod_Root_Element>
          <Email_Record1>
             <PERSON_NUMBER>123456</PERSON_NUMBER>
             <COUNTRY/>
              <EMAIL_TYPE>WORK</EMAIL_TYPE>
             <EMAIL>EMAIL3</EMAIL>
             <PRIMARY_FLAG>Y</PRIMARY_FLAG>
          </Email_Record1>
    </Email_Mod_Root_Element>
    </Email_Mod_Root>
    Output that I am getting:
    <?xml version = '1.0' encoding = 'UTF-8'?>
    <inp1:Email_Mod_Root xmlns:inp1="http://www.example.org">
       <Email_Mod_Root_Element>
          <Email_Record1>
             <PERSON_NUMBER>123456</PERSON_NUMBER>
             <COUNTRY/>
             <EMAIL_TYPE>WORK</EMAIL_TYPE>
             <EMAIL>EMAIL3</EMAIL>
             <PRIMARY_FLAG>Y</PRIMARY_FLAG>
          </Email_Record1>
    </Email_Mod_Root_Element>
    </Email_Mod_Root>
    Anyone, pls suggest.
    Thanks in advance,
    SG_SOA

    First of all :
    <inp1:Email_Mod_Root>
       <Email_Mod_Root_Element>
          <Email_Record1>
             <PERSON_NUMBER>123456</PERSON_NUMBER>
             <COUNTRY/>
              <EMAIL_TYPE>WORK</EMAIL_TYPE>
             <EMAIL>EMAIL3</EMAIL>
             <PRIMARY_FLAG>Y</PRIMARY_FLAG>
          </Email_Record1>
    </Email_Mod_Root_Element>
    </Email_Mod_Root>
    isn't valid xml (you start with inp1: prefix and you end the tag with no prefix, but let's assume you don't want any prefix/namespace at all)
    if i use :
    [code]
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:inp1="http://www.example.org" exclude-result-prefixes="inp1">
      <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="*">
        <xsl:element name="{local-name(.)}">
          <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
      </xsl:template>
      <xsl:template match="@*">
        <xsl:attribute name="{local-name(.)}">
          <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:template>
    </xsl:stylesheet>
    [/code]
    i get this
    [code]
    <Email_Root_Element>
      <Email_Record>
      <EMPLID>EMPLID46</EMPLID>
      <EMAIL>EMAIL48</EMAIL>
      <E_ADDR_TYPE>E_ADDR_TYPE49</E_ADDR_TYPE>
      <COUNTRY>US</COUNTRY>
      </Email_Record>
      <Email_Record>
      <EMPLID>EMPLID47</EMPLID>
      <EMAIL>EMAIL49</EMAIL>
      <E_ADDR_TYPE>E_ADDR_TYPE50</E_ADDR_TYPE>
      <COUNTRY>US</COUNTRY>
      </Email_Record>
      <Email_Record>
      <EMPLID>EMPLID48</EMPLID>
      <EMAIL>EMAIL49</EMAIL>
      <E_ADDR_TYPE>E_ADDR_TYPE51</E_ADDR_TYPE>
      <COUNTRY>US</COUNTRY>
      </Email_Record>
    </Email_Root_Element>
    [/code]

  • Removal of af:form element

    Hi all,
    JDeveloper 11.1.1.6.0
    We're in the process of implementing a credit card processing page that will be performing a cross domain form action via jQuery or some other means. One of our primary requirements is to guarantee that form data on this page is not submitted to our server but we would like ADF to render the page to maintain a consistent look and feel for the site.
    Would dropping the af:form element be an effective means of guaranteeing form data is not sent to our WLS server (via post, ajax, server side validation)? Any pitfalls?
    Thanks!

    Hi,
    removing the af:form element will not generate the HTML form element and this not submit anything to the server. So yes, this would work.
    Frank

  • "Device Removal" warning when trying to mount 2 Ext HDs

    I'm trying to copy some files from one external HD to another. When I connect these to my G5 and power up, one of them will mount and then the second one knocks the other other one off the desktop and I get the "Device Removal" warning. It happens regardless of which order I do this. HD 1 is about 3 years old, HD 2 is about 1 month old. I've tried disconnecting them both and reconnecting them, I've switched firewire cables and ports. They are both Western Digital firewire 7200 rpm. This has happened before with other ext HDs that I use. Some of them can all be connected to the G5 without any problems at times. There have been a couple of power failures due to some stormy weather lately but I disconnected everything from the power strip prior to bad weather. Don't know if this has any bearing on the problem, just thought I'd mention it.
    Any advice would be greatly appreciated. Steve L.

    Hello! Try them separately on one of the motherboard ports. Were they daisy chained together? This sometimes causes problems. Also when you connect them one at a time to different ports listed the them as they spin up as weak (or failing) power supplies on some externals have caused porblems. Tom

Maybe you are looking for

  • Why can't I use face time or send meg.

    OOk I am longed in to my Apple ID and all but ever time I try use use face time or send mesg. It tills me not delverd....help

  • New intel mac show old name

    The name of my Mac is still being showen as "Tom Reed's G5" in my profiler. I changed the name a week ago to reflect the new computer. It was right for a few days. I just noticed it went back to the older name. Can I fix this somehow?

  • Sigh slow download speeds iPad

    Is anyone having problems with slower download speeds on iPads and if so  any suggestions to fix? Also some videos on my laptop, ex: like twitter mobile uploads I'm trying to view, are slow. Come to think of it, some youtube things slow to download o

  • Let's discuss my application architecture,and give me your opinions

    hello we have several internal systems that are within the same lan and want to communicate with several external systems that may be in the other buildings by using the release line.i am now considering the architecture for the project,and have got

  • Mathematic formulae in a text document

    Hi everybody, I will have to type a document that would include mathematical notations. I will have to explain standard deviations and various probabilities formulae. The special symbol fonts don't really help because, for instance, I wouldn't be abl