diff --git a/BasicStockQuoteApplication.java b/BasicStockQuoteApplication.java new file mode 100644 index 0000000..66188de --- /dev/null +++ b/BasicStockQuoteApplication.java @@ -0,0 +1,177 @@ +package com.origamisoftware.teach.advanced.apps.stockquote; + +import com.origamisoftware.teach.advanced.model.StockQuery; +import com.origamisoftware.teach.advanced.model.StockQuote; +import com.origamisoftware.teach.advanced.services.StockService; +import com.origamisoftware.teach.advanced.services.StockServiceException; +import com.origamisoftware.teach.advanced.services.ServiceFactory; +import com.origamisoftware.teach.advanced.util.Interval; +import com.origamisoftware.teach.advanced.xml.Stock; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import java.io.StringReader; +import java.text.ParseException; +import java.util.List; + +/** + * A simple application that shows the StockService in action. + */ +public class BasicStockQuoteApplication { + + private StockService stockService; + + // an example of how to use enum - not part of assignment 3 but useful for assignment 4 + + /** + * An enumeration that indicates how the program terminates (ends) + */ + private enum ProgramTerminationStatusEnum { + + // for now, we just have normal or abnormal but could more specific ones as needed. + NORMAL(0), + ABNORMAL(-1); + + // when the program exits, this value will be reported to underlying OS + private int statusCode; + + /** + * Create a new ProgramTerminationStatusEnum + * + * @param statusCodeValue the value to return the OS. A value of 0 + * indicates success or normal termination. + * non 0 numbers indicate abnormal termination. + */ + private ProgramTerminationStatusEnum(int statusCodeValue) { + this.statusCode = statusCodeValue; + } + + /** + * @return The value sent to OS when the program ends. + */ + private int getStatusCode() { + return statusCode; + } + } + + /** + * Create a new Application. + * + * @param stockService the StockService this application instance should use for + * stock queries. + *
+ * NOTE: this is a example of Dependency Injection in action. + */ + public BasicStockQuoteApplication(StockService stockService) { + this.stockService = stockService; + } + + /** + * Given astockQuery get back a the info about the stock to display to th user.
+ *
+ * @param stockQuery the stock to get data for.
+ * @return a String with the stock data in it.
+ * @throws StockServiceException If data about the stock can't be retrieved. This is a
+ * fatal error.
+ */
+ public String displayStockQuotes(StockQuery stockQuery) throws StockServiceException {
+ StringBuilder stringBuilder = new StringBuilder();
+
+ ListJava class for anonymous complex type. + * + *
The following schema fragment specifies the expected content contained within this class. + * + *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <attribute name="price" use="required" type="{http://www.w3.org/2001/XMLSchema}anySimpleType" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "content"
+})
+@XmlRootElement(name = "price")
+public class Price implements XMLDomainObject {
+
+ @XmlValue
+ protected String content;
+ @XmlAttribute(name = "price", required = true)
+ @XmlSchemaType(name = "anySimpleType")
+ protected BigDecimal price;
+
+ /**
+ * Gets the value of the content property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getContent() {
+ return content;
+ }
+
+ /**
+ * Sets the value of the content property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setContent(String value) {
+ this.content = value;
+ }
+
+ /**
+ * Gets the value of the price property.
+ *
+ * @return
+ * possible object is
+ * {@link BigDecimal }
+ *
+ */
+ public BigDecimal getPrice() {
+ return price;
+ }
+
+ /**
+ * Sets the value of the price property.
+ *
+ * @param value
+ * allowed object is
+ * {@link BigDecimal }
+ *
+ */
+ public void setPrice(BigDecimal value) {
+ this.price = value;
+ }
+
+ @Override
+ public String toString() {
+ return "Price{" +
+ "content='" + content + '\'' +
+ ", price='" + price + '\'' +
+ '}';
+ }
+}
diff --git a/xml/Stock.java b/xml/Stock.java
new file mode 100644
index 0000000..416748e
--- /dev/null
+++ b/xml/Stock.java
@@ -0,0 +1,129 @@
+
+package com.origamisoftware.teach.advanced.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * Java class for anonymous complex type. + * + *
The following schema fragment specifies the expected content contained within this class. + * + *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <sequence>
+ * <element ref="{}symbol"/>
+ * <element ref="{}price"/>
+ * <element ref="{}time"/>
+ * </sequence>
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "symbol",
+ "price",
+ "time"
+})
+@XmlRootElement(name = "stock")
+public class Stock implements XMLDomainObject {
+
+ @XmlElement(required = true)
+ protected Symbol symbol;
+ @XmlElement(required = true)
+ protected Price price;
+ @XmlElement(required = true)
+ protected Time time;
+
+ /**
+ * Gets the value of the symbol property.
+ *
+ * @return
+ * possible object is
+ * {@link Symbol }
+ *
+ */
+ public Symbol getSymbol() {
+ return symbol;
+ }
+
+ /**
+ * Sets the value of the symbol property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Symbol }
+ *
+ */
+ public void setSymbol(Symbol value) {
+ this.symbol = value;
+ }
+
+ /**
+ * Gets the value of the price property.
+ *
+ * @return
+ * possible object is
+ * {@link Price }
+ *
+ */
+ public Price getPrice() {
+ return price;
+ }
+
+ /**
+ * Sets the value of the price property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Price }
+ *
+ */
+ public void setPrice(Price value) {
+ this.price = value;
+ }
+
+ /**
+ * Gets the value of the time property.
+ *
+ * @return
+ * possible object is
+ * {@link Time }
+ *
+ */
+ public Time getTime() {
+ return time;
+ }
+
+ /**
+ * Sets the value of the time property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Time }
+ *
+ */
+ public void setTime(Time value) {
+ this.time = value;
+ }
+
+
+ @Override
+ public String toString() {
+ return "stock{" +
+ "symbol=" + symbol +
+ ", price=" + price +
+ ", time=" + time +
+ '}';
+ }
+}
diff --git a/xml/Symbol.java b/xml/Symbol.java
new file mode 100644
index 0000000..0f7f9e1
--- /dev/null
+++ b/xml/Symbol.java
@@ -0,0 +1,98 @@
+
+package com.origamisoftware.teach.advanced.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+
+
+/**
+ * Java class for anonymous complex type. + * + *
The following schema fragment specifies the expected content contained within this class. + * + *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <attribute name="symbol" use="required" type="{http://www.w3.org/2001/XMLSchema}anySimpleType" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "content"
+})
+@XmlRootElement(name = "symbol")
+public class Symbol implements XMLDomainObject{
+
+ @XmlValue
+ protected String content;
+ @XmlAttribute(name = "symbol", required = true)
+ @XmlSchemaType(name = "anySimpleType")
+ protected String symbol;
+
+ /**
+ * Gets the value of the content property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getContent() {
+ return content;
+ }
+
+ /**
+ * Sets the value of the content property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setContent(String value) {
+ this.content = value;
+ }
+
+ /**
+ * Gets the value of the symbol property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getSymbol() {
+ return symbol;
+ }
+
+ /**
+ * Sets the value of the symbol property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setSymbol (String value) {
+ this.symbol = value;
+ }
+
+ @Override
+ public String toString() {
+ return "Symbol{" +
+ "content='" + content + '\'' +
+ ", symbol='" + symbol + '\'' +
+ '}';
+ }
+}
diff --git a/xml/Time.java b/xml/Time.java
new file mode 100644
index 0000000..3b068da
--- /dev/null
+++ b/xml/Time.java
@@ -0,0 +1,100 @@
+
+package com.origamisoftware.teach.advanced.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlValue;
+import java.math.BigDecimal;
+import java.util.Date;
+
+
+/**
+ * Java class for anonymous complex type. + * + *
The following schema fragment specifies the expected content contained within this class. + * + *
+ * <complexType>
+ * <complexContent>
+ * <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ * <attribute name="time" use="required" type="{http://www.w3.org/2001/XMLSchema}anySimpleType" />
+ * </restriction>
+ * </complexContent>
+ * </complexType>
+ *
+ *
+ *
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType(name = "", propOrder = {
+ "content"
+})
+@XmlRootElement(name = "time")
+public class Time implements XMLDomainObject {
+
+ @XmlValue
+ protected String content;
+ @XmlAttribute(name = "time", required = true)
+ @XmlSchemaType(name = "anySimpleType")
+ protected Date time;
+
+ /**
+ * Gets the value of the content property.
+ *
+ * @return
+ * possible object is
+ * {@link String }
+ *
+ */
+ public String getContent() {
+ return content;
+ }
+
+ /**
+ * Sets the value of the content property.
+ *
+ * @param value
+ * allowed object is
+ * {@link String }
+ *
+ */
+ public void setContent(String value) {
+ this.content = value;
+ }
+
+ /**
+ * Gets the value of the time property.
+ *
+ * @return
+ * possible object is
+ * {@link Date }
+ *
+ */
+ public Date getTime() {
+ return time;
+ }
+
+ /**
+ * Sets the value of the time property.
+ *
+ * @param value
+ * allowed object is
+ * {@link Date }
+ *
+ */
+ public void setTime(Date value) {
+ this.time = value;
+ }
+
+ @Override
+ public String toString() {
+ return "Time{" +
+ "content='" + content + '\'' +
+ ", time='" + time + '\'' +
+ '}';
+ }
+}
diff --git a/xml/XMLDomainObject.java b/xml/XMLDomainObject.java
new file mode 100644
index 0000000..0d51f7e
--- /dev/null
+++ b/xml/XMLDomainObject.java
@@ -0,0 +1,8 @@
+package com.origamisoftware.teach.advanced.xml;
+
+/**
+ * A marker class the indicates the class was created from an XML instance
+ *
+ */
+public interface XMLDomainObject {
+}
diff --git a/xml/stock_info.fxml b/xml/stock_info.fxml
new file mode 100644
index 0000000..28cee94
--- /dev/null
+++ b/xml/stock_info.fxml
@@ -0,0 +1,52 @@
+
+