KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infohazard > maverick > flow > ViewWithTransforms


1 /*
2  * $Id: ViewWithTransforms.java,v 1.1 2002/06/06 12:23:54 lhoriman Exp $
3  * $Source: /cvsroot/mav/maverick/src/java/org/infohazard/maverick/flow/ViewWithTransforms.java,v $
4  */

5
6 package org.infohazard.maverick.flow;
7
8 import java.io.IOException JavaDoc;
9 import javax.servlet.ServletException JavaDoc;
10
11 /**
12  * ViewWithTransforms is a decorator that sets transforms when
13  * rendering a view.
14  */

15 class ViewWithTransforms implements View
16 {
17     /** The decorated view */
18     protected View decorated;
19
20     /** The transforms associated with the decorated view */
21     protected Transform[] transforms;
22
23     /**
24      * @param decorate the view to be decorated
25      * @param trans the transforms used to decorate the view
26      */

27     public ViewWithTransforms(View decorate, Transform[] trans)
28     {
29         if (trans == null || trans.length == 0)
30             throw new IllegalArgumentException JavaDoc("Don't use this decorator without transforms");
31
32         if (decorate instanceof ViewWithTransforms)
33         {
34             final ViewWithTransforms other = (ViewWithTransforms)decorate;
35             final Transform[] transforms = new Transform[trans.length + other.transforms.length];
36             System.arraycopy(other.transforms, 0, transforms, 0, other.transforms.length);
37             System.arraycopy(trans, 0, transforms, other.transforms.length, trans.length);
38             this.transforms = transforms;
39             this.decorated = other.decorated;
40         }
41         else
42         {
43             this.decorated = decorate;
44             this.transforms = trans;
45         }
46     }
47
48     /**
49      * @param vctx the view context
50      * @throws IOException
51      * @throws ServletException
52      */

53     public void go(ViewContext vctx) throws IOException JavaDoc, ServletException JavaDoc
54     {
55         ((MaverickContext)vctx).setTransforms(this.transforms);
56
57         this.decorated.go(vctx);
58     }
59 }
Popular Tags