Dynamic ClassLoader - feasability question

Problem: need to be able to 'hot-replace' a class definition at runtime
Particulars:
A method of this class popuplates a hash map with 'key-<anon.class>' pairs, ie:
public void initTransformerMap() {
   xMap.put("Color", new Transformer() {
       public Object transform(Object in) {
           return ((Car)in).getColor();
   xMap.put("Engine Capacity", new Transformer() {
       public Object transform(Object in) {
           return ((Car)in).getEngine().getCapacity().toString() + " cc";
}I need to be able to define new map entries and change existing ones (including the definition of the anon. classes) and load the class in.
Any sensible suggestions are welcome

You can run the java compiler from your program to compile .java files to class files and then load and use the new classes.
You can't replace a class definition once it is loaded. But if you can load different classes with the same name with different classloaders. Which might look like replacing one class with the other.
search the forum/web and you'll find plenty of examples
regards
Spieler

Similar Messages

  • Dynamic Component Creation Question

    I have a process that looks up fields names from a database. I then loop through and create HtmlInputText components dynamically. The question I have is how do I create a value binding to these components? I have been trying to think of a way to create a separate class that can be applied to each field name I retrieve from the database. But I just can't think of a good solution for this. I assume people have had to do this before.
    Thanks

    Let it bind to a List<String> or Map<String, String>. To get/set elements in a List you can use the brace notation, e.g. #{list[0]} for the 1st element (list.get(0)). For map you can use the key name as propertyname, e.g. #{map.key} for the entry associated with key "key" (map.get("key")).

  • Dynamic Classloading

    Hello all,
    Could someone tell me a practical way to setup dynamic classloading in an EJB app? I'd like to set it up such that all of the shared codebase is deployed within the same ear with the EJB application. Is this practical or does dynamic classloading require the use of an external web-server? Right now I am trying to use the rmi.server.codebase system property via the %JAVA_OPTS% env. variable on appserver start-up to point to a servlet deployed in a .war my .ear. What is the practical approach? Thanks in advance.
    Cliff

    Thank you crackers,
    You've cleared alot for me. So if I follow what you're saying then my problem boils down to how my client talks to the server. And the principles of EJB state that the communication details are left to the vendor. All I have to do then is get my home interface via JNDI. This assumes of course that the stubs are available on the client.
    Now don't get me wrong here, I'm not trying to debate the advantages of EJB. I'm just trying to illustrate my dillemma and find a plausible solution. In my scenario I'm not really all that concerned with the transport layer (well I am concerned with the leaky abstractions therein but that's another story). I'm primarily concerned with versioning issues. I cannot maintain classes installed on the client as they could potentially fall out of date with the server. I need a dynamic classloading mechanism, which I thought would be provided with EJB as it is with RMI. I just naturally assumed it would be since EJB is typically (though not always, as you point out) layered always RMI. If you're saying that there is no such facility then I will have to find an alternative solution for my problem. You see I have no choice and I must concern myself with the underworkings of EJB as there are leaky abstractions within the technology. While it is a powerful technology it does not solve all of my problems. Also, I need to fill these holes in a vendor neutral way.
    Cliff

  • Dynamic ClassLoader

    Hi there,
    i am trying to program a dynamic classloader in Abap. by now i came this far:
    DATA classname TYPE string VALUE 'ZCL_TEST'.
    DATA dref TYPE REF TO data.
    DATA type_descr TYPE REF TO cl_abap_typedescr.
    FIELD-SYMBOLS <ref> TYPE ANY.
    type_descr = cl_abap_typedescr=>describe_by_name( p_name = classname ).
    classname = type_descr->absolute_name.
    CREATE DATA dref TYPE REF TO (classname).
    ASSIGN dref->* TO <ref>.
    CREATE OBJECT <ref> TYPE (classname).
    dref->to_string( ). -----> ERROR
    The ClassLoading itselfs works perfectly, but now i don't know how to call a method of that class... Can't beliieve that i can instantiate a Class but not call a method?!?
    So has someone done it already and can point me the right way?
    Thanks
    Mathias

    I don't know what would be the use of creating the object with REF TO DATA and than assign it back to the variable REF TO OBJECT to be able to access the data.
    CREATE DATA dref TYPE REF TO
               ('\program=kellerh_test\interface=i1').
    Here you are creating the TYPE at runtime which is type referent to the Interface. You get the object reference to the Field-Symbol. But Since field-symbol is not allowing to access the attributes, we need to cast that into the variable TYPE REF TO OBJECT.
    Check this code:
    REPORT  ztest_np_1.
    INTERFACE i1.
      DATA: w_num TYPE i.
    ENDINTERFACE.                    "i1
    CLASS c1 DEFINITION.
      PUBLIC SECTION.
        INTERFACES i1.
    ENDCLASS.                    "c1 DEFINITION
    DATA dref TYPE REF TO data.
    FIELD-SYMBOLS <ref> TYPE any.
    CREATE DATA dref TYPE REF TO
               ('\program=ZTEST_NP_1\interface=i1').
    ASSIGN dref->* TO <ref>.
    CREATE OBJECT <ref> TYPE c1.
    FIELD-SYMBOLS <attr> TYPE ANY.
    DATA: lo_obj TYPE REF TO object.
    lo_obj ?= <ref>.
    ASSIGN lo_obj->('I1~W_NUM') TO <attr>.
    <attr> = 10.
    WRITE: 'Test'.
    Regards,
    Naimesh Patel

  • Dynamic classloading without default constructor

    Just wondering if anyone has done dynamic classloading using a constructor other than the default. I know that newInstance() calls the default constructor. But how would you do it without that? Thanks for the help.

    If you know that there is a constructor that takes,
    for example, a single String argument you can use
    something like this:
    Class clazz = ...; // class to instantiate
    String stringArg = ...; // argument to pass to constructor
    Constructor c = clazz.getConstructor( new Class[] { String.class } );
    Object value = c.newInstance( new Object[] { stringArg > } );
    And even better, when JDK 1.5 is released, you'll be able to write:
        Class clazz = ...;
        String stringArg = ...;
        Constructor c = clazz.getConstructor(String.class);
        Object value = c.newInstance(stringArg);Geoff

  • Dynamic Link complicated question

    This is the story.....
    1. I shot & edited a training session (many sessions - over 40 hours)
    2. I did minor editing in Premiere, used Dynamic Link to send to Encore, set up a first run title page with 8 links to the 8 chapters.(all end actions going back to the main menu)
    3. Burned a DVD for the client
    4. The client made notes for additional changes for me to edit.
    5. I went back into Premiere, made the editing changes (mostly increases in volume from audience questions, removing some comments, etc.)
    Now... If I try and use Dynamic link again to "re-send" to Encore, my only choice is a new project... I cannot send using Dynamic link to an existing project (or if I can, I do not know how)
    I know one work around is to encode from Premiere, then open a Encore project, import as a timeline.... & author away....
    This way, If I go back to Premiere, make editing changes, export back out WITH THE SAME FILE NAME.... when I open the existing Encore project... everything is the same... except the timeline has the updated editing changes...
    The only problem is that on all 18 DVD's, I used dynamic link to send to Encore... so does that mean, (unless I use a work-around, like stated above), I have to re-author all 18 DVDs. I would think that even when using dynamic link, if you open the timeline again in Premiere, make editing changes, that the Encore project would reflect those changes (to make sure, I set the audio volume to 0 on the first 10 seconds in Premiere, saved the project & closed it, opened Encore, did a preview, the audio was still at the regular volume (no change).....
    Any suggestions...
    Or should I just once again use dynamic link, start a new Encore project, re-author (& basically do the same thing over)?
    Or should I do it the other way, encode from Premiere, (you know the rest), I do believe that all the editing changes have been made (according to the client)
    Or, is there some way from Premiere to use Dynamic link to send to an existing Encore project?
    David Kelley

    I didn't read all your note carefully.
    In your previous Encore project for DVD 1 (or whatever), right click on the "asset" for the timeline (the asset for a dynamic link is the Premiere sequece, not the Encore timeline that was created), and pick "revert to original." It should pick up your changes from Premiere.
    Note that to update markers, you must select the video in the Encore timeline itself, right click, "update markers from source." You will lose all previous markers. If you created the markers in Encore, you must update manually.

  • 802.1x Dynamic VLAN Switching Question

    Trying to set up 802.1x dynamic VLAN switching, and have a question. I think I've gotten it working except for one part. The VLAN on a protected interface is never getting switched. I can see an entry in the ACS stating that it applied the appropriate VLAN via RADIUS response, but it never changes on the switch.
    Environment:
    ACS Express 5.0.1
    C3550 running c3550-ipbasek9-mz.122-44.SE6.bin
    Switch config:
    aaa new-model
    aaa group server radius dot1x
    server-private 10.10.1.4 auth-port 1645 acct-port 1646 key 7 071C244F5C0C0D544541
    aaa authentication dot1x default group dot1x
    dot1x system-auth-control
    dot1x guest-vlan supplicant
    interface FastEthernet0/3
    switchport access vlan 3
    switchport mode access
    speed 100
    duplex full
    dot1x pae authenticator
    dot1x port-control auto
    dot1x violation-mode protect
    dot1x timeout tx-period 5
    dot1x timeout supp-timeout 5
    spanning-tree portfast
    ip radius source-interface FastEthernet0/1 vrf default!
    radius-server host 10.10.1.4 auth-port 1645 acct-port 1646 key 7 01000307490E125E731F
    Am I missing something easy?

    It looks like "aaa authorization network default group dot1x" was the missing command I needed to get this working.
    The only issue I'm having now is that if the client fails to meet the authentication requirements, the line status gets set as "down"

  • Dynamic Table Creation Question

    Can you dynamically add a column to a data table at run time using JSC and JSF? I have a case where I want to add a column to a table based on a selection by the user.

    Hi
    I have been trying to this when I saw your question first time two days back. I tried changing the rowset's query but nothing seems to work. I will try again and I am sure that I can give you something on this if there is any straight solution to this.
    Thanks
    Srinivas

  • Older Business HTML and Dynamic Page Table question

    I am not sure if anyone will know here (or if this is the best place to post), but I have a question concerning using the Business HTML template library controls/API for use with ITS. I am attempting to use the "Dynamic Page Table" control, and have hit some problems. Does anyone have any example code they can share on getting this to work correctly (ie, paging through records, selecting from rows, etc)? I have "torn apart" the underlying Javascript and even modified my code to adjust for some formatting issues that the API's do not handle, however, my "pages" all display at once in the beginning and only hide when I use one of the paging icons (forward,back,all back, etc). THe "isVisible" parameter seems to do nothing for the "page" DIVs. Currently running the latest version of ITS and R/3 4.6b on the backend if that helps. Also, the example from the SAP Design Guild cookbook is very basic and does not "page" as I need. Thanks in advance!
    CSolomon

    Check the following Tables
    FND_FORM_CUSTOM_RULES
    FND_FORM_CUSTOM_SCOPES
    FND_FORM_CUSTOM_ACTIONS
    FND_FORM_CUSTOM_PARAMS

  • Dynamically add component question?

    Hi:
    Here is part of my code in short:
    public class TextInputWithAutoComplete extends TextInput
    private function addComp():void{
    list = new List();
    list.id = "autoCompleteList";
    list.x = 0;
    list.y = 20;
    list.addEventListener(MouseEvent.MOUSE_UP, handleMouseDown);
    parentDocument.addChild(autoCompleteList); OR addChild(autoCompleteList); //my question is here
    private function handleMouseDown():void{
    //TODO
    I realized that if I do addChild, I can't really see the dynamically added component, since flex did not reserve space for my List to display. So I do parentDocument.addChild, and then the component appears no problem. My question is since it's being added in the parentDocument, so it is suppose to be a component belong to parentDocument, so is that component still be able to call this handleMouseDown?
    From my experience, it's still able to, but which doesn't make sense to me.
    Can someone explain a little about why it can still work, or any better approach other than parentDocument.addChild
    Thanks.

    In Flex there is a lifecycle that represents the contract between the component and its parent.  See the chapters on creating custom components and the lifecycle methods createChildren, commitProperties, measure and updateDisplayList.
    Some components size to content like Containers.  When you add a child to a container it will measure the child and make room for it or add scrollbars if there isn't enough room.
    If you add a child to TextInput, it doesn't expect additional children so it will not make room for it.  You can subclass and override its measure and updateDisplayList methods to make room for an additional child.
    I would not recommend adding another interactive control to an interactive control since that will make managing focus and accessibility much harder.  It is better to group these in a container in most cases.
    The reason the mouse handler still gets called is because a handler can be on any object whether it is a child or sibling or parent and will be called by the object dispatching the event if the handler is listening to that object.  If you had attached the handler to "this" it would not get called when the List is not a child of "this".
    Alex Harui
    Flex SDK Developer
    Adobe Systems Inc.
    Blog: http://blogs.adobe.com/aharui

  • Mapview dynamic theme generation questions

    In exercising the MapViewer tool with thematics map I had a view questions on the capabilities of the component:
    1. Is there a way in the map _request element reference a dynamically defined expression (column)
    that is returned from the query defined in the value of the "<jdbc_query>" element. I want to show counts from an inline view,
    but for brevity consider the the SQL
    select geom, state , state || '-' || state_abrv concat_state_name from states
    It seems that both the "label_column" attribute of the "<jdbc_query>" element and the "column" attribute of a "<rule>" element in
    a style rule can only reference columns that exist in the base table either of the base map/theme or in the query .
    I cannot seem to use a specification of "concat_state_name"
    in the "label_column" attribute ... throws ClassCastException. Should this be possible ?
    If not would the workaround would appear to use a view that is dynamically defined and insert a new map based on the view ?
    2. In my inline view example, I found in the "<jdbc_query>" element that when I specifed a "render_style" that
    was an advanced style with buckets it automatically selected my count expression and rendered the map correctly, which
    is great, but it might be a good idea to make it explicit if 1. could be handled (or can).
    3. For thematic maps it would be nice to dynamically define the buckets (<AdvancedStyle>)
    within the map request as the potient for permutations of numeric ranges in any application could vary.
    It looks like <styling_rules> might be able to handle this if you can use the BETWEEN operator or something
    like runway_number >= 10 and runway_number < 20 as expressions. Are these valid and if so where are they specified
    in the map_request ? I did not see them nested anywhere in the DTD yet the Example 2-1 in the documentation would
    imply they can be specified in the map request and the tool map definition tool does not seem to support the concept of a
    variable in the base table. The workaround would appear to be to dynamically add the theme using an insert.

    In exercising the MapViewer tool with thematics map I had a view questions on the capabilities of the component:
    1. Is there a way in the map _request element reference a dynamically defined expression (column)
    that is returned from the query defined in the value of the "<jdbc_query>" element. I want to show counts from an inline view,
    but for brevity consider the the SQL
    select geom, state , state || '-' || state_abrv concat_state_name from states
    It seems that both the "label_column" attribute of the "<jdbc_query>" element and the "column" attribute of a "<rule>" element in
    a style rule can only reference columns that exist in the base table either of the base map/theme or in the query .
    I cannot seem to use a specification of "concat_state_name"
    in the "label_column" attribute ... throws ClassCastException. Should this be possible ?
    If not would the workaround would appear to use a view that is dynamically defined and insert a new map based on the view ? MapViewer does allow dynamic expressions in <jdbc_query>. Can you test the following simple request:
    <?xml version="1.0" standalone="yes"?>
    <map_request datasource = "mvdemo">
    <themes>
    <theme name="theme1" min_scale="5.0E7" max_scale="0.0">
    <jdbc_query
    datasource="mvdemo"
    jdbc_srid="0"
    spatial_column="geom"
    render_style="C.RED"
    label_style="T.STREET NAME"
    label_column="concat_state_name"
    >select geom, state , state || '-' || state_abrv concat_state_name from states where state_abrv='MA' </jdbc_query>
    </theme>
    </themes>
    </map_request>
    As long as the name specified in lable_column matches the alias you give in the select list it should work.
    If not then maybe you need to use the view-based approach. It will definately work in the up-coming 9.0.4 version.
    2. In my inline view example, I found in the "<jdbc_query>" element that when I specifed a "render_style" that
    was an advanced style with buckets it automatically selected my count expression and rendered the map correctly, which
    is great, but it might be a good idea to make it explicit if 1. could be handled (or can).
    3. For thematic maps it would be nice to dynamically define the buckets (<AdvancedStyle>)
    within the map request as the potient for permutations of numeric ranges in any application could vary.
    It looks like <styling_rules> might be able to handle this if you can use the BETWEEN operator or something
    like runway_number >= 10 and runway_number < 20 as expressions. Are these valid and if so where are they specified
    in the map_request ? Yes that may indeed be a good thing to have in a future version of mapviewer. In the mean time yes you can always use such expressions as you provided in the styling_rules (which is only for predefined themes) or in a <jdbc_theme>.
    I did not see them nested anywhere in the DTD yet the Example 2-1 in the documentation would
    imply they can be specified in the map request and the tool map definition tool does not seem to support the concept of a
    variable in the base table. The workaround would appear to be to dynamically add the theme using an insert. The map definition tool is lagging behind in terms of supporting all the functions actually available in MapViewer server.
    Thanks,
    LJ

  • RMI dynamic classloading problems

    I wanted to know if you could help me answer this particular case,
    which i still haven't been able to solve in days:
    1>RMI Client and Server are on different hosts.
    2>the Client makes a RMI method call to a Server who has to execute
    dynamically a particular classfile specified by the client itself and
    return the result to the client
    PROBLEM IS:
    at the beginning only the client has the classfile to be executed by
    server and needs to transfer him the information in order to have its
    RMI method executed,and no ohter protocols except for RMI are
    allowed.
    QUESTION IS:
    how could i solve this case with the use of codebases and
    URLClassLoader Objects?
    hoping i've clearly made the point,thanXalot
    nicholas

    The client can set its own codebase. The client class that the server will call needs to implement an interface the server knows. Then the client will pass this object to the server, and the server will make its call on that object. Since this object is not exported it will be serialized to the server, and the call will run on the server.
    Quite insecure. But it should work just that simply I do believe.
    You do know how to use codebase?

  • Dynamic classloading and incompatibleclasschangeerror

    I have different versions of my applications like v1 v2 v3 and my current version is v4.
    In my case, v4 might need to talk to v3, v2 or v1. To achevie that I need that same versions of classes from the respective versions of the applications i.e. I will make jars like v3.jar, v2.jar and v1.jar which will be loaded dynamically using my own custom class loaders. When v4 trying to access v3 it uses the classes using the classloader which loaded v3.jar
    v4 contacts v3, v2, v1 through RMI.
    Now the problem is when v4 is calling a remote method of v3 I am getting IncompatibleClassChangeError
    I tried to recompile all the required classes in v3 and created a new v3.jar and I have loaded the same dynamically in v4. I also recompiled all the classes of v4, but still the result is same.
    Both v3 classes and v4 classes are compiled using the same JRE version.
    Can somebody help me to figure out what could be the issue.
    Thanks

    If you know that there is a constructor that takes,
    for example, a single String argument you can use
    something like this:
    Class clazz = ...; // class to instantiate
    String stringArg = ...; // argument to pass to constructor
    Constructor c = clazz.getConstructor( new Class[] { String.class } );
    Object value = c.newInstance( new Object[] { stringArg > } );
    And even better, when JDK 1.5 is released, you'll be able to write:
        Class clazz = ...;
        String stringArg = ...;
        Constructor c = clazz.getConstructor(String.class);
        Object value = c.newInstance(stringArg);Geoff

  • Dynamic stub downloading question.

    It turned out that I've been killing time over and over again when setting up dynamic stubs downloading for RMI implementations.
    Wouldn't be it simple if RMI isolates developer from all those steps by
    a) creating stubs on the fly when the remote object gets bound and
    b) upload them to the client as a part of Naming.lookup() call?
    No need to rmic, http-/ftp-/file--server, additional security, etc. Can somebody explain me this or I am missing something here??
    Thanks.

    It turned out that I've been killing time No, you havent been killing time.
    over and
    over again when setting up dynamic stubs downloading
    for RMI implementations.
    Wouldn't be it simple if RMI isolates developer from
    all those steps by
    a) creating stubs on the fly when the remote object
    gets boundDo you know what this will ultimately mean? It means that some PROCESS, either the registry or something else, will NEED TO LOOK AT THE OBJECT THAT IT HAS ACCEPTED TO BE BOUND, OR IS JUST ABOUT TO ACCEPT TO BE BOUND and then check to see if it REALLY does extend the proper superclasses (UnicastRemoteObject for plain RMI, or PortableRemoteObject for all those RMI-IIOP lovers out there), THEN check if the service object REALLY DOES implement the remote interface TO THE LETTER, ........THEN check to see if the proper exceptions are going to be thrown if something goes wrong!!
    (i'm panting right now.....)
    That's simply madness. Do you have any idea how often an object can be:
    1: Bound to the registry
    2. REBOUND under a different name
    3. Removed and later REBOUND
    ?????? Its sick. The JVM/registry overhead will hit the roof!!!
    ok, lets go on....
    and
    b) upload them to the client as a part of
    Naming.lookup() call?What?? IS IT FOR THE CLIENT TO TRY AND CONNECT TO THE SERVER USING STUBS IT ALREADY HAS .......or is it for the server to somehow keep TABS on its client and SEND the stubs to it, just so it can talk to the server???????
    Doesnt make sense at all.
    >
    No need to rmic, http-/ftp-/file--server, additional
    security, etc. Can somebody explain me this or I am
    missing something here?Oh, buddy: you ARE missing something.

  • Dynamic Parameter List questions: Length and Custom Values

    I've got a Crystal Report that I want to use Dynamic Values for.
    Right now... this report is simply a "SELECT stuff  FROM table" SQL query... with a parameter that the report uses to filter.
    I use a "Select DISTINCT value from table" to generate a list of values. I put those values into a txt. I then import the text into a static list. This creates a parameter list that is 11 "pages" long on the parameter screen. I also have "custom" values allowed. This is to allow for "new" values and also allow not needing to browse 11 pages for one or two known values.
    If I turn the parameter into a Dynamic List based on the same Select statement it stops at 5 pages, obviously cutting off half of the possible values.
    Dynamic List also removes the ability to do Custom Values. The filter option wouldn't be a bad alternative BUT it don't work for pages 6+ that aren't there.
    How can I remove the 5 page limit (or whatever it is) for Dynamic values?
    Thanks
    Chris
    Edited by: WernerCD on Aug 4, 2010 4:14 PM

    There is a limit of 1000 records in dynamic parameters. You can change this by adding a registry value:
    registry key : HKEY_CURRENT_USER\SOFTWARE\Business Objects\Suite 11.0\Crystal Reports\DatabaseOptions\LOV
    and then add a key called MaxRowsetRecords and give it a value.
    if you have Crystal 2008 then the above registry folder will say Suite 12.0.

Maybe you are looking for