1 package org.apache.turbine.pipeline; 2 3 56 57 import java.io.IOException ; 58 59 import org.apache.turbine.Turbine; 60 import org.apache.turbine.RunData; 61 import org.apache.turbine.TurbineException; 62 import org.apache.turbine.ValveContext; 63 import org.apache.turbine.Resolver; 64 import org.apache.turbine.modules.Module; 65 66 import org.apache.commons.logging.Log; 67 import org.apache.commons.logging.LogFactory; 68 69 78 public class RunModulesValve 79 extends AbstractValve 80 { 81 private static final Log log = LogFactory.getLog( RunModulesValve.class ); 82 83 87 private String targetModuleType; 88 89 92 public void initialize() 93 throws Exception 94 { 95 targetModuleType = Turbine.getConfiguration() 96 .getString( "pipeline.default.targetModuleType" ); 97 } 98 99 102 public void invoke( RunData data, ValveContext context ) 103 throws IOException , TurbineException 104 { 105 try 106 { 107 runModules( targetModuleType, data ); 108 } 109 catch ( Exception e ) 110 { 111 throw new TurbineException( "Failure in RunModulesValve", e ); 112 } 113 114 context.invokeNext( data ); 116 } 117 118 121 public void runModules( String moduleType, RunData data ) 122 throws Exception 123 { 124 String target; 125 String oldTarget = ""; 126 127 Resolver resolver = Turbine.getResolver(); 128 129 Module module; 130 131 target = normalizeTarget( data.getTarget() ); 132 133 while( ! oldTarget.equals( target ) && target != null ) 134 { 135 module = resolver.getModule( moduleType, target ); 136 137 if ( log.isDebugEnabled() ) 138 { 139 log.debug( "Executing module " + module.getClass().getName() 140 + " for target: " + target ); 141 } 142 143 module.execute( data ); 144 145 oldTarget = target; 147 target = data.getTarget(); 148 if ( target != null ) 149 { 150 target = normalizeTarget(target); 151 } 152 } 153 154 158 if ( log.isDebugEnabled() ) 159 { 160 log.debug( "Setting target to " + target ); 161 } 162 163 data.setTarget( target ); 164 } 165 166 172 private String normalizeTarget( String target ) 173 throws Exception 174 { 175 if (target == null || target.length() == 0) 176 { 177 throw new Exception ("RunModulesValve::normalizeTarget() target is null!"); 178 } 179 180 StringBuffer buffer = new StringBuffer ( target ); 181 182 char c; 183 184 int len = buffer.length(); 185 186 boolean lastWasDelim = true; 187 188 for ( int j = 0; j < len; j++ ) 189 { 190 c = buffer.charAt( j ); 191 192 if ( c == ',' || c == '/' ) 193 { 194 if ( lastWasDelim ) 195 { 196 buffer.deleteCharAt( j ); 197 198 j--; 199 len--; 200 } 201 else 202 { 203 buffer.setCharAt( j, '/' ); 204 } 205 206 lastWasDelim = true; 207 } 208 else 209 { 210 lastWasDelim = false; 211 } 212 } 213 214 if (len == 0) 215 { 216 new Exception ( "Syntax error in target: '" + target + '\''); 217 } 218 219 return buffer.toString(); 220 } 221 } 222 | Popular Tags |