View Javadoc
1 package org.apache.turbine.modules; 2 3 /* ==================================================================== 4 * The Apache Software License, Version 1.1 5 * 6 * Copyright (c) 2001 The Apache Software Foundation. All rights 7 * reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in 18 * the documentation and/or other materials provided with the 19 * distribution. 20 * 21 * 3. The end-user documentation included with the redistribution, 22 * if any, must include the following acknowledgment: 23 * "This product includes software developed by the 24 * Apache Software Foundation (http://www.apache.org/)." 25 * Alternately, this acknowledgment may appear in the software itself, 26 * if and wherever such third-party acknowledgments normally appear. 27 * 28 * 4. The names "Apache" and "Apache Software Foundation" and 29 * "Apache Turbine" must not be used to endorse or promote products 30 * derived from this software without prior written permission. For 31 * written permission, please contact apache@apache.org. 32 * 33 * 5. Products derived from this software may not be called "Apache", 34 * "Apache Turbine", nor may "Apache" appear in their name, without 35 * prior written permission of the Apache Software Foundation. 36 * 37 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED 38 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 39 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 40 * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR 41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 43 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 44 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 45 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 46 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 47 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 48 * SUCH DAMAGE. 49 * ==================================================================== 50 * 51 * This software consists of voluntary contributions made by many 52 * individuals on behalf of the Apache Software Foundation. For more 53 * information on the Apache Software Foundation, please see 54 * <http://www.apache.org/>;. 55 */ 56 57 // Java Core Classes 58 import java.util.Vector; 59 60 // Turbine Utility Classes 61 import org.apache.turbine.TurbineConstants; 62 import org.apache.turbine.services.resources.TurbineResources; 63 import org.apache.turbine.services.assemblerbroker.AssemblerBrokerService; 64 import org.apache.turbine.services.TurbineServices; 65 import org.apache.turbine.util.ObjectUtils; 66 import org.apache.turbine.util.RunData; 67 68 69 /*** 70 * The purpose of this class is to allow one to load and execute 71 * Layout modules. 72 * 73 * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> 74 * @version $Id: LayoutLoader.java,v 1.1.1.1 2001/08/16 05:08:30 jvanzyl Exp $ 75 */ 76 public class LayoutLoader extends GenericLoader 77 { 78 /*** The single instance of this class. */ 79 private static LayoutLoader instance = new LayoutLoader( 80 TurbineResources.getInt(TurbineConstants.LAYOUT_CACHE_SIZE, 10)); 81 82 /*** 83 * These ctor's are private to force clients to use getInstance() 84 * to access this class. 85 */ 86 private LayoutLoader() 87 { 88 super(); 89 } 90 91 /*** 92 * These ctor's are private to force clients to use getInstance() 93 * to access this class. 94 */ 95 private LayoutLoader(int i) 96 { 97 super(i); 98 } 99 100 /*** 101 * Adds an instance of an object into the hashtable. 102 * 103 * @param name Name of object. 104 * @param layout Layout to be associated with name. 105 */ 106 private void addInstance( String name, Layout layout ) 107 { 108 if ( cache() ) 109 this.put( name, (Layout) layout ); 110 } 111 112 /*** 113 * Attempts to load and execute the external layout. 114 * 115 * @param data Turbine information. 116 * @param name Name of object that will execute the layout. 117 * @exception Exception a generic exception. 118 */ 119 public void exec( RunData data, String name ) 120 throws Exception 121 { 122 // Execute layout 123 getInstance(name).build(data); 124 } 125 126 /*** 127 * Pulls out an instance of the object by name. Name is just the 128 * single name of the object. 129 * 130 * @param name Name of object instance. 131 * @return A Layout with the specified name, or null. 132 * @exception Exception a generic exception. 133 */ 134 public Layout getInstance(String name) 135 throws Exception 136 { 137 Layout layout = null; 138 139 if ( cache() && this.containsKey( name ) ) 140 { 141 layout = (Layout) this.get ( name ); 142 } 143 else 144 { 145 // We get the broker service 146 AssemblerBrokerService ab = 147 (AssemblerBrokerService)TurbineServices.getInstance() 148 .getService (AssemblerBrokerService.SERVICE_NAME); 149 150 try 151 { 152 // Attempt to load the screen 153 layout = (Layout) ab.getAssembler( 154 AssemblerBrokerService.LAYOUT_TYPE,name); 155 } 156 catch (ClassCastException cce) 157 { 158 // This can alternatively let this exception be thrown 159 // So that the ClassCastException is shown in the 160 // browser window. Like this it shows "Screen not Found" 161 layout = null; 162 } 163 164 if (layout == null) 165 { 166 // If we did not find a screen we should try and give 167 // the user a reason for that... 168 // FIX ME: The AssemblerFactories should each add it's own 169 // string here... 170 Vector packages = TurbineResources.getVector( 171 TurbineConstants.MODULE_PACKAGES); 172 ObjectUtils.addOnce( packages, 173 GenericLoader.getBasePackage() ); 174 175 throw new ClassNotFoundException( 176 "\n\n\tRequested Layout not found: " + name + "\n" + 177 "\tTurbine looked in the following modules.packages " + 178 "path: \n\t" + packages.toString() + "\n"); 179 } 180 else if ( cache() ) 181 { 182 // The new instance is added to the cache 183 addInstance( name, layout ); 184 } 185 } 186 return layout; 187 } 188 189 /*** 190 * The method through which this class is accessed. 191 * 192 * @return The single instance of this class. 193 */ 194 public static LayoutLoader getInstance() 195 { 196 return instance; 197 } 198 }

This page was automatically generated by Maven