001    /**
002     *  Licensed to the Apache Software Foundation (ASF) under one or more
003     *  contributor license agreements.  See the NOTICE file distributed with
004     *  this work for additional information regarding copyright ownership.
005     *  The ASF licenses this file to You under the Apache License, Version 2.0
006     *  (the "License"); you may not use this file except in compliance with
007     *  the License.  You may obtain a copy of the License at
008     *
009     *     http://www.apache.org/licenses/LICENSE-2.0
010     *
011     *  Unless required by applicable law or agreed to in writing, software
012     *  distributed under the License is distributed on an "AS IS" BASIS,
013     *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014     *  See the License for the specific language governing permissions and
015     *  limitations under the License.
016     */
017    package org.apache.geronimo.samples.daytrader;
018    
019    import java.io.Serializable;
020    import java.math.BigDecimal;
021    import java.util.Collection;
022    import java.util.Date;
023    
024    import org.apache.geronimo.samples.daytrader.util.FinancialUtils;
025    import org.apache.geronimo.samples.daytrader.util.Log;
026    
027    /**
028     * 
029     * @author aspyker
030     *
031     * This is a duplicate MarketSummaryDataBean to handle web service handling
032     * of collections.  Instead this class uses typed arrays.
033     */
034    public class MarketSummaryDataBeanWS implements Serializable
035    {
036    
037            private BigDecimal      TSIA;                   /* Trade Stock Index Average */
038            private BigDecimal      openTSIA;               /* Trade Stock Index Average at the open */     
039            private double          volume;                 /* volume of shares traded */
040            private QuoteDataBean   topGainers[];           /* Collection of top gaining stocks */
041            private QuoteDataBean   topLosers[];            /* Collection of top losing stocks */   
042            private Date                    summaryDate;   /* Date this summary was taken */
043            
044            //cache the gainPercent once computed for this bean
045            private BigDecimal  gainPercent=null;
046    
047            public MarketSummaryDataBeanWS(){ }
048            public MarketSummaryDataBeanWS(BigDecimal TSIA,
049                                                            BigDecimal  openTSIA,
050                                                            double          volume,
051                                                            QuoteDataBean[]         topGainers,
052                                                            QuoteDataBean[]         topLosers//, Collection topVolume
053                                                            )
054            {
055                    setTSIA(TSIA);
056                    setOpenTSIA(openTSIA);
057                    setVolume(volume);
058                    setTopGainers(topGainers);
059                    setTopLosers(topLosers);
060                    setSummaryDate(new java.sql.Date(System.currentTimeMillis()));
061                    gainPercent = FinancialUtils.computeGainPercent(getTSIA(), getOpenTSIA());
062                    
063            }
064            
065    
066            public String toString()
067            {
068                    String ret = "\n\tMarket Summary at: " + getSummaryDate()
069                            + "\n\t\t        TSIA:" + getTSIA()
070                            + "\n\t\t    openTSIA:" + getOpenTSIA()
071                            //+ "\n\t\t        gain:" + getGainPercent()
072                            + "\n\t\t      volume:" + getVolume()
073                            ;
074    
075                    if ( (getTopGainers()==null) || (getTopLosers()==null) )
076                            return ret;
077                    ret += "\n\t\t   Current Top Gainers:";
078                    for (int ii = 0; ii < topGainers.length; ii++) {
079                            QuoteDataBean quoteData = topGainers[ii];
080                            ret += ( "\n\t\t\t"  + quoteData.toString() );
081                    }
082                    ret += "\n\t\t   Current Top Losers:";
083                    for (int ii = 0; ii < topLosers.length; ii++) {
084                            QuoteDataBean quoteData = topLosers[ii];
085                            ret += ( "\n\t\t\t"  + quoteData.toString() );
086                    }
087                    return ret;             
088            }
089            public String toHTML()
090            {
091                    String ret = "<BR>Market Summary at: " + getSummaryDate()
092                            + "<LI>        TSIA:" + getTSIA() + "</LI>"
093                            + "<LI>    openTSIA:" + getOpenTSIA() + "</LI>"
094                            + "<LI>      volume:" + getVolume() + "</LI>"
095                            ;
096                    if ( (getTopGainers()==null) || (getTopLosers()==null) )
097                            return ret;
098                    ret += "<BR> Current Top Gainers:";
099                    for (int ii = 0; ii < topGainers.length; ii++) {
100                            QuoteDataBean quoteData = topGainers[ii];
101                            ret += ( "<LI>"  + quoteData.toString()  + "</LI>" );
102                    }
103                    ret += "<BR>   Current Top Losers:";
104                    for (int ii = 0; ii < topLosers.length; ii++) {
105                            QuoteDataBean quoteData = topLosers[ii];
106                            ret += ( "<LI>"  + quoteData.toString()  + "</LI>" );
107                    }
108                    return ret;
109            }
110            public void print()
111            {
112                    Log.log( this.toString() );
113            }       
114            
115            
116            /* Disabled for D185273
117            public BigDecimal getGainPercent()
118            {
119                    if ( gainPercent == null )
120                            gainPercent = FinancialUtils.computeGainPercent(getTSIA(), getOpenTSIA());
121                    return gainPercent;
122            }
123            */
124    
125    
126            /**
127             * Gets the tSIA
128             * @return Returns a BigDecimal
129             */
130            public BigDecimal getTSIA() {
131                    return TSIA;
132            }
133            /**
134             * Sets the tSIA
135             * @param tSIA The tSIA to set
136             */
137            public void setTSIA(BigDecimal tSIA) {
138                    TSIA = tSIA;
139            }
140    
141            /**
142             * Gets the openTSIA
143             * @return Returns a BigDecimal
144             */
145            public BigDecimal getOpenTSIA() {
146                    return openTSIA;
147            }
148            /**
149             * Sets the openTSIA
150             * @param openTSIA The openTSIA to set
151             */
152            public void setOpenTSIA(BigDecimal openTSIA) {
153                    this.openTSIA = openTSIA;
154            }
155    
156            /**
157             * Gets the volume
158             * @return Returns a BigDecimal
159             */
160            public double getVolume() {
161                    return volume;
162            }
163            /**
164             * Sets the volume
165             * @param volume The volume to set
166             */
167            public void setVolume(double volume) {
168                    this.volume = volume;
169            }
170    
171            /**
172             * Gets the topGainers
173             * @return Returns a Collection
174             */
175            public QuoteDataBean[] getTopGainers() {
176                    return topGainers;
177            }
178            /**
179             * Sets the topGainers
180             * @param topGainers The topGainers to set
181             */
182            public void setTopGainers(QuoteDataBean[] topGainers) {
183                    this.topGainers = topGainers;
184            }
185    
186            /**
187             * Gets the topLosers
188             * @return Returns a Collection
189             */
190            public QuoteDataBean[] getTopLosers() {
191                    return topLosers;
192            }
193            /**
194             * Sets the topLosers
195             * @param topLosers The topLosers to set
196             */
197            public void setTopLosers(QuoteDataBean[] topLosers) {
198                    this.topLosers = topLosers;
199            }
200    
201            /**
202             * Gets the summaryDate
203             * @return Returns a Date
204             */
205            public Date getSummaryDate() {
206                    return summaryDate;
207            }
208            /**
209             * Sets the summaryDate
210             * @param summaryDate The summaryDate to set
211             */
212            public void setSummaryDate(Date summaryDate) {
213                    this.summaryDate = summaryDate;
214            }
215            
216            public static MarketSummaryDataBeanWS convertBean(org.apache.geronimo.samples.daytrader.MarketSummaryDataBean origBean) {
217                    Collection gainCol = origBean.getTopGainers();
218                    QuoteDataBean gain[] = (QuoteDataBean[])gainCol.toArray(new QuoteDataBean[0]);
219                    Collection loseCol = origBean.getTopLosers();
220                    QuoteDataBean lose[] = (QuoteDataBean[])loseCol.toArray(new QuoteDataBean[0]);
221                    return new MarketSummaryDataBeanWS(origBean.getTSIA(), origBean.getOpenTSIA(), origBean.getVolume(), gain, lose);
222            }
223    
224    }