`
akiraray
  • 浏览: 88407 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Code with Jacorb In Action Vol.1

阅读更多

花了半天把Jacorb的那些东西都看下 自己动手写了一个CRUD的小应用,网上Jacorb的教程多时启动的……实际编码的不多(不过Corba都是相同的)
乘今天兴致好……就随便写写丢丢人

目标读者:Corba白丁,Java初心
预备知识:Jacorb的环境配置(可以看偶前一篇日志)
应用介绍 一个简单的银行交易迷你系统……(这个比附带的DEMO还要简单)
功能JUST增删改查

动手之前确定一下这个软件需要作什么……
这是个服务器端程序,我们不需要界面,我们只需要客户端和我们遵守一些接口约定便可以提供服务
而与客户端的约定就是IDL文件……

首先写一下IDL文件
module cn{
	module bankApp{
	struct Account{
	long long id;
	string accountNo;
	string password;
	double amount;
	long category;
	};

	interface Bank{

	typedef Account Accounts[20];


	boolean drawMoney(in Account targetAccounti,in double amount);
	boolean saveMoeny(in Account targetAccount,in double amount);	
	boolean moveMoney(in Account initAccount,in Account targetAccount,in double amount);
	boolean cancelAccount(in Account detail);
	boolean createAccount(in Account detail);
	boolean updateAccount(in Account targetAccount);
	Accounts showAccounts(in long page);
	Account showAccount(in Account tragetAccount);
	boolean accountIsHaded(in string name);
	};	
	};
};



简单的说一下IDL描述的功能

module cn{
	module bankApp{

相当于java中的包
	struct Account{
	long long id;
	string accountNo;
	string password;
	double amount;
	long category;
	};

一个结构体,相当于JAVA中的一个POJO对象,为了封装起一些相关的基础数据

引用

interface Bank{

一个接口,相当于java中一个interface对象

typedef Account Accounts[20];

定义一个Account类型的数组 大小为20(固定的),别名叫Accounts

	boolean drawMoney(in Account targetAccounti,in double amount);
	boolean saveMoeny(in Account targetAccount,in double amount);	
	boolean moveMoney(in Account initAccount,in Account targetAccount,in double amount);
	boolean createAccount(in Account detail);
	Accounts showAccounts(in long page);
	Account showAccount(in Account tragetAccount);

这个接口提供的相关方法行为
依次为取钱,存钱,转帐(英文差),开户,查询指定帐户,查询系列帐户
boolean moveMoney(in Account initAccount,in Account targetAccount,in double amount);

boolean 代表返回类型,moveMoney是方法名,参数的签名格式为 in(传入) Account(类型) initAccount(变量名)
基本的Java与Ide对应类型,可以去WIKI看看,这里说一下java中的int对应IDL就是long
,java的long 对应long long(其实就是算位长的)

保存一下IDL文件命名为bank.idl

打开命令行,输入 idl bank.idl,然后Jacorb就自动解析了这个IDL文件
成功后发现多了一个./cn/bankApp的文件路径
AccountHelper.java  BankHelper.java  BankOperations.java  BankPOATie.java
AccountHolder.java  BankHolder.java  BankPackage          _BankStub.java
Account.java        Bank.java        BankPOA.java

*Helper *.Holderd都是将IDL中的结构体序列化OR反序列化的助手类(可以忽略)
_BankStub是一个装 负责对请求调用相应的接口阿,返回值的处理
BankOperations.java 就是接口,只表述这个应用作点什么
POA和POATie则是CorbaPOA的相应类

可以说Jacorba把大部分代码都生成了 ,我们现在只要关心我们自己的业务就可以了。
我们现在需要作的事情有这些
1.自己写一个类 负责实现Bank.java中的方法
2.自己写一个服务器类,负责注册NameServer和帮定端口
---
扩展
3.可以写一个简单的客户端类,用于测试通讯
这些放再下一次写了
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics