Package objot.aspect

Examples of objot.aspect.Weaver


  static Class<X> weaved;

  @BeforeClass
  public static void init() throws Exception
  {
    weaved = new Weaver(A2.class, A1.class)
    {
      @Override
      protected Object forWeave(Class<? extends Aspect> ac, Method m) throws Exception
      {
        if (m.getDeclaringClass() == Object.class)
View Full Code Here


{
  /** @return container of services which parent is for session */
  public static Container build(final Codec codec, final SessionFactory hib,
    final boolean test) throws Exception
  {
    final Weaver w = new Weaver(Sign.As.class, Transac.As.class, EncAs.class,
      ResultAs.class)
    {
      CharSequence v = codec != null ? codec.enc(true, null) : null;

      @Override
      protected Object forWeave(Class<? extends Aspect> ac, Method m) throws Exception
      {
        if ( !m.isAnnotationPresent(Service.class))
          return this;
        if (ac == Sign.As.class)
          return m.isAnnotationPresent(Sign.Any.class) ? this : null;
        if (ac == Transac.As.class)
          return m.isAnnotationPresent(Transac.Any.class) ? this
            : new Transac.Config(m);
        if (codec == null || m.getReturnType() == byte[].class
          || InputStream.class.isAssignableFrom(m.getReturnType()))
          return ac == ResultAs.class ? null : this;
        if (ac == EncAs.class)
          return m.getReturnType() == void.class ? v : null;
        return this;
      }
    };
    final Weaver testW = new Weaver(TestAs.class)
    {
      @Override
      protected Object forWeave(Class<? extends Aspect> ac, Method m) throws Exception
      {
        if (m.getDeclaringClass().isSynthetic()
          && Mod2.match(m, Mod2.P.OBJECT, Mod2.PUBLIC_PROTECT, Mod2.FINAL))
          return null;
        return this;
      }
    };
    final Container sess = new Factory()
    {
      {
        for (Class<?> c: Class2.packageClasses(Do.class))
          if (Session.class.isAssignableFrom(c))
            bind(c);
        bind(SessionFactory.class);
      }

      @Override
      protected Object forBind(Class<?> c, Bind b) throws Exception
      {
        return c == SessionFactory.class ? b.obj(hib) : b;
      }
    }.create(null);
    Factory req = new Factory()
    {
      @Override
      protected Object forBind(Class<?> c, Bind b) throws Exception
      {
        if (sess.bound(c))
          return b.mode(Inject.Parent.class);
        if (c == Codec.class)
          return b.obj(codec);
        if (c.isSynthetic())
          return b;
        return b.cla(test ? testW.weave(w.weave(c)) : w.weave(c));
      }
    }.bind(Codec.class);
    for (Class<?> c: Class2.packageClasses(Do.class))
      if (Mod2.match(c, Mod2.PUBLIC, Mod2.ABSTRACT))
        req.bind(c);
View Full Code Here

TOP

Related Classes of objot.aspect.Weaver

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.