Is there an alternative to operator instanceof to be more dynamic

Is there a way to check whether an object is an instance of a class when the name of this class is not known at compile time. For example :
Let's assume I have 3 classes TestBean1, TestBean2, TestBean3
which extends the super class TestBean.
The objective of the TestBean super class constructor is to check whether a user is granted (according to a profile) to execute a particular TestBeanX (X= 1, 2 or 3) class.
The obvious advantage iwould be to avoid the same code to be repeated in each subclass.
The source code below works fine. However everytime a new class inherites from the super class,
TestBean has to be updated to include a specific class code checking.
Is there any way to make this more dynamic ?
To be more concrete, instead of the instructions :
res = "?????";
if (res.equals("TestBean1") && this instanceof TestBean1) .....
I'd rather like to have something like :
if (this instanceof res ) .....
which of course and unfortunately does not work. Is there an alternative to this kind of code ?
Thanks a lot.
Gerard
import java.io.*;
import java.util.StringTokenizer;
class TestBean
public TestBean(String userid)
     // String ACL = getProfile(userid); // return a list of authorized Beans
     String ACL = "TestBean1 TestBean3" ; // just for testing purpose      
     StringTokenizer st = new StringTokenizer(ACL);
     String res=null, msg=null;
     while (st.hasMoreTokens())
     res = st.nextToken();
     if (res.equals("TestBean1") && this instanceof TestBean1) { msg=res; break;}
     if (res.equals("TestBean2") && this instanceof TestBean2) { msg=res; break;}
     if (res.equals("TestBean3") && this instanceof TestBean3) { msg=res; break;}
     if (msg == null)
System.out.println(userid + " is not granted to run this bean");
     else
     System.out.println(userid + " is auhtorized to run the bean " + msg) ;
class TestBean1 extends TestBean
public TestBean1()
{   super("Gerard");
System.exit(0);
public static void main(String[] args) {new TestBean1();}      
class TestBean2 extends TestBean
public TestBean2()
{   super("Gerard");
System.exit(0);
public static void main(String[] args) {new TestBean2(); }      
class TestBean3 extends TestBean
public TestBean3()
{   super("Gerard");
System.exit(0);
public static void main(String[] args) {new TestBean3();}      

Thanks Ken however by investigating more, I have found a good way by using getClass().getName().
I modified my code as follows and it works fine now. thanks again:
Gerard
import java.io.*;
import java.util.StringTokenizer;
class TestBean
public TestBean(String userid)
String myclass = this.getClass().getName() ; // get class name
     String ACL = "TestBean1 TestBean3" // list of authorized Beans
     StringTokenizer st = new StringTokenizer(ACL);
     boolean ok = false;
     while (st.hasMoreTokens())
     if (st.nextToken().equals(myclass)) {ok = true; break;}
     if (ok)
     System.out.println(userid + " is auhtorized to run the bean " + myclass) ;
     else
System.out.println(userid + " is not granted to run this bean");
}

Similar Messages

  • Is there a alternative to Plugin-container (or a way to disable It)?

    == Issue
    ==
    I have another kind of problem with Firefox
    == Description
    ==
    Is there a alternative to Plugin-container? It just showed up In my system processes when I updated to Firefox 3.6.6. I've never had problems with plugins crashing but ever since plugin-container.exe crashes have happened more frequently and plugins like Adobe Flash are now taking a lot longer to load. I have an older computer and I noticed plugin-container Is a different process and takes up a large amount of memory, didn't have that problem before. Is there a way to disable It? Even though Its suppose to resolve problems, I've never had any before and now that I have It I'm having problems. Any help would be greatly appreciated.
    == This happened
    ==
    Not sure how often
    == I upgraded to Firefox 3.6.6 and for the first time had plugin-container.exe on my computer.
    ==
    == Troubleshooting information
    ==
    Application Basics
    Name
    Firefox
    Version
    3.6.6
    Profile Directory
    Open Containing Folder
    Installed Plugins
    about:plugins
    Build Configuration
    about:buildconfig
    Extensions
    Name
    Version
    Enabled
    ID
    Adblock Plus
    1.1.3
    true
    Classic Compact Options
    1.2.1
    true
    [email protected]
    DownloadHelper
    4.7.2
    true
    FoxTab
    1.3
    true
    Java Console
    6.0.07
    false
    Java Console
    6.0.14
    false
    Java Console
    6.0.15
    false
    Java Console
    6.0.17
    false
    Java Quick Starter
    1.0
    false
    [email protected]
    Personas
    1.5.2
    true
    [email protected]
    Remove New Tab Button
    1.0
    true
    [email protected]
    WOT
    20091028
    true
    Java Console
    6.0.20
    false
    Adobe DLM (powered by getPlus(R))
    1.6.2.63
    true
    Modified Preferences
    Name
    Value
    accessibility.typeaheadfind.flashBar
    0
    browser.history_expire_days.mirror
    180
    browser.places.importDefaults
    false
    browser.places.migratePostDataAnnotations
    false
    browser.places.smartBookmarksVersion
    2
    browser.places.updateRecentTagsUri
    false
    browser.startup.homepage
    http://www.google.com
    browser.startup.homepage_override.mstone
    rv:1.9.2.6
    browser.tabs.autoHide
    true
    dom.max_script_run_time
    0
    extensions.lastAppVersion
    3.6.6
    keyword.URL
    http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q=
    network.cookie.prefsMigrated
    true
    network.protocol-handler.warn-external.dnupdate
    false
    places.last_vacuum
    1273704069
    print.print_printer
    Dell Photo AIO Printer 924
    print.printer_Dell_Photo_AIO_Printer_924.print_bgcolor
    false
    print.printer_Dell_Photo_AIO_Printer_924.print_bgimages
    false
    print.printer_Dell_Photo_AIO_Printer_924.print_command
    print.printer_Dell_Photo_AIO_Printer_924.print_downloadfonts
    false
    print.printer_Dell_Photo_AIO_Printer_924.print_edge_bottom
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_edge_left
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_edge_right
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_edge_top
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_evenpages
    true
    print.printer_Dell_Photo_AIO_Printer_924.print_footercenter
    print.printer_Dell_Photo_AIO_Printer_924.print_footerleft
    &PT
    print.printer_Dell_Photo_AIO_Printer_924.print_footerright
    &D
    print.printer_Dell_Photo_AIO_Printer_924.print_headercenter
    print.printer_Dell_Photo_AIO_Printer_924.print_headerleft
    &T
    print.printer_Dell_Photo_AIO_Printer_924.print_headerright
    &U
    print.printer_Dell_Photo_AIO_Printer_924.print_in_color
    true
    print.printer_Dell_Photo_AIO_Printer_924.print_margin_bottom
    0.5
    print.printer_Dell_Photo_AIO_Printer_924.print_margin_left
    0.5
    print.printer_Dell_Photo_AIO_Printer_924.print_margin_right
    0.5
    print.printer_Dell_Photo_AIO_Printer_924.print_margin_top
    0.5
    print.printer_Dell_Photo_AIO_Printer_924.print_oddpages
    true
    print.printer_Dell_Photo_AIO_Printer_924.print_orientation
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_pagedelay
    500
    print.printer_Dell_Photo_AIO_Printer_924.print_paper_data
    1
    print.printer_Dell_Photo_AIO_Printer_924.print_paper_height
    11.00
    print.printer_Dell_Photo_AIO_Printer_924.print_paper_size_type
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_paper_size_unit
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_paper_width
    8.50
    print.printer_Dell_Photo_AIO_Printer_924.print_reversed
    false
    print.printer_Dell_Photo_AIO_Printer_924.print_scaling
    1.00
    print.printer_Dell_Photo_AIO_Printer_924.print_shrink_to_fit
    true
    print.printer_Dell_Photo_AIO_Printer_924.print_to_file
    false
    print.printer_Dell_Photo_AIO_Printer_924.print_unwriteable_margin_bottom
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_unwriteable_margin_left
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_unwriteable_margin_right
    0
    print.printer_Dell_Photo_AIO_Printer_924.print_unwriteable_margin_top
    0
    privacy.sanitize.migrateFx3Prefs
    true
    privacy.sanitize.timeSpan
    0
    security.warn_viewing_mixed
    false
    == Firefox version
    ==
    3.6.6
    == Operating system
    ==
    Windows XP
    == User Agent
    ==
    Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.6) Gecko/20100625 Firefox/3.6.6
    == Plugins installed
    ==
    *-Shockwave Flash 10.0 r45
    *getplusplusadobe16263
    *The QuickTime Plugin allows you to view a wide variety of multimedia content in Web pages. For more information, visit the QuickTime Web site.
    *Adobe Shockwave for Director Netscape plug-in, version 11.5
    *4.0.50524.0
    *Google Updater pluginhttp://pack.google.com/

    You can set the prefs dom.ipc.plugins.enabled.* to false on the about:config page to disable the plugin-container process.
    dom.ipc.plugins.enabled.npctrl.dll (Silverlight)
    dom.ipc.plugins.enabled.npqtplugin.dll (QuickTime)
    dom.ipc.plugins.enabled.npswf32.dll (Flash)

  • Is there an alternative email view that look like outlook?

    Is there n alternative view in Apple email that looks like Outlook?  A line for each email with date/time and subject.

    Thank You that was so simple,  in Yosemite it is Preferences->Viewing -> Classic

  • Apple says my epson perfection 1240u scanner no longer supported with 10.7. Is there an alternative way to get it to work?

    Apple says my epson perfection 1240u scanner is no longer supported with 10.7.
    Is there an alternative way to get it to work?

    Download updates from the manufacturers pages:
    http://www.epson.com/cgi-bin/Store/support/supDetail.jsp?oid=14549&BV_UseBVCooki e=yes&infoType=Downloads&platform=OSF_M_…

  • Is there a way to get idvd on a new macbook? or is there an alternative that works?

    I note that my new macbook pro (purchased with a dvd burner specifically) no longer comes with iDVD preloaded. Is there a way to get this, or is there an alternative that works. have checked the app store only to see a number of 'alternatives' that are crucified by the feedback, largely not compatible with mountain lion, etc. This was really dissapointing, to get a new apple computer, still with imovie (great), but without the ability to create a dvd to  share movies with friends and family...any ideas?

    There is no good replacement app for iDVD when it comes to ease of use, flexibilithy and professional looking results.
    You'll have to purchase an iLife disc and should be aware that the iLife 11 disc only provides iDVD 5-7 themes.  The Software Update no longer installs the earlier themes nor do any of the iDVD 7 updaters available from the Apple Downloads website contain them. 
    Currently the only sure fire way to get all themes is to start with the iLife 09 disc:
    This shows the iDVD contents in the iLife 09 disc via Pacifist:
    You then can upgrade from iDVD 7.0.3 to iDVD 7.1.2 via the updaters at the Apple Downloads webpage.
    OT

  • HT3176 Apple TV sleep mode remote shortcut no longer works? with new software update. Why? Is there an alternative other than nav to settings menu?

    Apple TV sleep mode remote shortcut no longer works with newest software update. Why? Is there an alternative other than nav to settings menu? Reset remote shortcut dead as well. :(

    Hold Menu + Play/Pause to reboot the box from the main menu.

  • Is there any alternative to GUI_DOWNLOAD  other than  WS_DOWNLOAD?

    Hi All,
    Is there any alternative FM other than GUI_DOWNLOAD and WS_DOWNLOAD?I need to download a PDF file to a network drive.
    Thanks in Advance,
    Anjaly

    Hi,
    If u want to download a PDF file from application server...
    u can use the transaction...  <b>CG3Y</b> directlyy..
    just check it and use it in ur program..
    cheers,
    Simha.

  • Is there an alternative to prevent access to a transaction?

    Hello Everyone!
    Is there an alternative to prevent access to a standard transaction when a user has the S_TCODE value already? A custom program was created through batch input recording and there are transaction calls made to the standard transaction. I had to give the S_TCODE value for the program to run for the user, but one requirement was to force the user to use the custom t-code and not use the standard one. Unfortunately, I have provided the user access to the standard t-code as demanded by the program. Is there a way around this? I assume this has to be manipulated in the program.
    Thanks!

    If no further intervention is needed, then you can execute the processing as a batch job with the SYSTEM type jobsstep user?
    If the dialog user is processing the session in SM35 themselves or the job is executed in their name, then must also have been able to process the data manually.
    In the stead of Batch Input, you should also consider redesigning the process to call a BAPI locally or via a group to process the data. This way they typically need the application authorizations but do not need an entry point to them such as S_TCODE or S_RFC.
    Or reconsider the transaction code used in the Batch Input call?
    Or reconsider the person (job function) who executes this processing?
    Or give the originator of the data a webservice to process the data real time?
    Lots of options...
    Cheers,
    Julius

  • How best to save photos?  I want to protect my photos (15,000 of them) by putting them on a portable drive and storing it in my safety deposit box.  Is it better to export them all, drag the Photo file, use Time Machine – or are there better alternatives?

    I am a 'newby' to the discussion world.  Hope I am doing this right.  How best to save photos?  I want to protect my photos (15,000 of them) by putting themon a portable drive and storing it in my safety deposit box.  Is it better to export them all, dragthe Photo file, use Time Machine – or are there better alternatives?

    Welcome to the discussions! You can use Time Machine and I would also recommend for you to manually copy your iPhoto Library (on your Pictures folder) to an external drive/thumb drive so you can restore it from there should you loose your TM backup. Exporting them from iPhoto would not preserve the libraries' integrity neither your originals, should you choose to edit them in iPhoto.
    Regards.

  • Is there an alternative flash player I can use for Firefox mobile

    I can't access my Facebook games it says the phone doesn't support abode is there an alternative I can use

    Unfortunately, it is not possible to play these types of games on Firefox OS. Some websites may use Adobe Flash, but Firefox OS does not support Adobe Flash at this moment....

  • It is there an alternative to the Test-SystemHealth powershell cmdlet for Exchange 2013?

    Hello
    The Powershell cmdlet Test-SystemHealth, that was available on Exchange 2010, is no longer available on Exchange 2013.
    Test-SystemHealth cmdlet gathered data about the Microsoft Exchange system and analyzed the data according to best practices.
    Are there any alternatives to this for Exchange 2013?
    Thanks!

    Haven't really played with it too much, but check out Get-ServerHealth
    http://technet.microsoft.com/en-us/library/jj218703(v=exchg.150).aspx
    Looks to have replaced Test-SystemHealth.

  • Why is there no updates to the firefox throttle add-ons ? Is there an alternative? throttle is Bandwidth utilization throttling and monitoring extension for Firefox

    Why is there no updates to the firefox throttle add-ons ? Is there an alternative? throttle is Bandwidth utilization throttling and monitoring extension for Firefox

    Well, it's probably one of two things: either the awesome dude(tte) who developed this awesome extension was tired of updating or the changes in FFox software architecture carried out between version 3.x and 4+ created challenges that were too difficult for him to surmount or a combination of both. Honestly, I love Mozilla but I think they dropped the ball on the throttle issue. It's such an obvious and necessary function and it's so easy to implement. They should have included it a long time ago as in built feature. And, if you are browsing and looking at this post and you agree. Add a suggestion in mozilla.org. The more of us asking for this function, the better.
    Meanwhile, I have the following solution for you:
    Solution 0.6.9.23.11 (DIY Version of my Solution ):
    Setting Up a Separate Portable Firefox 3.6.x that runs independently of and simultaneously to your latest version of Firefox
    Get FireFox Portable 3.6.24:
    http://portableapps.com/apps/internet/firefox_portable/localization#legacy36
    It's a portable app, meaning that it's got all it's profiles and preference and application files in the same directory. It won't compete with your current installation of Firefox, has it's own separate extension folder etc...
    Get Firefox Throttle 1.1.6
    http://firefox-throttle.en.softonic.com/ (I couldn't find it in the official mozilla site)
    It will be flagged as incompatible with even that old version of firefox (but it isn't). You just need to turn off compatibility checking. You can do that with this extension:
    https://addons.mozilla.org/en-US/firefox/addon/add-on-compatibility-reporter/?src=search
    If you have Bookmarks you want to port to the portable (bad pun intend), backup them up to bookmarks.json file on your desktop and import them to the portable version. You can export/import more stuff using FEBE addon but that's a whole world of headaches if you don't your doing.
    Many of your extensions favourites extensions will no longer work on FFox 3.6.x but if, in that same addon's page, you look around until you find a link to previous versions of the addon, you will notice that the compatibility info is right below the version numbers. Just download and install the latest version that is compatible with you 3.6.x....
    Voila mon ami! Your FFox 3.6 portable has just become your own private Download Mule whom you can throttle to your hearts content (ever throttle a real Mule??? I wouldn't try it, personally...) Do your regular browsing in another (unthrottled) browser and do your big downloads in the Mule...
    If you want to keep using your brand spanking new Firefox for other types of browsing while using this portable Mule edition for the downloads, just add -p -no-remote to the shortcut leading to your Firefox Portable Mule edition.
    For example, my taskbar shortcut to my Firefox Portable is:
    ""C:\Program Files (x86)\FirefoxPortableLegacy36\FirefoxPortable.exe"
    I just changed it to:
    "C:\Program Files (x86)\FirefoxPortableLegacy36\FirefoxPortable.exe" -p -no-remote
    This will make it occupy it's own independent instance and I can use the both my Firefox Nightly and the Firefox Portable editions at the same time (each one, using a different profile ie. extensions, cookies, password, cache etc).
    If you're on Linux, you can just run this on Wine and set the Windows Version to Windows 2000 in the Wine config,
    If you want to get rid of the Portable Apps splash screen, click here:
    http://www.ghacks.net/2011/06/06/getting-rid-of-portableapps-splash-screens/
    Solution 0.6.9.23.11 (Non-DIY Version of my Solution):
    Download my preconfigured but SWAGGED-THE-HECK-UP PortableFirefox 3.6
    Having realized that some of you may find the above to be daunting. I took my own customize firefox portable, took out all my data and compressed the folder (it's portable, so it'll run as soon as you unzip it).
    Here is a screenshot:
    http://www.mediafire.com/?o95nkwo8y6q535j
    Here is the download link:
    http://www.mediafire.com/?xdw87ivf3184u2s
    Don't forget to modify your Start/Taskbar shortcuts:
    "C:\wherever you decide to put it\FirefoxPortableLegacy36-Swagged-UP!\FirefoxPortable.exe"
    I just changed it to:
    "C:\wherever you decide to put it\FirefoxPortableLegacy36-Swagged-UP!\FirefoxPortable.exe" -p -no-remote

  • Are there  any other PPC  operating systems

    I would just like to know if there are any PPC operating systems
    I know theres the mac operating systems up to 10.5
    and Ubuntu works with PPC Macs
    Is there anything other operating systems that work with ppc

    The Wikipedia is your first resource, as BD has shown.
    Here are ten popular GNU/Linux distributions (not all PPC):
    http://distrowatch.com/dwres.php?resource=major
    Last year's OpenSUSE is PPC, and the last version of Fedora was PPC.
    What's really interesting is QNX, written by two famous computer scientists (Gordon Bell designed supercomputers). You can buy the source code and program for it (that's all). It's famous for its reliability, driving NASA's deep space probes. It runs your Audi.
    QNX
    http://en.wikipedia.org/wiki/QNX
    An OpenQNX was promised, but I don't see it. In any case, it's not for us. (Well, it might be good for watering gardens without worry.)
    Bruce

  • Is there an alternative to this MWST design?

    My client is a SG company registered for VAT in a few member states in the EU.  The Plant which we are using to do Third Party Sales buy/sell in those EU countries is assigned to a Company Code which Country is SG.  As a result of this design, we use SG as the Departure Country in MWST and we end up relying on Customer Tax Classification as the only determinant for assigning output tax codes in Export Taxes for all the transactions in the EU.
    For a particular Destination Country, we have only one Customer Tax Classification to be used for dispatches within the EU, i.e. non-taxable.  So we will get into a fix when we have more than one ship-from location to the same Destination Country.  For example, we are already using this value to determine the correct output VAT code when we ship from Hungary to Czech Republic.  If we are also to ship from Italy to Czech Republic, we will not have anymore values to use since Customer Tax Classification is a key field in MWST.
    Is there an alternative to this design?  It does not make sense for us to keep adding values for Customer Tax Classification each time we ship from a new EU country.  That does not seem to be SAP's intention of how MWST is to be used anyway.
    Thank you.

    Test the headphones with another device.
    The the device with other headphones.
    If the headphones are broken replace them.
    If the headphone jack in the device is broken you can purchase a replacement headphone jack and hold switch assembly. Make sure that the device otherwise appears to play tracks normally, i.e. you can select songs at random and the playback timer functions. Test in an iPod dock if you can.
    tt2

  • Why is Adobe Flash now asking me to quit 'QuicklookUIHelper' never had this issue before I upgraded to 10.8.5!  Is there an alternative to Flash do I can watch Youtibe?

    Why is Adobe Flash now asking me to quit 'QuicklookUIHelper' during install? I never had this issue before I upgraded to 10.8.5!  Is there an alternative to Flash if I want to watch Youtibe or play material that uses Flash?  Thanks in advance!

    http://hoyois.github.io/safariextensions/clicktoplugin/  and other extensions work if the website has alternatives to the Flash content (much of youtube does) but otherwise, no.
    You may need to restart before installing Flash.

Maybe you are looking for

  • Problem while releasing TP Request

    Hi, We have developed ZAM Object in Development GLD and tranported to GLI(Accept). we hav edited the object in GLI (im. req. basis ). While releasing i am getting following error. Kindly help. Only edit objects from package ZAM in local requests Diag

  • Windows 8 ask for password - I don't want to enter it

    When my laptop starts it shows my email address and asks for my password. I do not want to enter a password . How do I get rid of this because my wife would like to use the computer

  • Threads should be automatically locked after 30 days of inactivity

    I happens every now and then. Somone dredges up a years old post and askes a question sometimes only remotly related to the origonal thread, often it's more like "I am having this problem too but the fix did not work". Today a thread from 2005 was re

  • Lost my osx discs, used my sister's discs, why doesn't it work??

    My harddrive on my MacBook crashed recently, and I have now replaced it with a new one. But, I need to install os x, but my discs that came with my computer are gone (I had version 10.4). I borrowed my sister's discs (she have version 10.5.6), but it

  • Does Apple make Ukrainian/English wired/wireless keyboards?

    Hi, I'm just wondering, does Apple actually make a version of its current standard mac pro style wired keyboard, and/or wireless keyboard, fitted out with dual characters - English and Ukrainian (Cyrillic, but with some differences to Russian). I use