Package org.soybeanMilk.core.config

Examples of org.soybeanMilk.core.config.Interceptor


  @Test
  public void parse_interceptor() throws Exception
  {
    config=new ConfigurationParser().parse("org/soybeanMilk/test/unit/core/TestConfigurationParser-main.xml");
   
    Interceptor ii=config.getInterceptor();
   
    Assert.assertTrue(config.getExecutable("global_before") == ii.getBefore());
    Assert.assertTrue(config.getExecutable("global_after") == ii.getAfter());
    Assert.assertTrue(config.getExecutable("m1_exception") == ii.getException());
    Assert.assertEquals("executionKey", ii.getExecutionKey());
  }
View Full Code Here


    String exception=getAttributeValueIngoreEmpty(el, TAG_INTERCEPROT_ATTR_EXCEPTION);
    String executionKey=getAttributeValueIngoreEmpty(el, TAG_INTERCEPROT_ATTR_EXECUTION_KEY);
   
    assertNotEmpty(executionKey, "<"+TAG_INTERCEPROT+"> attribute ["+TAG_INTERCEPROT_ATTR_EXECUTION_KEY+"] must not be empty");
   
    Interceptor ii=createInterceptorInfoInstance();
    ii.setExecutionKey(executionKey);
   
    if(before != null)
      ii.setBefore(new ExecutableRefProxy(before, getCurrentExecutablePrefix()));
    if(after != null)
      ii.setAfter(new ExecutableRefProxy(after, getCurrentExecutablePrefix()));
    if(exception != null)
      ii.setException(new ExecutableRefProxy(exception, getCurrentExecutablePrefix()));
   
    getConfiguration().setInterceptor(ii);
  }
View Full Code Here

  /**
   * 替换拦截器的代理为真实的可执行对象
   */
  protected void processInterceptorInfoRefs()
  {
    Interceptor ii=getConfiguration().getInterceptor();
    if(ii == null)
      return;
   
    {
      Executable before=ii.getBefore();
      if(before instanceof ExecutableRefProxy)
      {
        Executable targetExe=getTargetRefExecutable((ExecutableRefProxy)before);
        if(targetExe == null)
          throw new ParseException("can not find 'before' interceptor named "+SbmUtils.toString(((ExecutableRefProxy)before).getRefName()));
       
        ii.setBefore(targetExe);
      }
    }
   
    {
      Executable after=ii.getAfter();
      if(after instanceof ExecutableRefProxy)
      {
        Executable targetExe=getTargetRefExecutable((ExecutableRefProxy)after);
        if(targetExe == null)
          throw new ParseException("can not find 'after' interceptor named "+SbmUtils.toString(((ExecutableRefProxy)after).getRefName()));
       
        ii.setAfter(targetExe);
      }
    }
   
    {
      Executable exception=ii.getException();
      if(exception instanceof ExecutableRefProxy)
      {
        Executable targetExe=getTargetRefExecutable((ExecutableRefProxy)exception);
        if(targetExe == null)
          throw new ParseException("can not find 'exception' interceptor named "+SbmUtils.toString(((ExecutableRefProxy)exception).getRefName()));
       
        ii.setException(targetExe);
      }
    }
  }
View Full Code Here

   * 创建空的拦截器信息对象,用于设置其属性
   * @return
   */
  protected Interceptor createInterceptorInfoInstance()
  {
    return new Interceptor();
  }
View Full Code Here

     
      if(cvtObjSource.getGenericConverter() == null)
        cvtObjSource.setGenericConverter(getConfiguration().getGenericConverter());
    }
   
    Interceptor itptInfo = getConfiguration().getInterceptor();
   
    //保存执行语境信息
    Execution context=null;
    if(itptInfo!=null && itptInfo.getExecutionKey()!=null)
    {
      context=new Execution(executable, objSource, null);
     
      try
      {
        objSource.set(itptInfo.getExecutionKey(), context);
      }
      catch(Exception e)
      {
        throw new ExecuteException(e);
      }
    }
   
    try
    {
      //before
      if(itptInfo!=null && itptInfo.getBefore()!=null)
        executeInterceptor(itptInfo.getBefore(), objSource);
     
      executeTargetExecutable(executable, objSource);
     
      //after
      if(itptInfo!=null && itptInfo.getAfter()!=null)
        executeInterceptor(itptInfo.getAfter(), objSource);
     
      return executable;
    }
    catch(ExecuteException e)
    {
      if(context != null)
        context.setExecuteException(e);
     
      Executable expExe= itptInfo == null ? null : itptInfo.getException();
      if(expExe == null)
        throw e;
     
      //exception
      executeInterceptor(expExe, objSource);
View Full Code Here

TOP

Related Classes of org.soybeanMilk.core.config.Interceptor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.