How to load a specific set of classes at runtime.

Howdy!
I want to load all the classes in a directory that implement a specific Interface, at runtime. Of course i can load all the classes if i know the String name.
Class t = Class.forName(ruleClass);
     cnst = t.getConstructor( new Class[] { Session.class } );
     try {
         Object obj = cnst.newInstance(new Object[] {            
                                          m_fwkSession });
         IRules rule = (IRules)obj;
            ...................where IRule is an interface.
How do i get all the files in that directory and find the classes implementing that interfaces ?

You can either load all the classes and then test if they are assignable from IRule.class (isAssignableFrom())
(you could use a custom classloader if you wanted these classes to be garbage collected)
or
Open the class files and scan them to see if they contain
"myPackage/IRule"
(maybe you would have to parse the .class file, but just scanning it might be good enough)

Similar Messages

  • How to set property classes at runtime.

    Well, as the subject line says my question is plain and simple. I don't see any property for this in SET_ITEM_PROPERTY built-in.
    Currently a form has 10 subclassed blocks and views. These blocks have almost similar/definite number of items. At a time only one block with its canvas will be shown to the user. Instead of using so many sub-classed objects, I would like to use only one block and canvas. Now I am looking get getting just property classes from the 10 child forms, which I am looking forward to apply to the common block and items. Any other ideas for the same also appreciated.
    Thanks,
    -- Raam.

    alsalamu alykom
    I think there is no way to set property classes at runtime.
    u must loop through the objects

  • Financial Analytics - limiting load to specific set of books

    Hi all,
    we are running POC for Financial Analytics BI Apps 7.9.6 and we are limiting load into OBAW tables to specific set of books from source EBS (using SET_OF_BOOKS_ID_LIST and $$FILTER_BY_SET_OF_BOOKS_ID DAC parameters) - I was a litlle bit digging in Informatica mappings definition and suprisingly found, that those parameters are just used for load of some fact tables (e.g. W_GL_BALANCE_F etc... ), but is not used to load corresponding dimension tables - like W_LEDGER_D or W_GL_ACCOUNT_D or W_GL_GROUP_ACCOUNT_D - which I would expect to be filtered by specified set of books as well - does anybody know, what tables are filtered by those parameters and what is the reason for not restricting all corresponding tables ?
    Thanks very much for your responses
    Michal Zima

    Hi Michal,
    I think you're saying that you noticed that the mappings/mapplets that load some of the tables (W_GL_ACCOUNT_D or W_GL_BALANCE_F, etc) are not using any logic to filter by your "set of books id list."
    Have you checked the mappings that load the staging and temp tables?
    For example: W_GL_BALANCE_F_TMP, W_GL_BALANCE_FS
    The reason you're not seeing the "set of books id list" might be that the logic was applied to one of the staging or temp tables (a source for the _f table). Thus it would be redundant to re-apply this logic.
    For example:
    Notice that SIL_GLBalanceFact uses W_GL_BALANCE_FS as a source table (and loads the W_GL_BALANCE_F table).
    But, SDE_ORA_GLBalanceFact is the mapping that loads the W_GL_BALANCE_FS table. The logic for "set of books id list" is included in this mapping (or actually, mapplet).
    Hope this helps!
    Thanks,
    Austin
    Edited by: Austin W on Nov 3, 2009 6:58 AM

  • How can I jar a set of class files programatically?

    I want to create a jar file, by taking a set of class files from a specific location , can it be done by running any java program?

    JarOutputStream extends ZipOutputStream

  • How to load binary content of a .class file?

    Hello everyone,
    I want to load the binary content of a .class file in a dynamic approach. In more detail, I want it to work in the following approach. When given the name of a class, I can retrieve the binary content of the .class file. I have written the following sample but it does not work. Can anyone help to find what is wrong with my sample? How to achieve my goal?
    String className = this.getClass().getName();
    InputStream inputStream = this.getClass().getResourceAsStream (className);When executing the above code, the inputStream is always returned as "null".
    Thanks in advance,
    George

    Thanks ruthf104,
    I haven't tested this, but I think you will need to
    transform the class name
    "test.Foo"
    into the resource path
    "/test/Foo.class"
    ie change '.' to '/', append '/' at the beginning
    and ".class" at the end.
    See the following paragraph from the
    Class.getResourceAsStream specification:
    "This method delegates the call to its class loader,
    , after making these changes to the resource name: if
    the resource name starts with "/", it is unchanged;
    otherwise, the package name is prepended to the
    resource name after converting "." to "/". If this
    object was loaded by the bootstrap loader, the call
    is delegated to
    ClassLoader.getSystemResourceAsStream."
    By these rules, the method will not be able to
    automatically transform the class name into a
    resource path for you (it doesn't append the
    ".class"), so you'll have to do it yourself.I have verified that your approach is working!
    regards,
    George

  • How to load only first set of rows only in pagination of interactive report

    Hi all,
    Iam using 3.2 x and database 10g.
    I have created interactive report and it contains 500000 records. and iam using pagination x to y but background it loads complete rows from database.
    To load complete 500000 records page taking 10 minutes.So My reqiurement is I need to load first set of rows like 500 rows and Once i click next button then only it should load next set of rows like 501 to 1000.
    Please tell any idea to resolve the above problem.
    thanks
    balu

    Balu,
    try to trace your page to see how your statement can be tuned. To do that add &p_trace=YES to the URL.
    This creates a standard Database Trace file which can be analyzed with TKPROF or SQL Developer or similiar tools.
    brgds,
    Peter
    Blog: http://www.oracle-and-apex.com
    ApexLib: http://apexlib.oracleapex.info
    BuilderPlugin: http://builderplugin.oracleapex.info
    Work: http://www.click-click.at

  • How to load an applet with 2 classes and get it to display properly

    Ok I am a very newbie as you can tell by code below but I need help duh. I am a student taking a Java course on my own (ie no marks) so I know what I am doing in a second level java courseI am not sure if my problem is with "Forte for Java 4, CE" or my code. I have two files. Door.java and Exercise4a.java
    The code is as follows:
    Door.java
    package Exercise4.Exercise4a;
    import java.awt.*;
    import java.applet.*;
    public class Door extends java.applet.Applet {
    /** Creates a new instance of Door */
    int x;
    int y;
    public void init() {
    Graphics b;
    public Door(Point aPoint)
    x = (int)aPoint.getX();
    y = (int)aPoint.getY();
    public void paint(Graphics graphics)
    graphics.drawRect(0 + x ,0 + y, 20,30);
    graphics.setColor(Color.black);
    graphics.fillOval(15 + x,15 + y ,5,5);
    graphics.drawImage(buffer,0,0,this);
    public static void main(String args[]){}
    and Exercise4a.java
    package Exercise4.Exercise4a;
    import java.awt.*;
    import java.applet.*;
    public class Exercise4a extends java.applet.Applet {
    Graphics b;
    public void init() {
    Point a = new Point(0,0);
    Door door = new Door(a);
    My problem is that I do not see my door when I compile either file.
    What am I doing wrong? Is this acode problem. ie how do I load the graphics or is it that I am not compiling it correctly.

    package Exercise4.Exercise4a;
    import java.awt.*;
    import java.applet.*;
    public class Exercise4a extends java.applet.Applet {
    Graphics b;
    public void init() {
    Point a = new Point(0,0);
    Door door = new Door(a);// door.paint (b)

  • How to load a specific view in a browser

    Hi Guys,
          In my application, I hav 3 views..I need to set particular view at window level..So How can I do that..Thanks in advance

    Good day,
    Please check my reply in the following thread.
    Re: Change of default view in a web dynpro window
    Regards and Best wishes.

  • DTP: How to load a specific request?

    I have created a DTP between two InfoCube objects. I would like to perform full loads of only a few selected requests from the source InfoCube.
    I couldn't find the request number field in the DTP filter list. How can I accomplish my requirement?
    Thank you for your time.

    You cannot send request vise data.
    Experts correct me if I am wrong.
    Message was edited by:
            Jr Roberto

  • Create a Custom ADFLogger for a specific set of classes

    I have two classes (one for ViewController and one for Model). I want to create a log file for them,because the default shows too much information that is not relevant.

    Miguel,
    it's a good practice to mention your jdev version.
    However my blog http://wp.me/pcBZk-85 might help you.
    Timo

  • SEM-BPS how to load additional data for special users at runtime?

    Let´s assume you have a transactional info cube which contains SD Data from the source system.
    If you want to show additional data, let´s say the attributes of the sold materials which can be read in the table MARA of the source system (provided you use R/3, etc.)
    and you only want to show this data for a small amount of users, which need to see it, then i wonder how to do  this.
    am i right, that i can use the exit functions to init key figures, i.e. i could write some code which connects to the source system over RFC, downloads the data at runtime and presents it at the users excel sheet????
    moreover, is it necessary to extend the existing cube, just to achieve this aim?
    Message was edited by: Gideon Lenz

    Hello Gideon,
    there's no need to program anything. You can display any attribute in planning layouts. In your case you would extract the master data from material from SAP R/3 (MARA) into BW. The setup the layout to show the required attribute(s) in the layout in BPS.
    If the attribute is relevant only for a specific user group, just give them access to this "special" layout (create a planning folder or web interface for this group).
    Regards
    Marc
    SAP NetWeaver RIG

  • Creating an instance of a class at runtime?

    Does anyone know how to create an instance of a class at RunTime? For example, I want to load classes from a JAR file at RunTime, and then create instances of certain classes of each JAR. I ask this because I do not see how to create an instance of one of those classes the traditional way, SomeClass var = new SomeClass(). I am pretty sure that someone out there has done this and succeeded in doing it. All of the post on this stuff only talk about loading the class from a JAR file, but I have already loaded them using URLClassLoader�s findClass() method. I have also created an instance of the class that findClass() returns using newInstance(), but newInstance() returns an object of type Object. How can I convert this object to an object of type SomeClass? You cannot cast it because the compiler will complain due to the import statement issue. So if you cannot include the import statement because that classpath does not exist, then how the heck would you cast the newInstance() object into a SomeClass object?

    You can cast the returned object to the type you need...that is what I do in my applet. The trick is that you must get the instance of the applets class loader (or you get a classCastException). Pay attention to this line below - that's the real key here.
    "// Get a reference to the applets own classloader"
    protected CBaseQuestionnaireFile m_BaseObject = null;// declared up front
    m_BaseObject = loadAndRunClass("com.cpm.dataentry.questionnaire.CQuestionnaireFile");// fully qualified base object
    Here is the load and run method:
       CBaseQuestionnaireFile loadAndRunClass(String classname)
          com.cpm.common.base.CBaseQuestionnaireFile questBase = null;
          Class cClass = null;
          try
             // first we open the jar file with the classes we need
             String[] aJarList = new String[10];
             // Questionnaire format file
             File fURL1 = new File(GetMainFrame().m_strQuestionnaireFileName);
             URL url1   = new URL(fURL1.toURL(),"");
             URL urlNew = new URL("jar:" + url1.toExternalForm() + "!/" );
             // Server base class directory
             String strServerDirectory = "http://" + GetMainFrame().m_strHost + "/APPLETS/";
             File fURL2 = new File(strServerDirectory);
             URL url2 = new URL(fURL2.toURL(),"");
             URL urlNew2 = new URL("jar:" + url2.toExternalForm() + "!/" );
             // Local base class directory
             String strLocalDirectory = CSystem.GetBasePath() + "/Research/bin/";
             File fURL3 = new File(strLocalDirectory);
             URL url3 = new URL(fURL3.toURL(),"");
             URL urlNew3 = new URL("jar:" + url3.toExternalForm() + "!/" );
             File fURLBase = new File(CSystem.GetBasePath() + "/Research/bin/base.jar");
             URL urlBase = new URL(fURLBase.toURL(),"");
             URL urlNewBase = new URL("jar:" + urlBase.toExternalForm() + "!/" );
             File fURLControl = new File(CSystem.GetBasePath() + "/Research/bin/controls.jar");
             URL urlControl = new URL(fURLControl.toURL(),"");
             URL urlNewControl = new URL("jar:" + urlControl.toExternalForm() + "!/" );
             File fURLUtil = new File(CSystem.GetBasePath() + "/Research/bin/utlities.jar");
             URL urlUtil= new URL(fURLUtil.toURL(),"");
             URL urlNewUtil = new URL("jar:" + urlUtil.toExternalForm() + "!/" );
             // Determine where to look
             URL[] urlList = null;
             if(GetMainFrame().m_isStandalone == false) {
                // From a browser
                CSystem.PrintDebugMessage("Running as an applet");
                if(GetMainFrame().m_bOnLineMode == true) {
                   // On line
                   CSystem.PrintDebugMessage("*** On Line Mode ***");
                   urlList = new URL[2];
                   urlList[0] = urlNew;
                   urlList[1] = urlNew2;
                else {
                   // Off line
                   CSystem.PrintDebugMessage("*** Off Line Mode ***");
                   urlList = new URL[4];
                   urlList[0] = urlNew;
                   urlList[1] = urlNewBase;
                   urlList[2] = urlNewControl;
                   urlList[3] = urlNewUtil;
              else {
                 CSystem.PrintDebugMessage("*** Stand Alone Mode ***");
                 urlList = new URL[1];
                 urlList[0] = urlNew;
    CSystem.PrintDebugMessage("Question file/path: " + GetMainFrame().m_strQuestionnaireFileName);
            // Set the wait cursor
            GetMainFrame().SetWaitCursor();
            // Get a reference to the applets own classloader
            Class myClass = getClass();
            ClassLoader appletClassLoader = myClass.getClassLoader();
            // Call our multi-jar class loader
            JarClassLoader jarLoader = new JarClassLoader(urlList,appletClassLoader);
    CSystem.PrintDebugMessage("CPM Test - passed Jar Loader" + jarLoader.toString());
             // Load the classname from the jarfile
             try
                  cClass = jarLoader.loadClass(classname);
             catch(ClassNotFoundException cnfe)
                Object[] optionsConfirm = { "Ok" };
                JOptionPane.showOptionDialog(GetMainFrame(),"Questionnaire file is either damaged or has been tampered with.", "Questionnaire File Error",
                JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsConfirm, optionsConfirm[0]);
                GetMainFrame().m_strQuestionnaireFileName = "";
                // Clear the wait cursor
                GetMainFrame().ClearWaitCursor();
                return null;
             Class cSuperclass = cClass.getSuperclass();
    CSystem.PrintDebugMessage("Test Superclass type is: " + cSuperclass.toString());
             Object o = cClass.newInstance();
    CSystem.PrintDebugMessage("Test plain class type is: " + o.toString());
             // Never remove this line of code
             // without it, a crafty user could use our load routine
             // to load/and run some nasty code
             // This test makes SURE that *ONLY* questionnaires get opened
             // and their methods get called
             if(o instanceof com.cpm.common.base.CBaseQuestionnaireFile)
                // Create the object
    CSystem.PrintDebugMessage("Test Is instance of CBaseQuestionnaireFile");
    CSystem.PrintDebugMessage("CPM Test - Casting to Base Class");
                questBase = (com.cpm.common.base.CBaseQuestionnaireFile)o;
    CSystem.PrintDebugMessage("CPM Test - Getting languages from questionnaire");
                GetMainFrame().GetLanguagesFromQuestionnaire(questBase);
    CSystem.PrintDebugMessage("CPM Test - Setting locale from Questionnaire selection");
                questBase.SetQuestionnaireLocale(GetMainFrame().m_locale);
    CSystem.PrintDebugMessage("CPM Test - Initializing Questionnaire");
                questBase.Initialize();
                questBase.InitializeCards();
              else
                Object[] optionsConfirm = { "Ok" };
                JOptionPane.showOptionDialog(GetMainFrame(),"Questionnaire file is either damaged or has been tampered with.", "Questionnaire File Error",
                JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, optionsConfirm, optionsConfirm[0]);
                GetMainFrame().m_strQuestionnaireFileName = "";
                // Clear the wait cursor
                GetMainFrame().ClearWaitCursor();
                return null;
          catch (Exception e)
              exDialog.showForThrowable(e.toString(),e);
         // Clear the wait cursor
         GetMainFrame().ClearWaitCursor();
         // Set MouseListener Pointer
    //     questBase.SetMouseListenerPointer(GetMainFrame().m_mouseListener);
         return questBase;
       }

  • How can I make server use single class loader for several applications

    I have several web/ejb applications. These applications use some common libraries and should share instances of classes from those libraries.
    But applications are being deployed independently thus packaging all them to EAR is not acceptable.
    I suppose the problem is that each application uses separate class loader.
    How can I make AS use single class loader for a set of applications?
    Different applications depend on different libraries so I need a way that will not share library for all applications on the domain but only for some exact applications.
    When I placed common jar to *%domain%/lib* - all works. But that jar is shared between all applications on the domain.
    When I tried to place common jar to *%domain%/lib/applibs* and specified --libraries* attribute on deploying I got exception
    java.lang.ClassCastException: a.FirstDao cannot be cast to a.FirstDaoHere http://download.oracle.com/docs/cd/E19879-01/820-4336/6nfqd2b1t/index.html I read:
    If multiple applications or modules refer to the same libraries, classes in those libraries are automatically shared.
    This can reduce the memory footprint and allow sharing of static information.Does it mean that classes should be able to be casted ?

    You didn't specify which version of the application server you are using, but the config is similar as long as you know what to look for. Basically, you need to change the classloader delegation. Here's how it is done in 8.2
    http://download.oracle.com/docs/cd/E19830-01/819-4721/beagb/index.html

  • A specific set of websites will not load.

    Operating a Time Capsule behind a cable modem, I now find a very specific set of websites (those that I manage) will not load.  We had a power outage yesterday which did something to my home network I think.
    I have rebooted modem and Time Capsule a number of times.  I have tried access from 2 mac mini's, one iPad and one iPhone.
    IF I direct connect a mac mini to the modem with a cable, I can access the sites.  If I leave the house and work on another wireless network, I can access the sites.  I checked the sites from that network -- they are NOT blocking any IP's.
    If I try to access the sites through the Time Capsule, I cannot.
    I think I just (inadvertently) did a full reset of the Time Capsule -- I had to re-define my network.  (Although it seemed to remember some things ...  )
    SO, I have concluded there is something with the Time Capsule and likely DNS that is preventing my access.  I tried simply changing DNS to public DNS servers (like Google) but that did nothing.
    Best thoughts on how to overcome this?

    Your best bet may be to purposely reset your TC to factory defaults and then set it up again.
    One thing to try from within your home LAN to see if DNS or connectivity is a problem is to simply open a terminal and "ping" the IP address of your webserver.  If you can ping the webserver by IP then you are able to reach it on the Internet.  Then try to ping the webserver by fully qualified server and domain name (i.e. www.example.com).  If ping resolves the name to the IP of your web server then you are fine with DNS as well.  If either of those basic tests fail to resolve the server and receive a reply, then you indeed have some other issue with your TC or internal network.

  • Class Loading on specific diretory

    I am writing a plugin based engine and I want to load up my classes(plugins) from a specific directory besides "classes/com/bla/bla/bla"
    So, I am using this code:
    URL[] url = new URL[1];
    try {
    url[0] = new URL("file:think/");
    catch (MalformedURLException ex) {
    URLClassLoader ucl = new URLClassLoader(url);
    try {
    Class cl = ucl.loadClass(pluginsPackage + "." + "Updater");
    System.out.println(cl);
    catch (ClassNotFoundException ex1) {
    ex1.printStackTrace();
    Actually, if I try something like this:
    new File("think").list()
    will return all my .class files located under that directory.
    Another doubt. when I call URLClassLoader.loadClass(string) I must pass the whole class name like "bla.blabla.blabla.myclass" or just "myclass"
    Class cl = ucl.loadClass("org.com.info.net.thing.Updater")
    (By the way, this ucl.loadClass is giving me the ClassNotFoundException!)
    OR
    Class cl = ucl.loadClass("Updater")
    (By the way, this ucl.loadClass is giving me the NoClassDefFoundError!)
    What Am I doing wrong ?
    If anybody had an idea, please contact me at msn([email protected]) or reply this topic. thank you!

    Actually, if I try something like this:
    new File("think").list()
    will return all my .class files located under that
    directory.
    Is there a question here?No! Thats a statement!
    I am telling that under my current directory, there is a another one, filled with .class files containing classes implementing some base Interface. That interface will be used to instantiate the object.
    Right ?
    Apparently you don't have the class you specified in the right place.Well.. Here is the thing...
    Even if I set the url using something like this:
    url[0] = new File("think").toURL();(You know. this File objet is ok.)
    and then:
    URLClassLoader ucl = new URLClassLoader(url);
    Class cl = ucl.loadClass(pluginsPackage + "." + "Updater");(pluginsPackage + "." + "Updater" = "bla.bla.bla.bla.Updater" )
    (just like you guys told me to do. Fully qualified class name)
    And then:
    java.lang.ClassNotFoundException: br.com.rsl.agent.plugins.think.Updater
         at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
    where is the failure ?
    :(

Maybe you are looking for

  • Sending an email using iBot to a Group

    Hello All, How do I send an email to a group by firing an ibot when users have not added their email device? Thanks!

  • Google woes- here we go again- iweb site stopped coming up in Google

    I have had such great support here- it was only about a month or two ago I got help here getting my site to come up on Google- everything was fine- then all of the sudden- BAM- nothing! It's just as it was before- I would check from time to time to j

  • HDTV thru HDMI will not work correctly

    Recently bought an Ideapad s12 netbook, has been running great. Was trying to hook it up to my bravia hdtv thru the hdmi port. Plugged the hdmi cable in and used the fn key to bring up the screen where you choose which display(s) you want to use. I s

  • N900 - Error in websites requiring java enabled de...

    I bought my device on 16.07.2010 for online stock streaming which requires java enabled device. I tried many sites which provide live stock market price but invain.Let me provide some websites: (1) https://trade.hdfcsec.com/ Or www.hdfcsecurities.com

  • File Associations and 64 vs 32 bit

    Since installing CS4, I've noticed the majority of my 3rd party plugins don't work. I do like keeping the 64 bit version - for when I need maximum RAM useage on huge files, but: how can I set my files to open under the 32 bit version and not 64? Ever