KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > batik > transcoder > TranscodingHints


1 /*
2
3    Copyright 2000-2001,2003 The Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        http://www.apache.org/licenses/LICENSE-2.0
10
11    Unless required by applicable law or agreed to in writing, software
12    distributed under the License is distributed on an "AS IS" BASIS,
13    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14    See the License for the specific language governing permissions and
15    limitations under the License.
16
17  */

18 package org.apache.batik.transcoder;
19
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 /**
25  * The <tt>TranscodingHints</tt> class defines a way to pass
26  * transcoding parameters or options to any transcoders.
27  *
28  * @author <a HREF="mailto:Thierry.Kormann@sophia.inria.fr">Thierry Kormann</a>
29  * @version $Id: TranscodingHints.java,v 1.11 2005/03/27 08:58:36 cam Exp $
30  */

31 public class TranscodingHints extends HashMap JavaDoc {
32
33     /**
34      * Constructs a new empty <tt>TranscodingHints</tt>.
35      */

36     public TranscodingHints() {
37         this(null);
38     }
39
40     /**
41      * Constructs a new <tt>TranscodingHints</tt> with keys and values
42      * initialized from the specified Map object (which may be null).
43      *
44      * @param init a map of key/value pairs to initialize the hints
45      * or null if the object should be empty
46      */

47     public TranscodingHints(Map JavaDoc init) {
48         super(7);
49         if (init != null) {
50             putAll(init);
51         }
52     }
53
54     /**
55      * Returns <tt>true</tt> if this <tt>TranscodingHints</tt> contains a
56      * mapping for the specified key, false otherwise.
57      *
58      * @param key key whose present in this <tt>TranscodingHints</tt>
59      * is to be tested.
60      * @exception ClassCastException key is not of type
61      * <tt>TranscodingHints.Key</tt>
62      */

63     public boolean containsKey(Object JavaDoc key) {
64         return super.containsKey(key);
65     }
66
67     /**
68      * Returns the value to which the specified key is mapped.
69      *
70      * @param key a trancoding hint key
71      * @exception ClassCastException key is not of type
72      * <tt>TranscodingHints.Key</tt>
73      */

74     public Object JavaDoc get(Object JavaDoc key) {
75         return super.get(key);
76     }
77
78     /**
79      * Maps the specified <tt>key</tt> to the specified <tt>value</tt>
80      * in this <tt>TranscodingHints</tt> object.
81      *
82      * @param key the trancoding hint key.
83      * @param value the trancoding hint value.
84      * @exception <tt>IllegalArgumentException</tt> value is not
85      * appropriate for the specified key.
86      * @exception ClassCastException key is not of type
87      * <tt>TranscodingHints.Key</tt>
88      */

89     public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
90         if (!((Key) key).isCompatibleValue(value)) {
91             throw new IllegalArgumentException JavaDoc(value+
92                                                " incompatible with "+
93                                                key);
94         }
95         return super.put(key, value);
96     }
97
98     /**
99      * Removes the key and its corresponding value from this
100      * <tt>TranscodingHints</tt> object.
101      *
102      * @param key the trancoding hints key that needs to be removed
103      * @exception ClassCastException key is not of type
104      * <tt>TranscodingHints.Key</tt>
105      */

106     public Object JavaDoc remove(Object JavaDoc key) {
107         return super.remove(key);
108     }
109
110     /**
111      * Copies all of the keys and corresponding values from the
112      * specified <tt>TranscodingHints</tt> object to this
113      * <tt>TranscodingHints</tt> object.
114      */

115     public void putAll(TranscodingHints hints) {
116         super.putAll(hints);
117     }
118
119     /**
120      * Copies all of the mappings from the specified <tt>Map</tt>
121      * to this <tt>TranscodingHints</tt>.
122      *
123      * @param m mappings to be stored in this <tt>TranscodingHints</tt>.
124      * @exception ClassCastException key is not of type
125      * <tt>TranscodingHints.Key</tt>
126      */

127     public void putAll(Map JavaDoc m) {
128         if (m instanceof TranscodingHints) {
129             putAll(((TranscodingHints) m));
130         } else {
131             Iterator JavaDoc iter = m.entrySet().iterator();
132             while (iter.hasNext()) {
133                 Map.Entry JavaDoc entry = (Map.Entry JavaDoc) iter.next();
134                 put(entry.getKey(), entry.getValue());
135             }
136         }
137     }
138
139     /**
140      * Defines the base type of all keys used to control various
141      * aspects of the transcoding operations.
142      */

143     public abstract static class Key {
144
145         /**
146          * Construcst a key.
147          */

148         protected Key() { }
149
150         /**
151          * Returns true if the specified object is a valid value for
152          * this key, false otherwise.
153          */

154         public abstract boolean isCompatibleValue(Object JavaDoc val);
155     }
156 }
157
Popular Tags