100 likes | 324 Views
HW 1 – Mortgage Calculator. Implemented as standalone Java Program Swing based GUI XML Processing using JAXP. HW1 – Writing XML. // write XML for this month fileout.write( "<MonthlyAmortization>" ); fileout.newLine(); fileout.write( "<Month>" + i + "</Month>" );
E N D
HW 1 – Mortgage Calculator • Implemented as standalone Java Program • Swing based GUI • XML Processing using JAXP
HW1 – Writing XML // write XML for this month fileout.write("<MonthlyAmortization>"); fileout.newLine(); fileout.write("<Month>"+ i + "</Month>"); fileout.newLine(); fileout.write("<Balance>"+ String.format("%.2f",balance) + "</Balance>"); fileout.newLine(); fileout.write("<Payment>"+ String.format("%.2f",payment) + "</Payment>"); fileout.newLine(); fileout.write("<Interest>"+ String.format("%.2f",interest) + "</Interest>"); fileout.newLine(); fileout.write("<Equity>"+ String.format("%.2f",equity) + "</Equity>"); fileout.newLine(); fileout.write("<Assessments>"+ String.format("%.2f",assessments) + "</Assessments>"); fileout.newLine(); …
HW1 – XML Parsing & Validation // Create parser factory javax.xml.parsers.DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); // Make it a validating parser dbf.setValidating(true); dbf.setNamespaceAware(true); dbf.setAttribute("http://xml.org/sax/features/validation", true); dbf.setAttribute("http://apache.org/xml/features/validation/schema", true); // create a parser javax.xml.parsers.DocumentBuilder parser = dbf.newDocumentBuilder();
HW2 – Output Schema <?xml version = "1.0" encoding = "UTF-8"?> <xsd:schema xmlns:xsd = "http://www.w3.org/2001/XMLSchema"> <xsd:element name = "PaymentSchedule"> <xsd:complexType> <xsd:sequence> <xsd:element name = "Name" type = "xsd:string" /> <xsd:element name = "BeginMonth" type = "xsd:integer" /> <xsd:element name = "Currency" type = "xsd:string" /> <xsd:element name = "MonthlyPayment" maxOccurs = "unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name = "DueDate" type = "xsd:date" /> <xsd:element name = "Payment" > <xsd:complexType> <xsd:simpleContent> <xsd:extension base="xsd:decimal"> <xsd:attribute name="made" type="xsd:boolean" use="required"/> </xsd:extension> </xsd:simpleContent> </xsd:complexType> </xsd:element> <xsd:element name = "Balance" type = "xsd:decimal" /> <xsd:element name = "Principal" type = "xsd:decimal" /> <xsd:element name = "Interest" type = "xsd:decimal" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema>
HW2 – Currency Conversion <?xml version="1.0"?> <currencies> <currency> <code>eur</code> <name>Euros</name> <convFactor>0.76</convFactor> </currency> <currency> <code>usd</code> <name>Dollars</name> <convFactor>1.0</convFactor> </currency> <currency> <code>cad</code> <name>Canadian dollars</name> <convFactor>1.15</convFactor> </currency> </currencies>
HW2 – XSL File <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:variable name="currencies" select="document('Currency.xml')/currencies"/> <xsl:param name="AccountHolderName" select="'DefaultAccountHolder'"/> <xsl:param name="BeginMonth" select="'0'"/> <xsl:param name="Currency" select="'Dollar'"/> <xsl:variable name="currencyMutiplier" select="$currencies/currency[code=$Currency]/convFactor"/> <xsl:variable name="currencyName" select="$currencies/currency[code=$Currency]/name"/> <xsl:template match="/"> <xsl:text> </xsl:text> <PaymentSchedule xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation= 'paymentSchedule.xsd'><xsl:text> </xsl:text> <Name><xsl:value-of select="$AccountHolderName"/></Name><xsl:text> </xsl:text> <BeginMonth><xsl:value-of select="$BeginMonth"/></BeginMonth><xsl:text> </xsl:text> <Currency><xsl:value-of select="$currencyName"/></Currency><xsl:text> </xsl:text> <xsl:text> </xsl:text> <xsl:for-each select="Amortization/MonthlyAmortization"> <MonthlyPayment><xsl:text> </xsl:text> <DueDate> <xsl:value-of select="2007 + floor(($BeginMonth+Month) div 12)"/>-<xsl:number value="(($BeginMonth+Month) mod 12) + 1" format="01"/>-01 </DueDate><xsl:text> </xsl:text> <Payment made='false'><xsl:value-of select="Payment*$currencyMutiplier"/></Payment><xsl:text> </xsl:text> <Balance><xsl:value-of select="Balance*$currencyMutiplier"/></Balance><xsl:text> </xsl:text> <Principal><xsl:value-of select="Equity*$currencyMutiplier"/></Principal><xsl:text> </xsl:text> <Interest><xsl:value-of select="Interest*$currencyMutiplier"/></Interest><xsl:text> </xsl:text> </MonthlyPayment><xsl:text> </xsl:text> <xsl:text> </xsl:text> </xsl:for-each> </PaymentSchedule> </xsl:template> </xsl:stylesheet>
HW3 – Home Search WSDL Definitions <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/HomeSearch/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="HomeSearch" targetNamespace="http://www.example.org/HomeSearch/">
HW3 – Home Search WSDL Types <xsd:complexType name="HomeSearchParametersType"> <xsd:sequence> <xsd:element name = "LowPrice" type = "xsd:float" /> <xsd:element name = "HighPrice" type = "xsd:float" /> <xsd:element name = "Bedrooms" type = "xsd:int" /> <xsd:element name = "PoolAndTennis" type = "xsd:boolean" /> <xsd:element name = "SchoolDistrict" type = "xsd:string" /> </xsd:sequence> </xsd:complexType> <xsd:complexType name="HomeSearchReturnType"> <xsd:sequence> <xsd:element name = "HomesMatched"> <xsd:complexType> <xsd:sequence> <xsd:element name = "Home" maxOccurs = "unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name = "Price" type = "xsd:float" /> <xsd:element name = "Bedrooms" type = "xsd:int" /> <xsd:element name = "SquareFootage" type = "xsd:float" /> <xsd:element name = "SchoolDistrict" type = "xsd:string" /> </xsd:sequence> </xsd:complexType> …
HW3 – Home Search WSDL Message <wsdl:message name="GetHomeSearchRequest"> <wsdl:part name="inParameters" element="tns:HomeSearchParameters"/> </wsdl:message> <wsdl:message name="GetHomeSearchResponse"> <wsdl:part name="returnValue" element="tns:HomeSearchReturn"/> </wsdl:message> Port Type <wsdl:portType name="HomeSearch"> <wsdl:operation name="GetHomeSearch"> <wsdl:input message="tns:GetHomeSearchRequest"/> <wsdl:output message="tns:GetHomeSearchResponse"/> </wsdl:operation> </wsdl:portType>
HW3 – Home Search WSDL Binding <wsdl:binding name="HomeSearchSOAP" type="tns:HomeSearch"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> <wsdl:operation name="GetHomeSearch"> <soap:operation soapAction="" /> <wsdl:input > <soap:body use="literal"/> </wsdl:input> <wsdl:output > <soap:body use="literal"/> </wsdl:output> </wsdl:operation> </wsdl:binding> Service <wsdl:service name="HomeSearch"> <wsdl:port binding="tns:HomeSearchSOAP" name="HomeSearchSOAP"> <soap:address location="http://www.example.org/"/> </wsdl:port> </wsdl:service>