001 /* 002 * Copyright 2004 The Apache Software Foundation 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017 018 package jsp2.examples.simpletag; 019 020 import javax.servlet.jsp.JspException; 021 import javax.servlet.jsp.tagext.JspFragment; 022 import javax.servlet.jsp.tagext.SimpleTagSupport; 023 import java.util.HashMap; 024 import java.io.IOException; 025 026 /** 027 * SimpleTag handler that accepts takes three attributes of type 028 * JspFragment and invokes then in a random order. 029 */ 030 public class ShuffleSimpleTag extends SimpleTagSupport { 031 private JspFragment fragment1; 032 private JspFragment fragment2; 033 private JspFragment fragment3; 034 035 public void doTag() throws JspException, IOException { 036 switch( (int)(Math.random() * 6) ) { 037 case 0: 038 fragment1.invoke( null ); 039 fragment2.invoke( null ); 040 fragment3.invoke( null ); 041 break; 042 case 1: 043 fragment1.invoke( null ); 044 fragment3.invoke( null ); 045 fragment2.invoke( null ); 046 break; 047 case 2: 048 fragment2.invoke( null ); 049 fragment1.invoke( null ); 050 fragment3.invoke( null ); 051 break; 052 case 3: 053 fragment2.invoke( null ); 054 fragment3.invoke( null ); 055 fragment1.invoke( null ); 056 break; 057 case 4: 058 fragment3.invoke( null ); 059 fragment1.invoke( null ); 060 fragment2.invoke( null ); 061 break; 062 case 5: 063 fragment3.invoke( null ); 064 fragment2.invoke( null ); 065 fragment1.invoke( null ); 066 break; 067 } 068 } 069 070 public void setFragment1( JspFragment fragment1 ) { 071 this.fragment1 = fragment1; 072 } 073 074 public void setFragment2( JspFragment fragment2 ) { 075 this.fragment2 = fragment2; 076 } 077 078 public void setFragment3( JspFragment fragment3 ) { 079 this.fragment3 = fragment3; 080 } 081 }