View Javadoc

1   package net.sf.tomp.xml.type;
2   
3   import net.sf.tomp.xtcl.filter.*;
4   
5   import org.xml.sax.XMLFilter;
6   
7   import javax.xml.transform.*;
8   
9   import java.util.*;
10  
11  /***
12   * DOCUMENT ME!
13   * 
14   * @author $author$
15   * @version $Revision$
16   */
17  public class StyleTypeTransformation implements TypeTransformation {
18      /*** DOCUMENT ME! */
19      public static final double STYLE_COSTS = 10;
20  
21      /*** DOCUMENT ME! */
22      protected String styleSystemId;
23  
24      /*** DOCUMENT ME! */
25      protected XTFilterFactory factory;
26  
27      /*** DOCUMENT ME! */
28      protected Map params = new HashMap();
29  
30      /***
31       * Creates a new StyleTypeTransformation object.
32       * 
33       * @param ff DOCUMENT ME!
34       * @param styleSystemId DOCUMENT ME!
35       * @throws TransformerConfigurationException DOCUMENT ME!
36       */
37      public StyleTypeTransformation(XTFilterFactory ff, String styleSystemId)
38              throws TransformerConfigurationException {
39          factory = ff;
40          this.styleSystemId = styleSystemId;
41      }
42  
43      /***
44       * DOCUMENT ME!
45       * 
46       * @param k DOCUMENT ME!
47       * @param v DOCUMENT ME!
48       */
49      public void setParameter(String k, Object v) {
50          params.put(k, v);
51      }
52  
53      /***
54       * DOCUMENT ME!
55       * 
56       * @return DOCUMENT ME!
57       * @throws TypeTransformationException DOCUMENT ME!
58       */
59      public XMLFilter newFilter() throws TypeTransformationException {
60          try {
61              // create new TransformerFilterImpl
62              XMLFilter f = factory.newTransformerFilter(styleSystemId);
63  
64              //System.out.println(" @"+Integer.toHexString(hashCode())+"
65              // newFilter()=>"+f);
66              // fill params
67              for (Iterator i = params.entrySet().iterator(); i.hasNext();) {
68                  Map.Entry e = (Map.Entry) i.next();
69                  String k = (String) e.getKey();
70                  Object v = e.getValue();
71  
72                  ((XTFilter) f).setParameter(k, v);
73              }
74  
75              return f;
76          } catch (TransformerConfigurationException tce) {
77              throw new TypeTransformationException(tce);
78          }
79      }
80  
81      /***
82       * DOCUMENT ME!
83       * 
84       * @return DOCUMENT ME!
85       */
86      public double getCosts() {
87          return STYLE_COSTS;
88      }
89  
90      /***
91       * DOCUMENT ME!
92       * 
93       * @return DOCUMENT ME!
94       */
95      public String toString() {
96          return "StyleTypeTransformation@" + Integer.toHexString(hashCode())
97                  + "(" + styleSystemId + ")";
98      }
99  
100     /***
101      * DOCUMENT ME!
102      * 
103      * @return DOCUMENT ME!
104      */
105     public boolean isIdentity() {
106         return false;
107     }
108 }
109 
110 /*
111  * The contents of this file are subject to the Mozilla Public License Version
112  * 1.1 (the "License"); you may not use this file except in compliance with the
113  * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
114  * Software distributed under the License is distributed on an "AS IS" basis,
115  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
116  * the specific language governing rights and limitations under the License. The
117  * Original Code is: all this file. The Initial Developer of the Original Code
118  * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
119  */