Cloning the class object
Hi
I have a class which looks something like this:
class A
String name = null ;
int age = 0 ;
Object a = null
Object b = null ;
The Object classes could be any types including Dates etc but it is not fixed and so I am using object. The problem is that I also want to copy this class. Now I am writing my own constrcutor to make a copy object but there is no clone() method available for object. The api shows one but it doesn't work.
Any idea what the problem is or how I may copy a raw object?
Cheers
go through this example
Cloning an Object
class CloneClass implements Cloneable
public CloneClass()
public Object clone()
Cloneable theClone = new CloneClass();
return theClone;
public String toString()
return "Hello";
public static void main(String[] args)
CloneClass myObject = new CloneClass();
System.out.println("MyOjbect: "+myObject);
CloneClass myObjectClone = (CloneClass)myObject.clone();
System.out.println("MyObjectCloned: "+myObject);
//Arrays are automatically cloneable:
int[] ints = new int[]{123, 234};
System.out.printf("%s\n","Array Before Clone ...");
for(int i:ints)
System.out.printf("%d,\n",i);
int[] intsClone = (int[])ints.clone();
System.out.printf("%s\n","Array After Clone ...");
for(int i:intsClone)
System.out.printf("%d,\n",i);
}
Similar Messages
-
Is there a way to find the class objects memory size?
Hi Friends,
Please help.
Is there a way to find the number of Objects created and total size?
For example:
class AgeRecord
int start;
int end;
AgeRecord(int start, int end)
this.start = start;
this.end = end;
In a loop if I create 1000 objects, how will I get the total memory size
Thanks and Regards
JGYou might find this useful...
package forums;
http://weblogs.java.net/blog/dwalend/archive/2007/11/the_thing_about.html
http://forums.sun.com/thread.jspa?threadID=457279&start=30&tstart=0
http://www.velocityreviews.com/forums/t364574-size-of-boolean-type.html
The JLS doesn't specify the size of a boolean, leaving it upto the JVM
implementor to define. Sun's JVM stores booleans as:
(1) a boolean is-an int; i.e. a signed 32 bit twos-compliment integer.
At face value, this is an innordinate waste of space, but Java uses a
32-bit stack frame, and most (modern) CPU's use a 32-bit word anyway,
so the wasted space is worth the CPU cycles, and it's simple.
(2) a boolean[] is-a byte array, using 1 byte per element, rounded up to the
nearest 8, plus 8 bytes for the array-object itself.
For example: boolean[] bools = boolean[100];
100 mod 8 = 4; so that'd be 104 bytes + 8 bytes = 112 bytes.
So, let's dis/prove the contention by experiment.
1,000,000 mod 8 = 0 so 1,000,000 + 8 bytes for the array = 1,000,008
class BooleanArraySizeTest
public static void main(String[] args) {
final Runtime rt = Runtime.getRuntime();
System.out.println("The contention is that each iteration should use 1,000,008 bytes.");
try {
long before, after;
final int TIMES = 32;
boolean[][] bools = new boolean[TIMES][];
for (int i=0; i<TIMES; i++) {
before = rt.totalMemory() - rt.freeMemory();
int n = 1000*1000-(TIMES/2)+i;
bools[i] = new boolean[n];
after = rt.totalMemory() - rt.freeMemory();
System.out.print(n);
System.out.print('\t');
System.out.print(after-before);
System.out.println();
} catch (Exception e) {
e.printStackTrace();
999984 used=1000000 bytes
999985 used=1000000 bytes
999986 used=1000000 bytes
999987 used=1000000 bytes
999988 used=1000000 bytes
999989 used=1000008 bytes
999990 used=1000008 bytes
999991 used=1000008 bytes
999992 used=1000008 bytes
999993 used=1000008 bytes
999994 used=1000008 bytes
999995 used=1000008 bytes
999996 used=1000008 bytes
999997 used=1000016 bytes
999998 used=1000016 bytes
999999 used=1000016 bytes
1000000 used=1000016 bytes
1000001 used=1000016 bytes
1000002 used=1000016 bytes
1000003 used=1000016 bytes
1000004 used=1000016 bytes
1000005 used=1000024 bytes
1000006 used=1000024 bytes
1000007 used=1000024 bytes
1000008 used=1000024 bytes
1000009 used=1000024 bytes
1000010 used=1000024 bytes
1000011 used=1000024 bytes
1000012 used=1000024 bytes
1000013 used=1000032 bytes
1000014 used=1000032 bytes
1000015 used=1000032 bytes
ENVIRONMENT:
Microsoft Windows [Version 6.0.6000]
Copyright (c) 2006 Microsoft Corporation. All rights reserved.
C:\Users\Administrator>java -version
java version "1.6.0_12"
Java(TM) SE Runtime Environment (build 1.6.0_12-b04)
Java HotSpot(TM) Client VM (build 11.2-b01, mixed mode, sharing)
*/Cheers. Keith. -
Getting the calling object reference / class?
Dear forum members,
Is it possible for A in the below example to get that B was the "caller"?
class A {
A() {
public void someMethod(String text) {
System.out.println("I was called with: " + text);
System.out.println("I was called by: " + thatMagicWayToGetCallerClassOrReference());
class B {
public static void main(String[] args) {
A a = new A();
a.someMethod("HOLA HOLA");
}Another way of getting the class of your caller is to use a SecurityManager object. getClassContext() is protected but you can get at it by subclassing SecurityManager (it works if you just instanciate the manager without installing it). This gives you a reference to the Class object itself where the stack trace returns only the class name. Bear in mind that the class in question will be several items up the array, the first entry is the SecurityManager itself, the second the called class.
However, I agree with others it doesn't sound like the best design. If you're having trouble with not being able to change the interface specifications to pass the extra information then consider using a static reference, if necessary a ThreadLocal. What happens if you want to call the offending method indirectly through some central method at some future time? You've lost the call origin data.
Why can't you simply add a parameter to the offending call? -
Vector clone references the same objects??
Hi all
I'm developing a simple chess program.
Obviously, each move the user tries must be checked against the following sets of chess rules:
1.) Whether it is that colour player's turn to move
2.) Whether this move is valid for this specific piece (eg. 3 forward for a King --> invalid of course)
3.) Whether this move will jeopardize the player's king (put it in check)
If from any of the above the move is found to be invalid, the move is not executed.
My program structure is briefly this:
A. abstract super class 'ChessPiece' - subclassed by the various specific Chess Piece classes.
Each of the specific ChessPiece subclasses must implement an abstract method to check if a
proposed move is valid, and also a method to actually do the move...
B. 'PieceManager' class - has a Vector of ChessPieces:
This class checks whether the given move is valid:
For the piece: by calling the checking method (see A above)
For the general game: by making sure the given move doesn't put the player's king in check.
NOTE: In chess (for those who don't know), it is illegal to move any piece if, at the end of
the move, your king will be in check [possible to be captured by any enemy piece]
This last check I want to do in the following way:
1) copy/clone the entire PieceManager object
2) in this copied object, actually do the move
3) still in the copied/cloned object, see if the moving player's king is now in check
4) based on this evaluation, execute the move in the original PieceManger object or don't...
The Problem:
When I clone this PieceManager object, its 'pieces' Vector is obviously also cloned.
BUT it seems that the cloned 'pieces' Vector references the same ChessPiece objects
as those referenced by the original 'pieces' Vector; ie the 2 Vectors are sharing the same Objects.
Thus, when I actually execute the move in the test/cloned PieceManager object,
the original PieceManager's corresponding piece is moved too (well, it seems it is the same piece...).
I am pretty stuck with this.
I've tried the Vector clone method; it doesn't seem to copy the objects, but create another reference
to the same objects, as I've said.
I've tried cloning the entire object ; also not helping......
I'd love any comments, helpful pointers, suggestions.
Also any comments on my program structure... is a Vector the best tool for this job?
Thanks very much -
luthaHi all, OP here.
Ok thanks guys for all your posts...
two points:
1) I have tried the "copy constructor", and it seems to be doing the same thing. (ie 'shallow clone')
What's really frustrating me is that nothing I do seems to actually physically copy the Vector's objects
to new, separate copies of those objects...
I had my PieceManager class implement Cloneable (just in case - not too sure on that one; in fact I
commented that out later), and I overrode the clone method like this:
public Object clone ()
PieceManager pm = new PieceManager ();
Vector pcs = new Vector ();
// Enumeration e = pieces.elements ();
//while (e.hasMoreElements ())
// ChessPiece p = (ChessPiece) e.nextElement ();
//pcs.add ();
//} // still references the same objects!!
pieces.trimToSize ();
int size = pieces.size ();
Object[] arr = new Object [size];
Object[] initial = pieces.toArray ();
System.arraycopy (initial, 0, arr, 0, size);
for (int i = 0 ; i < size ; i++)
ChessPiece p = (ChessPiece) arr ;
pcs.add (p);
pm.pieces = pcs;
return pm;
This all still does the same 'shallow cloning'...
2) m.winter, my ChessPiece objects are not immutable - they have a co-ordinate field that
changes as they are moved. This is for getting as called by another object, and for checking in
the ChessPiece's own internal method for checking whether the passed-in square co-ordinate
is a valid destination.
Anyway, I don't think that's the main issue here. How can I properly clone/copy a Vector, resulting
in :
a) the original Vector
b) a new, totally unrelated Vector.
Thanks again all for your input.
regards,
lutha -
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 -
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); -
Get the class file name of the JSP page
Hi
I'm wondering how I can get the class name associated with the current JSP page...
I found on this forum how get the name of current JSP page, but it doesn't help me...
ThanksHi,
Sometimes I can be really dumb; of course, the solution is to call the getClass() method on the this object, and eventually store the Class object returned in the SessionBean file if it's necessary (in a SessionBean field/property, or in a parameter of a SessionBean's method).
Sorry for this thread without any interest. :( -
Loading and viewing XML when a class object is created..Help Please
Hello,
I have writing a simple class which has a method that gets invoke when the object of the class is created. I am able to view the loaded XML content when I trace it with in my class method, but cannot assign the content to a instance variable using the mutator method. So the process goes like this:
Class object is instantiated
Class construtor then calls the loadXML method which laods the XML
And then assigns the XML to a class instance variable.
So now if I would like to access the loaded XML through class object, I should be able to see the loaded xml content which I am not able to see. I have spent over few hours and cannot get the class object to display the loaded XML content. I would highly appreciate it if someone can help in the right direction, please.
[code]
package com.as3.app
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.*;
public class Cars extends MovieClip {
public var _CarList:Object;
public function Quiz()
super();
loadCars();
// ===========================================================
// CARS GETTER SETTER
// ===========================================================
public function set Cars(val:XML):void
this._CarList = val;
public function get Cars():XML
return this._CarList;
// ===========================================================
// LOAD QUESTIONS FROM XML
// ===========================================================
public function loadcars()
var myXML:XML;
var myLoader:URLLoader = new URLLoader();
myLoader.load(new URLRequest("xml/cars.xml"));
myLoader.addEventListener(Event.COMPLETE, processXML);
function processXML(e:Event):void
myXML = new XML(e.target.data);
Cars = myXML; // Assigning the loaded xml data via mutator method to the _CarList;
//=============================================================
INSTANTIATING THE CLASS OBJECT
//=============================================================
package com.as3.app
import flash.display.*;
import flash.events.*;
import flash.text.*;
import flash.net.*;
import com.as3.app.*;
public class DocumentClass extends MovieClip {
public var c:Car;
public function DocumentClass()
super();
c = new Cars();
trace(c.Cars);
[/codewhere you have:
super();
c = new Cars();
trace(c.Cars);
c.Cars will not trace as the loaded xml, because it will not have loaded in time. After some time it should presumably have the correct value.
loading operations in actionscript are asynchronous, so your nested function which is acting as the listener ( function processXML(e:Event):void) only ever executes when the raw xml data has loaded and that is (I believe, not 100% sure) always at least one frame subsequent to the current one.
In general I would consider it bad practise to use nested functions like that, but I don't think its contributing to your issues here. I think its just a timing issue given how things work in flash....
Additional observation:
your Cars constructor calls loadCars() and your loadCars method is defined as:
public function loadcars()
I assume its just a typo in the forum that the uppercase is missing in the function name.... -
Safe to synchronize on Class object?
Is it considered safe and good practice for a method to synchronize on the Class object of it's own class? I am using lazy initialization for a static field; the field is initialized to null when the class is loaded and then set to its actual value the first time it is used. I need to make sure the actual initialization is thread safe. Here is a simplified example of what I am doing.
public class Test {
private static String myField = null;
public String foo() {
synchronized (Test.class) {
if (myField == null) {
myField = "Hello world!";
return myField;
}It seems like that should work, but I was a little worried that by locking the Class object I might cause a problem with the class loader or something.jschell wrote:
Nick_Radov wrote:
I have to use lazy initialization rather than initializing the static field in clinit because it's value depends on a superclass field which isn't fully available until the class loader finishes loading the class. So the lazy initialization is just to get around that sequencing problem.Huh? That is certainly phrased oddly at best. If a "superclass" is used then it is fully loaded before it is used. There is no sequencing problem with that.He might have a design problem. He can se a partly initialized super class if that method is overridden and invoked by the parent constructor.
Kaj -
Importing Class Objects created in IFS Manager into a JSP page
I create a class object using IFS Manager which consisted of extended attributes. I hope this is the right thing to do when I want to manage some extra attributes of a DOCUMENT. But the question is what package do I import to access this newly create Class Object
Thank you. The information was very helpful.
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Joyce Peng:
I believe you created a subclass of Document using iFS manager.
Your new subclass is like any other class object in iFS.
Here is an example of how to access a custom class EXPENSEREPORT with a custom attribute APPROVER.
//Gets the the collection of all the class objects.
//Then gets the specific EXPENSEREPORT class object.
Collection classObjectCollection = session.getClassObjectCollection();
ClassObject expenseReportClassObject =
(ClassObject) classObjectCollection.getItems("EXPENSEREPORT");
//Gets the APPROVER attribute for the class object.
Attribute attribute = expenseReportClassObject.getEffectiveClassAttributes("APPROVER");
<HR></BLOCKQUOTE>
null -
Pass Class Object To FMS Using NetConnection.call Method
Hello All,
I have a custom class that defines several methods on itself
to retrieve its data. This class object is then sent to FMS via the
NetConnection.call method. Once received by FMS, FMS calls the
remote method to dispaly the class object on connected clients
(minus the originator).
Now, standard properties are displayed correctly, but when I
call the class method to retrieve the class data, no data is
retrieved.
My question is, can FMS handle class objects as parameters in
a NetConnection call. If not, is there a better practice of
applying methods to retrieve the class data? Example below...
class com.QuizItem
var numOfAnswers;
var getAnswer;
function QuizItem(question)
this.numOfAnswers = 0;//<-- Returns correct number of
answers
this.getAnswer = function(answerNumberToGet)//<-- Does
not return any data when called by client side script
return this.answers[answerNumberToGet];//Already populated
array
Regards,
ShackFirst, I know JAVA does not working "pass by
reference". It's only working pass by value. (or call
by value)But obviously you don't fully understand what it means.
Isn't main_a and method_a alias?
if there is not alias, why? please explain to me.No. They're two independent references coincidentally pointing to the same object. In your swap method, you move method_a to point to something else. This does not affect main_a.
and why main_a.hashcode() is main_a's value?why not? What else should it be?
I think It's mean copy object. but main_a and
method_a, they have same object id! @_@;;;It means "copy reference", same object. -
Is a jclass object always a java.lang.Class object?
In a native method, I'm receiving a jobjectArray called "args" as a parameter. I'm writing this:
jclass cls1 = env->GetObjectClass(args);
jmethodID mid1 = env->GetMethodID(cls1, "isArray", "()Z");
but this returns 0, indicating there is no isArray in the jclass returned by GetObjectClass. On the other hand, this works:
jclass cls2 = env->GetObjectClass(env->GetObjectClass(args));
jmethodID mid2 = env->GetMethodID(cls2, "isArray", "()Z");
Why??
When I call getMethods() (via JNI) on cls1, I get only the methods of java.lang.Object. When I do that on cls2 I get the methods of java.lang.Class.Oops, I answered my own question. The jclass object represents the class of args, so its methods are those of the class of args, not those of java.lang.Class. I was misinterpreting what GetMethodID does -- it gets methods that would be returned by getMethods() in the Class object, not the methods of the Class object.
-
Can the Sound Object control two sounds at once?
I have a sound object that I want to control two seperate
sounds in different movie clips..one is intro music which lives on
the main shell of the website along with the sound object. This
fades out into a loop that lives on another movie clip that loads
into the shell on a loadMovie action naturally.
My goal:
To control both sound clips with ONE sound object living in
the main flash site's shell. Can this be done or would I have to
have two seperate sound objects for each sound clip?
Thank you,
DaytonYou could write a fairly simple class that would act as a
wrapper for the sound class. In this class you would let it define
the 2 sound objects but then you would only need to use call to the
class object to control both. This could also be expanded to
control more than 2 sounds. It is not exactly what you were hoping
for but in the long term it would simplify sound control and be
reusable in pretty much any setting that required sound.
Tim -
User defined class objects for a ADF component (button,inputfield)
How do I define a user defined class object for ADF objects?
My requirement is that when I do a modification to the class object, it should get reflectected to all the instances on my page.
E.g:- I'm having class object clsInputField, and all my input fields in my pages are based on this object. So when I change clsInputField it should get reflected to all my controls based on this class object.
Please help!!!Hi Timo,
In our client server environment, we have a custom control for managing the zip code (used a Custom InputText field which extends the actual TextField) . All zip code specific validations are written in this custom class. In our application many of the pages uses this Custom component. So if any of the zipcode specific behaviour changes, we could implement this by only changing the Custom InputText field class.
We need to implement this behaviour in our ADF applications. Please advise.
Thanks,
Vishnu -
Implicit parent class/object reference
Hello,
Is there any way I can get an implicitly reference to the class/object that instantiated a second object ? At the moment I have been doing this by creating this explicitly by passing the parent object as an argument through the constructor of the object to store it, but it would be nice if there was an implicit parent reference somewhere accessible from within the newly created object. Any thoughts about this ?
Many Thanks,
Remspublic class Thing { // note: extends Object, implements no interface
private Factory creator;
Thing(Factory creator) {
this.creator = creator;
public void foo() {
// do stuff here
public class DifferentThing // also extends Object, implements no interface, and doesn't subclass Thing
private Factory anyName;
DifferentThing(Factory whatever) {
anyname = whatever;
public int bar(String x) {
// do completely different stuff here
public class Factory {
public Object create(String s) {
if (s.equals("Thing")) {
return new Thing(this);
} else if (s.equals("Different thing")) {
return new DifferentThing(this);
} else {
return null;
}There you go. A brain-dead simple Factory class, that generates objects of different classes, which do not implement a common interface, and neither extends the other, yet both have a reference to the factory method that created them. All you have is a convention that the constructors of the classes in question take a Factory object as a parameter.
Maybe you are looking for
-
Function modules or BAPIs for ESS MSS
Hi Experts, I am new to HR (ESS/MSS & who's who). I am looking for standard BAPI's and Function Modules that would give me information about an employee's upper level's and lower levels (reporting). My requirement is to build an Webdynpro Application
-
Does the lightning to 30 pin adaptor work in speaker docks?
My old 3rd Generation iPod stopped working (the round scrolling dial won't work), so I bought a new 7th generation iPod last week. I realized I couldn't play it on my fairly low-end Memorex speaker dock, so I got one of those $30 lightning-to-30-pin
-
Editing audio files in Yosemite
How can I edit (trim, add chapters) audio (MP3) files in Yosemite on my iMac?
-
Batch no assigning during production order creation
Sir, We are manitaining the batch management for inut raw materials. During production order creation it is mandatory to assign the batch no for raw materials then only production order releasing is possible.In our case due to batch assignement to pr
-
If I buy an iphone in the USA can I set it up in canada?
I am moving to Canada but want to buy the new iphone, can I set it up in Canada