Re: SOLVED Question for the Java Gurus
Re: SOLVED Question for the Java Gurus
- Subject: Re: SOLVED Question for the Java Gurus
- From: Owen McKerrow <email@hidden>
- Date: Thu, 22 Apr 2004 15:06:46 +1000
Yeah sorry, re-read the email and yes I didn't explain myself very
well. The function was just an example really, just to put the
Object tempOb = (entity)array.objectAtIndex(0); line in some form of
context.
The question was basically, given the name of a class as a string, is
there anyway to use that String for casting an object to the class type
of class who's name is the contents of the string.
In the end I did it another way :
/**This class is deisgned to take a NSArray of objects from a join
table between two entities and return a NSArray of the objects from one
of the entities.
That is if you have 2 tables 'Frog' and 'Food" with the join table
'Eats' between them, you can pass this class the Frogs NSArray of Eats
objects and ask for an NSArray of Food items that match the given
relationship.
It only every really needs to be used when there is something in the
join table that doesn't allow it to be flattened.*/
/**
Given an Array of join table objects and a relationship name, it will
seek to return an array of objects from the other side of that
relationship
@param objects The array of objects you wish to strip
@param relationship The relationship that you wish to get an array of
objects from
*/
public static NSMutableArray stripJoin(NSArray objects, String
relationship) throws Exception
{
int i;
NSMutableArray wantedObjects = new NSMutableArray();
for (i=0;i < objects.count();i++) {
Object temp = objects.objectAtIndex(i);
Method tempMethod = temp.getClass().getMethod(relationship,null);
wantedObjects.addObject(tempMethod.invoke(temp,null));
}
return wantedObjects;
}
Owen
On 22/04/2004, at 2:17 PM, Art Isbell wrote:
On Apr 21, 2004, at 5:48 PM, Owen McKerrow wrote:
How can I make the following code work if entity is an instance of
String passed in as an argument to the function. i.e. Can I cast to a
specific Class if all I have is the name of the Class as a String ?
If not is there another way I can do this ?
public getOtherObjects(String entity, NSArray objects) {
for(int i=0;i<objects.count();i++) {
Object tempOb = (entity)array.objectAtIndex(0);
}
}
Not sure what you're trying to do since the above function really
does nothing. If objects is an array of enterprise objects, then you
can assign an array element to a variable of type EOEnterpriseObject:
EOEnterpriseObject tempOb =
(EOEnterpriseObject)objects.objectAtIndex(0);
Aloha,
Art
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.
'The test of a first-rate intelligence is the ability to hold two
opposed ideas in the mind at the same time and still be able to
function.'
-F.Scott Fitzgerald,
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.