To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm-----Original Message-----
From: Conway. Fintan (IT Solutions) [mailto:[EMAIL PROTECTED]]
Sent: 12 September 2002 16:27
To: JDJList
Subject: [jdjlist] RE: Determine type from textHi Jeff,You could try :String paramType = null;String[] primitives = {"byte", "short", "char", "int", "long", "float"," double", "boolean"}; // Finite list of primitivesArrayList primitiveList = Arrays.asList(primitives)// retrieve the parameter type from the XMLparamType = ...if (primitiveList.contains(paramType) { // the parameter type is a primitive} else { // the parameter type is a Class of some sortClass paramClass = class.forName(paramType);Object paramValue = paramClass.newInstance();paramValue = (paramClass)... // retrieve the value from XML doc}I have not tested this code, and am not 100% sure if the Class class works this way. It seems that XML parsers/readers should have some method to perform type conversions like this automatically.Regards,Fintan-----Original Message-----
From: Jeff Fisher [mailto:[EMAIL PROTECTED]]
Sent: 12 September 2002 15:37
To: JDJList
Subject: [jdjlist] RE: Determine type from textOk, let me refraise what I need to do. I know what the types are for the parameters by the xml doc or by the getParameterTypes method. The question now becomes, how do I convert the values of the parameters from the xml file into the correct types so I can pass those to the method. This is where I'm having problems.For example:I need to somehow take the string 100 and create the correct method argument (an int) without knowing ahead of time that the param is an int. The code that has to do this has no intrinsic knowledge of the method being called.To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 12, 2002 10:13 AM
To: JDJList
Subject: [jdjlist] RE: Determine type from textJeff,
I am not sure if your question is regarding whether or not an object can be represented using XML or if you are trying to find out the types of the parameters of a method.
I will assume the second. If I am wrong, so sorry:)
Since you have already looked at reflection, did you try the java.lang.reflect.Method.getParameterTypes()? This returns an array containing one class object for each of the method's parameters.
Chikeobi O. Njaka-----Original Message-----
From: Jeff Fisher [mailto:[EMAIL PROTECTED]]
Sent: Thursday, September 12, 2002 5:51 AM
To: JDJList
Subject: [jdjlist] Determine type from text
Given the following xml file:
<?xml version="1.0"?>
<ServiceRequest>
<Service>
com.emerywaterhouse.websvc.FrtCalc
</Service>
<Method>
getFreightCharge
</Method>
<Param>
<Type>
String
</Type>
<Value>
UPSG
</Value>
</Param>
<Param>
<Type>
String
</Type>
<Value>
04104
</Value>
</Param>
<Param>
<Type>
int
</Type>
<Value>
100
</Value>
</Param>
</ServiceRequest>Using reflection I can create the class, and call the method. The only problem is determining and converting the parameters to the correct type. I suppose I can use a brute force method and have a large number of if else statements, but that doesn't seem viable. Also, if the parameter is an object, I'll never be able to code for all possible objects.
I've looked through a number of resources, but nothing I've seen has examples of determining the types for parameters.
Does anyone have a suggestion here or a resource I can look at.
TIA
Jeff
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm Information contained in this email message is intended only for
use of the individual or entity named above. If the reader of
this message is not the intended recipient, or the employee or
agent responsible to deliver it to the intended recipient, you
are hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited. If you
have received this communication in error, please immediately
notify the [EMAIL PROTECTED] and destroy the original
message.To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm
* ** *** ** * ** *** ** * ** *** ** *
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed.
Any views or opinions presented are solely those of the author, and do not necessarily
represent those of ESB.
If you have received this email in error please notify the sender.
Although ESB scans e-mail and attachments for viruses, it does not guarantee
that either are virus-free and accepts no liability for any damage sustained
as a result of viruses.
* ** *** ** * ** *** ** * ** *** ** *
Title: Message
Unfortunately I you can't do the class cast "paramValue = (paramClass)..." using the class
type from Class.forName() - I believe it won't get past the compiler.
- [jdjlist] RE: Determine type from text Jeff Fisher
- [jdjlist] RE: Determine type from text CNjaka
- [jdjlist] RE: Determine type from text Jeff Fisher
- [jdjlist] RE: Determine type from text Jeff Fisher
- [jdjlist] RE: Determine type from t... Chris Gresty
- [jdjlist] RE: Determine type from text Alastair Rodgers
- [jdjlist] RE: Determine type from text Conway. Fintan (IT Solutions)
- [jdjlist] RE: Determine type from text Jeff Fisher
- [jdjlist] RE: Determine type from text Alastair Rodgers
- [jdjlist] RE: Determine type from text Greg Nudelman
