1 28 29 30 package org.objectweb.ccm.sessiondemo; 31 32 35 public class ServerImpl 36 extends Server_MainSegBase 37 implements java.io.Serializable 38 { 39 static private Product[] _aproducts = { 41 new Product("A", 10), 42 new Product("B", 20), 43 new Product("C", 30), 44 new Product("D", 10), 45 new Product("E", 50), 46 new Product("F", 90), 47 new Product("G", 20), 48 new Product("H", 60), 49 new Product("I", 10), 50 new Product("J", 70), 51 }; 52 53 static private java.util.Hashtable _products; 54 55 static { 56 _products = new java.util.Hashtable (); 57 for (int i=0;i<_aproducts.length;i++) { 58 _products.put(_aproducts[i].id, _aproducts[i]); 59 } 60 } 61 62 transient private java.util.ArrayList _purchased; 63 private String _spurchased; 64 65 public 67 ServerImpl() 68 { 69 _purchased = null; 71 _spurchased = null; 72 } 73 74 78 final public void 79 ccm_activate() 80 throws org.omg.Components.CCMException 81 { 82 System.err.println("### [ServerImpl] ###"); 83 System.err.println("### [ServerImpl] ccm_activate called"); 84 System.err.println("### [ServerImpl] ###"); 85 86 if (_purchased==null) { 88 _purchased = new java.util.ArrayList (); 89 } 90 91 if (_spurchased!=null) { 93 String purchased = _spurchased; 95 int idx = purchased.indexOf(','); 96 String pid = null; 97 while (idx!=-1) { 98 pid = purchased.substring(0, idx); 99 purchased = purchased.substring(idx+1); 100 idx = purchased.indexOf(','); 101 _purchased.add(pid); 102 } 103 104 _purchased.add(purchased); 105 _spurchased = null; 106 } 107 } 108 109 final public void 110 ccm_passivate() 111 throws org.omg.Components.CCMException 112 { 113 System.err.println("### [ServerImpl] ###"); 114 System.err.println("### [ServerImpl] ccm_passivate called"); 115 System.err.println("### [ServerImpl] ###"); 116 117 StringBuffer buffer = new StringBuffer (); 119 String [] purchased = (String [])_purchased.toArray(new String [0]); 120 for (int i=0;i<purchased.length;i++) { 121 buffer.append(purchased[i]+","); 122 } 123 124 _spurchased = buffer.toString(); 126 } 127 128 final public void 129 ccm_remove() 130 throws org.omg.Components.CCMException 131 { 132 System.err.println("### [ServerImpl] ###"); 133 System.err.println("### [ServerImpl] ccm_remove called"); 134 System.err.println("### [ServerImpl] ###"); 135 136 _purchased.clear(); 137 _purchased = null; 138 _spurchased = null; 139 } 140 141 145 149 final public Product[] 150 list_products() 151 { 152 return _aproducts; 153 } 154 155 final public void 156 purchase_products(String [] pids) 157 { 158 _purchased.addAll(java.util.Arrays.asList(pids)); 159 } 160 161 final public void 162 remove_products(String [] pids) 163 { 164 for (int i=0;i<pids.length;i++) { 165 for (int j=0;j<_purchased.size();j++) { 166 if (pids[i].equals(_purchased.get(j))) { 167 _purchased.remove(j); 168 break; 169 } 170 } 171 } 172 } 173 174 final public Product[] 175 view_caddie() 176 { 177 Product[] purchased = new Product[_purchased.size()]; 178 for (int i=0;i<purchased.length;i++) { 179 purchased[i] = (Product)_products.get(_purchased.get(i)); 180 } 181 182 return purchased; 183 } 184 } 185 | Popular Tags |