public virtual Object PostProcessBean(IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type beanType, Object targetBean, ISet <Type> requestedTypes) { if (!beanType.IsGenericType) { return(targetBean); } // ViewModelDataChangeController has exactly 1 generic argument Type genericTypeArgument = beanType.GetGenericArguments()[0]; // Instantiate TYPE to generic argument of given bean type if (!dataChangeControllerType.MakeGenericType(genericTypeArgument).IsAssignableFrom(beanType)) { return(targetBean); } Type[] arguments = beanType.GetGenericArguments(); Object eventListener = TypeFilteredDataChangeListener.CreateEventListener((IDataChangeListener)targetBean, arguments[0]); String eventListenerBeanName = beanConfiguration.GetName() + ".eventListener"; beanContextFactory.RegisterExternalBean(eventListenerBeanName, eventListener); if (beanContext.IsRunning) { beanContext.Link(eventListenerBeanName).To <IEventListenerExtendable>().With(typeof(IDataChange)); } else { beanContextFactory.Link(eventListenerBeanName).To <IEventListenerExtendable>().With(typeof(IDataChange)); } return(targetBean); }
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); } }
public void Link(IBeanConfiguration listenerBean, Type autowiredRegistryClass, params Object[] arguments) { ParamChecker.AssertParamNotNull(listenerBean, "listenerBean"); String listenerBeanName = listenerBean.GetName(); ParamChecker.AssertParamNotNull(listenerBeanName, "listenerBean.getName()"); IBeanConfiguration beanConfiguration = createLinkConfiguration(listenerBeanName, autowiredRegistryClass, arguments); AddBeanConfiguration(beanConfiguration); }
public Object PostProcessBean(IBeanContextFactory beanContextFactory, IServiceContext beanContext, IBeanConfiguration beanConfiguration, Type beanType, Object targetBean, ISet <Type> requestedTypes) { IProxyTargetAccessor factory = null; ICascadedInterceptor cascadedInterceptor = null; Object proxiedTargetBean = targetBean; if (targetBean is IProxyTargetAccessor) { factory = (IProxyTargetAccessor)targetBean; IInterceptor[] interceptors = factory.GetInterceptors(); IInterceptor callback = (interceptors != null && interceptors.Length > 0 ? interceptors[0] : null); if (callback is ICascadedInterceptor) { cascadedInterceptor = (ICascadedInterceptor)callback; proxiedTargetBean = cascadedInterceptor.Target; } } ICascadedInterceptor interceptor = HandleServiceIntern(beanContextFactory, beanContext, beanConfiguration, proxiedTargetBean.GetType(), requestedTypes); if (interceptor == null) { return(targetBean); } if (log.DebugEnabled) { log.Debug("Proxying bean with name '" + beanConfiguration.GetName() + "' by " + GetType().FullName); } Object target; if (cascadedInterceptor != null) { target = cascadedInterceptor; } else { target = proxiedTargetBean; } interceptor.Target = target; Object proxy = ProxyFactory.CreateProxy(requestedTypes.ToArray(), interceptor); postHandleServiceIntern(beanContextFactory, beanContext, beanConfiguration, proxiedTargetBean.GetType(), requestedTypes, proxy); return(proxy); }
protected void AddBeanConfiguration(IBeanConfiguration beanConfiguration) { String beanName = beanConfiguration.GetName(); if (beanName != null && beanName.Length > 0) { if (nameToBeanConfMap == null) { nameToBeanConfMap = new HashMap <String, IBeanConfiguration>(); } if (aliasToBeanNameMap != null && aliasToBeanNameMap.ContainsKey(beanName)) { throw new Exception("An alias with the name '" + beanName + "' of this bean is already registered in this context"); } if (!beanConfiguration.IsOverridesExisting()) { if (!nameToBeanConfMap.PutIfNotExists(beanName, beanConfiguration)) { IBeanConfiguration existingBeanConfiguration = nameToBeanConfMap.Get(beanName); if (!existingBeanConfiguration.IsOverridesExisting()) { throw ServiceContext.CreateDuplicateBeanNameException(beanName, beanConfiguration, existingBeanConfiguration); } // Existing config requests precedence over every other bean config. This is no error return; } } else { // Intentionally put the configuration in the map unaware of an existing entry nameToBeanConfMap.Put(beanName, beanConfiguration); } } if (beanConfigurations == null) { beanConfigurations = new List <IBeanConfiguration>(); } beanConfigurations.Add(beanConfiguration); }
public override String GetBeanName() { return(embeddedBean.GetName()); }