View Javadoc

1   package net.sf.tomp.xml.type;
2   
3   import net.sf.tomp.xtcl.filter.*;
4   
5   import org.xml.sax.*;
6   
7   import java.util.*;
8   
9   /***
10   * DOCUMENT ME!
11   * 
12   * @author $author$
13   * @version $Revision$
14   */
15  public class MultiFilterTypeTransformation implements MultiTransformation {
16      // FIXME: should we consider only-identities-multitransf as a special case?
17  
18      /*** DOCUMENT ME! */
19      protected double costs = 1;
20  
21      /*** DOCUMENT ME! */
22      protected List transformations = new ArrayList();
23  
24      /*** DOCUMENT ME! */
25      protected Map params = new HashMap();
26  
27      /***
28       * Creates a new MultiFilterTypeTransformation object.
29       */
30      public MultiFilterTypeTransformation() {
31      }
32  
33      /***
34       * Creates a new MultiFilterTypeTransformation object.
35       * 
36       * @param ts DOCUMENT ME!
37       */
38      public MultiFilterTypeTransformation(List ts) {
39          int size = ts.size();
40  
41          for (int i = 0; i < size; i++) {
42              TypeTransformation tt = (TypeTransformation) ts.get(i);
43  
44              if (tt.isIdentity()) {
45                  continue;
46              }
47  
48              costs += tt.getCosts();
49              transformations.add(tt);
50          }
51      }
52  
53      /***
54       * DOCUMENT ME!
55       * 
56       * @param k DOCUMENT ME!
57       * @param v DOCUMENT ME!
58       */
59      public void setParameter(String k, Object v) {
60          if (transformations.size() > 0) {
61              TypeTransformation tt = (TypeTransformation) transformations.get(0);
62  
63              tt.setParameter(k, v);
64          }
65  
66          //System.out.println("Setting param "+k+"="+v);
67      }
68  
69      /***
70       * DOCUMENT ME!
71       * 
72       * @param tt DOCUMENT ME!
73       */
74      public void addTransformation(TypeTransformation tt) {
75          if ((tt == null) || tt.isIdentity()) {
76              return;
77          }
78  
79          costs += tt.getCosts();
80          transformations.add(tt);
81      }
82  
83      /***
84       * DOCUMENT ME!
85       * 
86       * @return DOCUMENT ME!
87       * @throws TypeTransformationException DOCUMENT ME!
88       */
89      public XMLFilter newFilter() throws TypeTransformationException {
90          // FIXME: does not set parameters to newly created filter
91          DynamicMultiFilterImpl dmf = new DynamicMultiFilterImpl();
92  
93          //System.out.println(" @"+Integer.toHexString(hashCode())+"
94          // newFilter()=>"+dmf);
95          int size = transformations.size();
96  
97          for (int i = 0; i < size; i++) {
98              TypeTransformation tt = (TypeTransformation) transformations.get(i);
99  
100             XMLFilter f = null;
101 
102             try {
103                 f = tt.newFilter();
104                 dmf.addFilter(i, f);
105             } catch (SAXException se) {
106                 throw new TypeTransformationException("Cannot add filter " + f
107                         + " to " + dmf, se);
108             }
109         }
110 
111         //System.out.println(" @"+Integer.toHexString(hashCode())+" newFilter()
112         // CREATED");
113         return dmf;
114     }
115 
116     /***
117      * DOCUMENT ME!
118      * 
119      * @return DOCUMENT ME!
120      */
121     public double getCosts() {
122         return costs;
123     }
124 
125     /***
126      * DOCUMENT ME!
127      * 
128      * @return DOCUMENT ME!
129      */
130     public String toString() {
131         return "MultiFilterTypeTransformation@"
132                 + Integer.toHexString(hashCode()) + "(transformations="
133                 + transformations + ")";
134     }
135 
136     /***
137      * DOCUMENT ME!
138      * 
139      * @return DOCUMENT ME!
140      */
141     public boolean isIdentity() {
142         return transformations.size() == 0;
143     }
144 }
145 
146 /*
147  * The contents of this file are subject to the Mozilla Public License Version
148  * 1.1 (the "License"); you may not use this file except in compliance with the
149  * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
150  * Software distributed under the License is distributed on an "AS IS" basis,
151  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
152  * the specific language governing rights and limitations under the License. The
153  * Original Code is: all this file. The Initial Developer of the Original Code
154  * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
155  */