KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jsp2 > examples > simpletag > ShuffleSimpleTag


1
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the "License"). You may not use this file except
7  * in compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * glassfish/bootstrap/legal/CDDLv1.0.txt or
11  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * HEADER in each file and include the License file at
17  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
18  * add the following below this CDDL HEADER, with the
19  * fields enclosed by brackets "[]" replaced with your
20  * own identifying information: Portions Copyright [yyyy]
21  * [name of copyright owner]
22  *
23  * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24  *
25  * Portions Copyright Apache Software Foundation.
26  */

27
28 package jsp2.examples.simpletag;
29
30 import javax.servlet.jsp.JspException JavaDoc;
31 import javax.servlet.jsp.tagext.JspFragment JavaDoc;
32 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
33 import java.util.HashMap JavaDoc;
34 import java.io.IOException JavaDoc;
35
36 /**
37  * SimpleTag handler that accepts takes three attributes of type
38  * JspFragment and invokes then in a random order.
39  */

40 public class ShuffleSimpleTag extends SimpleTagSupport JavaDoc {
41     private JspFragment JavaDoc fragment1;
42     private JspFragment JavaDoc fragment2;
43     private JspFragment JavaDoc fragment3;
44
45     public void doTag() throws JspException JavaDoc, IOException JavaDoc {
46         switch( (int)(Math.random() * 6) ) {
47             case 0:
48                 fragment1.invoke( null );
49                 fragment2.invoke( null );
50                 fragment3.invoke( null );
51                 break;
52             case 1:
53                 fragment1.invoke( null );
54                 fragment3.invoke( null );
55                 fragment2.invoke( null );
56                 break;
57             case 2:
58                 fragment2.invoke( null );
59                 fragment1.invoke( null );
60                 fragment3.invoke( null );
61                 break;
62             case 3:
63                 fragment2.invoke( null );
64                 fragment3.invoke( null );
65                 fragment1.invoke( null );
66                 break;
67             case 4:
68                 fragment3.invoke( null );
69                 fragment1.invoke( null );
70                 fragment2.invoke( null );
71                 break;
72             case 5:
73                 fragment3.invoke( null );
74                 fragment2.invoke( null );
75                 fragment1.invoke( null );
76                 break;
77         }
78     }
79
80     public void setFragment1( JspFragment JavaDoc fragment1 ) {
81         this.fragment1 = fragment1;
82     }
83     
84     public void setFragment2( JspFragment JavaDoc fragment2 ) {
85         this.fragment2 = fragment2;
86     }
87     
88     public void setFragment3( JspFragment JavaDoc fragment3 ) {
89         this.fragment3 = fragment3;
90     }
91 }
92
Popular Tags