• <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
            數據加載中……

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

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

            引言

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

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

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







            安裝 XSD SDO 轉換功能

            為了安裝 XSD SDO 的轉換功能,請按照 第 1 部分 中的詳細步驟操作。







            場景

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

            • 我們假設 XYZ 保險公司有許多已注冊的代理人。
            • 每個代理人都有許多客戶,并且每個客戶都同代理人簽訂了許多策略。
            • 保險公司通過標準的 BrokerService 方案來展示代理人的服務(清單 1),并使用有效代服務 validCodesService schema(清單 2)進行檢索,例如有效的狀態碼。
            • 任何來自代理人的通信就是一個 XML 請求/響應,它服從清單 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 場景

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


            圖 3. BrokerUpdate 請求/響應信息流
            圖 3. BrokerUpdate 請求/響應信息流

            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>
            
            												
            										







            應用程序設計流

            圖 4 描繪了用于該場景的應用程序設計流。


            圖 4. 應用程序設計流
            應用程序設計流






            運行時架構

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

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


            圖 5. 運行時架構
            運行時架構






            實現解決方案

            在下面的章節中詳細描述了實現該解決方案的步驟:

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

            1. 導入項目轉換

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

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


              圖 6. 項目轉換的導入指南
              項目轉換的導入指南
            2. 創建來自 XSD 計劃的 SDO包

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


              圖 7. 創建 SDO 包
              創建 SDO 包

              因此,將產生如圖 8 所示的情景。


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

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


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

              用戶可以修改已經生成的 SDO,使之包含特定的變量或者行為。當再次生成該 SDO 以用于同一個 schema 的命名空間時,任何沒有使用 @generated 標簽注解的方法或者變量將不能被替換。用戶也可以將這樣的文件標記為 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 實現類中添加以下的屬性和方法,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;以下的方法演示了基本的轉換能力:

                /**
                 * 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. 將已經改動的文件標記為 non-derived,以便在項目“clean”期間保留這些改動(圖 10)。


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

              ValidCodesServiceRoot.java 文件包含了計劃命名空間 URI 的注冊,用于有效代碼服務的屬性和它的獲取/設置方法。通過調用這些有效的代碼服務來慢慢地裝載所有有效的代碼。在 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. 更新現有的根 bean 封裝器

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

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

                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 調用來裝載從服務調用中返回的響應。創建 SDO 包時,所有不屬于計劃的元素將會通過裝載調用記錄下來。當該數據對象使用轉變 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. 該方法向客戶端現有的策略清單中添加新的策略。ClientType 中的 createPolicy 方法創建新的 PolicyType 對象,并將其添加到現有 Policy 清單中。

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



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

                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 頁代碼文件,并添加下列方法作為命令行為來使用。(這些方法中使用的控制數據訪問器在下一步中定義。)

              1. 該操作調用了 BrokerUpdateRoot.class 上的 addNewPolicy 方法以向現有的策略清單中添加新的策略行。當前的 Client 行是使用 Client 數據表的 rowData 檢索得到的。

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



              2. 該操作調用了BrokerUpdateRoot.class上的 deleteSelectedPolicy 方法來刪除現有的策略清單上選中的策略。

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



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

                public String doUpdatePolicyAction(){
                		return "";
                	}
                



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

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



            7. 附加到頁數據的 Bean

              1. 在頁數據中配置 varBrokerUpdateRootBean 使其成為受 JSF 管理的 bean,并設置范圍為 session (圖 11)。這將用戶會話生命周期的 bean 實例。這樣有關策略的創建、更新或者刪除操作,將會繼續保存在會話中,除非他們被應用到 Apply Changes 行為。
                圖 11. 配置頁數據中的 Java Bean
                配置頁數據中的 Java Bean
              2. 在頁數據中添加 varValidCodesRootBean 使其成為受 JSF 管理的 bean,并設置范圍為應用程序。這將緩存應用程序實例生命周期的 bean 實例。
                圖 12. 配置頁數據中的 Java Bean
                配置頁數據中的 Java Bean

            8. 將頁上的控制綁定更新為頁數據中的 SDO 類型

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

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

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

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

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

                圖 30. Dropdown 綁定
                Dropdown 綁定

            9. 運行 brokerupdate.jsp

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







            結束語

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

            在該系列文章中將介紹:

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








            下載

            描述 名字 大小 下載方法
            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 閱讀(283) 評論(0)  編輯 收藏 引用 所屬分類: 技術文章

            久久人人爽人人爽人人片AV不| 国产精品久久午夜夜伦鲁鲁| 精品国产91久久久久久久a| 色综合久久久久| 久久天天躁狠狠躁夜夜av浪潮| 久久99精品久久久大学生| 99久久综合狠狠综合久久止| 欧美一级久久久久久久大| 久久人人爽爽爽人久久久| 国内精品久久久久久久久 | 久久人妻无码中文字幕| 久久人人爽人人爽人人片AV高清| 久久久久久无码Av成人影院| 国产成人香蕉久久久久| 中文字幕无码免费久久| 91精品国产高清久久久久久91| 中文字幕无码av激情不卡久久| 国产精品久久99| 国产亚洲精品久久久久秋霞 | 人妻丰满AV无码久久不卡| 999久久久国产精品| 看久久久久久a级毛片| 久久久WWW成人免费毛片| 婷婷综合久久中文字幕蜜桃三电影| 国产精品内射久久久久欢欢| 九九久久自然熟的香蕉图片| 久久精品极品盛宴观看| 国产午夜福利精品久久| 国内精品久久久人妻中文字幕| 伊人热热久久原色播放www| 国产精品亚洲美女久久久| 国产精品久久99| 成人免费网站久久久| 久久天天躁狠狠躁夜夜96流白浆| 伊人久久大香线蕉av一区| 久久久国产视频| 伊人久久大香线蕉AV色婷婷色| 久久无码AV一区二区三区| 无码任你躁久久久久久老妇App| 婷婷久久综合九色综合九七| 欧美麻豆久久久久久中文|