1 package com.calipso.reportgenerator.reportcalculator; 2 3 import com.calipso.reportgenerator.common.InfoException; 4 import com.calipso.reportgenerator.common.LanguageTraslator; 5 6 import java.util.Iterator ; 7 import java.util.LinkedList ; 8 import java.util.Date ; 9 import java.util.Collection ; 10 import java.io.Serializable ; 11 import java.io.ObjectOutputStream ; 12 import java.io.IOException ; 13 import java.io.ObjectInputStream ; 14 15 21 public class Pivot implements Serializable { 22 23 protected Matrix matrix; 24 26 30 public Matrix getMatrix() { 31 return matrix; 32 } 33 34 38 public void setMatrix(Matrix matrix) { 39 this.matrix = matrix; 40 } 41 42 47 public void fill(PivotClient pivotClient) throws InfoException { 48 try { 49 pivotClient.reset(); 50 Iterator iterator; 51 System.out.println(LanguageTraslator.traslate("492")+ new Date ()); 52 iterator = matrix.iterator(); 53 try { 54 while (iterator.hasNext()) { 55 pivotClient.fillWith((Object []) iterator.next()); 56 } 57 System.out.println(LanguageTraslator.traslate("493") + new Date ()); 58 pivotClient.afterFill(); 59 } catch (Exception e) { 60 throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("105"), e); 61 } 62 } catch(OutOfMemoryError e) { 63 throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("326"), e); 64 } 65 } 66 67 76 public Object executeAction(CubeAction action, Cube cube, int metric, int[] dimensions, Object [] values) throws InfoException{ 77 LinkedList involved; 78 Object [] row; 79 80 involved = new LinkedList (); 81 Iterator iterator; 82 83 iterator = matrix.iterator(); 84 while (iterator.hasNext()) { 85 row = (Object []) iterator.next(); 86 if (matches(row, cube, dimensions, values)) { 87 involved.add(row); 88 } 89 } 90 return action.executeOn(involved, cube, metric, dimensions, values); 91 } 92 93 101 private boolean matches(Object [] row, Cube cube, int[] dimensions, Object [] values) { 102 int index; 103 int lenght; 104 int dimension; 105 Object value; 106 107 if (cube.getQuery().matches(row) && cube.getQuery().valuesEnabled(row)) { 108 lenght = dimensions.length; 109 for (index = 0; index < lenght; ++index) { 110 dimension = dimensions[index]; 111 value = values[index]; 112 if (row[dimension] != value) { 113 return false; 114 } 115 } 116 return true; 117 } 118 else { 119 return false; 120 } 121 } 122 123 128 public void writeTo(ObjectOutputStream stream) throws IOException { 129 130 stream.writeObject(matrix); 131 } 132 133 139 public void readFrom(ObjectInputStream stream) throws IOException , ClassNotFoundException { 140 matrix = (Matrix) stream.readObject(); 141 } 142 143 public Collection getDimensionValues(int index) throws InfoException { 144 throw new InfoException("592"); 145 } 146 } | Popular Tags |