taylor 2005/04/12 16:16:08 Added: src/java/org/apache/jetspeed/webservices/finance/stockmarket JetspeedStockQuoteService2.java Log: phasing out old stock quote service and replacing with new, Axis based one Revision Changes Path 1.1 jakarta-jetspeed/src/java/org/apache/jetspeed/webservices/finance/stockmarket/JetspeedStockQuoteService2.java Index: JetspeedStockQuoteService2.java =================================================================== /* * Copyright 2000-2001,2004 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.jetspeed.webservices.finance.stockmarket; import java.net.MalformedURLException; import java.net.URL; import java.rmi.RemoteException; import javax.servlet.ServletConfig; import org.apache.turbine.services.InitializationException; import org.apache.turbine.services.TurbineBaseService; import org.apache.turbine.services.TurbineServices; import org.apache.turbine.services.resources.ResourceService; import com.bluesunrise.ws.finance.stockmarket.webservice.BaseQuote; import com.bluesunrise.ws.finance.stockmarket.webservice.QuoteService; import com.bluesunrise.ws.finance.stockmarket.webservice.QuoteServiceServiceLocator; /** Implements StockQuoteService, providing a web service for getting stock quotes. @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a> @version $Id: JetspeedStockQuoteService2.java,v 1.1 2005/04/12 23:16:08 taylor Exp $ */ public class JetspeedStockQuoteService2 extends TurbineBaseService implements StockQuoteService { private String soapEndPoint = SERVICE_END_POINT; private static final String SERVICE_END_POINT = "http://www.bluesunrise.com/axis/services/QuoteService"; private URL serviceURL = null; private QuoteServiceServiceLocator locator; public synchronized void init(ServletConfig conf) throws InitializationException { ResourceService serviceConf = ((TurbineServices)TurbineServices.getInstance()) .getResources(StockQuoteService.SERVICE_NAME); soapEndPoint = serviceConf.getString( "endpoint", SERVICE_END_POINT); initURL(soapEndPoint); super.init(conf); } private void initURL(String sep) throws InitializationException { try { serviceURL = new URL(soapEndPoint); locator = new QuoteServiceServiceLocator(); } catch (MalformedURLException e) { throw new InitializationException("Failed to locate Quote Service: " + soapEndPoint, e); } } /* (non-Javadoc) * @see org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService#quote(java.lang.String) */ public String quote(String symbol) throws RemoteException { try { QuoteService quoteService = locator.getQuoteService(serviceURL); return quoteService.quote(symbol); } catch (Exception e) { throw new RemoteException(e.toString()); } } /* (non-Javadoc) * @see org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService#fullQuote(java.lang.String) */ public StockQuote fullQuote(String symbol) throws RemoteException { try { QuoteService quoteService = locator.getQuoteService(serviceURL); BaseQuote quote = quoteService.fullQuote(symbol); StockQuote newQuote = new BaseStockQuote(); convertQuote(quote, newQuote); return newQuote; } catch (Exception e) { throw new RemoteException(e.toString()); } } /* (non-Javadoc) * @see org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService#fullQuotes(java.lang.String[]) */ public StockQuote[] fullQuotes(String[] symbols) throws RemoteException { try { QuoteService quoteService = locator.getQuoteService(serviceURL); BaseQuote[] quotes = quoteService.fullQuotes(symbols); StockQuote[] newQuotes = new BaseStockQuote[quotes.length]; for (int ix = 0; ix < quotes.length; ix ++) { newQuotes[ix] = new BaseStockQuote(); convertQuote(quotes[ix], newQuotes[ix]); } return newQuotes; } catch (Exception e) { throw new RemoteException(e.toString()); } } private void convertQuote(BaseQuote source, StockQuote dest) { dest.setChange(source.getChange()); dest.setDate(source.getDate()); dest.setHigh(source.getHigh()); dest.setLow(source.getLow()); dest.setName(source.getName()); dest.setOpening(source.getOpening()); dest.setPrice(source.getPrice()); dest.setSymbol(source.getSymbol()); dest.setTime(source.getTime()); dest.setVolume(source.getVolume()); } /* (non-Javadoc) * @see org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService#setWebService(java.lang.String) */ public void setWebService( String service ) { try { serviceURL = new URL(service); locator = new QuoteServiceServiceLocator(); } catch (MalformedURLException e) { return; } this.soapEndPoint = service; } /* (non-Javadoc) * @see org.apache.jetspeed.webservices.finance.stockmarket.StockQuoteService#getWebService() */ public String getWebService() { return this.soapEndPoint; } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]