KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > calipso > reportgenerator > reportcalculator > Pivot


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 JavaDoc;
7 import java.util.LinkedList JavaDoc;
8 import java.util.Date JavaDoc;
9 import java.util.Collection JavaDoc;
10 import java.io.Serializable JavaDoc;
11 import java.io.ObjectOutputStream JavaDoc;
12 import java.io.IOException JavaDoc;
13 import java.io.ObjectInputStream JavaDoc;
14
15 /**
16  * Contiene la matriz de datos, administra el llenado de un Cube a partir
17  * de una CubeQuery y evalúa las acciones
18  * @see Matrix
19  * @see Cube
20  */

21 public class Pivot implements Serializable JavaDoc {
22
23   protected Matrix matrix;
24   //private CubeQuery lastQuery;
25

26   /**
27    * Devuelve la matriz
28    * @return la matriz
29    */

30   public Matrix getMatrix() {
31     return matrix;
32   }
33
34   /**
35    * Asigna una matriz
36    * @param matrix
37    */

38   public void setMatrix(Matrix matrix) {
39     this.matrix = matrix;
40   }
41
42   /**
43    * Llena el Cube
44    * @param pivotClient
45    * @throws InfoException Si se produce un erro al llenar el pivotClient
46    */

47   public void fill(PivotClient pivotClient) throws InfoException {
48     try {
49       pivotClient.reset();
50       Iterator JavaDoc iterator;
51       System.out.println(LanguageTraslator.traslate("492")+ new Date JavaDoc());
52       iterator = matrix.iterator();
53       try {
54         while (iterator.hasNext()) {
55           pivotClient.fillWith((Object JavaDoc[]) iterator.next());
56         }
57         System.out.println(LanguageTraslator.traslate("493") + new Date JavaDoc());
58         pivotClient.afterFill();
59       } catch (Exception JavaDoc e) {
60         throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("105"), e);
61       }
62     } catch(OutOfMemoryError JavaDoc e) {
63       throw new InfoException(com.calipso.reportgenerator.common.LanguageTraslator.traslate("326"), e);
64     }
65   }
66
67   /**
68    * Resuelve la ejecución de una acción devolviendo todos los rows asociados
69    * @param action
70    * @param cube
71    * @param metric
72    * @param dimensions
73    * @param values
74    * @return Object
75    */

76   public Object JavaDoc executeAction(CubeAction action, Cube cube, int metric, int[] dimensions, Object JavaDoc[] values) throws InfoException{
77     LinkedList JavaDoc involved;
78     Object JavaDoc[] row;
79
80     involved = new LinkedList JavaDoc();
81     Iterator JavaDoc iterator;
82
83     iterator = matrix.iterator();
84     while (iterator.hasNext()) {
85       row = (Object JavaDoc[]) 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   /**
94    * Resuelve si una row cumple con los filtros de la query
95    * @param row
96    * @param cube
97    * @param dimensions
98    * @param values
99    * @return true si cumple con los filtros
100    */

101   private boolean matches(Object JavaDoc[] row, Cube cube, int[] dimensions, Object JavaDoc[] values) {
102     int index;
103     int lenght;
104     int dimension;
105     Object JavaDoc 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   /**
124    * Resuelve la serialización
125    * @param stream
126    * @throws IOException
127    */

128   public void writeTo(ObjectOutputStream JavaDoc stream) throws IOException JavaDoc {
129
130     stream.writeObject(matrix);
131   }
132
133   /**
134    * Resuelve la des-serialización
135    * @param stream
136    * @throws IOException
137    * @throws ClassNotFoundException
138    */

139   public void readFrom(ObjectInputStream JavaDoc stream) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
140     matrix = (Matrix) stream.readObject();
141   }
142
143   public Collection JavaDoc getDimensionValues(int index) throws InfoException {
144     throw new InfoException("592");
145   }
146 }
Popular Tags