• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            隨筆 - 181, 文章 - 2, 評論 - 85, 引用 - 0
            數(shù)據(jù)加載中……

            使用 Rational Application Developer 和 WebSphere Application Server 來加速基于 XML 的 SOA 的 JSF 開發(fā)——第 2 部分

            本文提出了加快基于 XML 的面向服務(wù)的體系結(jié)構(gòu)(Service Oriented Architecture,SOA)應(yīng)用程序表示開發(fā)的解決方案系列文章的第 2 部分。這種解決方案包括 Eclipse 功能,可以生成靜態(tài)類型的用于 XSD Schema 的服務(wù)對象數(shù)據(jù)(Service Data Object,SDO),并提供了在表示元素數(shù)據(jù)與 XML 數(shù)據(jù)相互轉(zhuǎn)換中使用 SDO 的運行框架。第 2 部分增強了在第 1 部分中開發(fā)的解決方案。

            引言

            這個由五部分組成的系列文章提出了能夠加快基于 XML 的 SOA 應(yīng)用程序表示開發(fā)的解決方案,這種解決方案包括 Eclipse 功能,可以生成靜態(tài)類型的用于 XSD Schema 的服務(wù)對象數(shù)據(jù)(Service Data Object,SDO),并提供了在表示元素數(shù)據(jù)與 XML 數(shù)據(jù)相互轉(zhuǎn)換中使用 SDO 的運行框架。在該系列文獻(xiàn)的 第 1 部分 中,我們經(jīng)歷了通過使用提供的插件集來向每個指定的 XML schema 中的服務(wù)傳遞信息的簡單 JSF 應(yīng)用程序的整個開發(fā)過程,我們使用的應(yīng)用程序場景進(jìn)行了一次服務(wù)調(diào)用——發(fā)出一個 XML 請求及收到一個 XML 響應(yīng)。這個應(yīng)用程序說明了主從復(fù)合結(jié)構(gòu)的數(shù)據(jù)對象視圖,連同分頁及分類的能力。

            在第 2 部分中,我們將擴展在 第 1 部分 中開發(fā)的解決方案,使之包括創(chuàng)建、更新和刪除功能,包括用本地附加的變量及基本的轉(zhuǎn)換來自定義生成 SDO。該文章將舉例說明多 schema 模型、對于單一頁面中多個請求及響應(yīng)的場景,并且說明綁定 XML 數(shù)據(jù)的 JSF 下拉式控制。

            IBM? Rational? Application Developer V6 以及 Websphere? Application Server V6 需要利用這種轉(zhuǎn)換功能。本文假定讀者是精通 Rational Application Developer 的 JSF 頁面設(shè)計師。







            安裝 XSD SDO 轉(zhuǎn)換功能

            為了安裝 XSD SDO 的轉(zhuǎn)換功能,請按照 第 1 部分 中的詳細(xì)步驟操作。







            場景

            我們的場景擴展了第 1 部分 中開發(fā)的保險應(yīng)用程序,使之包括創(chuàng)建、更新以及刪除功能,本地附加的變量,基本的轉(zhuǎn)換和 下拉式綁定的功能。在該場景中:

            • 我們假設(shè) XYZ 保險公司有許多已注冊的代理人。
            • 每個代理人都有許多客戶,并且每個客戶都同代理人簽訂了許多策略。
            • 保險公司通過標(biāo)準(zhǔn)的 BrokerService 方案來展示代理人的服務(wù)(清單 1),并使用有效代服務(wù) validCodesService schema(清單 2)進(jìn)行檢索,例如有效的狀態(tài)碼。
            • 任何來自代理人的通信就是一個 XML 請求/響應(yīng),它服從清單 1 和清單 2 中的 schema 定義。(這些清單同樣也在下載文件xsd_sdo_soa_part2_listings.zip 中的提供。)

            清單 1. BrokerService.xsd

            												
            														<?xml version="1.0" encoding="UTF-8"?>
            <xsd:schema xmlns="http:///xyz.brokerservice.ecore"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
            targetNamespace="http:///xyz.brokerservice.ecore">
            	<xsd:annotation>
            		<xsd:documentation xml:lang="en">
               			Broker Service Schema for xyz.com.
               			Copyright 2004 ibm.com. All rights reserved.
              		</xsd:documentation>
            	</xsd:annotation>
            	<xsd:element name="brokerService" type="brokerServiceType"/>
            	<xsd:complexType name="brokerServiceType">
            		<xsd:sequence>
            			<xsd:element minOccurs="0" name="broker" type="brokerType"/>
            			<xsd:element minOccurs="0" name="error" type="errorType"/>
            		</xsd:sequence>
            	</xsd:complexType>
            	<xsd:complexType name="brokerType">
            		<xsd:sequence>
            			<xsd:element minOccurs="0" ref="firstName"/>
            			<xsd:element minOccurs="0" ref="lastName"/>
            			<xsd:element minOccurs="0" name="loginName" type="xsd:string"/>
            			<xsd:element minOccurs="0" name="loginPassword" type="xsd:string"/>
            			<xsd:element maxOccurs="unbounded" minOccurs="0" name="client" type="clientType"/>
            		</xsd:sequence>
            		<xsd:attribute name="brokerId" type="xsd:string" use="required"/>
            	</xsd:complexType>
            	<xsd:complexType name="clientType">
            		<xsd:sequence>
            			<xsd:element minOccurs="0" ref="firstName"/>
            			<xsd:element minOccurs="0" ref="lastName"/>
            			<xsd:element minOccurs="0" name="dateOfBirth" type="xsd:date"/>
            			<xsd:element minOccurs="0" name="currentAddress" type="addressType"/>
            			<xsd:element minOccurs="0" name="permanentAddress" type="addressType"/>
            			<xsd:element maxOccurs="unbounded" minOccurs="0" name="policy" type="policyType"/>
            		</xsd:sequence>
            		<xsd:attribute name="clientId" type="xsd:string" use="required"/>
            	</xsd:complexType>
            	<xsd:complexType name="addressType">
            		<xsd:sequence>
            			<xsd:element name="street" type="xsd:string"/>
            			<xsd:element name="city" type="xsd:string"/>
            			<xsd:element name="state" type="xsd:string"/>
            			<xsd:element name="zip" type="xsd:string"/>
            			<xsd:element name="country" type="xsd:string"/>
            		</xsd:sequence>
            	</xsd:complexType>
            	<xsd:complexType name="policyType">
            		<xsd:sequence>
            			<xsd:element name="policyName" type="xsd:string"/>
            			<xsd:element name="policyStartDate" type="xsd:date"/>
            			<xsd:element name="policyEndDate" type="xsd:date"/>
            			<xsd:element name="policyAmount" type="xsd:string"/>
            			<xsd:element name="policyDescription" type="xsd:string"/>
            		</xsd:sequence>
            		<xsd:attribute name="policyId" type="xsd:string" use="required"/>
            	</xsd:complexType>
            	<xsd:complexType name="errorType">
            		<xsd:sequence>
            			<xsd:element name="errorCode" type="xsd:string"/>
            			<xsd:element name="errorDescription" type="xsd:string"/>
            		</xsd:sequence>
            	</xsd:complexType>
            	<xsd:element name="firstName" type="xsd:string"/>
            	<xsd:element name="lastName" type="xsd:string"/>
            </xsd:schema>
            
            												
            										


            圖 1. BrokerService Schema 模型
            BrokerService Schema 模型

            清單 2. ValidCodesService.xsd

            												
            														<?xml version="1.0" encoding="UTF-8"?>
            <xsd:schema xmlns="http:///xyz.validcodesservice.ecore"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
            targetNamespace="http:///xyz.validcodesservice.ecore">
            	<xsd:annotation>
            		<xsd:documentation xml:lang="en">
               			Valid Codes Service Schema for xyz.com.
               			Copyright 2004 ibm.com. All rights reserved.
              		</xsd:documentation>
            	</xsd:annotation>
            	<xsd:element name="validCodesService" type="validCodesServiceType"/>
            	<xsd:complexType name="validCodesServiceType">
            		<xsd:sequence>
            			<xsd:element minOccurs="0" name="stateList" type="stateListType"/>
            			<xsd:element minOccurs="0" name="policyCodeList" type="policyCodeListType"/>
            		</xsd:sequence>
            	</xsd:complexType>
            	
            	<xsd:complexType name="stateListType">
            		<xsd:sequence>
            			<xsd:element maxOccurs="unbounded" minOccurs="0" name="state" type="stateType"/>
            		</xsd:sequence>
            	</xsd:complexType>
            	
            		<xsd:complexType name="stateType">
            		<xsd:sequence>
            			<xsd:element name="shortName" type="xsd:string"/>
            			<xsd:element name="fullName" type="xsd:string"/>
            		</xsd:sequence>
            	</xsd:complexType>
            	
            		<xsd:complexType name="policyCodeListType">
            		<xsd:sequence>
            			<xsd:element maxOccurs="unbounded" minOccurs="0" name="policyCode" type="policyCodeType"/>
            		</xsd:sequence>
            	</xsd:complexType>
            			<xsd:complexType name="policyCodeType">
            		<xsd:sequence>
            			<xsd:element name="shortName" type="xsd:string"/>
            			<xsd:element name="fullName" type="xsd:string"/>
            		</xsd:sequence>
            	</xsd:complexType>
            	
            </xsd:schema>
            
            												
            										


            圖 2. ValidCodesService schema 模型
            ValidCodesService schema 模型

            BrokerUpdate 場景

            該場景為現(xiàn)有的 brokerupdate.jsp JavaServer Faces JSP 頁增添了新的功能。該頁已經(jīng)發(fā)送請求以獲得代理人的詳細(xì)資料(第 1 部分 中的 brokerDetailRequest.xml),并且接收到了包含代理人的所有客戶和他們的策略的響應(yīng)信息(第 1 部分中的brokerDetailResponse.xml)。該頁也將會調(diào)用有效的代碼服務(wù)來檢索有效的代碼值作為一個 XML 響應(yīng)(清單 5 中的 allValidCodesResponse.xml),同時也能夠創(chuàng)建、更新和刪除策略,還能夠演示除了用于基本轉(zhuǎn)換的來自已經(jīng)生成的 SDO 的行為之外的操作行為。轉(zhuǎn)換作為 brokerUpdateRequest.xml (清單 3)發(fā)送到該服務(wù),對操作成功或者失敗的響應(yīng)作為brokerUpdateResponse.xml (清單 4)接收。 brokersummary.jsp 頁在檢索來自服務(wù)更新后的改動之后將顯示出來。


            圖 3. BrokerUpdate 請求/響應(yīng)信息流
            圖 3. BrokerUpdate 請求/響應(yīng)信息流

            Listing 3. brokerUpdateRequest.xml

            												
            														<?xml version="1.0" encoding="UTF-8"?>
            <brokerService xmlns="http:///xyz.brokerservice.ecore"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
            <broker brokerId="000-00-9999">
            	<firstName>Narinder</firstName>
            	<lastName>Makin</lastName>
            	<client clientId="001-00-9999">
            		<firstName>Dan</firstName>
            		<lastName>Moore</lastName>
            		<dateOfBirth>1967-08-13</dateOfBirth>
            		<currentAddress>
            			<street>113 Oak Pine St.</street>
            			<city>Santa Clara</city>
            			<state>LA</state>
            			<zip>91929</zip>
            			<country>US</country>
            		</currentAddress>
            		<permanentAddress>
            			<street>123 Demi Lane</street>
            			<city>Cary</city>
            			<state>NC</state>
            			<zip>22999</zip>
            			<country>US</country>
            		</permanentAddress>
            		<policy policyId="L000000000">
            			<policyName>Life</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>200000.00</policyAmount>
            			<policyDescription>Life Insurance</policyDescription>
            		</policy>
            		<policy policyId="H000000000">
            		<policyName>House</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>20000.00</policyAmount>
            			<policyDescription>Home Insurance</policyDescription>
            		</policy>
            		<policy policyId="C000000001">
            		<policyName>Car 1</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>15000.00</policyAmount>
            			<policyDescription>Car Insurance - Ferrari 2004 - Primary Car </policyDescription>
            		</policy>
            		<policy policyId="C000000002">
            		<policyName>Car 2</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>5000.00</policyAmount>
            			<policyDescription>Car Insurance - Lexus 2003 - Secondary Car </policyDescription>
            		</policy>
            		<policy policyId="B000000002">
            		<policyName>Restaurant</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>25000.00</policyAmount>
            			<policyDescription>Business Insurance - Restaurant</policyDescription>
            		</policy>
            		<policy policyId="B000000003">
            		<policyName>Golf Course</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>25000.00</policyAmount>
            			<policyDescription>Second Business Insurance - Golf Course</policyDescription>
            		</policy>
            	</client>
            	<client clientId="002-00-9999">
            		<firstName>Tom</firstName>
            		<lastName>Cross</lastName>
            		<dateOfBirth>1970-11-11</dateOfBirth>
            		<currentAddress>
            			<street>113 Duke St.</street>
            			<city>Shelton</city>
            			<state>CT</state>
            			<zip>08989</zip>
            			<country>US</country>
            		</currentAddress>
            		<permanentAddress>
            			<street>123 Lex Lane</street>
            			<city>Fairfield</city>
            			<state>NY</state>
            			<zip>09833</zip>
            			<country>US</country>
            		</permanentAddress>
            		<policy policyId="L100000000">
            			<policyName>Life</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>100000.00</policyAmount>
            			<policyDescription>Life Insurance</policyDescription>
            		</policy>
            		<policy policyId="H100000000">
            			<policyName>House</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>2000.00</policyAmount>
            			<policyDescription>Home Insurance</policyDescription>
            		</policy>
            		<policy policyId="C100000001">
            			<policyName>Car 1</policyName>
            			<policyStartDate>2004-01-01</policyStartDate>
            			<policyEndDate>2005-01-01</policyEndDate>
            			<policyAmount>2000.00</policyAmount>
            			<policyDescription>Car Insurance - Camry 2004 - Primary Car </policyDescription>
            		</policy>
            	</client>
            </broker>
            </brokerService>
            												
            										

            清單 4. brokerUpdateResponse.xml

            												
            														<?xml version="1.0" encoding="UTF-8"?>
            <brokerService xmlns="http:///xyz.brokerservice.ecore"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            	<broker brokerId="099-99-9999"/>
            	<error>
            		<errorCode>0</errorCode>
            		<errorDescription>Success: The changes have been successfully applied to the policy.</errorDescription>
            	</error>
            </brokerService>
            
            												
            										

            清單 5. allValidCodesResponse.xml

            												
            														<?xml version="1.0" encoding="UTF-8"?>
            <validCodesService xmlns="http:///xyz.validcodesservice.ecore"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
            	<stateList>
            		<state>
            			<shortName>CT</shortName>
            			<fullName>Connecticut</fullName>
            		</state>
            		<state>
            			<shortName>LA</shortName>
            			<fullName>Los Angelas</fullName>
            		</state>
            		<state>
            			<shortName>NC</shortName>
            			<fullName>North Carolina</fullName>
            		</state>
            		<state>
            			<shortName>CA</shortName>
            			<fullName>California</fullName>
            		</state>
            		<state>
            			<shortName>NH</shortName>
            			<fullName>New Hampshire</fullName>
            		</state>
            		<state>
            			<shortName>VA</shortName>
            			<fullName>Virginia</fullName>
            		</state>
            	</stateList>
            	<policyCodeList>
            		<policyCode>
            			<shortName>H</shortName>
            			<fullName>House</fullName>
            		</policyCode>
            		<policyCode>
            			<shortName>C</shortName>
            			<fullName>Car</fullName>
            		</policyCode>
            		<policyCode>
            			<shortName>B</shortName>
            			<fullName>Business</fullName>
            		</policyCode>
            	</policyCodeList>	
            </validCodesService>
            
            												
            										







            應(yīng)用程序設(shè)計流

            圖 4 描繪了用于該場景的應(yīng)用程序設(shè)計流。


            圖 4. 應(yīng)用程序設(shè)計流
            應(yīng)用程序設(shè)計流






            運行時架構(gòu)

            一旦頁請求到來,就會發(fā)生以下事件 (圖 5):

            1. JSF 運行時將調(diào)用 BrokerUpdateRoot bean。
            2. BrokerUpdateRoot 將向 BrokerService 發(fā)送 brokerDetailRequest.xml 來預(yù)加載數(shù)據(jù)。
            3. BrokerService 將已經(jīng)被傳送到 XMLTransformServiceFactory 的響應(yīng)作為 brokerDetailResponse.xml 發(fā)送。
            4. XML 被轉(zhuǎn)換為封裝在 BrokerUpdateRoot bean 中的 SDO。
            5. JSF 運行時將調(diào)用 ValidCodesServiceRoot bean。
            6. ValidCodesServiceRoot Java? bean 將調(diào)用 ValidCodesService 來預(yù)裝載這些數(shù)據(jù)。
            7. ValidCodesService 已經(jīng)被傳送到 XMLTransformServiceFactory 的響應(yīng)作為 allValidCodesResponse.xml 發(fā)送。
            8. XML 被轉(zhuǎn)換為封裝在 ValidCodesServiceRoot bean 中的 SDO。
            9. JSF 運行時移交數(shù)據(jù)的控制權(quán)。
            10. 從 bean 中調(diào)用 XMLTransformServiceFactory。SDO 實例會傳送到 XMLTransformServiceFactory,并轉(zhuǎn)變成發(fā)送到 BrokerService 的 brokerUpdateRequest.xml
            11. brokerUpdateResponse.xml 作為響應(yīng)接收,并傳送到封裝在 BrokerUpdateRoot bean 中的 SDO。


            圖 5. 運行時架構(gòu)
            運行時架構(gòu)






            實現(xiàn)解決方案

            在下面的章節(jié)中詳細(xì)描述了實現(xiàn)該解決方案的步驟:

            1. 導(dǎo)入項目轉(zhuǎn)換
            2. 從 XSD schema 創(chuàng)建 SDO 包
            3. 向已經(jīng)生成的 SDO 增添附加的屬性和行為
            4. 添加新的根 bean 封裝器
            5. 更新現(xiàn)有的根 bean 封裝器
            6. 向頁代碼中增添命令方法
            7. 將 bean 附加到頁面數(shù)據(jù)
            8. 將頁面上綁定的控件修改為頁面數(shù)據(jù)的 SDO 類型
            9. 運行 brokerdetail.jsp

            1. 導(dǎo)入項目轉(zhuǎn)換

              將項目轉(zhuǎn)換 xsd_sdo_soa_xml_tutorial.zip 下載文件 導(dǎo)入到 Application Developer 的工作區(qū)中。因此,下面的項目將被導(dǎo)入(圖 6):

              • XYZInsuranceEAR:以模塊化或者有效性來包含所有其他項目的企業(yè)應(yīng)用程序項目。
              • XYZInsuranceWeb:用于創(chuàng)建了所有 JSF JSP 頁的應(yīng)用程序的動態(tài) Web 項目。該項目的 WebContent 文件夾中的 Schema 文件夾中有 BrokerService.xsd schema 文件和實例數(shù)據(jù)文件。為簡化起見,本例中的 schema 和 SDO 包是的 WebProject 的一部分。如果用戶愿意通過多個 Web 項目分享同一個 SDO,那么用戶就能創(chuàng)建一個單獨的 Java 項目用于 SDO 包。SDO 包構(gòu)建在存有 XML Schema 的同一個項目中。本例中已經(jīng)創(chuàng)建了brokerupdate.jspbrokersummary.jspBrokerUpdateRoot.javaBrokerSummaryRoot.java 組件。
              • XYZInsuranceService:包含了用于代理人服務(wù)和有效代碼服務(wù)的 Java 類實現(xiàn)。該服務(wù)加載并且發(fā)送了合適的基于服務(wù)方法請求的 XML 響應(yīng)。這種基本實現(xiàn)用來模擬服務(wù)行為,其實現(xiàn)方法已經(jīng)超出本文講述的范圍。
              • XYZInsuranceServiceProxy:包括了用于調(diào)用代理人服務(wù)的 ServiceProxy 的基本實現(xiàn)。


              圖 6. 項目轉(zhuǎn)換的導(dǎo)入指南
              項目轉(zhuǎn)換的導(dǎo)入指南
            2. 創(chuàng)建來自 XSD 計劃的 SDO包

              在 Application Developer 中,在 ValidCodesService.xsd 上單擊右鍵,然后選擇 Create SDO Package(圖 7)。


              圖 7. 創(chuàng)建 SDO 包
              創(chuàng)建 SDO 包

              因此,將產(chǎn)生如圖 8 所示的情景。


              圖 8. 生成的 SDO 包
              生成的 SDO 包

              該包的名稱來自 targetNamespace,它在 XSD 聲明的 schema 中定義(圖 9)。


              圖 9. TargetNamespace 聲明
              TargetNamespace 聲明
            3. 向已經(jīng)生成的 SDO 增添附加的屬性和行為

              用戶可以修改已經(jīng)生成的 SDO,使之包含特定的變量或者行為。當(dāng)再次生成該 SDO 以用于同一個 schema 的命名空間時,任何沒有使用 @generated 標(biāo)簽注解的方法或者變量將不能被替換。用戶也可以將這樣的文件標(biāo)記為 non-derived 類型,以便項目 "clean" 時刪除這些文件。

              1. 向策略 SDO 接口中添加 get/set 方法,xyz.brokerservice.PolicyType

                /**
                 * Get the value for selected
                 */
                boolean getSelected();
                /**
                 * Set the value for selected
                 */
                void setSelected(boolean selected);



              2. 向策略 SDO 實現(xiàn)類中添加以下的屬性和方法,xyz.brokerservice.impl.PolicyTypeImpl

                /**
                 * add selected attribute as local variable.
                 */
                protected boolean selected = false;
                /**
                 * Get the value for selected
                 */
                public boolean getSelected(){
                	return selected;
                  }
                /**
                 * Set the value for selected
                 */
                public void setSelected(boolean selected){
                	this.selected = selected;
                  }



              3. 向客戶端 SDO 接口中添加獲取的方法,xyz.brokerservice.ClientType

                /**
                 * TotalPolicyAmount is computed by summation of the client's Policy Amounts
                 */
                  double getTotalPolicyAmount();



              4. 向客戶端 SDO 接口中添加以下的方法,xyz.brokerservice.impl.ClientTypeImpl;以下的方法演示了基本的轉(zhuǎn)換能力:

                /**
                 * totalPolicyAmount is computed by summation of the client's Policy Amounts
                 */
                public double getTotalPolicyAmount(){
                	double totalPolicyAmount = 0.00;
                	for(int index=0; index < getPolicy().size(); ++index){
                		PolicyType policyType = (PolicyType)getPolicy().get(index);
                		if(policyType.getPolicyAmount() != null){
                			double temp = 0.00;
                			try{
                				temp = Double.parseDouble(policyType.getPolicyAmount());
                			}catch(NumberFormatException ex){
                
                			}
                			totalPolicyAmount += temp;
                		}
                	}
                	return totalPolicyAmount;
                }



              5. 將已經(jīng)改動的文件標(biāo)記為 non-derived,以便在項目“clean”期間保留這些改動(圖 10)。


              圖 10. 更改派生屬性
              更改派生屬性
            4. 添加新的根 bean 封裝器

              ValidCodesServiceRoot.java 文件包含了計劃命名空間 URI 的注冊,用于有效代碼服務(wù)的屬性和它的獲取/設(shè)置方法。通過調(diào)用這些有效的代碼服務(wù)來慢慢地裝載所有有效的代碼。在 brokerservice.root 包中添加 ValidCodesServiceRoot.java Java 類:

              																														
              																																package brokerservice.root;
              import org.eclipse.emf.ecore.EPackage;
              import proxy.ValidCodesServiceProxy;
              import xyz.validcodesservice.DocumentRoot;
              import xyz.validcodesservice.ValidCodesServiceType;
              import xyz.validcodesservice.ValidcodesservicePackage;
              import dw.ibm.etools.xsd.sdo.xmltransformservice.XMLTransformServiceFactory;
              
              public class ValidCodesServiceRoot extends BaseRoot{
              	protected ValidCodesServiceType validCodesServiceRoot;
              	static{
              		EPackage.Registry.INSTANCE.put(
              				ValidcodesservicePackage.eINSTANCE.getNsURI()
              				, ValidcodesservicePackage.eINSTANCE);
              	}
              	protected void loadValidCodesResponse(String response){
              
              		DocumentRoot docRoot=
              		 (DocumentRoot) XMLTransformServiceFactory.INSTANCE.load(response);
              		validCodesServiceRoot =  docRoot.getValidCodesService();
              	}
              	public ValidCodesServiceType getValidCodesServiceRoot() {
              		if(validCodesServiceRoot == null){
              			preLoadValidCodes();
              		}
              		return validCodesServiceRoot;
              	}
              	public void setValidCodesServiceRoot(
              			ValidCodesServiceType validCodesServicetRoot) {
              		this.validCodesServiceRoot = validCodesServicetRoot;
              	}
              	protected void preLoadValidCodes(){
              	    String response = ValidCodesServiceProxy.invoke(
              	    			ValidCodesServiceProxy.ALL_REQUEST);
              	    loadValidCodesResponse(response);
              	}
              }
              																														
              																												

            5. 更新現(xiàn)有的根 bean 封裝器

              更新 brokerservice.root 包中現(xiàn)有的BrokerUpdateRoot.java Java 類 ,該包提供了相關(guān)的下載文件,或者更新帶有以下附加物的文件:

              1. 下列方法通過使用框架 API 以將數(shù)據(jù)對象轉(zhuǎn)變?yōu)?XML 字符串的方式向服務(wù)發(fā)送這些更新,從而更新 broker 信息。轉(zhuǎn)變 API 的第 2 個參數(shù)確保所有的空屬性將不屬于序列化 XML 的一部分。如果這樣的元素聲明被接收端的 XML 處理器接收,那么用戶就可以使用轉(zhuǎn)變 API 的其他實現(xiàn)。

                public void applyPolicyChanges(){
                		//unset all the features that are empty
                	    String xmlData = XMLTransformServiceFactory.INSTANCE.convert((DataObject)brokerServiceRoot, true);
                	    String response =
                	    	BrokerServiceProxy.invoke(xmlData,
                	    			BrokerServiceProxy.BROKERUPDATE_REQUEST);
                	    loadBrokerDetailUpdateResponse(response);
                	}



              2. 使用裝載 API 調(diào)用來裝載從服務(wù)調(diào)用中返回的響應(yīng)。創(chuàng)建 SDO 包時,所有不屬于計劃的元素將會通過裝載調(diào)用記錄下來。當(dāng)該數(shù)據(jù)對象使用轉(zhuǎn)變 API 被序列化到 XML 時, 這些元素就會被寫回。

                protected void loadBrokerDetailUpdateResponse(String response){
                		DocumentRoot docRoot=
                		  (DocumentRoot) XMLTransformServiceFactory.INSTANCE.load(response);
                		BrokerServiceType brokerdetailUpdateRespRoot =  docRoot.getBrokerService();
                		//set the error type
                		brokerServiceRoot.setError(brokerdetailUpdateRespRoot.getError());
                	}



              3. 該方法向客戶端現(xiàn)有的策略清單中添加新的策略。ClientType 中的 createPolicy 方法創(chuàng)建新的 PolicyType 對象,并將其添加到現(xiàn)有 Policy 清單中。

                public void addNewPolicy(ClientType clientType){
                		clientType.createPolicy();
                	}



              4. 該方法刪除了客戶端現(xiàn)有策略清單中選中的策略。

                public void deleteSelectedPolicy(ClientType clientType){
                                for(int index=clientType.getPolicy().size()-1; index >= 0; --index){
                                        PolicyType policyType = ((PolicyType)clientType.getPolicy().get(index));
                                        if(policyType.getSelected()){
                                                clientType.getPolicy().remove(policyType);
                                        }
                                }
                        }



            6. 向頁代碼中添加命令方法

              編輯 brokerupdate.jspBrokerupdate.java 頁代碼文件,并添加下列方法作為命令行為來使用。(這些方法中使用的控制數(shù)據(jù)訪問器在下一步中定義。)

              1. 該操作調(diào)用了 BrokerUpdateRoot.class 上的 addNewPolicy 方法以向現(xiàn)有的策略清單中添加新的策略行。當(dāng)前的 Client 行是使用 Client 數(shù)據(jù)表的 rowData 檢索得到的。

                public String doAddNewPolicyAction(){
                		this.getVarBrokerUpdateRootBean().addNewPolicy((ClientType)getTable1().getRowData());
                		//returning empty string re-displays the page with same data binding
                		return "";
                	}
                



              2. 該操作調(diào)用了BrokerUpdateRoot.class上的 deleteSelectedPolicy 方法來刪除現(xiàn)有的策略清單上選中的策略。

                public String doDeleteSelectedPolicyAction(){
                		this.getVarBrokerUpdateRootBean().deleteSelectedPolicy((ClientType)getTable1().getRowData());
                		return "";
                	}
                



              3. 該操作反映了帶有任何數(shù)據(jù)改動的 Java bean,在此僅作演示之用。在實際的應(yīng)用程序中,用戶在這里可以進(jìn)行一些數(shù)據(jù)處理,或者根本不需要這種方法。

                public String doUpdatePolicyAction(){
                		return "";
                	}
                



              4. 該操作調(diào)用了 BrokerUpdateRoot.class 上的 applyPolicyChanges 方法以將更新后的數(shù)據(jù)發(fā)送給服務(wù)。varBrokerUpdateRootBean,會話的受 JSF 管理的會話范圍 bean,它將從該會話中移出,以便該 bean 從下一個調(diào)用的新數(shù)據(jù)中重新寫入。

                public String doApplyPolicyChangesAction(){
                		this.getVarBrokerUpdateRootBean().applyPolicyChanges();
                		this.sessionScope.remove("varBrokerUpdateRootBean");
                		//a navigation rule is defined for this return
                		return "applyChanges";
                	}
                



            7. 附加到頁數(shù)據(jù)的 Bean

              1. 在頁數(shù)據(jù)中配置 varBrokerUpdateRootBean 使其成為受 JSF 管理的 bean,并設(shè)置范圍為 session (圖 11)。這將用戶會話生命周期的 bean 實例。這樣有關(guān)策略的創(chuàng)建、更新或者刪除操作,將會繼續(xù)保存在會話中,除非他們被應(yīng)用到 Apply Changes 行為。
                圖 11. 配置頁數(shù)據(jù)中的 Java Bean
                配置頁數(shù)據(jù)中的 Java Bean
              2. 在頁數(shù)據(jù)中添加 varValidCodesRootBean 使其成為受 JSF 管理的 bean,并設(shè)置范圍為應(yīng)用程序。這將緩存應(yīng)用程序?qū)嵗芷诘?bean 實例。
                圖 12. 配置頁數(shù)據(jù)中的 Java Bean
                配置頁數(shù)據(jù)中的 Java Bean

            8. 將頁上的控制綁定更新為頁數(shù)據(jù)中的 SDO 類型

              1. 選擇 Policy 數(shù)據(jù)表,并在其屬性中添加新列(圖 13)。將該列重命名為 "Delete",并將其移動到列表的第一列。
                圖 13. 添加列
                添加列
              2. 從控制面板中拖動 checkbox,將其添加到新的表格列中(圖 14)。
                圖 14. 添加 Checkbox
                添加 Checkbox
              3. 從頁數(shù)據(jù)視圖中定義的策略 SDO 中拖動"selected"屬性,并且將其放到測量數(shù)據(jù)表中的 checkbox 上(圖 15)。
                圖 15. Checkbox 綁定
                Checkbox 綁定
              4. 向策略數(shù)據(jù)表中添加命令按鈕,并且將按鈕的標(biāo)簽改為 "Add New Policy"(圖 16)。顯示出用于策略數(shù)據(jù)表的頁腳區(qū),以便用戶能夠放置該命令按鈕。
                圖 16. 添加命令按鈕
                添加命令按鈕
              5. 將這個命令按鈕綁定到 doAddNewPolicyAction(圖 17)。如果沒有顯示 "action" 屬性,那么就顯示數(shù)據(jù)表的所有屬性。
                圖 17. 將命令綁定到行為
                將命令綁定到行為
              6. 向策略數(shù)據(jù)表中添加命令按鈕,將該按鈕的標(biāo)簽改為 "Delete Selected Policy"(圖 18),并將此按鈕綁定到 doDeleteSelectedPolicyAction(圖 19)。
                圖 18. 添加命令按鈕
                添加命令按鈕

                圖 19. 將命令綁定到行為
                將命令綁定到行為
              7. 向策略數(shù)據(jù)表中添加命令按鈕,將該按鈕的標(biāo)簽改為 "Update Policy"(圖 20),并將該按鈕綁定到 doUpdatePolicyAction(圖 21)。
                圖 20. 添加命令按鈕
                添加命令按鈕

                圖 21. 將命令綁定到行為
                將命令綁定到行為
              8. 向客戶端數(shù)據(jù)表中添加命令按鈕,將該按鍵的標(biāo)簽更改為 "Apply Changes"(圖 22),然后將此按鈕綁定到 doApplyPolicyChangesAction(圖 23)。(能顯示出表格的頁腳區(qū)來放置該命令按鈕。)
                圖 22. 添加命令按鈕
                添加命令按鈕

                圖 23. 將命令綁定到行為
                將命令綁定到行為
              9. 添加規(guī)則以轉(zhuǎn)到反映了這些策略改動的 brokersummary.jsp (圖 24)。
                圖 24. 添加結(jié)果規(guī)則
                添加結(jié)果規(guī)則
              10. 在客戶端數(shù)據(jù)表格中 "policy" 的前面添加新的 "TotalPolicyAmount" 列。拖動 JSF outputtext 控制,將其放到新列中(圖 25)。
                圖 25. 添加列
                添加列
              11. 從 varBrokerServiceRootBean 頁數(shù)據(jù)中拖動 totalPolicyAmount(圖 26),將其放到 outputtext 控制上(圖 27)。
                圖 26. 頁數(shù)據(jù)
                頁數(shù)據(jù)

                圖 27. 控制綁定
                控制綁定
              12. 在客戶端數(shù)據(jù)表中策略的前面添加新的 "State" 列。拖動 JSF dropdown 控制,將其放到新列中(圖 28)。
                圖 28. 添加 Dropdown
                添加 Dropdown
              13. 從頁數(shù)據(jù)里的 varValidCodesRootBean 中拖動 fullName (圖 29),并且將其放到 dropdown 控制上(圖 30)。
                圖 29. 頁數(shù)據(jù)
                頁數(shù)據(jù)

                圖 30. Dropdown 綁定
                Dropdown 綁定

            9. 運行 brokerupdate.jsp

              1. 在 Application Developer 中,在 brokerupdate.jsp 上單擊右鍵,然后選擇 Run On Server。(如果沒有提示用戶啟動服務(wù)器,那么啟動服務(wù)器后,然后在運行該頁之前將 XYZInsuranceEAR 項目添加到服務(wù)器。)
              2. 測試容器中用于該頁的 URL 是(或者與之類似): http://localhost:9080/XYZInsuranceWeb/faces/brokerupdate.jsp.
                圖 31. brokerupdate.jsp
                brokerupdate.jsp
              3. 使用該頁上的多個按鈕來執(zhí)行不同的操作(圖 32)。
                圖 32. brokerupdate.jsp
                brokerupdate.jsp







            結(jié)束語

            在該系列文章的第 2 部分中,我們描述了加速開發(fā)用于基于 XML 的應(yīng)用程序的 JSF 的解決方案。這個解決方案提供了 Eclipse 功能以及框架工具,在設(shè)計時可用其將 XML Schema 轉(zhuǎn)換成包括靜態(tài)服務(wù)對象數(shù)據(jù)的 Java 包,在運行時可用其將 XML 實例文件與這些 SDO 相互轉(zhuǎn)化。SDO 包裝成 JavaBean,連同 JavaServer Faces 一起被用于表示開發(fā)。本文也提供了擴展保險應(yīng)用程序的基本場景所需的通用步驟,該應(yīng)用程序包括新建、更新以及刪除的功能,本地附加的變量,基本的轉(zhuǎn)換和下拉式綁定。這些增強實現(xiàn)了單一頁面中多 schema 模型和多個請求及響應(yīng)的場景。

            在該系列文章中將介紹:

            • 第 3 部分將描述操作已生成的 SDO 以及自定義 XML-SDO 轉(zhuǎn)換器的高級技術(shù)。它也提供了聚集方法(sun、mean、average 等)的工具,這些方法是對SDO 對象及集合的一般操作。
            • 第 4 部分重在使用 XSDO SDO 轉(zhuǎn)換功能進(jìn)行基于 XML 的 SOA 的 portlet 開發(fā),為 JSR 168 portlet 新建的對象尋址、portlet 的參數(shù)傳遞,以及在任何其他 portlet 中的 portlet 動作上動態(tài)地設(shè)置對象 portlet 視圖。
            • 第 5 部分將討論使用 XSDO SDO 轉(zhuǎn)換功能使 JSF 及基于 XML 的 SOA 的 portlet 應(yīng)用程序局部化,并且提出基于首選地點顯示的靜態(tài)及動態(tài)內(nèi)容。








            下載

            描述 名字 大小 下載方法
            Download file 1 xsd_sdo_soa_xml_sample.zip 766 KB ?FTP|HTTP
            Download file 2 xsd_sdo_soa_xml_tutorial.zip 738 KB ?FTP|HTTP
            Download file 3 xsdsdotransform-feature.zip 50 KB ?FTP|HTTP
            Download file 4 XYZInsuranceEAR.zip 764 KB ?FTP|HTTP
            Download file 5 xsd_sdo_soa_part1_listings.zip 8 KB ?FTP|HTTP

            posted on 2006-04-17 03:17 wsdfsdf 閱讀(282) 評論(0)  編輯 收藏 引用 所屬分類: 技術(shù)文章

            免费一级欧美大片久久网| 亚洲AV日韩精品久久久久久| 久久精品九九亚洲精品| 国产精品久久久久9999| 国产午夜精品久久久久九九| 亚洲一级Av无码毛片久久精品| 伊人精品久久久久7777| 色综合久久中文字幕无码| 青草影院天堂男人久久| 亚洲国产精品一区二区三区久久| 无码久久精品国产亚洲Av影片 | 久久久久亚洲AV成人片| 93精91精品国产综合久久香蕉 | 亚洲成色www久久网站夜月| 狠狠久久亚洲欧美专区| 久久夜色精品国产亚洲| 韩国三级中文字幕hd久久精品| 香蕉久久夜色精品升级完成| 国产精品va久久久久久久| 久久99精品久久久久子伦| 亚洲国产精品狼友中文久久久 | 国产精品美女久久久m| 欧美亚洲另类久久综合婷婷| 国产精品一区二区久久| 伊人久久大香线蕉av不卡| 少妇久久久久久被弄到高潮| 国产成人久久久精品二区三区| 久久99精品久久久久久动态图| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 久久久久久久波多野结衣高潮 | 中文字幕成人精品久久不卡| 奇米影视7777久久精品| 亚洲精品乱码久久久久久按摩 | 久久青草国产精品一区| 久久国产精品无码HDAV | 欧美国产成人久久精品| 国内精品久久国产| 久久综合久久美利坚合众国| 久久久久久久综合狠狠综合| 久久久久人妻一区二区三区| 亚洲乱码中文字幕久久孕妇黑人|