|
Microsoft.Net 的Java实现广告 Microsoft.Net 的Java实现 李文军 众所周知,微软公司正在全力打造.Net,并准备将它作为向其他公司进攻的砝码,来保证其在业界的技术领先地位。 其实,微软公司在许多领域都处于领导地位,一些优秀的产品让其他公司难望其项颈,如操作系统,办公软件等基于Windows平台的一些优秀的应用软件(如:IE)。但在美国,许多大公司非常反感微软一手包办的作风,也对微软的不放心,对其产品的安全性的担忧,所以大部分都用Unix 和linux等非Windows平台,许多服务器也是用的非Windows平台,或是用自己开发的操作系统。但Windows的方便性和界面友好性及众多的工具也是其他平台难以比拟的(应该没什么争议的),而Unix和Linux平台似乎只适合一些专家。能不能找到一个桥梁将Windows产品同其他平台联系起来呢?目前有www.stryon.com公司正在实现这一点,开发了iNet,将Microsoft.Net转换成java代码来实现跨平台。例如用Visual Studio.Net开发了一个Web Service程序: testClient.asmx: <%@ WebService Language="C#" Class="testClient" %>
using System.Web.Services; using System.Web.Services.Protocols; using System.Web.Services.Description; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using System.Data;
public int testInt(int a,int b){ return a+b; }
public struct1 testStruct(struct1 a){ return a; }
public int[] testIntArr(int[] a){ return a; }
public struct1[] testStrArr(struct1[] a){ return a; }
public struct1 testStructAndArr(struct1 a,struct1[] b){ return a; }
public struct1[][] testStrManyArr(struct1[][] a){ return a; } }
public string j="ok"; public struct2 s2; } public class parent{
}
}
testClient.java:
import system.Reflection.*; import system.Web.Services.*;
return a+b; }
return a; }
return a; }
return a; }
return a; }
return a; }
super();
} 用来指明Web Service中有哪些Web方法,以便被客户调用;
import system.Reflection.*; import system.Web.Services.*;
long value = TypeAttributes.AnsiClass.value__ | TypeAttributes.AutoLayout.value__ | TypeAttributes.BeforeFieldInit.value__ | TypeAttributes.Class.value__ | TypeAttributes.Public.value__; TypeAttributes attributes = new TypeAttributes(value); t.set_Attributes(attributes); }
return new FieldInfo[0]; }
long value = 0; ConstructorInfo ctor = null; ParameterInfo param = null; MethodAttributes attributes = null; ParameterAttributes paramAttrs = null; java.util.Vector ctorVec = new java.util.Vector();
value = MethodAttributes.HideBySig.value__ | MethodAttributes.Public.value__ | MethodAttributes.ReuseSlot.value__ | MethodAttributes.RTSpecialName.value__ | MethodAttributes.SpecialName.value__; attributes = new MethodAttributes(value); ctor = new ConstructorInfo(t); ctorVec.addElement(ctor); ctor.set_Attributes(attributes); ctor.set_Name("testClient"); ctor.set_BindingFlags(BindingFlags.Public.value__ | BindingFlags.Instance.value__);
ctorVec = null; ConstructorInfo[] ctors = new ConstructorInfo[objs.length]; java.lang.System.arraycopy(objs, 0, ctors, 0, objs.length); return ctors; }
long value = 0; MethodInfo method = null; ParameterInfo param = null; MethodAttributes attributes = null; ParameterAttributes paramAttrs = null; java.util.Vector mdVec = new java.util.Vector();
value = MethodAttributes.HideBySig.value__ | MethodAttributes.Public.value__ | MethodAttributes.ReuseSlot.value__; attributes = new MethodAttributes(value); method = new MethodInfo(t); mdVec.addElement(method); method.set_Attributes(attributes); method.set_Name("testInt"); method.set_ReturnType("System.Int32"); method.set_BindingFlags(BindingFlags.Public.value__ | BindingFlags.Instance.value__); value = 0; paramAttrs = new ParameterAttributes(value); param = new ParameterInfo(method); param.set_Attributes(paramAttrs); param.set_Name("a"); param.set_ParamType("System.Int32"); method.addParameterInfo(param); value = 0; paramAttrs = new ParameterAttributes(value); param = new ParameterInfo(method); param.set_Attributes(paramAttrs); param.set_Name("b"); param.set_ParamType("System.Int32"); method.addParameterInfo(param);
value = MethodAttributes.HideBySig.value__ | MethodAttributes.Public.value__ | MethodAttributes.ReuseSlot.value__; attributes = new MethodAttributes(value); method = new MethodInfo(t); mdVec.addElement(method); method.set_Attributes(attributes); method.set_Name("testStruct"); method.set_ReturnType("struct1"); method.set_BindingFlags(BindingFlags.Public.value__ | BindingFlags.Instance.value__); value = 0; paramAttrs = new ParameterAttributes(value); param = new ParameterInfo(method); param.set_Attributes(paramAttrs); param.set_Name("a"); param.set_ParamType("struct1"); method.addParameterInfo(param);
value = MethodAttributes.HideBySig.value__ | MethodAttributes.Public.value__ | MethodAttributes.ReuseSlot.value__; attributes = new MethodAttributes(value); method = new MethodInfo(t); mdVec.addElement(method); method.set_Attributes(attributes); method.set_Name("testIntArr"); method.set_ReturnType("System.Int32[]"); method.set_BindingFlags(BindingFlags.Public.value__ | BindingFlags.Instance.value__); value = 0; paramAttrs = new ParameterAttributes(value); param = new ParameterInfo(method); param.set_Attributes(paramAttrs); param.set_Name("a"); param.set_ParamType("System.Int32[]"); method.addParameterInfo(param);
value = MethodAttributes.HideBySig.value__ | MethodAttributes.Public.value__ | MethodAttributes.ReuseSlot.value__; attributes = new MethodAttributes(value); method = new MethodInfo(t); mdVec.addElement(method); method.set_Attributes(attributes); method.set_Name("testStrArr"); method.set_ReturnType("struct1[]"); method.set_BindingFlags(BindingFlags.Public.value__ | BindingFlags.Instance.value__); value = 0; paramAttrs = new ParameterAttributes(value); param = new ParameterInfo(method); param.set_Attributes(paramAttrs); param.set_Name("a"); param.set_ParamType("struct1[]"); method.addParameterInfo(param);
value = MethodAttributes.HideBySig.value__ | MethodAttributes.Public.value__ | MethodAttributes.ReuseSlot.value__; attributes = new MethodAttributes(value); method = new MethodInfo(t); mdVec.addElement(method); method.set_Attributes(attributes); method.set_Name("testStructAndArr"); method.set_ReturnType("struct1"); method.set_BindingFlags(BindingFlags.Public.value__ | BindingFlags.Instance.value__); value = 0; paramAttrs = new ParameterAttributes(value); param = new ParameterInfo(method); param.set_Attributes(paramAttrs); param.set_Name("a"); param.set_ParamType("struct1"); method.addParameterInfo(param); value = 0; paramAttrs = new ParameterAttributes(value); param = new ParameterInfo(method); param.set_Attributes(paramAttrs); param.set_Name("b"); param.set_ParamType("struct1[]"); method.addParameterInfo(param);
value = MethodAttributes.HideBySig.value__ | MethodAttributes.Public.value__ | MethodAttributes.ReuseSlot.value__; attributes = new MethodAttributes(value); method = new MethodInfo(t); mdVec.addElement(method); method.set_Attributes(attributes); method.set_Name("testStrManyArr"); method.set_ReturnType("struct1[][]"); method.set_BindingFlags(BindingFlags.Public.value__ | BindingFlags.Instance.value__); value = 0; paramAttrs = new ParameterAttributes(value); param = new ParameterInfo(method); param.set_Attributes(paramAttrs); param.set_Name("a"); param.set_ParamType("struct1[][]"); method.addParameterInfo(param);
mdVec = null; MethodInfo[] methods = new MethodInfo[objs.length]; java.lang.System.arraycopy(objs, 0, methods, 0, objs.length); return methods; }
return new EventInfo[0]; }
return new PropertyInfo[0]; }
Object[] attrObjArr = {}; return attrObjArr; }
return new Object[0]; }
return new Object[0]; }
if(str.equals("testInt&System.Int32&System.Int32")){ WebMethodAttribute attrObj0 = new WebMethodAttribute(); Object[] attrObjArr = {attrObj0}; return attrObjArr; } if(str.equals("testStruct&struct1")){ WebMethodAttribute attrObj0 = new WebMethodAttribute(); Object[] attrObjArr = {attrObj0}; return attrObjArr; } if(str.equals("testIntArr&System.Int32[]")){ WebMethodAttribute attrObj0 = new WebMethodAttribute(); Object[] attrObjArr = {attrObj0}; return attrObjArr; } if(str.equals("testStrArr&struct1[]")){ WebMethodAttribute attrObj0 = new WebMethodAttribute(); Object[] attrObjArr = {attrObj0}; return attrObjArr; } if(str.equals("testStructAndArr&struct1&struct1[]")){ WebMethodAttribute attrObj0 = new WebMethodAttribute(); Object[] attrObjArr = {attrObj0}; return attrObjArr; } if(str.equals("testStrManyArr&struct1[][]")){ WebMethodAttribute attrObj0 = new WebMethodAttribute(); Object[] attrObjArr = {attrObj0}; return attrObjArr; } return new Object[0]; }
return new Object[0]; }
return new Object[0]; }
return new Object[0]; }
return new Object[0]; }
return Assembly.Load("muiepsyi"); }
return Module.Load("muiepsyi"); } } 用来保存Web Service中的一些有用的信息,如:Field 域,Property域,方法的一些信息(参数,用户定制属性等),构造器等。Il2java工具产生的一Info文件对应Web Service中的Type。 如果是Tomcat4x服务器,那么可以在server.xml中配置testClient的虚拟目录,如:<Context path="/testClient" docBase="c:\temp"> </Context>,也可以用iNet中的自动配置工具去配置。(iNet支持多个服务器,如:IIS,Apache,WebSphere,Bea WebLogical,Tomcat,Orcal9i等,实现真正意义上的系统兼容)。配置好以后,我们就可以运行了,我们可以发现速度并不比微软慢(因为Microsoft.Net每次都要编译成IL代码才能运行,而iNet在il2java 的时候已经产生了class,所以运行时不占用编译时间)。 但是,微软一个重要的技术XML是非常好的,完全用java去做性能上可能要差一点,因为java的速度本身是要慢,而且Apache公司的JAXP的解释器性能存在瓶颈(Apache公司自己也承认这一点),我想iNet在XML方面可能存在一些问题(在www.stryon.com的网站上也可看到有说明)。 不管怎么说,我觉得iNet这个产品非常的新颖,有创意,应该大有市场。 本文原载于计算机世界 如果您希望与本文章的作者或其所在机构,进一步交流,请联系:畅享网 姜小姐 jill.jiang@amteam.org | 021-51096826-112 | 在线联系 |
节能与优化IT 企业CIO过冬良策当前金融危机的影响还在继续漫延,很多企业都在苦寻过冬的良策,在这种情况下,节能与优化技术与产品无疑成为CIO们关注的首要对象,本次选题就是针对节能与优化IT来为CIO们提供过冬的良…… |
|
|