001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package samples.services;
020:
021: import java.util.Date;
022:
023: import javax.xml.stream.XMLStreamException;
024: import org.apache.axiom.om.OMAbstractFactory;
025: import org.apache.axiom.om.OMElement;
026: import org.apache.axiom.om.OMFactory;
027: import org.apache.axiom.om.OMNamespace;
028:
029: public class FastStockQuoteService {
030:
031: private final static OMElement response = createResponse();
032:
033: private static OMElement createResponse() {
034:
035: OMFactory fac = OMAbstractFactory.getOMFactory();
036: OMNamespace ns = fac.createOMNamespace(
037: "http://services.samples/xsd", "ns");
038: OMElement getQuoteResponse = fac.createOMElement(
039: "getQuoteResponse ", ns);
040: OMElement returnElt = fac.createOMElement("return", ns);
041:
042: OMElement change = fac.createOMElement("change", ns);
043: change.addChild(fac.createOMText(change, "-2.573165716892239"));
044: returnElt.addChild(change);
045:
046: OMElement earnings = fac.createOMElement("earnings", ns);
047: earnings.addChild(fac.createOMText(earnings,
048: "12.729598827258027"));
049: returnElt.addChild(earnings);
050:
051: OMElement high = fac.createOMElement("high", ns);
052: high.addChild(fac.createOMText(high, "181.57938605633444"));
053: returnElt.addChild(high);
054:
055: OMElement last = fac.createOMElement("last", ns);
056: last.addChild(fac.createOMText(last, "79.93167957835779"));
057: returnElt.addChild(last);
058:
059: OMElement lastTradeTimestamp = fac.createOMElement(
060: "lastTradeTimestamp", ns);
061: lastTradeTimestamp.addChild(fac.createOMText(
062: lastTradeTimestamp, "Thu Jan 25 17:39:12 IST 2007"));
063: returnElt.addChild(lastTradeTimestamp);
064:
065: OMElement low = fac.createOMElement("low", ns);
066: low.addChild(fac.createOMText(low, "9.93167957835779"));
067: returnElt.addChild(low);
068:
069: OMElement marketCap = fac.createOMElement("marketCap", ns);
070: marketCap.addChild(fac.createOMText(marketCap,
071: "5.93167957835779"));
072: returnElt.addChild(marketCap);
073:
074: OMElement name = fac.createOMElement("name", ns);
075: name.addChild(fac.createOMText(name, "IBM Company"));
076: returnElt.addChild(name);
077:
078: OMElement open = fac.createOMElement("open", ns);
079: open.addChild(fac.createOMText(open, "15.93167957835779"));
080: returnElt.addChild(open);
081:
082: OMElement peRatio = fac.createOMElement("peRatio", ns);
083: peRatio.addChild(fac
084: .createOMText(peRatio, "24.283806785853777"));
085: returnElt.addChild(peRatio);
086:
087: OMElement percentageChange = fac.createOMElement(
088: "percentageChange", ns);
089: percentageChange.addChild(fac.createOMText(percentageChange,
090: "-2.334460572410184"));
091: returnElt.addChild(percentageChange);
092:
093: OMElement prevClose = fac.createOMElement("prevClose", ns);
094: prevClose.addChild(fac.createOMText(prevClose,
095: "-179.58650497565893"));
096: returnElt.addChild(prevClose);
097:
098: OMElement symbol = fac.createOMElement("symbol", ns);
099: symbol.addChild(fac.createOMText(symbol, "IBM"));
100: returnElt.addChild(symbol);
101:
102: OMElement volume = fac.createOMElement("volume", ns);
103: volume.addChild(fac.createOMText(volume, "7618"));
104: returnElt.addChild(volume);
105:
106: getQuoteResponse.addChild(returnElt);
107: return getQuoteResponse;
108: }
109:
110: // in-out
111: public OMElement getQuote(OMElement request) {
112: //System.out.println(new Date() + " FastStockQuoteService :: Generating quote for : " + request.getSymbol());
113: //return new GetQuoteResponse(request.getSymbol());
114: return response;
115: }
116:
117: // in only
118: /*public void placeOrder(OMElement order) {
119: System.out.println(new Date() + " FastStockQuoteService :: Accepted order for : " +
120: order.getQuantity() + " stocks of " + order.getSymbol() +
121: " at $ " + order.getPrice());
122: }*/
123: }
|