`

Ajax框架Buffalo深度研究

阅读更多

Buffalo深度研究

——2010.01.11IT进行时[MSN:zhengxianquan AT hotmail Dot com]

目录

1. BUFFALO概述 2
1.1. 主要产品特性 2
1.2. 初次印象 5
2. BUFFALO的关键序列图 5
3. BUFFALO的协议分析 6
3.1. 概述 6
3.2. 请求[BUFFALO.CALL]协议定义 8
3.3. 响应[BUFFALO.RESPONSE]协议定义 8
3.3.1. List-数组或列表 8
3.3.1.1. List 8
3.3.1.2. Array 9
3.3.2. Map & POJO 9
3.3.3. Ref对象引用 10
3.4. FAULT异常 11
3.5. 其他 12
3.5.1. java.sql.Date 12
3.5.2. java.math.BigDecimal/ java.math.BigInteger 12
3.5.3. 还不够? 13
4. 核心类分析 13
4.1. 概述 13
4.2. SERVICE 14
4.2.1. 服务注册与初始化 14
4.2.2. 服务的匹配与调用 18
4.3. PROTOCOL 21
4.3.1. converters(类型转换解析器) 21
4.3.2. io(协议marshal/unmarshal) 22
5. 协议可能需要完善的专题讨论 26
5.1. 深度分析 26
5.2. 可能的解决方案 27
5.2.1. 在ProtocalTag中加入新协议标签 27
5.2.2. 定义两个工具类 28
5.2.2.1. PrimitiveObjectWrapper 28
5.2.2.2. PrimitiveObjectUtil 28
5.2.3. 新增转换器PrimitiveDoubleConverter 29
5.2.4. 修改DoubleConverter的协议标签类型 30
5.2.5. 注册转换器到DefaultConverterLookup 30
5.2.6. 修订FastStreamReader 33
5.2.7. 完善BuffaloCall 33
5.2.8. 客户端buffalo.js 34
5.3. 测试结果 35
6. 参考 36

 

1.  Buffalo概述

Buffalo一个贯穿前后端的比较完整的Ajax框架,目前最新的版本是2.0.1,其主页是:

http://buffalo.sourceforge.net/,可通过该页面找到下载。

不过该版本自2007年来就没有更新了,有点遗憾,不管怎样,一出来就关注到了,早前通读过代码,是个好作品。

上周开始用了些零碎的时间,重新评估并进行了深入的研究,其目的在于通过深度掌握某个优秀的贯穿前后端的AJAX框架,以提高自己的整体认知感。

1.1.      主要产品特性

略,可参考:http://buffalo.sourceforge.net/features.html

1.2.      初次印象

Buffalo最有价值之处,个人感觉有两点:

1、  后端实现了较为完整的基于xmlxml<->object序列化反序列化协议;

2、  前端提供了适配协议的调用封装和响应解析机制,并基于回调机制提供编码API

 

另,作品受xstream影响颇深,如果看过xstream的代码大家的感觉会更明显,不知道这样说Michael是否有意见:buffalo后端转换器、IO部分的代码,是xstreamlightweight版本:)

分享到:
评论
5 楼 itstarting 2010-01-11  
<h2 style="margin: 12pt 0cm; text-indent: 0cm;"><a name="_Toc250983406"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">4.3.</span><span style='font: 7pt "Times New Roman";'>      </span></span></span><span lang="EN-US"><span style="font-size: large; font-family: Times New Roman;">protocol</span></span></a></h2>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">协议在第三章节的“</span><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span><span style="">的协议分析”中做了详细的描述,这章主要分析代码。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">协议部分的代码,总体分为</span><span lang="EN-US"><span style="font-family: Times New Roman;">converters</span></span><span style="">(转换器)、</span><span lang="EN-US"><span style="font-family: Times New Roman;">io</span></span><span style="">(协议</span><span lang="EN-US"><span style="font-family: Times New Roman;">marshal/unmarshal</span></span><span style="">)两个部分,。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">从代码的结构和设计技巧可以看出,</span><span lang="EN-US"><span style="font-family: Times New Roman;">Michael</span></span><span style="">深入研究过</span><span lang="EN-US"><span style="font-family: Times New Roman;">xstream</span></span><span style="">的代码。</span></span></p>
<h3 style="margin: 12pt 0cm; text-indent: 0cm;">
<a name="_Toc250983407"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">4.3.1.</span><span style='font: 7pt "Times New Roman";'>         </span></span></span><span lang="EN-US"><span style="font-size: large; font-family: Times New Roman;">converters</span></span></a><span style=""><span style=""><span style="font-size: large;">(类型转换解析器)</span></span></span>
</h3>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">转换器的代码实现了我们</span><span lang="EN-US"><span style="font-family: Times New Roman;">WEB</span></span><span style="">开发常用的类型解析,从代码结构分为</span><span lang="EN-US"><span style="font-family: Times New Roman;">basic</span></span><span style="">、</span><span lang="EN-US"><span style="font-family: Times New Roman;">collection</span></span><span style="">、</span><span lang="EN-US"><span style="font-family: Times New Roman;">map</span></span><span style="">,还有一些</span><span lang="EN-US"><span style="font-family: Times New Roman;">exceptional</span></span><span style="">(例外)的类型解析。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">Converter</span></span><span style="">的接口定义为:</span></span></p>
<table class="MsoTableGrid" style="border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody><tr style="">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; background-color: transparent;" width="568" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">public</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">interface</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> Converter {<span style="">    </span></span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">boolean</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> canConvert(<span style="text-decoration: underline;">Class</span> type);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> marshal(Object source, MarshallingContext marshallingContext, StreamWriter streamWriter);<span style=""> </span></span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>Object unmarshal(StreamReader reader, UnmarshallingContext unmarshallingContext);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm;"><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">}</span></p>
</td>
</tr></tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="font-size: small;">类图罗列如下:</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><br><img src="http://dl.iteye.com/upload/attachment/191457/a0c60822-c126-38ef-9a49-f7c8ba051241.gif" alt=""><br> <br><img src="http://dl.iteye.com/upload/attachment/191459/eef25b4d-6bb4-3aa3-b17c-fd82d623c2e8.gif" alt=""><br> <br><img src="http://dl.iteye.com/upload/attachment/191461/9eabb347-d86b-3e9d-9746-1d912fda0ad1.gif" alt=""><br> <br><img src="http://dl.iteye.com/upload/attachment/191463/e902eb70-e1fc-36ad-930b-242f277e8550.gif" alt=""><br> </span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">总而言之,这些代码质量都非常高,设计精巧,合理有效使用了各种设计模式,尤其是</span><span lang="EN-US"><span style="font-family: Times New Roman;">Template</span></span><span style="">模式运用的非常精彩。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">需要说明的是,转换器可对</span><span lang="EN-US"><span style="font-family: Times New Roman;">Array</span></span><span style="">及实现了</span><span lang="EN-US"><span style="font-family: Times New Roman;">collection</span></span><span style="">接口的对象进行处理,也可对</span><span lang="EN-US"><span style="font-family: Times New Roman;">Map</span></span><span style="">结果的对象进行了完美的支持,而</span><span lang="EN-US"><span style="font-family: Times New Roman;">POJO</span></span><span style="">其实在</span><span lang="EN-US"><span style="font-family: Times New Roman;">unmarshal</span></span><span style="">与</span><span lang="EN-US"><span style="font-family: Times New Roman;">Map</span></span><span style="">是一样的而仅仅在</span><span lang="EN-US"><span style="font-family: Times New Roman;">marshal</span></span><span style="">上有些特殊。</span></span></p>
<h3 style="margin: 12pt 0cm; text-indent: 0cm;">
<a name="_Toc250983408"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">4.3.2.</span><span style='font: 7pt "Times New Roman";'>         </span></span></span><span lang="EN-US"><span style="font-size: large; font-family: Times New Roman;">io</span></span></a><span style="font-size: large;"><span style=""><span style="">(协议</span><span lang="EN-US"><span style="font-family: Times New Roman;">marshal/unmarshal</span></span></span><span style=""><span style="">)</span></span></span>
</h3>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">io</span></span><span style="">这块代码是最复杂的代码之一,涉及到协议解析的很多细节。代码由于解释过少,有些代码我需要反复调试多次才能明白具体意义——可能跟个人能力和资质有关,汗一个。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="font-size: small;">类图说明如下:</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><br><img src="http://dl.iteye.com/upload/attachment/191465/b5a1f243-fb8a-3b8f-87d7-565d73f3d425.gif" alt=""><br> <br><img src="http://dl.iteye.com/upload/attachment/191467/52e40e33-2c14-3c1e-932d-5c2de0cfa9ae.gif" alt=""><br> </p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="font-size: small;">包括五个非常重要的接口,即</span></span><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">MarshallingContext</span><span style="">、</span><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">UnmarshallingContext</span><span style="">、</span><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">MarshallingStrategy</span><span style="">、</span><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">StreamReader</span><span style="">和</span><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">StreamWriter</span><span style="">。分别如下:</span><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">MarshallingContext</span><span style="">:</span><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;">
</p>
<table class="MsoTableGrid" style="border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody><tr style="">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; background-color: transparent;" width="568" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">public</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">interface</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> <span style="background: silver;">MarshallingContext</span> {</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> convertAnother(Object value);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span><span style="text-decoration: underline;">List</span> getObjects();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> addObjectRef(Object object);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm;"><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">}</span></p>
</td>
</tr></tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">UnmarshallingContext</span><span style="">:</span><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;">
</p>
<table class="MsoTableGrid" style="border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody><tr style="">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; background-color: transparent;" width="568" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">public</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">interface</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> <span style="background: silver;">UnmarshallingContext</span> {</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>Object convertAnother();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> addObject(Object object);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span><span style="text-decoration: underline;">List</span> getObjects();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm;"><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">}</span></p>
</td>
</tr></tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">MarshallingStrategy</span><span style="">:</span><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;">
</p>
<table class="MsoTableGrid" style="border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody><tr style="">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; background-color: transparent;" width="568" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">public</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">interface</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> <span style="background: silver;">MarshallingStrategy</span> {</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> marshal(Object obj, ConverterLookup converterLookup, StreamWriter streamWriter);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>BuffaloCall unmarshal(StreamReader reader, ConverterLookup converterLookup);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm;"><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">}</span></p>
</td>
</tr></tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">StreamReader</span><span style="">:</span><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;">
</p>
<table class="MsoTableGrid" style="border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody><tr style="">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; background-color: transparent;" width="568" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">public</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">interface</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> <span style="background: silver;">StreamReader</span> {</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">boolean</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> hasMoreChildren();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> moveDown();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> moveUp();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>String getNodeName();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>String getValue();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> close();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm;"><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">}</span></p>
</td>
</tr></tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">StreamWriter</span><span style="">:</span><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;">
</p>
<table class="MsoTableGrid" style="border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody><tr style="">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 426.1pt; padding-top: 0cm; background-color: transparent;" width="568" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">public</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">interface</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> <span style="background: silver;">StreamWriter</span> {</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> startNode(String name);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> setValue(String text);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> endNode();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> flush();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> close();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"> </span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm;"><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">}</span></p>
</td>
</tr></tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">从客户端读入的流(</span><span style="line-height: 120%;" lang="EN-US"><span style="font-family: Times New Roman;">request.getInputStream()</span></span><span style="">),将使用实现了</span><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">MarshallingStrategy</span><span style="">接口的</span><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">DefaultMarshallingStrategy</span><span style="">的</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">unmarshal</span><span style="">方法,并通过实现了</span><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">StreamReader</span><span style="">的</span><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">FastStreamReader</span><span style="">解析输入流(为</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">XML</span><span style="">),获得必要的目标业务服务的方法和参数,以最终构建</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">BuffaloCall</span><span style="">对象,并最终得以调用(可参见“服务的匹配与调用”章节)。</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">业务服务调用完毕后,</span><span style="">将使用实现了</span><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">MarshallingStrategy</span><span style="">接口的</span><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">DefaultMarshallingStrategy</span><span style="">的</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">marshal</span><span style="">方法,并通过实现了</span><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">StreamWriter</span><span style="">的</span><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">FastStreamWriter</span><span style="">输入协议流(为</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">XML</span><span style="">)到客户端,实现了</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">XML</span><span style="">协议的解析与交换。</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style='background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">FastStreamReader</span><span style="">那种一个字符一个字符读进来并解析的过程,我是在鼓足勇气后才通读完毕的,并通过多次调试才理解所有的细节,过程中还补了不少课,善哉善哉。(以后如果要通读</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">xstream</span><span style="">,只怕这种勇气得更大更多,</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">^0*</span><span style="">)</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US"></span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">解读过程得益于</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">Buffalo</span><span style="">提供的单元测试类,再次感受到</span><span style='color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">TDD</span><span style="">的好处咯。</span></span><span style="line-height: 120%;" lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"> </p>
4 楼 itstarting 2010-01-11  
<h1 style="margin: 24pt 0cm; text-indent: 0cm;"><a name="_Toc250983401"><span style="" lang="EN-US"><span style="">4.<span style='font: 7pt "Times New Roman";'>  </span></span></span><span style="">核心类分析</span></a></h1>
<h2 style="margin: 12pt 0cm; text-indent: 0cm;"><a name="_Toc250983402"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">4.1.</span><span style='font: 7pt "Times New Roman";'>      </span></span></span><span style=""><span style="font-size: large;">概述</span></span></a></h2>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="font-size: small;">先来看看代码结构,如下:</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><br><img src="http://dl.iteye.com/upload/attachment/191444/8ba24673-e813-3c97-afb3-43a9ec115f54.jpg" alt=""><br> </span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">整体而言,与</span><span lang="EN-US"><span style="font-family: Times New Roman;">xstream</span></span><span style="">有点像,但考虑到</span><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span><span style="">是贯穿前后端的</span><span lang="EN-US"><span style="font-family: Times New Roman;">Ajax</span></span><span style="">框架,还包括了</span><span lang="EN-US"><span style="font-family: Times New Roman;">web/view/request</span></span><span style="">等部分。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">代码的核心部分,主要包括了两个部分,分别为</span><span lang="EN-US"><span style="font-family: Times New Roman;">service</span></span><span style="">和</span><span lang="EN-US"><span style="font-family: Times New Roman;">protocol</span></span><span style="">,下面分别重点分析说明。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"></span></p>
<p><span style="font-size: small;">
<p><span style="">
<h2 style="margin: 12pt 0cm; text-indent: 0cm;"><a name="_Toc250983403"><span style="" lang="EN-US"><span style="">4.2.<span style='font: 7pt "Times New Roman";'>      </span></span></span><span lang="EN-US"><span style="font-family: Times New Roman;">service</span></span></a></h2>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="">此为</span><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span><span style="">目前实现了的</span><span lang="EN-US"><span style="font-family: Times New Roman;">BuffaloWorker</span></span><span style="">为核心的</span><span lang="EN-US"><span style="font-family: Times New Roman;">package</span></span><span style="">,主要包括了业务服务</span><span lang="EN-US"><span style="font-family: Times New Roman;">Repository</span></span><span style="">、业务服务方法适配定位和业务服务调用等部分。</span></p>
<h3 style="margin: 12pt 0cm; text-indent: 0cm;"><a name="_Toc250983404"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">4.2.1.</span><span style='font: 7pt "Times New Roman";'>         </span></span></span><span style=""><span style="font-size: large;">服务注册与初始化</span></span></a></h3>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="">核心类图如下:</span></p>
</span></p>
</span></p>
3 楼 itstarting 2010-01-11  
<h2 style="margin: 12pt 0cm; text-indent: 0cm;">
<a name="_Toc250983396"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">3.4.</span><span style='font: 7pt "Times New Roman";'>      </span></span></span><span lang="EN-US"><span style="font-size: large; font-family: Times New Roman;">fault</span></span></a><span style=""><span style=""><span style="font-size: large;">异常</span></span></span>
</h2>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="font-size: small;">对于异常,我们经常需要关注三个东西:异常编码、异常信息和详细堆栈。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span><span style="">关注业务服务所抛出的异常。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span><span style="">通过捕捉</span></span><span style='font-size: 10pt; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">java.lang.reflect.InvocationTargetException</span><span style="font-size: small;"><span style="">异常,使用</span><span lang="EN-US"><span style="font-family: Times New Roman;">ExceptionConverter</span></span><span style="">转换器提供了类似于</span><span lang="EN-US"><span style="font-family: Times New Roman;">Map</span></span><span style="">的三个属性,</span><span lang="EN-US"><span style="font-family: Times New Roman;">code, message, detail</span></span><span style="">。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="font-size: small;">其中:</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt 21pt; text-indent: 20pt;"><span style='font-size: 10pt; color: #2a00ff; line-height: 120%; font-family: "Courier New";' lang="EN-US">code</span><span style="font-size: small;"><span style="">——异常名称,即</span><span lang="EN-US"><span style="font-family: Times New Roman;">ex.getClass().getName()</span></span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt 21pt; text-indent: 20pt;"><span style='font-size: 10pt; color: #2a00ff; line-height: 120%; font-family: "Courier New";' lang="EN-US">message</span><span style="font-size: small;"><span style="">——异常消息,即</span><span lang="EN-US"><span style="font-family: Times New Roman;">ex.getMessage()</span></span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt 21pt; text-indent: 20pt;"><span style='font-size: 10pt; color: #2a00ff; line-height: 120%; font-family: "Courier New";' lang="EN-US">detail</span><span style="font-size: small;"><span style="">——异常详细消息,如果有,则为</span><span lang="EN-US"><span style="font-family: Times New Roman;">ex.getCause().getMessage()</span></span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="font-size: small;">相关代码如下:</span></span></p>
<table class="MsoTableGrid" style="width: 437.4pt; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0" width="583"><tbody><tr style="">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 437.4pt; padding-top: 0cm; background-color: transparent;" width="583" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">public</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">void</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> marshal(Object source, MarshallingContext marshallingContext, StreamWriter streamWriter) {</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>Throwable ex = (Throwable) source;</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>String detail = </span><span style='font-size: 10pt; color: #2a00ff; font-family: "Courier New";' lang="EN-US">""</span><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">;</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span></span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">if</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> (ex.getCause() != </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">null</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">) {</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">       </span>detail = </span><span style='font-size: 10pt; color: #2a00ff; font-family: "Courier New";' lang="EN-US">"caused by: "</span><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> + ex.getCause().getMessage();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>}</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>streamWriter.startNode(ProtocalTag.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">TAG_FAULT</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>node(streamWriter, ProtocalTag.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">TAG_STRING</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">, </span><span style='font-size: 10pt; color: #2a00ff; font-family: "Courier New";' lang="EN-US">"code"</span><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>node(streamWriter, ProtocalTag.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">TAG_STRING</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">, ex.getClass().getName());</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>node(streamWriter, ProtocalTag.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">TAG_STRING</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">, </span><span style='font-size: 10pt; color: #2a00ff; font-family: "Courier New";' lang="EN-US">"message"</span><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>node(streamWriter, ProtocalTag.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">TAG_STRING</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">, ex.getMessage());</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>node(streamWriter, ProtocalTag.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">TAG_STRING</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">, </span><span style='font-size: 10pt; color: #2a00ff; font-family: "Courier New";' lang="EN-US">"detail"</span><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>node(streamWriter, ProtocalTag.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">TAG_STRING</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">, detail);</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style="">    </span>streamWriter.endNode();</span><span style='font-size: 10pt; font-family: "Courier New";' lang="EN-US"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">}</span></p>
</td>
</tr></tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"> </span></span></p>
<h2 style="margin: 12pt 0cm; text-indent: 0cm;"><a name="_Toc250983397"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">3.5.</span><span style='font: 7pt "Times New Roman";'>      </span></span></span><span style=""><span style="font-size: large;">其他</span></span></a></h2>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span><span style="">还实现了一些例外的对象的协议定义和转换。</span></span></p>
<h3 style="margin: 12pt 0cm; text-indent: 0cm;"><a name="_Toc250983398"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">3.5.1.</span><span style='font: 7pt "Times New Roman";'>         </span></span></span><span lang="EN-US"><span style="font-size: large; font-family: Times New Roman;">java.sql.Date</span></span></a></h3>
<table class="MsoTableGrid" style="margin: auto auto auto 32.4pt; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody>
<tr style="height: 9pt;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0cm; width: 198pt; padding-top: 0cm; height: 9pt;" width="264" valign="top">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm; line-height: 50%; text-align: center;" align="center"><strong style=""><span style="font-size: small;"><span style="">例子</span><span lang="EN-US"></span></span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0cm; border-left: #ece9d8; width: 153pt; padding-top: 0cm; height: 9pt;" width="204" valign="top">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm; line-height: 50%; text-align: center;" align="center"><strong style=""><span style="font-size: small;"><span style="">说明</span><span lang="EN-US"></span></span></strong></p>
</td>
</tr>
<tr style="height: 3.5pt;">
<td style="padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; width: 198pt; padding-top: 0cm; height: 3.5pt; background-color: transparent;" width="264" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">&lt;map&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;type&gt;java.sql.Date&lt;/type&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;string&gt;value&lt;/string&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;date&gt;20061018T211400Z&lt;/date&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">&lt;/map&gt;</span></span></p>
</td>
<td style="padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; border-left: #ece9d8; width: 153pt; padding-top: 0cm; height: 3.5pt; background-color: transparent;" width="204" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style="font-size: small;"><span style="">注意多了个</span><span lang="EN-US"><span style="font-family: Times New Roman;">value</span></span><span style="">,且值是经过特定格式化的</span></span></p>
</td>
</tr>
</tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"> </span></span></p>
<h3 style="margin: 12pt 0cm; text-indent: 0cm;"><a name="_Toc250983399"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">3.5.2.</span><span style='font: 7pt "Times New Roman";'>         </span></span></span><span lang="EN-US"><span style="font-size: large; font-family: Times New Roman;">java.math.BigDecimal/ java.math.BigInteger</span></span></a></h3>
<table class="MsoTableGrid" style="margin: auto auto auto 32.4pt; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody>
<tr style="height: 9pt;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0cm; width: 198pt; padding-top: 0cm; height: 9pt;" width="264" valign="top">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm; line-height: 50%; text-align: center;" align="center"><strong style=""><span style="font-size: small;"><span style="">例子</span><span lang="EN-US"></span></span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0cm; border-left: #ece9d8; width: 153pt; padding-top: 0cm; height: 9pt;" width="204" valign="top">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm; line-height: 50%; text-align: center;" align="center"><strong style=""><span style="font-size: small;"><span style="">说明</span><span lang="EN-US"></span></span></strong></p>
</td>
</tr>
<tr style="height: 3.5pt;">
<td style="padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; width: 198pt; padding-top: 0cm; height: 3.5pt; background-color: transparent;" width="264" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">&lt;map&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;type&gt;java.math.BigDecimal&lt;/type&gt; </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;string&gt;value&lt;/string&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;string&gt;1234567890&lt;/string&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">&lt;/map&gt;</span></span></p>
</td>
<td style="padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; border-left: #ece9d8; width: 153pt; padding-top: 0cm; height: 3.5pt; background-color: transparent;" width="204" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style="font-size: small;"><span style="">注意多了个</span><span lang="EN-US"><span style="font-family: Times New Roman;">value </span></span></span></p>
</td>
</tr>
</tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"> </span></span></p>
<table class="MsoTableGrid" style="margin: auto auto auto 32.4pt; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody>
<tr style="height: 9pt;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0cm; width: 198pt; padding-top: 0cm; height: 9pt;" width="264" valign="top">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm; line-height: 50%; text-align: center;" align="center"><strong style=""><span style="font-size: small;"><span style="">例子</span><span lang="EN-US"></span></span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0cm; border-left: #ece9d8; width: 153pt; padding-top: 0cm; height: 9pt;" width="204" valign="top">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm; line-height: 50%; text-align: center;" align="center"><strong style=""><span style="font-size: small;"><span style="">说明</span><span lang="EN-US"></span></span></strong></p>
</td>
</tr>
<tr style="height: 3.5pt;">
<td style="padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; width: 198pt; padding-top: 0cm; height: 3.5pt; background-color: transparent;" width="264" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">&lt;map&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;type&gt; java.math.BigInteger&lt;/type&gt; </span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;string&gt;value&lt;/string&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;string&gt;1234567890&lt;/string&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">&lt;/map&gt;</span></span></p>
</td>
<td style="padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; border-left: #ece9d8; width: 153pt; padding-top: 0cm; height: 3.5pt; background-color: transparent;" width="204" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style="font-size: small;"><span style="">注意多了个</span><span lang="EN-US"><span style="font-family: Times New Roman;">value </span></span></span></p>
</td>
</tr>
</tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">You can use object.value to get the real value of those objects. When deserializing, it will use the constructor BigDecimal(String) or BigInteger(String) to create a new one.</span></span></p>
<h3 style="margin: 12pt 0cm; text-indent: 0cm;">
<span style="">3.</span><a name="_Toc250983400"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">5.3.</span><span style='font: 7pt "Times New Roman";'>         </span></span></span><span style=""><span style="font-size: large;">还不够?</span></span></a>
</h3>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">那就自己写,实现</span><span lang="EN-US"><span style="font-family: Times New Roman;">Converter</span></span><span style="">,但需要修改(目前只能这么干,</span><span lang="EN-US"><span style="font-family: Times New Roman;">BuffaloProtocal</span></span><span style="">这个类应该要完善下,可方便实现配置</span><span lang="EN-US"><span style="font-family: Times New Roman;">/</span></span><span style="">注入)如下注册类:</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">net.buffalo.protocal.converters.DefaultConverterLookup.java</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">Converter</span></span><span style="">包括三个接口:</span></span></p>
<table class="MsoTableGrid" style="width: 446.4pt; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0" width="595"><tbody><tr style="">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; padding-bottom: 0cm; width: 446.4pt; padding-top: 0cm; background-color: transparent;" width="595" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;">public interface Converter {<span style="">   </span></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 10.5pt; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">boolean canConvert(Class type);</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 10.5pt; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">void marshal(Object source, MarshallingContext marshallingContext, StreamWriter streamWriter);</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 10.5pt; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">Object unmarshal(StreamReader reader, UnmarshallingContext unmarshallingContext);</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">}</span></span></p>
</td>
</tr></tbody></table>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"> </span></span></p>
<p><span style="">提示:可以参考</span><span style="" lang="EN-US">xstream</span><span style="">进行扩展,但一般的</span><span style="" lang="EN-US">WEB</span><span style="">开发,这些转换器还是够了的。</span></p>
2 楼 itstarting 2010-01-11  
<h1 style="margin: 24pt 0cm; text-indent: 0cm;">3<a name="_Toc250983387"><span style="" lang="EN-US"><span style="">.<span style='font: 7pt "Times New Roman";'>  </span></span></span><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span></a><span style=""><span style="">的协议分析</span></span>
</h1>
<h2 style="margin: 12pt 0cm; text-indent: 0cm;"><a name="_Toc250983388"><span style="" lang="EN-US"><span style=""><span style="font-size: large;">3.1.</span><span style='font: 7pt "Times New Roman";'>      </span></span></span><span style=""><span style="font-size: large;">概述</span></span></a></h2>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">协议就是前后端用以通信的约定,</span><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span><span style="">提供的是</span><span lang="EN-US"><span style="font-family: Times New Roman;">XML</span></span><span style="">的协议。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">请求过程是协议</span><span lang="EN-US"><span style="font-family: Times New Roman;">unmarshal</span></span><span style="">的过程,需要通过解析</span><span lang="EN-US"><span style="font-family: Times New Roman;">request.getInputStream()</span></span><span style="">;而把业务执行结果写回客户端的过程是协议的</span><span lang="EN-US"><span style="font-family: Times New Roman;">marshal</span></span><span style="">过程。(说句题外话,</span><span lang="EN-US"><span style="font-family: Times New Roman;">Michael</span></span><span style="">应该是笔误了,在</span><span lang="EN-US"><span style="font-family: Times New Roman;">BuffaloProtocal</span></span><span style="">类中写成了</span><span lang="EN-US"><span style="font-family: Times New Roman;">unmarshall/marshall</span></span><span style="">)</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">显然</span><span lang="EN-US"><span style="font-family: Times New Roman;">Michael</span></span><span style="">是主张测试驱动的开发,单元测试用例写的非常到位,应该说覆盖性是没问题。通过测试用例学习协议,是不错的办法。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">当然了,也可直接参考官方网站的说明:</span><span lang="EN-US"><a href="http://buffalo.sourceforge.net/protocol.html"><span style="font-family: Times New Roman;">http://buffalo.sourceforge.net/protocol.html</span></a></span></span></p>
<p><span style="font-size: small;">
<p><span lang="EN-US">
<h2 style="margin: 12pt 0cm; text-indent: 0cm;">
<a name="_Toc250983389"><span style="" lang="EN-US"><span style="">3.2.<span style='font: 7pt "Times New Roman";'>      </span></span></span><span style="">请求</span><span lang="EN-US"><span style="font-family: Times New Roman;">[Buffalo.Call]</span></span></a><span style=""><span style="">协议定义</span></span>
</h2>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="">所有的请求,都通过如下格式发出:</span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-family: Times New Roman;">buffalo.remoteCall(<strong style=""><em style="">{Service.Method}</em></strong>, <strong style=""><em style="">{Params}</em></strong>, <strong style=""><em style="">{CallBackFunction}</em></strong>)</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="">其中:</span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt 21pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-family: Times New Roman;">Service.Method</span></span><span style="">——</span><span lang="EN-US"><span style="font-family: Times New Roman;">Service</span></span><span style="">为在</span><span lang="EN-US"><span style="font-family: Times New Roman;">buffalo-service.properties</span></span><span style="">或</span><span lang="EN-US"><span style="font-family: Times New Roman;">Spring</span></span><span style="">注册的服务标识;</span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt 21pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-family: Times New Roman;">Params</span></span><span style="">——参数</span><span lang="EN-US"><span style="font-family: Times New Roman;">Array</span></span><span style="">,没有参数则定义一个空的数组“</span><span lang="EN-US"><span style="font-family: Times New Roman;">[]</span></span><span style="">”(建议对</span><span lang="EN-US"><span style="font-family: Times New Roman;">null</span></span><span style="">进行保护);</span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt 21pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-family: Times New Roman;">CallBackFunction</span></span><span style="">——回调函数,提供一个</span><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo.Reply</span></span><span style="">参数</span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-family: Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="">最终给服务器端发出的请求,是标准的基于</span><span lang="EN-US"><span style="font-family: Times New Roman;">UTF-8</span></span><span style="">的</span><span lang="EN-US"><span style="font-family: Times New Roman;">XML</span></span><span style="">,格式举例如下:</span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;">
</p>
<table class="MsoTableGrid" style="margin: auto auto auto 32.4pt; border-collapse: collapse;" border="1" cellspacing="0" cellpadding="0"><tbody>
<tr style="height: 9pt;">
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0cm; width: 198pt; padding-top: 0cm; height: 9pt;" width="264" valign="top">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm; line-height: 50%; text-align: center;" align="center"><strong style=""><span style="font-size: small;"><span style="">例子</span><span lang="EN-US"></span></span></strong></p>
</td>
<td style="padding-right: 5.4pt; padding-left: 5.4pt; background: silver; padding-bottom: 0cm; border-left: #ece9d8; width: 153pt; padding-top: 0cm; height: 9pt;" width="204" valign="top">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 0cm; line-height: 50%; text-align: center;" align="center"><strong style=""><span style="font-size: small;"><span style="">说明</span><span lang="EN-US"></span></span></strong></p>
</td>
</tr>
<tr style="height: 78.05pt;">
<td style="padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; width: 198pt; padding-top: 0cm; height: 78.05pt; background-color: transparent;" width="264" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">&lt;buffalo-call&gt;</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;method&gt;sum&lt;/method&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style=""> </span><span style=""> </span>&lt;double&gt;1&lt;/double&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small;"><span style="font-family: Times New Roman;"><span style="">  </span>&lt;double&gt;2&lt;/double&gt;</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;">&lt;/buffalo-call&gt;</span></span></p>
</td>
<td style="padding-right: 5.4pt; border-top: #ece9d8; padding-left: 5.4pt; padding-bottom: 0cm; border-left: #ece9d8; width: 153pt; padding-top: 0cm; height: 78.05pt; background-color: transparent;" width="204" valign="top">
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span lang="EN-US"><span style="font-size: small; font-family: Times New Roman;"> </span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">-&gt;</span></span><span style="">这是</span><span lang="EN-US"><span style="font-family: Times New Roman;">Service</span></span><span style="">对应的方法</span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 0cm; line-height: normal; text-align: left;" align="left"><span style="font-size: small;"><span lang="EN-US"><span style="font-family: Times New Roman;">-&gt;</span></span><span style="">之后的都是参数,这里表示有两个参数,均为</span><span lang="EN-US"><span style="font-family: Times New Roman;">double</span></span></span></p>
</td>
</tr>
</tbody></table></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span lang="EN-US"><span style="font-family: Times New Roman;"> </span></span></p>
</span></p>
1 楼 itstarting 2010-01-11  
<h1 style="margin: 24pt 0cm; text-indent: 0cm;">
<a name="_Toc250983833"></a><a name="_Toc250983386"><span style=""><span style="" lang="EN-US"><span style="">2.<span style='font: 7pt "Times New Roman";'>  </span></span></span><span lang="EN-US"><span style="font-family: Times New Roman;">Buffalo</span></span></span></a><span style=""><span style=""><span style="">的关键序列图</span></span></span>
</h1>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">要了解</span><span lang="EN-US"><span style="font-family: Times New Roman;">buffalo</span></span><span style="">,与其他开源框架一样,最好的实践在于“跑起来”,跟踪并分析其调用执行过程,即可串接其核心的代码组织、逻辑调用关系等细节。</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="font-size: small;">其请求过程的序列图可大概绘制如下:</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style=""><span style="" lang="EN-US"> <br><img src="http://dl.iteye.com/upload/attachment/191438/f8611e37-9dde-32c4-a4bf-64f193a44c20.gif" alt=""></span></span></p>
<p><span style=""><span style="" lang="EN-US">
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><span style="">概要说明:</span></p>
<p class="MsoNormal" style=""><span style="" lang="EN-US"><span style="">1、<span style='font: 7pt "Times New Roman";'>  </span></span></span><span style="">整体提供了一个</span><span lang="EN-US">Servlet</span><span style="">叫</span><span lang="EN-US">ApplicationServlet</span><span style="">作为唯一的前后端通讯窗口;通过</span><span lang="EN-US">Servlet</span><span style="">的</span><span lang="EN-US">init</span><span style="">过程初始化配置暴露给</span><span lang="EN-US">Buffalo</span><span style="">远程调用的服务(支持内置的</span><span lang="EN-US">buffalo-service.properties</span><span style="">配置及</span><span lang="EN-US">spring</span><span style="">配置),置于</span><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">ServiceRepository</span><span style="">中;</span></p>
<p class="MsoNormal" style=""><span style="" lang="EN-US"><span style="">2、<span style='font: 7pt "Times New Roman";'>  </span></span></span><span style="">根据</span><span lang="EN-US">request.getPathInfo()</span><span style="">所得到的</span><span lang="EN-US">URL</span><span style="">规则,如“</span><span lang="EN-US">/buffalo/simpleService</span><span style="">”,创建对应的</span><span lang="EN-US">Worker</span><span style="">,目前仅实现了</span><span lang="EN-US">BuffaloWorker</span><span style="">;</span></p>
<p class="MsoNormal" style=""><span style="" lang="EN-US"><span style="">3、<span style='font: 7pt "Times New Roman";'>  </span></span></span><span style="">同样根据</span><span lang="EN-US">pageInfo</span><span style="">解析服务名称(如</span><span lang="EN-US">simpleService</span><span style="">),并从</span><span style='font-size: 10pt; background: silver; color: black; line-height: 120%; font-family: "Courier New";' lang="EN-US">ServiceRepository</span><span style="">中获取对应的服务实例;</span></p>
<p class="MsoNormal" style=""><span style="" lang="EN-US"><span style="">4、<span style='font: 7pt "Times New Roman";'>  </span></span></span><span style="">通过</span><span lang="EN-US">BuffaloProtocal</span><span style="">实例</span><span lang="EN-US">unmarshall</span><span style="">客户端发出的</span><span lang="EN-US">InputStream</span><span style="">,并通过获取方法和参数,构建完整的</span><span lang="EN-US">BuffaloCall</span><span style="">;</span></p>
<p class="MsoNormal" style=""><span style="" lang="EN-US"><span style="">5、<span style='font: 7pt "Times New Roman";'>  </span></span></span><span style="">通过分析</span><span lang="EN-US">BuffaloCall</span><span style="">对应业务服务各方法参数的匹配权重,获取最合适的调用方法,并调用,匹配过的方法,将置入缓存以提升性能;</span></p>
<p class="MsoNormal" style=""><span style="" lang="EN-US"><span style="">6、<span style='font: 7pt "Times New Roman";'>  </span></span></span><span style="">根据调用结果,需要通过</span><span lang="EN-US">BuffaloProtocal</span><span style="">实例</span><span lang="EN-US">marshall</span><span style="">结果,并通过</span><span lang="EN-US">StreamWriter</span><span style="">(</span><span lang="EN-US">wrap</span><span style="">了</span><span lang="EN-US">response.getOutputStream()</span><span style="">)写回调用客户端;</span></p>
<p class="MsoNormal" style=""><span style="" lang="EN-US"><span style="">7、<span style='font: 7pt "Times New Roman";'>  </span></span></span><span style="">客户端通过</span><span lang="EN-US">Buffalo.Reply</span><span style="">解析返回的结果,并实现与</span><span lang="EN-US">UI</span><span style="">的交互。</span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"><br> </p>
</span></span></p>
<p class="MsoNormal" style="margin: 6pt 0cm 0pt; text-indent: 21pt;"> </p>

相关推荐

    国产Ajax框架 Buffalo

    【Ajax框架Buffalo详解】 Ajax(Asynchronous JavaScript and XML)技术自2005年以来,极大地改变了网页应用程序的开发方式,使得页面无需刷新即可与服务器进行数据交互,提升了用户体验。而“国产Ajax框架 Buffalo...

    JAVA源码国产Ajax框架Buffalo

    JAVA源码国产Ajax框架Buffalo

    java资源国产Ajax框架Buffalo

    java资源国产Ajax框架 Buffalo提取方式是百度网盘分享地址

    国产Ajax框架 Buffalo.7z

    《国产Ajax框架 Buffalo详解》 Ajax(Asynchronous JavaScript and XML)技术在Web开发领域中扮演着重要的角色,它使得网页可以实现异步更新,提升了用户体验。而在众多Ajax框架中,国产Ajax框架Buffalo以其独特的...

    基于Java的实例源码-国产Ajax框架 Buffalo.zip

    【标题】"基于Java的实例源码-国产Ajax框架 Buffalo.zip" 提供的是一个使用Java语言实现的国产Ajax框架——Buffalo的相关源代码。Ajax(Asynchronous JavaScript and XML)技术是一种在无需重新加载整个网页的情况下...

    java源码:国产Ajax框架 Buffalo.rar

    《Java源码解析:国产Ajax框架Buffalo》 在当今Web开发领域,Ajax技术因其能够实现页面...通过深入研究其源码,我们可以从中获取到许多关于Ajax框架设计、性能优化和事件处理的宝贵经验,进一步提升我们的编程技能。

    基于java的开发源码-国产Ajax框架 Buffalo.zip

    **Ajax框架Buffalo详解** Ajax(Asynchronous JavaScript and XML)技术是现代Web开发中的关键组成部分,它使得网页能够实现异步更新,提升了用户体验。而基于Java的Ajax框架Buffalo则是国内开发者为解决这一需求而...

    基于java的国产Ajax框架 Buffalo.zip

    【标题】基于Java的国产Ajax框架 Buffalo Ajax(Asynchronous JavaScript and XML)是一种在无需刷新整个网页的情况下,能够更新部分网页的技术。它通过在后台与服务器进行少量数据交换,使网页实现异步更新,极大...

    基于Java的国产Ajax框架 Buffalo.zip

    **基于Java的国产Ajax框架 Buffalo** Ajax(Asynchronous JavaScript and XML)是一种在无需重新加载整个网页的情况下,能够更新部分网页的技术。它通过在后台与服务器进行少量数据交换,使网页实现异步更新,提升...

    Buffalo 1.1 ajax框架

    AJAX是开发基于web的rich client的一种方式,Buffalo则是实现AJAX的一个框架。Buffalo中定义了Web远程调用的传输基础,并且将远程调用对象完整的序列化到了本地,成为可以被JavaScript编程触及的对象。Buffalo中的...

    国产Ajax框架 Buffalo源码

    《国产Ajax框架 Buffalo源码详解》 Ajax,全称Asynchronous JavaScript and XML,是一种在无需刷新整个网页的情况下,能够更新部分网页的技术。它通过在后台与服务器进行少量数据交换,使得网页实现异步更新,极大...

    buffalo-1.2alpha1 ajax框架

    Buffalo则是实现AJAX的一个框架。Buffalo中定义了Web远程调用的传输基础,并且将远程调用对象完整的序列化到了本地,成为可以被JavaScript编程触及的对象。Buffalo中的重要组件-BuffaloBinding,提供了将JavaScript...

    小程序 国产Ajax框架 Buffalo(源码).rar

    免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,...

    buffalo1.2ajax框架应用演示例子

    buffalo1.2ajax框架应用演示例子 buffalo1.2下载地址: http://www.codechina.net/resource/html/2005-12/06/119641.html

    基于Ajax的buffalo技术的helloword和三级联动菜单

    基于Ajax的buffalo技术的helloword和三级联动菜单 包含入门模块:helloword、延伸模块:三级联动菜单 项目已包含所有文件,只需导入myeclipse运行即可。 开发环境:myeclipse6.0、jdk1.5、tomcat5.0 说明:连数据库...

    AJAX(Buffalo)配置使用

    Buffalo是一个用于构建Web应用程序的Go框架,它提供了方便的工具来处理HTTP请求,包括AJAX请求。要使用AJAX,你需要在前端设置JavaScript代码来发起请求,同时在后端配置相应的路由和处理函数。 1. **前端配置**:...

    ajax十大框架

    根据给定的信息,我们可以梳理出以下关于Ajax框架的相关知识点: ### 1. Prototype Prototype 是一个功能强大的 JavaScript 库,它扩展了 DOM API,并提供了一系列便捷的方法和对象。该库非常优雅,支持丰富的 ...

    Buffalo框架所需文件

    Buffalo框架是一个基于Java开发的轻量级Web应用框架,其设计目标是简化开发流程,提高开发效率。在描述中提到的"Buffalo框架所需文件"压缩包,包含了该框架运行所必需的组件,主要是jar文件和JS文件。这些文件在Java...

    buffalo-l 包buffalo-sc包

    在IT行业中,`buffalo-l` 和 `buffalo-sc` 是两个特定的软件包,它们可能涉及特定的开发框架或工具。尽管提供的信息有限,但我们可以根据这些关键词推测出一些可能的知识点。以下是对这两个包的详细解释以及与之相关...

    buffalo.jar

    buffalo2.0.jar,ajax使用buffalo框架!

Global site tag (gtag.js) - Google Analytics