How to typecast Object Class object dynamically
Hai every one
i have a object of any particular class , but i don't know the variables in that class object. But i have string variable contains value of variables in that class object.
So i use following method for get value of variables in that class object.
class ObjectCLass
Sub s=new Sub();
public static void main(String[] args)
ObjectCLass a=new ObjectCLass();
try
System.out.println(*a.getClass().getDeclaredField("s").get(a)*);
catch(Exception e)
System.out.println("Exception");
class Sub
int i=5;
public void print()
System.out.println("Hello World!");
}Here the bolder line give Object class object. By using this Object class object i need access the variable i and method print(). So i need to cast Object class object into sub class
so how can i typecast it
i try with following methods , but i cant succeed
1.( *(a.getClass().getDeclaredField("s").get(a).getClass)* a.getClass().getDeclaredField("s").get(a) ).print() ;
2.( (Class.forName(�Sub�) ) a.getClass().getDeclaredField("s").get(a) ).print();Please any one one help me how to typecast it dynamically
By
Thiagu
If you know you're going to invoke the "print" method on an object, then you also need to know the type of the class, or interface, which has that method.
It seems what you are looking for is a tutorial on interfaces.
http://java.sun.com/docs/books/tutorial/java/IandI/index.html
In a nutshell, you can set up an interface which defines a "print" method, and create class(es) which implement that interface. Then as long as you have an object which implements that interface, but do not know the exact type of that object, you can simply cast it to the interface type and invoke the method.
Similar Messages
-
How to load a .class file dynamically?
Hello World ;)
Does anyone know, how I can create an object of a class, that was compiled during the runtime?
The facts:
- The user puts a grammar in. Saved to file. ANTLR generates Scanner and Parser (Java Code .java)
- I compile these file, so XYScanner.class and XYParser.class are available.
- Now I want to create an object of XYScanner (the classnames are not fixed, but I know the filename). I tried to call the constructor of XYScanner (using reflection) but nothing works and now I am really despaired!
Isn't there any way to instantiate the class in a way like
Class c = Class.forName("/home/mark/XYScanner");
c scan = new c("input.txt");
The normal call would be:
XYLexer lex = new XYLexer(new ANTLRFileStream("input.txt"));The problem using reflection is now that the parameter is a ANTLRFileStream, not only an Integer, as in this example shown:
Class cls = Class.forName("method2");
Class partypes[] = new Class[2];
partypes[0] = Integer.TYPE;
partypes[1] = Integer.TYPE;
Method meth = cls.getMethod("add", partypes);
method2 methobj = new method2();
Object arglist[] = new Object[2];
arglist[0] = new Integer(37);
arglist[1] = new Integer(47);
Object retobj = meth.invoke(methobj, arglist);
Integer retval = (Integer)retobj;
System.out.println(retval.intValue());Has anyone an idea? Thanks for each comment in advance!!!Dump all of your class files into a directory.
Use the File class to list all files and iterateover
the files.NastyNot really, when you are dynamically creating code, I would expect the output to be centralized, not spread out all over the place.
>
Use a URLClassloader to load the URL that isobtained
for each file with file.toURI().toURL()(file.toURL()
is depricated in 1.6)Wrong, the URL you give it must be that of the
directory, not the class file.No, I did this quite recently, you can give it a specific class file to load.
>
Load all of the classes in this directory, thatway
any anonymous classes are loaded as well.Anonymous classes automatically loaded when the real
one isIt can't load it if it doesn't know where the code is. Since you haven't used a URL classloader to load once class file at a time, you would never encounter this. But if you loaded a class file that had an anonymous classfile it needed, would it know where to look for it?
>
From this point you should be able to just get a
class with Class.forName(name)No. Class.forName uses the classloader of the class
it's called in, which will be the system classloader.
It won't find classes loaded by a URLClassLoader.got me there. -
How to make a class object from a string representation of the same
i have the name of a class whose object i want to make in the form of a string i.e. String s="S1"; i get this name after some prosessing. so what i want to do is to create an object of S1 which is actually one class that i have implemented.plz hlp. it is urgent.thnx in advance.
reflection api...
see java.lang.Class. Read the api docs.
mostly, u need to do the following:
Class myClass = Class.forName(s1);
Object x = myClass.newInstance();
reg
s giri -
Why we need set the 'Create object xx' between 'class definition' and 'class implementation'??
If i set the 'CREATE OBJECT' under the 'Class implementation' in a report, the system will tell me that: 'Statement is not accessible'.
This is my code:
CLASS lcl_retal DEFINITION.
PUBLIC SECTION.
METHODS constructor.
PRIVATE SECTION.
DATA: lv_car(10) TYPE c VALUE 'CAR',
lv_truck(10) TYPE c VALUE 'TRUCK'.
ENDCLASS. "lcl_retal DEFINITION
CLASS lcl_retal IMPLEMENTATION.
METHOD constructor .
WRITE: lv_car, space, lv_truck.
ENDMETHOD. "print_detaile
ENDCLASS. "lcl_retal IMPLEMENTATION
DATA: lo_retal TYPE REF TO lcl_retal.
CREATE OBJECT lo_retal.
Edited by: YINYAN LU on Sep 2, 2009 9:14 AMClass definition - class implementation is treated by system as declaration part. This is similary considered as DATA, TYPES section.
Every single statement which is not part of declaration/definition is part of program to execute (is automatically embraced to START-OF-SELECTION event). In regular program when you set DATA, TYPES it can both occur in declaration part and in execution part. On the other hand CLASS...ENDCLASS is considered purely as declaration/definition (not executable code itself) so can't be placed in START-OF-SELECTION.
Assuming above, when you place CREATE OBJECT b/w CLASS....DEFINITON - CLASS .... IMPLEMENTATION it is recognized as part of executable code, but is placed within the one not intended to be executed. System can't split this code to declaration/execution part. It must be explicitly pointed. So it must be of strcuture
"------------------------- DECLARATION/DEFINITION ---------------------
CLASS lcl_retal DEFINITION.
PUBLIC SECTION.
METHODS constructor.
PRIVATE SECTION.
DATA: lv_car(10) TYPE c VALUE 'CAR',
lv_truck(10) TYPE c VALUE 'TRUCK'.
ENDCLASS. "lcl_retal DEFINITION
"<- here still part of this block, so no executable statements allowed
CLASS lcl_retal IMPLEMENTATION.
METHOD constructor .
WRITE: lv_car, space, lv_truck.
ENDMETHOD. "print_detaile
ENDCLASS. "lcl_retal IMPLEMENTATION
"---------------------------- EXECUTABLE CODE HERE ---------------
DATA: lo_retal TYPE REF TO lcl_retal.
CREATE OBJECT lo_retal.
Hope now it is clear
Regards
Marcin -
How to get a Class object with a generic type of list
Hi,
I want to get an instance of a class which is of type List<ABC>. How can I get that ?
What I tried was Class c = List<ABC>.class , bu this is not compiling. I can get new ArrayList<ABC>().getClass() , but the type of that class would be Class<? extends ArrayList<ABC>> but not what I want Class<? extends List<ABC>> ...
Thanks in Advance.
BhargavaThanks for so many responses. I understand that you can not get a class instance of type Class<List<E>>. Am I correct?
My use case was something like this:
Class X implements Y<SrcType, DescType> {
public DestType transform(SrcType src) { ---- }
}Now I want to write a factory which maintains a list of implemenrations of interface Y in a map. For e.g. {List(SrcType,DestType) -> X}. This factory provides one method with the following signature:
Class Yfactory {
public Y transform(SrcType o, Class destType) {
//This figures out which transformer to apply based on SrcType and destType and gives it back.
}Now, there is one case where a transformer transforms from type A to List<B> (X implements Y<A, List<B>>) . How should I add it to the map in factory and how do I call the factory's transform method so that it choose this transformer? -
How to assign the class value dynamically in jsp:useBean ?its urgent
Hi
I want to set the class value of <jsp:useBean> dynamically
when i am trying to this way
<jsp:useBean id="<%=id %>" class="<%=beanclass %>" scope="request">
<jsp:setProperty name="<%=id %>" property="*"/>
</jsp:useBean>
where beanclass is .class file that is to be used by the usebean tag
i am getting following error
The value for the useBean class attribute <%=beanclass %> is invalid.
please help as soon as possible
regards,
RameshwariYou can not do that.The jsp:useBean and jsp:setProperty are action tags and not custom tags. Action tags get translated into Java code in the translation unit and are then compiled. Custom tag are backed by classes and the tag get translated into a method call of the class.
-
How to pass class object as in parameter in call to pl/sql procedure ?
hi,
i have to call pl/sql proecedure through java. In pl/sql procedure as "In" parameter i have created "user defined record type" and i am passing class object as "In" parameter in call to pl/sql procedure. but it is giving error.
so, anyone can please tell me how i can pass class object as "In" parameter in call to pl/sql procedure ?
its urgent ...
pls help me...793059 wrote:
I want to pass a cursor to a procedure as IN parameter.You can use the PL/SQL type called sys_refcursor - and open a ref cursor and pass that to the procedure as input parameter.
Note that the SQL projection of the cursor is unknown at compilation time - and thus cannot be checked. As this checking only happens at run-time, you may get errors attempting to fetch columns from the ref cursor that does not exist in its projection.
You also need to ask yourself whether this approach is a logical and robust one - it usually is not. The typical cursor processing template in PL/SQL looks as follows:
begin
open cursorVariable;
loop
fetch cursorVariable bulk collect into bufferVariable limit MAX_ROWS_FETCH;
for i in 1..bufferVariable.Count
loop
MyProcedure( buffer(i) ); --// <-- Pass a row structure to your procedure and not a cursor
end loop;
..etc..
exit when cursorVariable%not_found;
end loop;
close cursorVariable;
end; -
Sharing an object/class bewteen servlets and applications
Hi there,
I wish to know how to share a class/object between all
types of other classes, be they applications or servlets, but I encounter the following problem.
Basically, if I instantiate the common class using, say a servlet, then when I try to gain a handle on the instance of that class from an application, the application creates a new(or it's own) instance. Similarly, if I instantiate first within an application.
How do I prevent this from happening?
The actual class files for both the application and servlets are all the same.
Appreciate the help,
Fintan.I am actually implementing the singleton pattern in
this common class.ok, that clarifies the issue a bit...
The RMI route seems to me to be a bit too much work > as a solution to a very simple concept.actually, it's really not a simple concept. What you really want isn't just an application singleton, where there is one instance in the application/servlet JVM. What you really want is more along the lines of a universal singleton, where there is only one instance for ALL applications/servlets...
Interestingly, if I run two java apps side by side in
two DOS windows that each call a getInstance
method in common singleton, both apps create their
own instance.
How come? Separate instances of VM?Yes, this is exactly correct. The same is true of C++ Singletons; if you start a second application it will create another instance of the Singleton because one does not yet exist in the application.
How do I get aroun this one?Like I said, think of it as a universal singleton. Consider Verisign a universal singleton--everyone comes to them for certificates. How does this run? Well, truthfully, Verisign operates as a service, right? So you need some way of setting up a service that really holds onto the object and brokers (aha, 5 dollar word!) who has access to it, who can modify it, and who can read from it. This leads you to a few options... RMI, CORBA, or writing your own object server.
Networking is really easy in Java, so here's another option... You can set up a server that listens for messages on a specific socket/port with whatever protocol you specify to get/set values. Have the server run on only one specific machine. Then you can have all the servlets and applications come to the machine to get the information.
Gee, this sounds like a back-end database. =)
If all this is too complex, maybe you need to rethink the design... do you really need to have the exact same object shared between all application/servlet instances? Or is it acceptable to just make sure they all contain the same data?
If what you really want is a real-time data update scheme, then you probably want something like a subscribe-publish architecture where the one server publishes the origainal data. Then when a client updates the server, the server posts an update message to all the clients, who then in turn update their internal data.
Anyway, I'm just throwing out some ideas. I'm sure you can come up with some better ones of your own since you know what your requirements are. =)
Once again appreciate the help!I hope it actually was. =)
--David -
Difference Between Business Object And Class Object
Hi all,
Can any one tel me the difference between business object and class Object....
Thanks...
..AshishHello Ashish
A business object is a sematic term whereas a class (object) is a technical term.
Business objects are all important objects within R/3 e.g. sales order, customer, invoice, etc.
The business objects are defined in the BOR (transaction SWO1). The have so-called "methods" like
BusinessObject.Create
BusinessObject.GetDetail
BusinessObject.Change
which are implemented (usually) by BAPIs, e.g.:
Business Object = User
User.Create => BAPI_USER_CREATE1
User.GetDetail => BAPI_USER_GET_DETAIL
CONCLUSION: Business Object >< Class (Object)
Regards
Uwe -
How to typecast an object, if the target class name is stored in a str var
Hi,
I have a method, in which i will receive an object as an attribute. I need to typecast it to another class, and that class name is stored in a string variable.
public void printContent(Object obj)
/* Here i have a variable strClassName - in which a class name is stored.
I need to create a variable for that class and type cast the object obj into that class. */
Please kindly help me to find out a way to do this.
Thanks in advanceTypecasting does one thing: it enables you to store an object in a reference variable of the target type (if it is of a type which is allowed to be in that variable). It doesn't alter the object in any way.
Therefore it simply isn't meaningful to talk about typecasting to a type name known only at run time. The whole point of typecasting is to tell the compiler to treat a reference as being of a specified type.
I don't know what you're trying to do but I think you should probably be looking at the reflection api, getting field an method information from the object's Class object. -
As 2.0 class objects- how to swap depths of a movie clip
How do you bring an object to the top? if it's just a movie
clip, I could do a swapdepths, but if it's a movieclip that's part
of an AS 2.0 object, how do you swap depths of the whole object?
I create 2 objects (same class) which each have a movieclip
within them. The movie clip is created on a unique level with
getNextHighestDepth().
I have a button which tries to swapDepths of the 2 objects,
but I can't get it to work. Can anyone help?
here's the detail:
1. create a symbol in the library called "someShape_mc" and
put some shape in it - a circle, a square, whatever - this symbol
is exported for action script, and has an AS 2.0 Class of
"ClassObject" ( I also put a dynamic text field in the shape to
display the current depth - it's called "depth_txt")
2. create a button called "swap_btn" on the stage.
Frame 1 has the following actionscript:
var BottomObject:ClassObject = new ClassObject(this,100,150);
var topObject:ClassObject = new ClassObject(this,110,160);
// for the button add this:
Swap_btn.onRelease=function() {
// try it with the full path:
_root.BottomObject.__LocalMovieClip.swapDepths(_root.topObject.__LocalMovieClip);
// try it with with just the objects:
BottomObject.__LocalMovieClip.swapDepths(topObject.__LocalMovieClip);
// try it with the object as a movieclip
BottomObject.swapDepths(topObject);
trace("Did it Swap?");
// try it with a method in the class....
BottomObject.swapIt(topObject.__LocalMovieClip);
BottomObject.swapIt(topObject);
trace("nope... no swapping going on...");
================================
here's the AS file: "ClassObject.as"
class ClassObject extends MovieClip{
var __LocalMovieClip;
var __Depth;
function ClassObject(passedIn_mc:MovieClip,x:Number,y:Number)
__Depth = passedIn_mc.getNextHighestDepth();
__LocalMovieClip =
passedIn_mc.attachMovie("someShape_mc","__LocalMovieClip",__Depth);
trace("made a shape at " + __Depth);
__LocalMovieClip._x = x;
__LocalMovieClip._y = y;
__LocalMovieClip.depth_txt.text = __Depth;
public function swapIt(targetMc) {
__LocalMovieClip.swapDepths(targetMc);
__LocalMovieClip.depth_txt.text =
__LocalMovieClip.getDepth(); // no difference.
trace("Tried to swap from within the class...");
========================
so- the goal is to bring the "bottom" Class object on top of
the "top" object. The button tries various methods of swapping the
depths of the movie clips - but there is not one that works. What
am I missing?
tia
ferdThank you for your response - and here I have included the
code I reworked to show how it works, and doesn't work. you're
right about not needing the extra containers, but this example is
part of a bigger thing...
I'm confused - it works ONLY if I attach the movie outside
the class, even though the "attachment" occurs, I'm thinking, at
the same scope level, that is, _root.holder_mc, in both examples.
it seems that the advantage of having a class is defeated
since I have to do the extra coding for each object that will be
created. It's like the class can only have a reference to the
movieclip outside itself, and not have a clip INSIDE that is fully
functioning. am I right about this? Is there someplace good I can
learn more about class objects and movieclip usage?
also, my class object IS a movieclip, but " this.getDepth() "
is meaningless inside the class object. hmmm...
This one works..... attaching the movies at the root level
(to a holder_mc)
// Frame 1
tmp1 =
holder_mc.attachMovie("someShape_mc","tmp1",holder_mc.getNextHighestDepth());
var BottomObject:ClassObject3 = new
ClassObject3(tmp1,100,150);
tmp2 =
holder_mc.attachMovie("someShape_mc","tmp2",holder_mc.getNextHighestDepth());
var topObject:ClassObject3 = new ClassObject3(tmp2,110,160);
// for the button add this:
Swap_btn.onRelease=function() {
BottomObject.swapIt(topObject);
trace("clicked button");
// ClassObject3.as
class ClassObject3 extends MovieClip{
var __LocalMovieClip:MovieClip;
function
ClassObject3(passedInMovieClip:MovieClip,x:Number,y:Number) {
trace(" this class object is at ["+this.getDepth()+"]");
__LocalMovieClip = passedInMovieClip;
__LocalMovieClip._x = x;
__LocalMovieClip._y = y;
public function swapIt(targetMc:MovieClip):Void {
trace("do the swap in the class");
trace("===========================");
trace("target type :" + typeof(targetMc));
trace("__LocalMovieClip type :" + typeof(__LocalMovieClip));
__LocalMovieClip.swapDepths(targetMc.__LocalMovieClip);
This one does NOT work..... attaching the movies within the
class object...
// Frame 1
var BottomObject:ClassObject2 = new
ClassObject2(holder_mc,100,150);
var topObject:ClassObject2 = new
ClassObject2(holder_mc,110,160);
// for the button add this:
Swap_btn.onRelease=function() {
BottomObject.swapIt(topObject);
trace("clicked button");
// ClassObject2.as
class ClassObject2 extends MovieClip{
var __LocalMovieClip:MovieClip;
function
ClassObject2(passedInMovieClip:MovieClip,x:Number,y:Number) {
__LocalMovieClip =
passedInMovieClip.attachMovie("someShape_mc","stuff1",passedInMovieClip.getNextHighestDep th());
__LocalMovieClip._x = x;
__LocalMovieClip._y = y;
public function swapIt(targetMc:MovieClip):Void {
trace("do the swap in the class");
trace("===========================");
trace("target type :" + typeof(targetMc));
trace("__LocalMovieClip type :" + typeof(__LocalMovieClip));
__LocalMovieClip.swapDepths(targetMc.__LocalMovieClip); -
How to create custom BOL object for dynamic query in CRM 7.0
Hi,
Could anyone please explain me with steps that how to create the custom BOL object for dynamic query in CRM 7.0, I did it in previous version but its throwing exception when i try to create the object of my dynamic query class. I just defined the entry of my in crmv_obj_btil to create the dynamic query BOL object. do i need to do any other thing also to make it work?
Regards,
Kamesh Bathla
Edited by: Kamesh Bathla on Jul 6, 2009 5:12 PMHi Justin,
First of thanks for your reply, and coming to my requirement, I need to report the list of items which are there in the dynamic select statement what am getting from the DB. The select statement number of columns may vary in my example for different countries the select item columns count is different. For US its '15', for UK it may be 10 ...like so, and some of the column value might be a combination or calculation part of other table columns (The select query contains more than one table in the from clause).
In order to execute the dynamic select statement and return the result i choose to write a function which will parse the cursor for dynamic query and then iterate the values and construct a Type Object and append it to the pipe row.
Am relatively very new for these sort of things, welcome in case of any suggestions to make it simple (Instead of the function what i thought to work with) also a sample narrating the new procedure will be appreciated.
Thanks in Advance,
mallikj2. -
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 add custom attributes to a new Class Object using the API ?
Hello everyone,
Here is my problem. I just created a subclass of Document using the API (not XML), by creating a ClassObjectDefinition and a ClassObject. Here is the code :
// doc is an instance of Document
ClassObject co = doc.getClassObject();
ClassObjectDefinition cod = new ClassObjectDefinition(ifsSession);
cod.setSuperclass(co);
cod.setSuperclassName(co.getName());
cod.setName("MYDocument");
ClassObject c = (ClassObject)ifsSession.createSchemaObject(cod);
Everything seems to be OK since i can see the new class when i use ifsmgr. But my question is : how can i add custom attributes to this new class ? Here is what i tried :
AttributeDefinition value = new AttributeDefinition(ifsSession);
value.setAttribute("FOO", AttributeValue.newAttributeValue("bar"));
c.addAttribute(value);
But i got the following error message :
oracle.ifs.common.IfsException: IFS-30002: Unable to create new LibraryObject
java.sql.SQLException: ORA-01400: impossible d'insirer NULL dans ("IFSSYS"."ODM_ATTRIBUTE"."DATATYPE")
oracle.ifs.server.S_LibraryObjectData oracle.ifs.beans.LibrarySession.DMNewSchemaObject(oracle.ifs.server.S_LibraryObjectDefinition)
oracle.ifs.beans.SchemaObject oracle.ifs.beans.LibrarySession.NewSchemaObject(oracle.ifs.beans.SchemaObjectDefinition)
oracle.ifs.beans.SchemaObject oracle.ifs.beans.LibrarySession.createSchemaObject(oracle.ifs.beans.SchemaObjectDefinition)
void fr.sword.ifs.GestionDocument.IFSDocument.createDocument(java.lang.String)
void fr.sword.ifs.GestionDocument.IFSDocument.main(java.lang.String[])
So, what am i doing wrong ?
More generally, are we restricted in the types of the attributes ? (for example, would it be possible to add an attribute that would be an inputStream ? Or an object that i have already created ?).
Any help would be appreciated. Thanks in advance.
Guillaume
PS : i'm using Oracle iFS 1.1.9 on NT4 SP6 and Oracle 8.1.7
nullHi Guillaume,
you're welcome. Don't know exactly, but assume that ATTRIBUTEDATATYPE_UNKNOWN
is used to check for erronous cases only
and it shouldn't be used otherwise.
Creating your own objects could be simply done via
ClassObject ifsClassObject;
DocumentDefinition ifsDocDef = new DocumentDefinition(ifsSession);
// get class object for my very own document
ifsClassObject = ClassObject.getClassObjectFromLabel(ifsSession, "MYDOCUMENT");
// set the class for the document i'd like to create
ifsDocDef.setClassObject(ifsClassObject);
// set attributes and content for the document...
ifsDocDef.setAttribute("MYFOO_ATTRIBUTE",....);
ifsDocDef.setContent("This is the content of my document");
// create the document...
PublicObject doc = ifsSession.createPublicObject(ifsDocDef);
null -
How to automate the creation of Function Module & Class Object (SE24)
Experts,
I have the requirement to automate the creation of any type of programs: ie function module (like how we normally create in SE37 together with the parameters), class object (like how we normally create in SE24 together with attribute & method), normal report (like how we did in SE38), module pool and so on.
For example. I backuped my program into a flat file (the entire source code in txt formal or HTML) through a download program and I need to upload back this flat file into another installation of SAP.
Does SAP provide any predefined FM to cater for the above cases or better still, does anyone know of any upload program which I can use for the above requirement.
Thanks in advance.Hi Kris, I can't use the transport system as these are 2 separate SAP installation in a different place. The requirement came in the form of creation of program to be able to generate FM/Class/Report on the go.
Maybe you are looking for
-
Can I split an external hard?
I have an external hard that has 2 partitions (time machine and Storage) both are Mac OS extended. Can I add a third one. I need to add a very small one (around 10 MB) that I can use to transfer DVD contents from my PC (that has a DVD drive) to my M
-
The humanist's Question:
''locking - duplicate - https://support.mozilla.com/en-US/questions/852452'' I will never understand how this machine behaves and why the matters addressed always requires some kind of technical approach that always misses the very matter at hand. Th
-
Is it just me, or is this happening to all of us? (READ)
See i had the first iphone and i notice a couple of things that were bothering me- such as - iphone will always go back to home screen when using the main applications(safari,Weather,Maps etc) for no reason, later i realize the bug was fixed Now i pu
-
How can i recover my deleted codes of firefox?
By mistake i deleted my codes for facebook, yahoo etc. Do you know if there is way to have again my codes?
-
Macbook Pro Retina Display (Oct 2013)
I have the new MBPr that came out in late october 2013. The battery is obviously not going to last me 9 hours because I'm using it.. but it sure does drain fast. Most I do is internet browsing and listen to music on youtube. Is there something I can