2009/05/20 - Apache Shale has been retired.

For more information, please explore the Attic.

View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to you under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  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.shale.test.mock;
19  
20  import java.io.IOException;
21  import java.io.OutputStream;
22  import java.io.Writer;
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  import javax.faces.context.ResponseStream;
27  import javax.faces.context.ResponseWriter;
28  import javax.faces.render.RenderKit;
29  import javax.faces.render.Renderer;
30  import javax.faces.render.ResponseStateManager;
31  
32  /***
33   * <p>Mock implementation of <code>RenderKit</code>.</p>
34   *
35   * $Id$
36   */
37  
38  public class MockRenderKit extends RenderKit {
39  
40  
41      // ------------------------------------------------------------ Constructors
42  
43  
44      /***
45       * <p>Return a default instance.</p>
46       */
47      public MockRenderKit() {
48      }
49  
50  
51      // ----------------------------------------------------- Mock Object Methods
52  
53  
54      // ------------------------------------------------------ Instance Variables
55  
56  
57      /***
58       * <p>The set of renderers registered here.</p>
59       */
60      private Map renderers = new HashMap();
61  
62  
63      // ------------------------------------------------------- RenderKit Methods
64  
65  
66      /*** {@inheritDoc} */
67      public void addRenderer(String family, String rendererType,
68                              Renderer renderer) {
69  
70          if ((family == null) || (rendererType == null) || (renderer == null)) {
71              throw new NullPointerException();
72          }
73          renderers.put(family + "|" + rendererType, renderer);
74  
75      }
76  
77  
78      /*** {@inheritDoc} */
79      public Renderer getRenderer(String family, String rendererType) {
80  
81          if ((family == null) || (rendererType == null)) {
82              throw new NullPointerException();
83          }
84          return (Renderer) renderers.get(family + "|" + rendererType);
85  
86      }
87  
88  
89      /*** {@inheritDoc} */
90      public ResponseWriter createResponseWriter(Writer writer,
91                                                 String contentTypeList,
92                                                 String characterEncoding) {
93  
94         return new MockResponseWriter(writer, contentTypeList, characterEncoding);
95  
96      }
97  
98  
99      /*** {@inheritDoc} */
100     public ResponseStream createResponseStream(OutputStream out) {
101 
102         final OutputStream stream = out;
103         return new ResponseStream() {
104 
105             public void close() throws IOException {
106                 stream.close();
107             }
108 
109             public void flush() throws IOException {
110                 stream.flush();
111             }
112 
113             public void write(byte[] b) throws IOException {
114                 stream.write(b);
115             }
116 
117             public void write(byte[] b, int off, int len) throws IOException {
118                 stream.write(b, off, len);
119             }
120 
121             public void write(int b) throws IOException {
122                 stream.write(b);
123             }
124 
125         };
126 
127 
128     }
129 
130 
131     /*** {@inheritDoc} */
132     public ResponseStateManager getResponseStateManager() {
133 
134         throw new UnsupportedOperationException();
135 
136     }
137 
138 
139 }