001    /*
002    * Licensed to the Apache Software Foundation (ASF) under one or more
003    * contributor license agreements.  See the NOTICE file distributed with
004    * this work for additional information regarding copyright ownership.
005    * The ASF licenses this file to You under the Apache License, Version 2.0
006    * (the "License"); you may not use this file except in compliance with
007    * the License.  You may obtain a copy of the License at
008    *
009    *     http://www.apache.org/licenses/LICENSE-2.0
010    *
011    * Unless required by applicable law or agreed to in writing, software
012    * distributed under the License is distributed on an "AS IS" BASIS,
013    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014    * See the License for the specific language governing permissions and
015    * limitations under the License.
016    */
017    
018    
019    package jsp2.examples.simpletag;
020    
021    import javax.servlet.jsp.JspException;
022    import javax.servlet.jsp.tagext.JspFragment;
023    import javax.servlet.jsp.tagext.SimpleTagSupport;
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    }