本文整理汇总了Java中net.sourceforge.stripes.controller.Interceptor类的典型用法代码示例。如果您正苦于以下问题:Java Interceptor类的具体用法?Java Interceptor怎么用?Java Interceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Interceptor类属于net.sourceforge.stripes.controller包,在下文中一共展示了Interceptor类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initInterceptors
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
/**
* Splits a comma-separated list of class names and maps each {@link LifecycleStage} to the
* interceptors in the list that intercept it. Also automatically finds Interceptors in
* packages listed in {@link BootstrapPropertyResolver#PACKAGES} if searchExtensionPackages is true.
*
* @return a Map of {@link LifecycleStage} to Collection of {@link Interceptor}
*/
@SuppressWarnings("unchecked")
protected Map<LifecycleStage, Collection<Interceptor>> initInterceptors(List classes) {
Map<LifecycleStage, Collection<Interceptor>> map = new HashMap<LifecycleStage, Collection<Interceptor>>();
for (Object type : classes) {
try {
Interceptor interceptor = getObjectFactory().newInstance(
(Class<? extends Interceptor>) type);
addInterceptor(map, interceptor);
}
catch (Exception e) {
throw new StripesRuntimeException("Could not instantiate configured Interceptor ["
+ type.getClass().getName() + "].", e);
}
}
return map;
}
示例2: initCoreInterceptors
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
/**
* Looks for a list of class names separated by commas under the configuration key
* {@link #CORE_INTERCEPTOR_LIST}. White space surrounding the class names is trimmed,
* the classes instantiated and then stored under the lifecycle stage(s) they should
* intercept.
*
* @return a Map of {@link LifecycleStage} to Collection of {@link Interceptor}
*/
@Override
protected Map<LifecycleStage, Collection<Interceptor>> initCoreInterceptors() {
List<Class<?>> coreInterceptorClasses = getBootstrapPropertyResolver().getClassPropertyList(CORE_INTERCEPTOR_LIST);
if (coreInterceptorClasses.size() == 0)
return super.initCoreInterceptors();
else
return initInterceptors(coreInterceptorClasses);
}
示例3: getInterceptors
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
/**
* Returns a list of interceptors that should be executed around the lifecycle stage
* indicated. By default returns a single element list containing the
* {@link BeforeAfterMethodInterceptor}.
*/
public Collection<Interceptor> getInterceptors(LifecycleStage stage) {
Collection<Interceptor> interceptors = this.interceptors.get(stage);
if (interceptors == null) {
interceptors = Collections.emptyList();
}
return interceptors;
}
示例4: mergeInterceptorMaps
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
/**
* Merges the two {@link Map}s of {@link LifecycleStage} to {@link Collection} of
* {@link Interceptor}. A simple {@link Map#putAll(Map)} does not work because it overwrites
* the collections in the map instead of adding to them.
*/
protected void mergeInterceptorMaps(Map<LifecycleStage, Collection<Interceptor>> dst,
Map<LifecycleStage, Collection<Interceptor>> src) {
for (Map.Entry<LifecycleStage, Collection<Interceptor>> entry : src.entrySet()) {
Collection<Interceptor> collection = dst.get(entry.getKey());
if (collection == null) {
collection = new LinkedList<Interceptor>();
dst.put(entry.getKey(), collection);
}
collection.addAll(entry.getValue());
}
}
示例5: addInterceptor
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
/**
* Adds the interceptor to the map, associating it with the {@link LifecycleStage}s indicated
* by the {@link Intercepts} annotation. If the interceptor implements
* {@link ConfigurableComponent}, then its init() method will be called.
*/
protected void addInterceptor(Map<LifecycleStage, Collection<Interceptor>> map,
Interceptor interceptor) {
Class<? extends Interceptor> type = interceptor.getClass();
Intercepts intercepts = type.getAnnotation(Intercepts.class);
if (intercepts == null) {
log.error("An interceptor of type ", type.getName(), " was configured ",
"but was not marked with an @Intercepts annotation. As a ",
"result it is not possible to determine at which ",
"lifecycle stages the interceptor should be applied. This ",
"interceptor will be ignored.");
return;
}
else {
log.debug("Configuring interceptor '", type.getSimpleName(),
"', for lifecycle stages: ", intercepts.value());
}
// call init() if the interceptor implements ConfigurableComponent
if (interceptor instanceof ConfigurableComponent) {
try {
((ConfigurableComponent) interceptor).init(this);
}
catch (Exception e) {
log.error("Error initializing interceptor of type " + type.getName(), e);
}
}
for (LifecycleStage stage : intercepts.value()) {
Collection<Interceptor> stack = map.get(stage);
if (stack == null) {
stack = new LinkedList<Interceptor>();
map.put(stage, stack);
}
stack.add(interceptor);
}
}
示例6: initCoreInterceptors
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
/** Instantiates the core interceptors, allowing subclasses to override the default behavior */
protected Map<LifecycleStage, Collection<Interceptor>> initCoreInterceptors() {
Map<LifecycleStage, Collection<Interceptor>> interceptors = new HashMap<LifecycleStage, Collection<Interceptor>>();
addInterceptor(interceptors, new BeforeAfterMethodInterceptor());
addInterceptor(interceptors, new HttpCacheInterceptor());
return interceptors;
}
示例7: setupContext
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
@BeforeClass
@SuppressWarnings("unchecked")
public void setupContext() throws Exception {
context = new MockServletContext("waitpage");
// Add the Stripes Filter
Map<String,String> filterParams = new HashMap<String,String>();
filterParams.put("CoreInterceptor.Classes",
"org.stripesstuff.tests.waitpage.TestableWaitPageInterceptor," +
"net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor," +
"net.sourceforge.stripes.controller.HttpCacheInterceptor");
filterParams.put("ActionResolver.Packages",
"org.stripesstuff.tests.waitpage.action");
filterParams.put("WaitPageInterceptor.ContextTimeout",
"2000");
context.addFilter(StripesFilter.class, "StripesFilter", filterParams);
// Add the Stripes Dispatcher
context.setServlet(DispatcherServlet.class, "StripesDispatcher", null);
// Obtain WaitPageInterceptor instance.
StripesFilter stripesFilter = (StripesFilter)context.getFilters().get(0);
Iterator<Interceptor> interceptorsIter = stripesFilter.getInstanceConfiguration().getInterceptors(LifecycleStage.ActionBeanResolution).iterator();
WaitPageInterceptor waitPageInterceptor = null;
while (waitPageInterceptor == null && interceptorsIter.hasNext()) {
Interceptor interceptor = interceptorsIter.next();
if (interceptor instanceof WaitPageInterceptor) {
waitPageInterceptor = (WaitPageInterceptor)interceptor;
}
}
assertNotNull(waitPageInterceptor);
Field field = WaitPageInterceptor.class.getDeclaredField("contexts");
field.setAccessible(true);
waitContexts = (Map<Integer, Context>)field.get(waitPageInterceptor);
}
示例8: initInterceptors
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
/** Allows subclasses to initialize a non-default Map of Interceptor instances. */
protected Map<LifecycleStage,Collection<Interceptor>> initInterceptors() { return null; }
示例9: getInterceptors
import net.sourceforge.stripes.controller.Interceptor; //导入依赖的package包/类
/**
* Fetches the interceptors that should be executed around the lifecycle stage applied.
* Must return a non-null collection, but the collection may be empty. The Interceptors
* are invoked around the code which executes the given lifecycle function (e.g.
* ActionBeanResolution), and as a result can execute code both before and after it.
*
* @return Collection<Interceptor> an ordered collection of interceptors to be executed
* around the given lifecycle stage.
*/
Collection<Interceptor> getInterceptors(LifecycleStage stage);