Re: [Ikvm-developers] Am I doing this right
Brought to you by:
jfrijters
|
From: Jeroen F. <je...@su...> - 2013-06-19 05:33:18
|
Hi Graham,
This is the right approach in general, but in specific cases there may be improvements possible if the dynamic parts implements a statically known interface.
I don't know much about jtapi.jar, but in a jtapi.jar I have there is a javax.telephony package. It might be possible to write your code (mostly) in terms of this interface and then statically compile a dll that contains just the javax.telephony classes. If you then use the assembly class loader of this assembly as the parent of your URLClassLoader that loads jtapi.jar, the statically compiled javax.telephony classes will be used.
Regards,
Jeroen
From: Graham Old [mailto:gra...@on...]
Sent: Tuesday, June 18, 2013 21:52
To: ikv...@li...
Subject: [Ikvm-developers] Am I doing this right
Hi Team
I have written a program using the Cisco API for the Call Manager phone system. The API comes as a jtapi.jar
I have converted the jtapi.jar to a jtapi.dll and my program works great.
The problem I have is that there are lots of versions of Call Manager and you have to use the matching jtapi.jar file, so I was looking into loading the jtapi.jar at run time then I can just load whatever version is installed.
These are from VS2010 so using the dll I have this
try
{
CiscoJtapiVersion jv = new CiscoJtapiVersion();
label1.Text = jv.getVersionName();
label2.Text = jv.getVersion();
label3.Text = jv.getMinorVersion().ToString();
label4.Text = jv.getMajorVersion().ToString();
}
catch (Exception ex)
{
label4.Text = ex.Message;
}
And loading at Run Time I have this:
// Create a URL instance for every jar file that you need
java.net.URL url = new java.net.URL("file:C:\\Windows\\Java\\lib\\jtapi.jar");
// Create an array of all URLS
java.net.URL[] urls = { url };
// Create a ClassLoader
java.net.URLClassLoader loader = new java.net.URLClassLoader(urls);
try
{
// load the Class
java.lang.Class cl = java.lang.Class.forName("CiscoJtapiVersion", true, loader);
// Create a Object via Java reflection
Type type = ikvm.runtime.Util.getInstanceTypeFromClass(cl);
dynamic jv = type.GetConstructor(new Type[] { }).Invoke(null);
label1.Text = jv.getVersionName();
label2.Text = jv.getVersion();
label3.Text = jv.getMinorVersion().ToString();
label4.Text = jv.getMajorVersion().ToString();
}
catch (Exception ex)
{
label4.Text = ex.Message;
}
My question is:
Am I going about this the right way?
I assume I need to define all my objects as dynamic as there is no way of getting a static reference
Defining the objects as dynamic makes it a bit unforgiving of any typo's etc.
Thanks
Graham Old
Software Integration
ddi 01582 420950 (single number reach)
ONI Plc is a Cisco GOLD Certified Partner specialising in:
Advanced Unified Communications
Advanced Wireless LAN
Advanced Routing & Switching
Advanced Security
Registered in England No. 2698057'
CONFIDENTIALITY
This e-mail, its content and any files transmitted with it are intended solely for the addressee(s) and are confidential and may be legally privileged. If you are not the intended recipient, any use, disclosure or copying of this document is unauthorised. If you have received this document in error please immediately notify the sender on +44 1582 429999 and delete this email from your computer. Thank you
|