1 Reply Latest reply on Mar 11, 2011 4:42 AM by captainvoid

    lookupInStatefulContexts doesn't call factory

    captainvoid

      Hi,
      I noticed a strange behaviour:
      Contexts.lookupInStatefulContexts(myObject) does not call the factory that should create the object. (myObject is not a component, just an object).
      However, if I use an @In annotation to inject the object, the factory is called.


      The thing is that in my class (a custom PermissionResolver) I have set @BypassInterceptors, so I have to lookup objects in the context programmtically.


      Is this a bug or a known behaviour of lookupInStatefulContexts?


      Here the example code:

      @Name("myPermissionResolver")
      @Scope(ScopeType.SESSION)
      @BypassInterceptors
      public class AaPermissionResolver implements PermissionResolver {

           @Override
           public boolean hasPermission(Object target, String action) {
                Object myObject = Contexts.lookupInStatefulContexts("myObject");
                // myObject is null!!!
                ...
           }

      }

      @Name("myObjectFactory")
      @AutoCreate
      public class MyObjectFactory {
           
           @Factory(value="myObject", autoCreate=true, scope=ScopeType.SESSION)
           public Set<Object> getBuiltInObjects() {
                // instantiate myObject
                ...
                return myObject;
           }

      }


      Thanks for any information!

        • 1. Re: lookupInStatefulContexts doesn't call factory
          captainvoid

          Sorry for the bad code format..


          @Name("myPermissionResolver")
          @Scope(ScopeType.SESSION)
          @BypassInterceptors
          public class AaPermissionResolver implements PermissionResolver {
          
               @Override
               public boolean hasPermission(Object target, String action) {
                    Object myObject = Contexts.lookupInStatefulContexts("myObject");
                    // myObject is null!!!
                    ...
               }
          
          }
          
          @Name("myObjectFactory")
          @AutoCreate
          public class MyObjectFactory {
               
               @Factory(value="myObject", autoCreate=true, scope=ScopeType.SESSION)
               public Object getMyObject() {
                    // instantiate myObject
                    ...
                    return myObject;
               }
          
          }