예제 #1
0
        protected ICascadedInterceptor HandleServiceClientAnnotation(AnnotationEntry <ServiceClientAttribute> serviceClientAnnotation, IBeanContextFactory beanContextFactory, IServiceContext beanContext,
                                                                     IBeanConfiguration beanConfiguration, Type type)
        {
            String serviceName = ExtractServiceName(serviceClientAnnotation.Annotation.Name, serviceClientAnnotation.DeclaringType);

            IMethodLevelBehavior <Attribute> behavior = CreateInterceptorModeBehavior(type);

            CacheInterceptor interceptor = new CacheInterceptor();

            if (beanContext.IsRunning)
            {
                interceptor = beanContext.RegisterWithLifecycle(interceptor) //
                              .PropertyValue("ServiceName", serviceName)     //
                              .PropertyValue("Behavior", behavior)           //
                              .Finish();
            }
            else
            {
                beanContextFactory.RegisterWithLifecycle(interceptor) //
                .PropertyValue("ServiceName", serviceName)            //
                .PropertyValue("Behavior", behavior);
            }

            if (Log.InfoEnabled)
            {
                Log.Info("Creating application service stub for service '" + serviceName + "' accessing with '" + serviceClientAnnotation.DeclaringType.FullName + "'");
            }
            return(interceptor);
        }
예제 #2
0
            public void AfterPropertiesSet(IBeanContextFactory beanContextFactory)
            {
                List <int> testList = new List <int>();

                testList.Add(1);
                testList.Add(2);
                beanContextFactory.RegisterWithLifecycle(testList).Autowireable <IList <int> >();
            }
예제 #3
0
        protected ICascadedInterceptor HandleServiceAnnotation(ServiceAttribute serviceAnnotation, IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type type)
        {
            if (serviceAnnotation.CustomExport)
            {
                // Do nothing if the service wants to be exported by some special way anywhere else
                return(null);
            }
            String beanName    = beanConfiguration.GetName();
            String serviceName = ExtractServiceName(serviceAnnotation.Name, type);

            if (!IsNetworkClientMode)
            {
                IMethodLevelBehavior <Attribute> behavior = CreateInterceptorModeBehavior(type);

                CacheInterceptor interceptor = new CacheInterceptor();
                if (beanContext.IsRunning)
                {
                    interceptor = beanContext.RegisterWithLifecycle(interceptor) //
                                  .PropertyValue("ServiceName", serviceName)     //
                                  .PropertyValue("Behavior", behavior)           //
                                  .IgnoreProperties("ProcessService")            //
                                  .Finish();
                    beanContext.Link(beanName).To <IServiceExtendable>().With(serviceName);
                }
                else
                {
                    beanContextFactory.RegisterWithLifecycle(interceptor) //
                    .PropertyValue("ServiceName", serviceName)            //
                    .PropertyValue("Behavior", behavior)                  //
                    .IgnoreProperties("ProcessService");
                    beanContextFactory.Link(beanName).To <IServiceExtendable>().With(serviceName);
                }
                if (Log.InfoEnabled)
                {
                    Log.Info("Registering application service '" + serviceName + "'");
                }
                return(interceptor);
            }
            else
            {
                if (Log.InfoEnabled)
                {
                    Log.Info("Registering application mock service '" + serviceName + "'");
                }
                if (beanContext.IsRunning)
                {
                    beanContext.Link(beanName).To <IServiceExtendable>().With(serviceName);
                }
                else
                {
                    beanContextFactory.Link(beanName).To <IServiceExtendable>().With(serviceName);
                }
                return(null);
            }
        }
예제 #4
0
        protected override ICascadedInterceptor HandleServiceIntern(IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type type, ISet <Type> requestedTypes)
        {
            if (!WrapAllInteractions)
            {
                return(null);
            }
            if (annotationCache.GetAnnotation(type) == null)
            {
                return(null);
            }
            LogInterceptor logInterceptor = new LogInterceptor();

            if (beanContext.IsRunning)
            {
                logInterceptor = beanContext.RegisterWithLifecycle(logInterceptor).Finish();
            }
            else
            {
                beanContextFactory.RegisterWithLifecycle(logInterceptor);
            }
            return(logInterceptor);

            //if (service is IProxyTargetAccessor || service is IInterceptor)
            //{
            //    return service;
            //}
            //if (!requestedType.IsInterface)
            //{
            //    MethodInfo[] methods = service.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance);
            //    foreach (MethodInfo method in methods)
            //    {
            //        if (typeof(Object).Equals(method.DeclaringType))
            //        {
            //            continue;
            //        }
            //        if (!method.IsVirtual)
            //        {
            //            if (Log.DebugEnabled)
            //            {
            //                Log.Debug(service.GetType().FullName + "." + LogTypesUtil.PrintMethod(method.Name, method.GetParameters(), null, PrintShortStringNames)
            //                    + " is not virtual. Skipping LoggingProxy for this service instance");
            //            }
            //            return service;
            //        }
            //    }
            //}
            //ICascadedInterceptor logInterceptor = BeanContext.MonitorObject<LogInterceptor>();
            //logInterceptor.Target = service;
            //return ProxyFactory.CreateProxy(requestedType, logInterceptor);
        }
예제 #5
0
        protected override ICascadedInterceptor HandleServiceIntern(IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type type, ISet <Type> requestedTypes)
        {
            CacheContext cacheContext = annotationCache.GetAnnotation(type);

            if (cacheContext == null)
            {
                return(null);
            }
            IMethodLevelBehavior <Attribute> cacheBehavior = CachePostProcessor.CreateInterceptorModeBehavior(type);

            CacheInterceptor interceptor = new CacheInterceptor();

            if (beanContext.IsRunning)
            {
                interceptor = beanContext.RegisterWithLifecycle(interceptor)     //
                              .PropertyValue("Behavior", cacheBehavior)          //
                              .IgnoreProperties("ProcessService", "ServiceName") //
                              .Finish();
            }
            else
            {
                beanContextFactory.RegisterWithLifecycle(interceptor) //
                .PropertyValue("Behavior", cacheBehavior)             //
                .IgnoreProperties("ProcessService", "ServiceName");
            }

            CacheType cacheType = cacheContext.CacheType;
            String    cacheProviderName;

            switch (cacheType)
            {
            case CacheType.PROTOTYPE:
            {
                cacheProviderName = CacheNamedBeans.CacheProviderPrototype;
                break;
            }

            case CacheType.SINGLETON:
            {
                cacheProviderName = CacheNamedBeans.CacheProviderSingleton;
                break;
            }

            case CacheType.THREAD_LOCAL:
            {
                cacheProviderName = CacheNamedBeans.CacheProviderThreadLocal;
                break;
            }

            case CacheType.DEFAULT:
            {
                return(interceptor);
            }

            default:
                throw new Exception("Not supported type: " + cacheType);
            }
            CacheContextInterceptor ccInterceptor = new CacheContextInterceptor();

            if (beanContext.IsRunning)
            {
                return(beanContext.RegisterWithLifecycle(ccInterceptor) //
                       .PropertyRef("CacheProvider", cacheProviderName) //
                       .PropertyValue("Target", interceptor)            //
                       .Finish());
            }
            beanContextFactory.RegisterWithLifecycle(ccInterceptor) //
            .PropertyRef("CacheProvider", cacheProviderName)        //
            .PropertyValue("Target", interceptor);
            return(ccInterceptor);
        }
예제 #6
0
        public virtual Object PostProcessBean(IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type beanType, Object targetBean, ISet <Type> requestedTypes)
        {
            if (!typeof(FrameworkElement).IsAssignableFrom(beanType))
            {
                // Handle only FrameworkElements
                return(targetBean);
            }
            if (beanType.IsAssignableFrom(typeof(UserControl)))
            {
                // Ignore all instances which are base types of UserControl
                return(targetBean);
            }

            ISet <Object> alreadyHandledBeans = factoryToAlreadyHandledNames[beanContextFactory];

            if (alreadyHandledBeans == null)
            {
                alreadyHandledBeans = new IdentityHashSet <Object>();
                factoryToAlreadyHandledNames[beanContextFactory] = alreadyHandledBeans;
            }
            if (alreadyHandledBeans.Contains(targetBean))
            {
                //Do not yet add the Bean to the list.
                return(targetBean);
            }

            FrameworkElement frameworkElement          = (FrameworkElement)targetBean;
            MethodInfo       initializeComponentMethod = beanType.GetMethod("InitializeComponent");

            if (initializeComponentMethod != null)
            {
                IServiceContext oldCurrentBeanContext = XamlBeanProvider.CurrentBeanContext;
                try
                {
                    XamlBeanProvider.CurrentBeanContext = beanContext;
                    initializeComponentMethod.Invoke(targetBean, null);
                }
                catch (Exception e)
                {
                    throw new Exception("InitializeComponent of \"" + frameworkElement.Name + "\" (" + beanType.FullName + ") failed.", e);
                }
                finally
                {
                    XamlBeanProvider.CurrentBeanContext = oldCurrentBeanContext;
                }
            }

            if (!typeof(UIElement).IsAssignableFrom(beanType))
            {
                return(targetBean);
            }

            ISet <Object> unnamedBeans = new IdentityHashSet <Object>();
            IDictionary <String, Object> namedBeans = new Dictionary <String, Object>();

            CollectChildBeans((UIElement)targetBean, unnamedBeans, namedBeans, alreadyHandledBeans);

            foreach (Object unnamedBean in unnamedBeans)
            {
                IBeanConfiguration nestedBeanConfiguration = beanContextFactory.RegisterWithLifecycle(unnamedBean);
                if (unnamedBean is ISelfRegisteringControlBean)
                {
                    ((ISelfRegisteringControlBean)unnamedBean).RegisterSelf(nestedBeanConfiguration, beanContext, beanContextFactory);
                }
            }
            foreach (KeyValuePair <String, Object> namedBean in namedBeans)
            {
                Object             currentNamedBean        = namedBean.Value;
                IBeanConfiguration nestedBeanConfiguration = beanContextFactory.RegisterWithLifecycle(namedBean.Key, currentNamedBean);
                if (currentNamedBean is ISelfRegisteringControlBean)
                {
                    ((ISelfRegisteringControlBean)currentNamedBean).RegisterSelf(nestedBeanConfiguration, beanContext, beanContextFactory);
                }
            }
            if (targetBean is ISelfRegisteringControlBean)
            {
                ((ISelfRegisteringControlBean)targetBean).RegisterSelf(beanConfiguration, beanContext, beanContextFactory);
            }
            return(targetBean);
        }
예제 #7
0
        public void AfterPropertiesSet(IBeanContextFactory beanContextFactory)
        {
            ParamChecker.AssertNotNull(ProxyFactory, "ProxyFactory");

            IBeanConfiguration serviceResultcache = beanContextFactory.RegisterBean <ServiceResultCache>().Autowireable <IServiceResultCache>();

            beanContextFactory.Link(serviceResultcache, "HandleClearAllCaches").To <IEventListenerExtendable>().With(typeof(ClearAllCachesEvent));

            beanContextFactory.RegisterBean <ValueHolderIEC>().Autowireable(typeof(ValueHolderIEC), typeof(IProxyHelper));

            beanContextFactory.RegisterBean <CacheHelper>().Autowireable(typeof(ICacheHelper), typeof(ICachePathHelper), typeof(IPrefetchHelper));

            IBeanConfiguration prioMembersProvider = beanContextFactory.RegisterBean <PrioMembersProvider>().Autowireable <IPrioMembersProvider>();

            beanContextFactory.Link(prioMembersProvider, PrioMembersProvider.handleMetaDataAddedEvent).To <IEventListenerExtendable>()
            .With(typeof(IEntityMetaDataEvent));

            beanContextFactory.RegisterBean <CacheWalker>().Autowireable <ICacheWalker>();

            beanContextFactory.RegisterAutowireableBean <ICacheMapEntryTypeProvider, CacheMapEntryTypeProvider>();

            beanContextFactory.RegisterAutowireableBean <IRootCacheValueFactory, RootCacheValueFactory>();

            //IBeanConfiguration rootCache = beanContextFactory.registerBean<RootCache>("rootCache").autowireable(typeof(RootCache), typeof(IWritableCache));
            //if (IsUseSingleChildCache)
            //{
            //    beanContextFactory.registerBean<SingletonCacheFactory>("cacheFactory")
            //        .propertyRefs("singletonChildCache")
            //        .autowireable<ICacheFactory>();

            //    IWritableCache childCache = (IWritableCache)beanContextFactory.registerBean<ChildCache>("singletonChildCache")
            //        .propertyRefs("rootCache")
            //        .autowireable(typeof(ICache)).GetInstance();

            //    ((RootCache)rootCache.GetInstance()).AddChildCache(childCache);
            //}
            //else
            //{
            //    rootCache.autowireable(typeof(ICache), typeof(IWritableCache), typeof(ICacheFactory));
            //}

            //beanContextFactory.registerBean<RootCache>(ROOT_CACHE).autowireable<RootCache>();
            //beanContextFactory.Link("rootCache").To<IOfflineListenerExtendable>();

            beanContextFactory.RegisterBean <CacheRetrieverRegistry>(ROOT_CACHE_RETRIEVER).Autowireable(typeof(ICacheServiceByNameExtendable), typeof(ICacheRetrieverExtendable));

            beanContextFactory.RegisterBean <FirstLevelCacheManager>("firstLevelCacheManager").Autowireable(typeof(IFirstLevelCacheExtendable), typeof(IFirstLevelCacheManager));

            String rootCacheBridge = "rootCacheBridge";

            beanContextFactory.RegisterBean <RootCacheBridge>(rootCacheBridge).PropertyRefs(COMMITTED_ROOT_CACHE, ROOT_CACHE_RETRIEVER);

            TransactionalRootCacheInterceptor txRcInterceptor = new TransactionalRootCacheInterceptor();

            beanContextFactory.RegisterWithLifecycle("txRootCacheInterceptor", txRcInterceptor).PropertyRefs(COMMITTED_ROOT_CACHE, rootCacheBridge)
            .Autowireable(typeof(ITransactionalRootCache), typeof(ISecondLevelCacheManager));

            Object txRcProxy = ProxyFactory.CreateProxy(new Type[] { typeof(IRootCache), typeof(ICacheIntern), typeof(IOfflineListener) }, txRcInterceptor);

            beanContextFactory.RegisterExternalBean(ROOT_CACHE, txRcProxy).Autowireable(typeof(IRootCache), typeof(ICacheIntern));

            if (IsSecondLevelCacheActive)
            {
                // One single root cache instance for whole context
                beanContextFactory.RegisterBean <RootCache>(COMMITTED_ROOT_CACHE).PropertyRef("CacheRetriever", ROOT_CACHE_RETRIEVER)
                .PropertyValue("Privileged", true);
                beanContextFactory.Link(CacheModule.COMMITTED_ROOT_CACHE).To <IOfflineListenerExtendable>();
            }
            else
            {
                // One root cache instance per thread sequence. Most often used in server environment where the "deactivated"
                // second level cache means that each thread hold his own, isolated root cache (which gets cleared with each service
                // request. Effectively this means that the root cache itself only lives per-request and does not hold a longer state
                IInterceptor threadLocalRootCacheInterceptor = (IInterceptor)beanContextFactory
                                                               .RegisterBean <ThreadLocalRootCacheInterceptor>("threadLocalRootCacheInterceptor")
                                                               .PropertyRef("StoredCacheRetriever", CacheModule.ROOT_CACHE_RETRIEVER).PropertyValue("Privileged", true).GetInstance();

                RootCache rootCacheProxy = ProxyFactory.CreateProxy <RootCache>(threadLocalRootCacheInterceptor);

                beanContextFactory.RegisterExternalBean(CacheModule.COMMITTED_ROOT_CACHE, rootCacheProxy).Autowireable <RootCache>();
            }
            beanContextFactory.RegisterBean <CacheEventTargetExtractor>("cacheEventTargetExtractor");
            beanContextFactory.Link("cacheEventTargetExtractor").To <IEventTargetExtractorExtendable>().With(typeof(ICache));

            beanContextFactory.RegisterBean <CacheFactory>().Autowireable <ICacheFactory>();

            IInterceptor cacheProviderInterceptor = (IInterceptor)beanContextFactory
                                                    .RegisterBean <CacheProviderInterceptor>("cacheProviderInterceptor")
                                                    .Autowireable(typeof(ICacheProviderExtendable), typeof(ICacheProvider), typeof(ICacheContext)).GetInstance();

            ICache cacheProxy = ProxyFactory.CreateProxy <ICache>(new Type[] { typeof(ICacheProvider), typeof(IWritableCache) }, cacheProviderInterceptor);

            beanContextFactory.RegisterExternalBean("cache", cacheProxy).Autowireable <ICache>();

            beanContextFactory.RegisterBean <PagingQueryServiceResultProcessor>("pagingQuerySRP");
            beanContextFactory.Link("pagingQuerySRP").To <IServiceResultProcessorExtendable>().With(typeof(IPagingResponse));

            beanContextFactory.RegisterBean <CacheProvider>(CacheNamedBeans.CacheProviderSingleton).PropertyValue("CacheType", CacheType.SINGLETON);

            beanContextFactory.RegisterBean <CacheProvider>(CacheNamedBeans.CacheProviderThreadLocal).PropertyValue("CacheType", CacheType.THREAD_LOCAL);

            beanContextFactory.RegisterBean <CacheProvider>(CacheNamedBeans.CacheProviderPrototype).PropertyValue("CacheType", CacheType.PROTOTYPE);

            String defaultCacheProviderBeanName;

            switch (DefaultCacheType)
            {
            case CacheType.PROTOTYPE:
            {
                defaultCacheProviderBeanName = CacheNamedBeans.CacheProviderPrototype;
                break;
            }

            case CacheType.SINGLETON:
            {
                defaultCacheProviderBeanName = CacheNamedBeans.CacheProviderSingleton;
                break;
            }

            case CacheType.THREAD_LOCAL:
            {
                defaultCacheProviderBeanName = CacheNamedBeans.CacheProviderThreadLocal;
                break;
            }

            case CacheType.DEFAULT:
            {
                defaultCacheProviderBeanName = CacheNamedBeans.CacheProviderThreadLocal;
                break;
            }

            default:
                throw new Exception("Not supported type: " + DefaultCacheType);
            }
            beanContextFactory.Link(defaultCacheProviderBeanName).To <ICacheProviderExtendable>();

            // CacheContextPostProcessor must be registered AFTER CachePostProcessor...
            Object cachePostProcessor = beanContextFactory.RegisterBean <CachePostProcessor>().GetInstance();

            beanContextFactory.RegisterBean <CacheContextPostProcessor>().PropertyValue("CachePostProcessor", cachePostProcessor);

            if (IsNetworkClientMode && IsCacheServiceBeanActive)
            {
                IBeanConfiguration remoteCacheService = beanContextFactory.RegisterBean <ClientServiceBean>(CacheModule.EXTERNAL_CACHE_SERVICE)
                                                        .PropertyValue("Interface", typeof(ICacheService))
                                                        .PropertyValue("SyncRemoteInterface", typeof(ICacheServiceWCF))
                                                        .PropertyValue("AsyncRemoteInterface", typeof(ICacheClient)).Autowireable <ICacheService>();

                beanContextFactory.RegisterAlias(CacheModule.DEFAULT_CACHE_RETRIEVER, CacheModule.EXTERNAL_CACHE_SERVICE);

                // register to all entities in a "most-weak" manner
                beanContextFactory.Link(remoteCacheService).To <ICacheRetrieverExtendable>().With(typeof(Object));
                //beanContextFactory.RegisterAlias(CacheModule.ROOT_CACHE_RETRIEVER, CacheModule.EXTERNAL_CACHE_SERVICE);
                //beanContextFactory.registerBean<CacheServiceDelegate>("cacheService").autowireable<ICacheService>();
            }
            beanContextFactory.RegisterBean <DataObjectMixin>().Autowireable <DataObjectMixin>();
            beanContextFactory.RegisterBean <EntityEqualsMixin>().Autowireable <EntityEqualsMixin>();
            beanContextFactory.RegisterBean <EmbeddedTypeMixin>().Autowireable <EmbeddedTypeMixin>();
            beanContextFactory.RegisterBean <PropertyChangeMixin>().Autowireable(typeof(PropertyChangeMixin),
                                                                                 typeof(IPropertyChangeExtensionExtendable), typeof(ICollectionChangeExtensionExtendable));
            beanContextFactory.RegisterBean <ValueHolderContainerMixin>().Autowireable <ValueHolderContainerMixin>();
        }