王朝网络
分享
 
 
 

Microsoft.Net的Java实现

王朝java/jsp·作者佚名  2008-05-31
宽屏版  字体: |||超大  

众所周知,微软公司正在全力打造.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:

using System;

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 class testClient : WebService {

[WebMethod()]

public int testInt(int a,int b){

return a+b;

}

[WebMethod()]

public strUCt1 testStruct(struct1 a){

return a;

}

[WebMethod()]

public int[] testIntArr(int[] a){

return a;

}

[WebMethod()]

public struct1[] testStrArr(struct1[] a){

return a;

}

[WebMethod()]

public struct1 testStructAndArr(struct1 a,struct1[] b){

return a;

}

[WebMethod()]

public struct1[][] testStrManyArr(struct1[][] a){

return a;

}

}

public class struct1:parent{

public int i=1;

public string j="ok";

public struct2 s2;

}

public class parent{

public String p;

}

public class struct2{

public String sField;

}

我们可以用il2java 工具转换成java代码(il2java工具可以在www.stryon.com 网站上下载,包括在iNet产品中),如:il2java http://localhost/testClient/testClient.asmx c:\temp,运行这个命令,将在c盘temp目录下产生 testClient.java 和testClient_Info.java:

testClient.java:

import system.*;

import system.Reflection.*;

import system.Web.Services.*;

public class testClient extends WebService{

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 testClient(){

super();

}

}

用来指明Web Service中有哪些Web方法,以便被客户调用;

testClient_Info.java:

import system.*;

import system.Reflection.*;

import system.Web.Services.*;

public class testClient_Info implements IMetaData{

public void fillType(Type t){

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);

}

public FieldInfo[] GetFieldsImpl(Type t){

return new FieldInfo[0];

}

public ConstructorInfo[] GetConstructorsImpl(Type t){

long value = 0;

ConstructorInfo ctor = null;

ParameterInfo param = null;

MethodAttributes attributes = null;

ParameterAttributes paramAttrs = null;

java.util.Vector ctorVec = new java.util.Vector();

// public testClient();

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__);

Object[] objs = ctorVec.toArray();

ctorVec = null;

ConstructorInfo[] ctors = new ConstructorInfo[objs.length];

java.lang.System.arraycopy(objs, 0, ctors, 0, objs.length);

return ctors;

}

public MethodInfo[] GetMethodsImpl(Type t){

long value = 0;

MethodInfo method = null;

ParameterInfo param = null;

MethodAttributes attributes = null;

ParameterAttributes paramAttrs = null;

java.util.Vector mdVec = new java.util.Vector();

// public int testInt(int a, int b);

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);

// public struct1 testStruct(struct1 a);

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;

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
>>返回首页<<
推荐阅读
 
 
频道精选
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
© 2005- 王朝网络 版权所有