| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| ScreenLoader |
|
| 1.0;1 |
| 1 | package org.apache.turbine.modules; | |
| 2 | ||
| 3 | ||
| 4 | /* | |
| 5 | * Licensed to the Apache Software Foundation (ASF) under one | |
| 6 | * or more contributor license agreements. See the NOTICE file | |
| 7 | * distributed with this work for additional information | |
| 8 | * regarding copyright ownership. The ASF licenses this file | |
| 9 | * to you under the Apache License, Version 2.0 (the | |
| 10 | * "License"); you may not use this file except in compliance | |
| 11 | * with the License. You may obtain a copy of the License at | |
| 12 | * | |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 14 | * | |
| 15 | * Unless required by applicable law or agreed to in writing, | |
| 16 | * software distributed under the License is distributed on an | |
| 17 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
| 18 | * KIND, either express or implied. See the License for the | |
| 19 | * specific language governing permissions and limitations | |
| 20 | * under the License. | |
| 21 | */ | |
| 22 | ||
| 23 | ||
| 24 | import org.apache.ecs.ConcreteElement; | |
| 25 | import org.apache.turbine.Turbine; | |
| 26 | import org.apache.turbine.pipeline.PipelineData; | |
| 27 | import org.apache.turbine.util.RunData; | |
| 28 | ||
| 29 | /** | |
| 30 | * The purpose of this class is to allow one to load and execute | |
| 31 | * Screen modules. | |
| 32 | * | |
| 33 | * @author <a href="mailto:mbryson@mont.mindspring.com">Dave Bryson</a> | |
| 34 | * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a> | |
| 35 | * @author <a href="mailto:peter@courcoux.biz">Peter Courcoux</a> | |
| 36 | * @version $Id: ScreenLoader.java 1078552 2011-03-06 19:58:46Z tv $ | |
| 37 | */ | |
| 38 | 54 | public class ScreenLoader |
| 39 | extends GenericLoader<Screen> | |
| 40 | implements Loader<Screen> | |
| 41 | { | |
| 42 | /** The single instance of this class. */ | |
| 43 | 58 | private static ScreenLoader instance = new ScreenLoader(); |
| 44 | ||
| 45 | /** | |
| 46 | * These ctor's are private to force clients to use getInstance() | |
| 47 | * to access this class. | |
| 48 | */ | |
| 49 | private ScreenLoader() | |
| 50 | { | |
| 51 | 58 | super(); |
| 52 | 58 | } |
| 53 | ||
| 54 | /** | |
| 55 | * Attempts to load and execute the external Screen. This is used | |
| 56 | * when you want to execute a Screen which returns its output via | |
| 57 | * a MultiPartElement instead of out the data.getPage() value. | |
| 58 | * This allows you to easily chain the execution of Screen modules | |
| 59 | * together. | |
| 60 | * | |
| 61 | * @deprecated Use PipelineData version instead. | |
| 62 | * @param data Turbine information. | |
| 63 | * @param name Name of object that will execute the screen. | |
| 64 | * @exception Exception a generic exception. | |
| 65 | */ | |
| 66 | @Deprecated | |
| 67 | public ConcreteElement eval(RunData data, String name) | |
| 68 | throws Exception | |
| 69 | { | |
| 70 | // Execute screen | |
| 71 | 0 | return getAssembler(name).build(data); |
| 72 | } | |
| 73 | ||
| 74 | /** | |
| 75 | * Attempts to load and execute the external Screen. This is used | |
| 76 | * when you want to execute a Screen which returns its output via | |
| 77 | * a MultiPartElement instead of out the data.getPage() value. | |
| 78 | * This allows you to easily chain the execution of Screen modules | |
| 79 | * together. | |
| 80 | * | |
| 81 | * @param data Turbine information. | |
| 82 | * @param name Name of object that will execute the screen. | |
| 83 | * @exception Exception a generic exception. | |
| 84 | */ | |
| 85 | public ConcreteElement eval(PipelineData pipelineData, String name) | |
| 86 | throws Exception | |
| 87 | { | |
| 88 | // Execute screen | |
| 89 | 6 | return getAssembler(name).build(pipelineData); |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * Attempts to load and execute the Screen. This is used when you | |
| 94 | * want to execute a Screen which returns its output via the | |
| 95 | * data.getPage() object. | |
| 96 | * @deprecated Use PipelineData version instead. | |
| 97 | * @param data Turbine information. | |
| 98 | * @param name Name of object that will execute the screen. | |
| 99 | * @exception Exception a generic exception. | |
| 100 | */ | |
| 101 | @Deprecated | |
| 102 | @Override | |
| 103 | public void exec(RunData data, String name) | |
| 104 | throws Exception | |
| 105 | { | |
| 106 | 0 | this.eval(data, name); |
| 107 | 0 | } |
| 108 | ||
| 109 | /** | |
| 110 | * Attempts to load and execute the Screen. This is used when you | |
| 111 | * want to execute a Screen which returns its output via the | |
| 112 | * data.getPage() object. | |
| 113 | * | |
| 114 | * @param data Turbine information. | |
| 115 | * @param name Name of object that will execute the screen. | |
| 116 | * @exception Exception a generic exception. | |
| 117 | */ | |
| 118 | @Override | |
| 119 | public void exec(PipelineData pipelineData, String name) | |
| 120 | throws Exception | |
| 121 | { | |
| 122 | 0 | this.eval(pipelineData, name); |
| 123 | 0 | } |
| 124 | ||
| 125 | /** | |
| 126 | * Pulls out an instance of the object by name. Name is just the | |
| 127 | * single name of the object. This is equal to getInstance but | |
| 128 | * returns an Assembler object and is needed to fulfil the Loader | |
| 129 | * interface. | |
| 130 | * | |
| 131 | * @param name Name of object instance. | |
| 132 | * @return A Screen with the specified name, or null. | |
| 133 | * @exception Exception a generic exception. | |
| 134 | */ | |
| 135 | public Screen getAssembler(String name) | |
| 136 | throws Exception | |
| 137 | { | |
| 138 | 66 | return getAssembler(Screen.NAME, name); |
| 139 | } | |
| 140 | ||
| 141 | /** | |
| 142 | * @see org.apache.turbine.modules.Loader#getCacheSize() | |
| 143 | */ | |
| 144 | public int getCacheSize() | |
| 145 | { | |
| 146 | 188 | return ScreenLoader.getConfiguredCacheSize(); |
| 147 | } | |
| 148 | ||
| 149 | /** | |
| 150 | * The method through which this class is accessed. | |
| 151 | * | |
| 152 | * @return The single instance of this class. | |
| 153 | */ | |
| 154 | public static ScreenLoader getInstance() | |
| 155 | { | |
| 156 | 198 | return instance; |
| 157 | } | |
| 158 | ||
| 159 | /** | |
| 160 | * Helper method to get the configured cache size for this module | |
| 161 | * | |
| 162 | * @return the configure cache size | |
| 163 | */ | |
| 164 | private static int getConfiguredCacheSize() | |
| 165 | { | |
| 166 | 188 | return Turbine.getConfiguration().getInt(Screen.CACHE_SIZE_KEY, |
| 167 | Screen.CACHE_SIZE_DEFAULT); | |
| 168 | } | |
| 169 | } |