public void testInit() throws Exception {
   ComponentDef cd = new ComponentDefImpl(D.class);
   cd.addInitMethodDef(new InitMethodDefImpl("init"));
   cd.init();
   D d = (D) cd.getComponent();
   assertEquals("1", true, d.isInited());
 }
 public void testDestroy() throws Exception {
   ComponentDef cd = new ComponentDefImpl(D.class);
   cd.addDestroyMethodDef(new DestroyMethodDefImpl("destroy"));
   D d = (D) cd.getComponent();
   cd.destroy();
   assertEquals("1", true, d.isDestroyed());
 }
Example #3
0
 /**
  * {@link ComponentDef}を登録します。
  *
  * @param componentDef
  */
 public void register0(ComponentDef componentDef) {
   if (componentDef.getContainer() == null) {
     componentDef.setContainer(this);
   }
   registerByClass(componentDef);
   registerByName(componentDef);
 }
  /** @throws Exception */
  public void testComponent() throws Exception {
    S2Container container = S2ContainerFactory.create(PATH);
    ComponentDeployerFactory.setProvider(new ExternalComponentDeployerProvider());
    MockServletContextImpl ctx = new MockServletContextImpl("s2jsf-example");
    HttpServletRequest request = ctx.createRequest("/hello.html");
    ExternalContext extCtx = new HttpServletExternalContext();
    extCtx.setRequest(request);
    extCtx.setApplication(ctx);
    container.setExternalContext(extCtx);

    container.init();
    assertNotNull(container.getComponent(List.class));
    assertNotNull(container.getComponent("aaa"));
    assertEquals(new Integer(1), container.getComponent("bbb"));
    assertEquals(true, container.getComponent("ccc") != container.getComponent("ccc"));
    ComponentDef cd = container.getComponentDef("ddd");
    assertEquals(AutoBindingDefFactory.NONE, cd.getAutoBindingDef());
    Map map = new HashMap();
    container.injectDependency(map, "eee");
    assertEquals("111", map.get("aaa"));
    assertNotNull(container.getComponent("fff"));
    assertNotNull(container.getComponent("ggg"));

    assertNotNull(container.getComponent("hhh"));
    assertNotNull(container.getComponent("iii"));
    assertEquals("jjj", container.getComponent("jjj"));
    request.setAttribute("name", "aaa");
    cd = container.getComponentDef("kkk");
    assertEquals(true, cd.isExternalBinding());
    Kkk kkk = (Kkk) cd.getComponent();
    assertEquals("aaa", kkk.getName());
  }
Example #5
0
 /**
  * @see org.seasar.framework.container.S2Container#injectDependency(java.lang.Object,
  *     java.lang.Class)
  */
 public void injectDependency(Object outerComponent, Class componentClass) {
   assertParameterIsNotNull(outerComponent, "outerComponent");
   assertParameterIsNotNull(componentClass, "componentClass");
   ComponentDef cd = S2ContainerBehavior.acquireFromInjectDependency(this, componentClass);
   if (cd != null) {
     cd.injectDependency(outerComponent);
   }
 }
 /**
  * @see
  *     org.seasar.framework.xml.sax.handler.TagHandler#end(org.seasar.framework.xml.sax.handler.TagHandlerContext,
  *     java.lang.String)
  */
 public void end(TagHandlerContext context, String body) {
   AspectDef aspectDef = (AspectDef) context.pop();
   if (!StringUtil.isEmpty(body)) {
     aspectDef.setExpression(body);
   }
   ComponentDef componentDef = (ComponentDef) context.peek();
   componentDef.addAspectDef(aspectDef);
 }
Example #7
0
 /**
  * @see org.seasar.framework.container.S2Container#injectDependency(java.lang.Object,
  *     java.lang.String)
  */
 public void injectDependency(Object outerComponent, String componentName) {
   assertParameterIsNotNull(outerComponent, "outerComponent");
   assertParameterIsNotEmpty(componentName, "componentName");
   ComponentDef cd = S2ContainerBehavior.acquireFromInjectDependency(this, componentName);
   if (cd != null) {
     cd.injectDependency(outerComponent);
   }
 }
Example #8
0
 /** @see org.seasar.framework.container.S2Container#getComponent(java.lang.Object) */
 public Object getComponent(Object componentKey) {
   assertParameterIsNotNull(componentKey, "componentKey");
   ComponentDef cd = S2ContainerBehavior.acquireFromGetComponent(this, componentKey);
   if (cd == null) {
     return null;
   }
   return cd.getComponent();
 }
 /** @throws Exception */
 public void testNormal() throws Exception {
   String name = "bbbDto";
   ComponentDef cd = getComponentDef(name);
   assertNotNull(cd);
   assertSame(cd, getComponentDef(name));
   assertEquals(name, cd.getComponentName());
   Object o = cd.getComponent();
   Method m = o.getClass().getMethod("getName", null);
   assertEquals("Hoge", m.invoke(o, null));
 }
 public void testDeployForHotswap() throws Exception {
   MockServletContextImpl ctx = new MockServletContextImpl("s2jsf-example");
   HttpServletRequest request = ctx.createRequest("/hello.html");
   S2Container container = new S2ContainerImpl();
   container.setHotswapMode(true);
   container.setRequest(request);
   ComponentDef cd = new ComponentDefImpl(Foo.class, "foo");
   container.register(cd);
   container.init();
   ComponentDeployer deployer = new SessionComponentDeployer(cd);
   Foo foo = (Foo) deployer.deploy();
   Hotswap hotswap = cd.getHotswap();
   Thread.sleep(500);
   hotswap.getFile().setLastModified(new Date().getTime());
   assertNotSame("1", foo.getClass(), deployer.deploy().getClass());
 }
Example #11
0
 /**
  * コンポーネントのクラスを返します。AOPでクラスが拡張されている場合は、拡張前のクラスが返されます。
  *
  * @param componentDef
  * @param component
  * @return コンポーネントのクラス
  */
 public static Class getComponentClass(ComponentDef componentDef, Object component) {
   Class clazz = componentDef.getConcreteClass();
   if (clazz != null) {
     return clazz;
   }
   return component.getClass();
 }
  public Object invoke(final MethodInvocation invocation) throws Throwable {
    if (!(invocation instanceof S2MethodInvocation)) {
      return invocation.proceed();
    }

    final ComponentDef cd = getComponentDef(invocation);
    if (cd == null) {
      return invocation.proceed();
    }

    final Object target = cd.getComponent();
    final Field targetField = invocation.getClass().getDeclaredField("target");
    targetField.setAccessible(true);
    targetField.set(invocation, target);
    return invocation.proceed();
  }
Example #13
0
 /**
  * カスタマイズ対象のコンポーネント定義をカスタマイズをします。
  *
  * <p>設定されたインタータイプ名を持つインタータイプ定義をコンポーネント定義に登録します。
  * インタータイプ名が複数設定された場合は、設定された順にインタータイプ定義をコンポーネント定義に登録します。
  *
  * @param componentDef コンポーネント定義
  */
 protected void doCustomize(final ComponentDef componentDef) {
   for (int i = 0; i < interTypeNames.size(); ++i) {
     final InterTypeDef interTypeDef = new InterTypeDefImpl();
     interTypeDef.setExpression(new OgnlExpression((String) interTypeNames.get(i)));
     componentDef.addInterTypeDef(interTypeDef);
   }
 }
 /**
  * 指定のインターセプタを指定のメソッドに適用する{@link AspectDef アスペクト定義}を作成して{@link ComponentDef コンポーネント定義}に追加します。
  *
  * @param componentDef コンポーネント定義
  * @param interceptor インターセプタを示すOGNL式
  * @param pointcut インターセプタを適用するメソッド
  */
 protected void appendAspect(
     final ComponentDef componentDef, final String interceptor, final Method pointcut) {
   if (interceptor == null) {
     throw new EmptyRuntimeException("interceptor");
   }
   final AspectDef aspectDef = AspectDefFactory.createAspectDef(interceptor, pointcut);
   componentDef.addAspectDef(aspectDef);
 }
Example #15
0
 protected void doCustomize(ComponentDef componentDef) {
   System.out.println(componentDef.getComponentClass().getName());
   matched = true;
 }
Example #16
0
 /**
  * {@link Class}をキーにして {@link ComponentDef}を登録します。
  *
  * @param componentDef
  */
 protected void registerByClass(ComponentDef componentDef) {
   Class[] classes = S2ContainerUtil.getAssignableClasses(componentDef.getComponentClass());
   for (int i = 0; i < classes.length; ++i) {
     registerMap(classes[i], componentDef);
   }
 }
Example #17
0
 /**
  * 名前をキーにして {@link ComponentDef}を登録します。
  *
  * @param componentDef
  */
 protected void registerByName(ComponentDef componentDef) {
   String componentName = componentDef.getComponentName();
   if (componentName != null) {
     registerMap(componentName, componentDef);
   }
 }