Dynamic Loding a class
Hi,
How can i load a class dynamically?explain me and give me small example
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Class.html
use method forName:
try {
Class.forName("ClassName");
} catch(Exception exc) {
System.out.println("Can't find class: " + exc);
return;
}
Similar Messages
-
I've started getting an intermittent error editing my Windows 7 OSD task sequence. Sometimes I can open the TS to edit, but when I try to apply changes I get the error. Other times I get the error when trying to open the TS. If I try again
right away, I still get the error, but if I wait a few minutes and try again sometimes it will open the TS.
The error reads:
ConfigMgr Error Object:instance of SMS_Extended Status{Description = "Failed to load dynamic properties for class \"SMS_TaskSequence_ApplyWindowsSettingsAction\" from XML into WMI";Error Code = 2147943746;File = "e:\\qfe\\nts\\sms\\siteserver\\sdk_provider\\smsprov\\ssptspackage.cpp";Line = 3454;Operation = "ExecMethod";ParameterInfo = "SMS_TaskSequencePackage";ProviderName = "WinMgmt";StatusCode = 2147749889;}
Coinciding with this error, I show the following entries in the TaskSequenceProvider.log file:
[PID: 7608] Invoking method SMS_TaskSequence.LoadFromXml
TaskSequenceProvider
Failed to protect memory buffer, hr=0x80070542
TaskSequenceProvider
Failed to load dynamic properties for class "SMS_TaskSequence_ApplyWindowsSettingsAction" from XML into WMI 0x80070542 (2147943746)
TaskSequenceProvider
Failed to load node Apply Windows Settings from XML into WMI 0x80070542 (2147943746)
TaskSequenceProvider
Failed to load children steps for node "PostInstall" from XML 0x80070542 (2147943746)
TaskSequenceProvider
Failed to load children steps for node "Execute Task Sequence" from XML 0x80070542 (2147943746)
TaskSequenceProvider
Failed to load children steps for node "" from XML 0x80070542 (2147943746)
TaskSequenceProvider
Failed to load XML for the task sequence into WMI 0x80070542 (2147943746)
TaskSequenceProvider
[PID: 7608] Done with method SMS_TaskSequence.LoadFromXml
TaskSequenceProvider
Setting status complete: status code = 0x80070542; Failed to load dynamic properties for class "SMS_TaskSequence_ApplyWindowsSettingsAction" from XML into WMI
TaskSequenceProvider
I exported the task sequence and checked in "object.xml" for the "ApplyWindowsSettingsAction", to see if there was something odd in the xml, but I don't find anything that jumps out as being wrong. Here's the section of XML for
that step. I've removed identifying info, and replaced it with a generic term in bold.
<step type="SMS_TaskSequence_ApplyWindowsSettingsAction" name="Apply Windows Settings" description="" runIn="WinPE" successCodeList="0" runFromNet="false"><action>osdwinsettings.exe /config</action><defaultVarList><variable name="OSDLocalAdminPassword" property="AdminPassword"></variable><variable name="OSDComputerName" property="ComputerName">%_SMSTSMachineName%</variable><variable name="OSDProductKey" property="ProductKey"></variable><variable name="OSDRandomAdminPassword" property="RandomAdminPassword">false</variable><variable name="OSDRegisteredOrgName" property="RegisteredOrgName">COMPANY NAME</variable><variable name="OSDRegisteredUserName" property="RegisteredUserName">COMPANY NAME</variable><variable name="OSDServerLicenseConnectionLimit" property="ServerLicenseConnectionLimit">5</variable><variable name="OSDTimeZone" property="TimeZone">Central Standard Time</variable></defaultVarList></step><step type="SMS_TaskSequence_ApplyNetworkSettingsAction" name="Apply Network Settings" description="" runIn="WinPEandFullOS" successCodeList="0" runFromNet="false"><action>osdnetsettings.exe configure</action><defaultVarList><variable name="OSDDomainName" property="DomainName">DOMAIN.COM</variable><variable name="OSDJoinPassword" property="DomainPassword"></variable><variable name="OSDJoinAccount" property="DomainUsername">DOMAIN ACCOUNT</variable><variable name="OSDEnableTCPIPFiltering" property="EnableTCPIPFiltering" hidden="true">false</variable><variable name="OSDNetworkJoinType" property="NetworkJoinType">0</variable><variable name="OSDAdapterCount" property="NumAdapters" hidden="true">0</variable></defaultVarList></step>
Is there any other log I should check for a clue on this issue? What could be causing this error?Thanks for sharing that! I tend to save contacting MS support until after I've exhausted other options. I'm always afraid that I'll spend the $500 to open a case and then it turns out to be something simple that I would have found if I had just
kept working on it myself a little longer.
It looks like that link is for an update released in February as KB3023562. I downloaded and installed it. I'll try opening/editing/saving the task sequence a few times today to see if the issue is resolved.
After I had already installed it, I thought to look up that update in configmgr. The update is listed as superseded by 2 other updates. The newest of those is KB3046049, which just installed last night with the other March patches, so it's possible
that I didn't need to install KB3023562 after all. -
Dynamically loading a class that is part of a larger loaded package
I am dynamically loading a class that is part of a large package, much of which is loaded at startup. The code directly references protected variables in the parts of the package that is loaded by the default class loader. Attempting to access these protected variables gives an access error when the class is dynamically loaded that doesnt occur when the class is loaded at startup.
Is there a way to make this work?To answer my own question -- no
A reference from http://access1.sun.com/techarticles/DR-article.html says:
The use of Dynamic Class Reloading can introduce problems when classes that are being dynamically reloaded make calls to non-public methods of helper classes that are in the same package. Such calls are likely to cause a java.lang.IllegalAccesserror to be thrown. This is because a class that is dynamically reloaded is loaded by a different classloader than the one used to load the helper classes. Classes that appear to be in the same package are effectively in different packages when loaded by different classloaders. If class com.myapp.MyServlet is loaded by one classloader and an instance of it tries to call a non-public method of an instance of class com.myapp.Helper loaded by a different classloader, the call will fail because the two classes are in different packages.
So not being able to access non-private variables in this scenario is the way it works. -
Dynamic Java bean classes for XSD using JAVA (not any external batch or sh)
Hi,
How can we generate dynamic Java bean classes for XSD (dynamically support All XSD at runtime)?
Note: - Through java code via only needs to generate this process. (Not using any xjc.bat or xjc.sh from JAXB).
ThanksMuthu wrote:
How can we generate dynamic Java bean classes for XSD (dynamically support All XSD at runtime)?
Pretty sure you can't. Probably can do a lot of them with years of work.
And can probably can do a resonable subset suitable for the business at hand with only a moderate effort.
Note: - Through java code via only needs to generate this process. (Not using any xjc.bat or xjc.sh from JAXB).The Sun jdk, not jre, comes with the java compiler as part of it. You can create in memory class (I believe in memory) based on java code you create.
I believe BCEL alllows the same thing (in memory) but you start with byte codes.
You could just create a dynamic meta data solution as well, via maps and generic methods. Not as fast though. -
Using keyword dynamic before a class
Hi ,
I have seen some examples on to Flex , where when creating a ValueObject with ActionScript , they specify the word dynamic before
the class .
For example see the below code .
public dynamic class Employee
private var name:String ;
private var age:String ;
public function Employee()
Thank you .So your question probably is what the dynamic keyword does?
Flex 3 livedocs is your friend: http://livedocs.adobe.com/flex/3/html/help.html?content=03_Language_and_Syntax_10.html -
F4 Help for a dynamic input field( class CL_DD_INPUT_ELEMENT)
Hi all,
I am programming a dynamic document which has several input fields on it. I want to program F4 helps for these fields, does anyone have an idea how I can do that?
I have the idea to program a button(class CL_DD_BUTTON_ELEMENT) next to the input field and manually program an F4 help in the event handler of the button. But I do not know how I can handle pattern entries with '*' etc. in the input field. Is there a function module which could give me an F4 list(F4IF_INT_TABLE_VALUE_REQUEST could not be used, because it needs a dynpro field as a return field, which we do not have in this case).
Kind Regards,
Sükrühi
good
SELECTION-SCREEN DYNAMIC SELECTIONS FOR NODE|TABLE node.
allows you to define further nodes for dynamic selections. If the node has type T, you can use TABLE instead of NODE. The user can then decide at runtime the components of the node for which he or she wants to enter selections. Dynamic selections require special handling in the database program
F4 HELP->
AT SELECTION SCREEN ON VALUE REQUEST FOR P_SACHA.
PERFORM VALUES_SACHA.
THANKS
MRUTYUN^ -
Dynamic creation of class at runtime
I need to be able to dynamically create an instance of a
class that isn't known until runtime - actually based on the
filename
so in my fla:
var className:String="Test"; /* code to get a class name
derived from the filename */
var obj = new [className]();
trace(obj);
the code above only works if i put the literal directly in [
like so:
var obj = new ["Test"]();
is there a way to do this???
Any help much appreciated
cheers SteveThis might help you out:
http://dynamicflash.com/2005/03/class-finder/
"steveanson" <[email protected]> wrote in
message
news:e3fcnv$6c7$[email protected]..
> I need to be able to dynamically create an instance of a
class that isn't
known
> until runtime - actually based on the filename
>
> so in my fla:
> var className:String="Test"; /* code to get a class name
derived from
the
> filename */
> var obj = new ();
> trace(obj);
>
> the code above only works if i put the literal directly
in
> like so:
> var obj = new ();
>
> is there a way to do this???
> Any help much appreciated
> cheers Steve
>
>
> -
Dynamically create a class based on database tables
I am trying to build a database and tables on the fly, and save to the harddisk(done). Then I need to create a class using the info from the tables on the fly.
For example,
I built a database BANK, and a table Customer,
Customer
ID
Phoneno
Address
Could I create a class named CUSTOMER (table name)
dynamically, and have ID, PHONENO, ADDRESS,as the attributes of the class?
Could anyone help or show the direction?
Cheers.You could use a HashMap, and use the String keys "Customer", "ID", etc, and if you have primitive values like an int, you just wrap it inside Integer or any of the other wrapper classes, because HashMap only works with objects.
Then you can use an ArrayList to hold all the records (one record is one HashMap as described above). -
Dynamic Call Function/Class Method
Hi,
I have a requirement for which I need your help.
I want to Call a Method dynamically inside a program. how to do it?
My another quary is that how to call more than one class method dynamicaly in the program one at a time, based on certain conditions.
All the requirements mentioned above feels awakward to me, but are they feasible. Eagerly waiting for a reply.
Regards,
Pulokesh
Moderator message - Cross post locked
Edited by: Rob Burbank on Oct 26, 2009 9:48 AMHello,
you can call a Method like this where the name of the method is concatenated.
CONCATENATE 'SC_' me->gf_scenario '_SAVE' INTO lf_method.
CALL METHOD me->(lf_method).
Than I can imagine to loop over a tabele with all the Method Call to be executes un there:
Loop at gt_meth_calls into ls_meth_call.
ls_meth_call-object_instance->(ls_meth_call-meth_name).
endloop.
The table should be structured such that the first component contains a reference to the instance and the second component will be the Method name to run. -
Dynamic or Static Objects
It seems to me there is a big cliff at the point of deciding to instantiate your class at runtime or static load
on start-up.
My swf apps have a pent-up burst that happens a couple seconds into the run. I think I get this on most
web pages that have flash banners.
Flash apps that have a loader bar can take 60 secs. These ones usually come on with a bang with a lot of
high quality graphics.
Therer is a big processor spike at start-up with the browser loading http page. Flash seems to want a big spike
with its initial load. The javascript embed doesn't help either.
How to get a smooth start-up? Me English good.
This seems like a matter of correctness, only indirectly relating to speed.
The speed that a SWF loads from a web page is determined by many things, like server connection speed, client connection speed, browser cache size, client RAM, etc. Having static vs. dynamic classes would not impact this very much.
First of all, "static objects" is kind of an oxymoron because you can't instantiate (create an object) of a static class. I would say that having static variables/methods in a class is usually when you want some shared values/functionality without requiring an actual object (taking up memory) -- although static practices certainly extend beyond just this. I always try to think of a Math class. You wouldn't have to have to say m = new Math() just to use some common methods (square, sin, cos, etc.) or values (pi, e, etc.). They become kind of like "global constants/methods" in a sense (not to invoke the debate over correctness of that wording).
In short, it's more of a memory issue, which will like not have much influence over loading speed. If you want to improve your loading speed, you can try to delay the creation of your objects based on certain events instead of having them all load at startup.
How to get a smooth start-up? Me English good. -
Dynamically Loading a Class with Parameters
Hi,
I'm working on small program during my spare time and I have run into a problem. I have one abstract class (Foo) which is extended by several other subclasses (subFoo1, subFoo2). I am trying to avoid making a whole host of if statements depending on user input by coding in dynamic class loading.
The newInstance() method I've read about works well except that it does not accept arguments, something that I sorely need:
Foo a = Class.forName(input).asSubclass(Foo.class).newInstance();The other method works for creating the objects but I get an error:
Class foo = Class.forName(input);
Constructor cons = cs.getConstructor(new Class[]{String.class, Long.TYPE});
Object a = cons.newInstance(new Object[]{ FooString, FooInt});
a.method()
cannot find symbol
symbol : method(java.math.BigDecimal)
location : java.lang.ObjectI can understand the problem that the new 'Object' can't find the methods of 'foo', but i don't know how to solve the problem.Object a = cons.newInstance(new Object[]{ FooString, FooInt});
a.method();That isn't very strange, is it? a is an Object, and class Object doesn't have the method you're calling. You have to cast it to a Foo:
Foo a = (Foo)cons.newInstance(new Object[]{ FooString, FooInt});
a.method(); -
Dynamic names for class and variable
Hi Folks,
How do you make a new instance of a class with a dynamic name.
var dynamicname = new dynamicname()
i try something
var this["test"]:Class = new ["Test"]()
but offcourse its not this...
I need this couse i have a librairy with SWC fonts they are only reference.. I get the font name from a CSS file and after i need to make a instance of the SWC file so the font is embedded.
Thanks anyone who can help me!
Cheer, MichierlBtw Murphy its not working......
var fontRef = Class(getDefinitionByName("Arial"));
var font = new fontRef();
trace(font);
The varibable definition not defined.
I have 5 fonts as SWC Files set as reference lib in flex.
But i dont wann to load all fonts yet cosue that will make my movie 200kb ... so i copy the fontname of the stylesheet and then make a instance of that font class.
But how? With yours it need already a refrences to that class. -
Trouble w/ multiple applets dynamically starting and Class.forName()
I'm trying to start applets dynamically and I see strange behavior on some systems it works fine and gets the applet class from the jar file. On other systems it makes an http request back to the server to try and get the class. I don't know where in the Class or ClassLoader it's deciding whether to get this class from the jarfile or from the server and all of these classes are contained in the jarfile? Any suggestions?
Here's the method to start new applets
public Component startApplet( String className ) {
System.out.println("Starting applet "+className);
Class appletClass = null;
JApplet japplet = null;
try {
appletClass = Class.forName("com.actsolar.ui.applet."+className);
System.out.println(appletClass);
japplet = (JApplet)appletClass.newInstance();
japplet.init();
} catch (Exception e) {
System.out.println("startapplet Exception: "+e.getMessage());
return japplet;
thanks,
andrewHi,
I have seen the same problem when I mix up small letters and BIG LETTERS.
Ex :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<applet code="Function3.class"width="100" height="100">
</applet>
</html>
will work with Function3.class
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<applet code="function3.class"width="100" height="100">
</applet>
</html>
Will NOT work.
Maybe this will help you , I am also new on JAVA so maybe you make the same mistake like I did ?
Best Regards,
Didier. -
Problem with Dynamically accessing EJB Class objects in WL 7.0 SP1
I am trying to build a component which has the ability to instantiate and execute
an known EJB method on the fly.
I have managed to build the component but when I try and execute it I get a ClassNotFoundException.
I know that the EJB I am trying to invoke is deployed and available on the server,
as I can see it in the console, I also seen to have been able to get the remote
interface of the object, my problem occurs when I try and access the class object
so I can perform a create on the object and then execute my method
The code I have written is below:
private Object getRemoteObject(Context pCtx, String pJNDIName, String pHomeBean)
throws Exception {
String homeCreate = "create";
Class []homeCreateParam = { };
Object []homeCreateParamValues = {};
try {
//This call seems to work and doesn't throw an exception
Object home = pCtx.lookup(pJNDIName);
//However this call throws a java.lang.ClassNotFoundException
Class homeBean = Class.forName(pHomeBean);
Method homeCreateMethod = homeBean.getMethod(homeCreate,homeCreateParam);
return homeCreateMethod.invoke(home, homeCreateParamValues);
} catch (NamingException ne) {
logStandardErrorMessage("The client was unable to lookup the EJBHome.
Please make sure ");
logStandardErrorMessage("that you have deployed the ejb with the JNDI
name "+pJNDIName+" on the WebLogic server ");
throw ne;
} catch (Exception e) {
logStandardErrorMessage(e.toString());
throw e;
Any advice would be really appreciated, I'm fast running out of ideas, I suspect
it has something to do with the class loader but I'm not sure how to resolve it
Regards
Jo CorlessHello Joanne,
Congratulations! I'm very happy that you've managed to fix your problem. It's
always essential to understand how to package applications when deploying on BEA
WebLogic. Usually, by throwing everything into an EAR file solves just about all
the class loader problems. :-) Let us know if you have any further problems that
we can assist you with.
Best regards,
Ryan LeCompte
[email protected]
http://www.louisiana.edu/~rml7669
"Joanne Corless" <[email protected]> wrote:
>
>
I've fixed it!!!!!!!!
Thanks to everyone who gave me help!!!!
The class loader was the culprit which is what I suspected all along.
As soon
as I put the 2 jar files I was using into an EAR file the problem went
away!!!!!
Thanks again
Jo Corless
"Ryan LeCompte" <[email protected]> wrote:
Hello Joanne,
As Mr. Woollen mentioned, I also believe it's a problem with the class
loader.
You need to be careful how you arrange your EJBs, because WebLogic has
a specific
method in which it loads classes in an EAR, JAR, and WAR file(s). Please
refer
to http://dev2dev.bea.com/articles/musser.jsp for more information about
BEA WebLogic
class loading mechanisms and caveats. Also, try printing out the various
methods
that are available on the object that was returned to you via reflection.
For
example, use the getMethods() method, which returns an array of Method
objects
that you can subsequently cycle through and print out the various method
names.
This way you can discover if the class found/returned to you is indeed
the one
you intend to locate.
Hope this helps,
Ryan LeCompte
[email protected]
http://www.louisiana.edu/~rml7669
Rob Woollen <[email protected]> wrote:
I believe the issue is the home interface class for this EJB is not
available in the class loader which is doing the reflection.
If you do:
getClass().getClassLoader().loadClass(homeInterfaceClassName)
I suspect it will fail. Reflection still requires that the class be
loadable.
-- Rob
Joanne Corless wrote:
Hi Slava,
If I make my code look like you describe below I get a compliationerror telling
me that
home.getMethod() is not recognised (no such method)
If I change it slightly and use
Method homeCreateMethod =
home.getClass().getMethod(homeCreate,homeCreateParam);
The code will compile OK but when executed it still throws a NoSuchMethodException
Any ideas ?
Thanks for your help so far
Regards
Jo Corless
Your code should look like
Object home = pCtx.lookup(pJNDIName);
Method homeCreateMethod =
home.getMethod(homeCreate,homeCreateParam);
return homeCreateMethod.invoke(home, homeCreateParamValues);
Regards,
Slava Imeshev
"Joanne Corless" <[email protected]> wrote in message
news:[email protected]...
Hi Ryan,
I also wanted to mention that if you do a "header search" in this
particular
newsgroup
with the search query as "reflection", you will see many previousmessages
regarding
reflection and EJBs. I believe you could learn a lot from thedifficulties
that
others have faced and solved.I tried that and although there was a number of similar cases noneof them
actually
seem to fix my issue. Thanks for the suggestion though
Are the EJBs that you are trying to access accessible via your
system
classpath?
Try to avoid having them accessible via the main system classpath,and
only bundle
them in your appropriate EJB jar files (contained in an EAR file,for
example).Maybe I should have laid the problem out a little clearer.
I have a number of EJB's bundled up in a JAR file which is hot deployedto
the
server. Within this first JAR file is an EJB (SSB) component that
needs
to
be
able to invoke a known method on another EJB. This second EJB may
or
may
not be
within the first JAR file but it also will be hot deployed.
The component trying to invoke the method on the 2nd EJB has to
be
able to
create
an instance of the 2nd EJB without actually knowing anything bar
a
JNDI
Name which
is passed in at runtime.
I can get as far as doing the
Object home = pCtx.lookup(pJNDIName);
This returned a class with the name
"com.csc.edc.projects.allders.httppostoffice.postman.PostmanBean_mp8qy2_Home
Impl_WLStub"
My problem seems to occur when I try and invoke the create method
Method homeCreate = home.getClass().getMethod("create", new Class[0]);
My code throws a java.lang.NoSuchMethodException at this point so
I
am
unable
to progress to the next step of :
Object bean = homeCreate.invoke(home, null);
So I can return the instantiated bean back to the calling client.
Why am I getting the NoSuchMethodException, is is because I am gettinga
stub
back rather than the home interface and if so how do I get the truehome
interface
from the bean
Thanks in advance
Jo Corless -
How can I get a dynamic list of Classes Loaded
I assume this may need to use some sort of reflection. Does
anyone have code or ideas where I can:
a) I can get a list of all Classes loaded and their
properties. This would probably be all instances of Class
b) A list of all
global instance variables. (This may not even be possible. I
know it can be done in other languages)
I assume this may need to use some sort of reflection.
Thank youAdobe Newsbot hopes that the following resources helps you.
NewsBot is experimental and any feedback (reply to this post) on
its utility will be appreciated:
mx.controls.List (Flex 3):
If the data is incorrect, you can call the preventDefault()
method to stop Flex from passing the new data back to the list
control and from closing the
Link:
http://livedocs.adobe.com/flex/3/langref/mx/controls/List.html
Displaying icons in a Flex List control at Flex Examples:
http://blog.flexexamples.com/2007/08/17/displaying-icons-in-a-flex-list-control/
--> <mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
Link:
http://blog.flexexamples.com/2007/08/17/displaying-icons-in-a-flex-list-control/
Populate the list -- Flex 2.01:
You populate a list-based form control with the
<mx:dataProvider> child tag. The <mx:dataProvider> tag
lets you specify list items in several ways.
Link:
http://livedocs.adobe.com/flex/201/html/tutorial_controls_019_4.html
Smooth Scroll for Horizontal List - Flex India Community |
Google:
I have created image gallery with Horizontal List[Flex 2.0].
Just as below ref site. My Problem is i need a smooth scroll for
Horizontal List. where images
Link:
http://groups.google.com/group/flex_india/browse_thread/thread/a12441143b98d32c?hide_quote s=no
Creating a List control -- Flex 2.01:
The following example code adds a handler for a change event
to the List control. Flex broadcasts a mx.ListEvent.CHANGE event
when the value of the control
Link:
http://livedocs.adobe.com/flex/201/html/dpcontrols_062_03.html
Disclaimer: This response is generated automatically by the
Adobe NewsBot based on Adobe
Community
Engine.
Maybe you are looking for
-
How can i delete a UserName from a text file using Strings or io.
hi i m trainee i have been assigned to make java program which deletes a UserName and his Passwor from a Text File i m unable to do it using the code below plz help do reply import javax.swing.*; import java.awt.*; import java.awt.event.*; import j
-
MP4 files in Premiere Element 7 not playing
I have recently bought a Sanyo Xacti Cmaera for my wife and have tried to edit the files in Premiere elements 7. When I try to open the files I am told they are not supported and that a codec may be missing. I can open them and play them in Nero an
-
Security Advisories RSS problem
Dear all, I cannot download Security Advisories RSS Content using microsoft outlook 2007, Does anyone have the same problem? Thanks and best regards!,
-
OutputText : why both bind and value attribute and other gripes
Hi gripe1 I have started using creator and I'm a bit confused as to why creator insists on the binding attribute being in place to link the outputText field to the default managed bean - like most of us I want to set the value via a resource bundle.
-
Lately my keyboard and mouse just stop working, the keyboard misses typed letters, mouse doenst move, and if I just unplug and plug again the wireless stick it works again, plus I listen from time to time the windows sound of when you reconnect a usb