001    package railo.runtime.tag;
002    
003    import java.io.Serializable;
004    import java.util.Date;
005    import java.util.TimeZone;
006    
007    import railo.runtime.PageContext;
008    import railo.runtime.exp.PageException;
009    import railo.runtime.op.Caster;
010    
011    public class ChartDataBean implements Serializable,Comparable {
012    
013            private Object item;
014            private String strItem;
015            private double value;
016            /**
017             * @return the item
018             */
019            public Object getItem() {
020                    return item;
021            }
022            public String getItemAsString() {
023                    return strItem;
024            }
025            /**
026             * @param item the item to set
027             * @throws PageException 
028             */
029            public void setItem(PageContext pc,Object obj) throws PageException {
030                    this.strItem = itemToString(pc, obj);
031                    this.item=obj;
032            }
033            public void setItem(String str)  {
034                    this.strItem = str;
035                    this.item=str;
036            }
037            /**
038             * @return the value
039             */
040            public double getValue() {
041                    return value;
042            }
043            /**
044             * @param value the value to set
045             */
046            public void setValue(double value) {
047                    this.value = value;
048            }
049            
050            /**
051             *
052             * @see java.lang.Object#toString()
053             */
054            public String toString() {
055                    return "item:"+item+";"+"value;"+value+";";
056            }
057            public int compareTo(Object o) {
058                    if(!(o instanceof ChartDataBean)) return 0;
059                    ChartDataBean other=(ChartDataBean) o;
060                    return getItemAsString().compareTo(other.getItemAsString());
061            }
062            
063    
064            private String itemToString(PageContext pc,Object obj) throws PageException {
065                    if(obj instanceof Date) {
066                            TimeZone tz = pc.getTimeZone();
067                            return new railo.runtime.format.DateFormat(pc.getLocale()).format(Caster.toDate(obj, tz),"short",tz)+" "+
068                            new railo.runtime.format.TimeFormat(pc.getLocale()).format(Caster.toDate(obj, tz),"short",tz);
069                    }
070                    return Caster.toString(obj);
071            }
072    }