1 / 10

HW 1 – Mortgage Calculator

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>" );

Download Presentation

HW 1 – Mortgage Calculator

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HW 1 – Mortgage Calculator • Implemented as standalone Java Program • Swing based GUI • XML Processing using JAXP

  2. 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(); …

  3. 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();

  4. 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>

  5. 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>

  6. 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>&#10;</xsl:text> <PaymentSchedule xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation= 'paymentSchedule.xsd'><xsl:text>&#10;</xsl:text> <Name><xsl:value-of select="$AccountHolderName"/></Name><xsl:text>&#10;</xsl:text> <BeginMonth><xsl:value-of select="$BeginMonth"/></BeginMonth><xsl:text>&#10;</xsl:text> <Currency><xsl:value-of select="$currencyName"/></Currency><xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text> <xsl:for-each select="Amortization/MonthlyAmortization"> <MonthlyPayment><xsl:text>&#10;</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>&#10;</xsl:text> <Payment made='false'><xsl:value-of select="Payment*$currencyMutiplier"/></Payment><xsl:text>&#10;</xsl:text> <Balance><xsl:value-of select="Balance*$currencyMutiplier"/></Balance><xsl:text>&#10;</xsl:text> <Principal><xsl:value-of select="Equity*$currencyMutiplier"/></Principal><xsl:text>&#10;</xsl:text> <Interest><xsl:value-of select="Interest*$currencyMutiplier"/></Interest><xsl:text>&#10;</xsl:text> </MonthlyPayment><xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text> </xsl:for-each> </PaymentSchedule> </xsl:template> </xsl:stylesheet>

  7. 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/">

  8. 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> …

  9. 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>

  10. 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>

More Related