예제 #1
0
 public static void HandleTypesFromCurrentDomainWithAnnotation <T>(TypeHandleDelegate typeHandleDelegate) where T : Attribute
 {
     foreach (Type type in typesFromCurrentDomain)
     {
         if (!AnnotationUtil.IsAnnotationPresent <T>(type, true))
         {
             continue;
         }
         typeHandleDelegate(type);
     }
 }
예제 #2
0
 protected bool IsAnnotationPresentIntern <V>(Type type) where V : Attribute
 {
     if (type == null)
     {
         return(false);
     }
     if (AnnotationUtil.IsAnnotationPresent <V>(type, false))
     {
         return(true);
     }
     return(IsAnnotationPresentIntern <V>(type.BaseType));
 }
예제 #3
0
 public virtual bool IsEntityType(Type type)
 {
     if (type == null || type.IsPrimitive || type.IsEnum || primitiveTypes.Contains(type) || noEntityTypeExtendables.GetExtension(type))
     {
         return(false);
     }
     if (AnnotationUtil.IsAnnotationPresent <Embeddable>(type, false) || typeof(IImmutableType).IsAssignableFrom(type))
     {
         return(false);
     }
     return(true);
 }
예제 #4
0
        protected override Object InterceptApplication(IInvocation invocation, Attribute annotation, Boolean?isAsyncBegin)
        {
            bool oldProcessServiceActive = processServiceActiveTL.Value;

            if (oldProcessServiceActive || ProcessService == null || !AnnotationUtil.IsAnnotationPresent <ServiceClientAttribute>(invocation.Method.DeclaringType, false))
            {
                return(base.InterceptApplication(invocation, annotation, isAsyncBegin));
            }
            ISecurityScope[]    securityScopes     = SecurityScopeProvider.SecurityScopes;
            IServiceDescription serviceDescription = SyncToAsyncUtil.CreateServiceDescription(ServiceName, invocation.Method, invocation.Arguments, securityScopes);

            processServiceActiveTL.Value = true;
            try
            {
                return(ProcessService.InvokeService(serviceDescription));
            }
            finally
            {
                processServiceActiveTL.Value = oldProcessServiceActive;
            }
        }
예제 #5
0
        protected override Statement MethodBlock(MethodInfo method)
        {
            Statement statement = base.MethodBlock(method);

            return(new Statement(delegate()
            {
                if (!hasContextBeenRebuildForThisTest)
                {
                    if (method == null || !AnnotationUtil.IsAnnotationPresent <IgnoreAttribute>(method, false))
                    {
                        IList <IAnnotationInfo <TestRebuildContext> > rebuildContextList = FindAnnotations <TestRebuildContext>(testClass);
                        if (rebuildContextList.Count > 0)
                        {
                            bool rebuildContext = ((TestRebuildContext)rebuildContextList[rebuildContextList.Count - 1].Annotation).Value;
                            if (rebuildContext)
                            {
                                RebuildContext(method);
                                hasContextBeenRebuildForThisTest = true;
                                isRebuildContextForThisTestRecommended = false;
                            }
                        }
                        if (method != null)
                        {
                            if (AnnotationUtil.IsAnnotationPresent <TestModule>(method, false) || AnnotationUtil.IsAnnotationPresent <TestFrameworkModule>(method, false) ||
                                AnnotationUtil.IsAnnotationPresent <TestProperties>(method, false))
                            {
                                RebuildContext(method);
                                hasContextBeenRebuildForThisTest = true;
                                isRebuildContextForThisTestRecommended = false;
                            }
                        }
                    }
                }
                if (beanContext == null || isRebuildContextForThisTestRecommended)
                {
                    RebuildContext(method);
                }
                statement();
            }));
        }
예제 #6
0
        protected Type[] GetModules(bool scanForFrameworkModule)
        {
            if (log.InfoEnabled)
            {
                log.Info("Looking for " + (scanForFrameworkModule ? "Ambeth" : "Application") + " bootstrap modules in classpath...");
            }
            IList <Type> bootstrapOrFrameworkModules = ClasspathScanner.ScanClassesAnnotatedWith(scanForFrameworkModule ? typeof(FrameworkModuleAttribute)
                                    : typeof(BootstrapModuleAttribute));

            List <Type> bootstrapModules = new List <Type>(bootstrapOrFrameworkModules.Count);

            foreach (Type bootstrapOrFrameworkModule in bootstrapOrFrameworkModules)
            {
                if (scanForFrameworkModule && AnnotationUtil.IsAnnotationPresent <FrameworkModuleAttribute>(bootstrapOrFrameworkModule, false))
                {
                    bootstrapModules.Add(bootstrapOrFrameworkModule);
                }
                else if (AnnotationUtil.IsAnnotationPresent <BootstrapModuleAttribute>(bootstrapOrFrameworkModule, false) &&
                         !AnnotationUtil.IsAnnotationPresent <FrameworkModuleAttribute>(bootstrapOrFrameworkModule, false))
                {
                    bootstrapModules.Add(bootstrapOrFrameworkModule);
                }
            }
            if (log.InfoEnabled)
            {
                log.Info("Found " + bootstrapModules.Count + (scanForFrameworkModule ? " Ambeth" : " Application")
                         + " modules in classpath to include in bootstrap...");
                bootstrapModules.Sort(delegate(Type o1, Type o2)
                {
                    return(o1.FullName.CompareTo(o2.FullName));
                });
                for (int a = 0, size = bootstrapModules.Count; a < size; a++)
                {
                    Type boostrapModule = bootstrapModules[a];
                    log.Info("Including " + boostrapModule.FullName);
                }
            }
            return(bootstrapModules.ToArray());
        }
예제 #7
0
            public PropertyEntry(Type type, String propertyName)
            {
                this.propertyName = propertyName;
                LinkedHashSet <String> propertyNames = new LinkedHashSet <String>();

                propertyNames.Add(propertyName);
                PropertyInfo prop = type.GetProperty(propertyName);

                doesModifyToBeUpdated        = !AnnotationUtil.IsAnnotationPresent <IgnoreToBeUpdated>(prop, false);
                isParentChildSetter          = AnnotationUtil.IsAnnotationPresent <ParentChild>(prop, false);
                isAddedRemovedCheckNecessary = !prop.PropertyType.IsPrimitive && ImmutableTypeSet.GetUnwrappedType(prop.PropertyType) == null &&
                                               !typeof(String).Equals(prop.PropertyType) && !prop.PropertyType.IsValueType;

                EvaluateDependentProperties(type, prop, propertyNames);

                while (true)
                {
                    int startCount = propertyNames.Count;

                    foreach (String currPropertyName in new List <String>(propertyNames))
                    {
                        PropertyInfo currProp = type.GetProperty(currPropertyName);
                        if (currProp.CanWrite)
                        {
                            continue;
                        }
                        // Is is just an evaluating property which has to be re-evaluated because of the change on the current property
                        EvaluateDependentProperties(type, currProp, propertyNames);
                    }
                    if (startCount == propertyNames.Count)
                    {
                        break;
                    }
                }
                this.propertyNames = propertyNames.ToArray();
                bool firesToBeCreatedPCE = false;

                unknownValues = CreateArrayOfValues(UNKNOWN_VALUE, this.propertyNames.Length);
                pceArgs       = new PropertyChangedEventArgs[propertyNames.Count];
                int index = 0;

                foreach (String invokedPropertyName in propertyNames)
                {
                    pceArgs[index] = new PropertyChangedEventArgs(invokedPropertyName);
                    index++;
                    firesToBeCreatedPCE |= "ToBeCreated".Equals(invokedPropertyName);
                }
                this.firesToBeCreatedPCE = firesToBeCreatedPCE;
                if (prop.CanRead)
                {
                    getDelegate = TypeUtility.GetMemberGetDelegate(type, ValueHolderIEC.GetGetterNameOfRelationPropertyWithNoInit(prop.Name), true);
                    if (getDelegate == null)
                    {
                        getDelegate = TypeUtility.GetMemberGetDelegate(type, prop.Name);
                    }
                }
                if (prop.CanWrite)
                {
                    setDelegate = TypeUtility.GetMemberSetDelegate(type, ValueHolderIEC.GetSetterNameOfRelationPropertyWithNoInit(prop.Name), true);
                    if (setDelegate == null)
                    {
                        setDelegate = TypeUtility.GetMemberSetDelegate(type, prop.Name);
                    }
                }
            }
예제 #8
0
        protected PropertyInfoEntry GetPropertyEntry(Type type, SmartCopyMap <Type, PropertyInfoEntry> map, bool isOldIocMode, bool isIocMode)
        {
            ParamChecker.AssertParamNotNull(type, "type");
            PropertyInfoEntry propertyEntry = map.Get(type);

            if (propertyEntry != null)
            {
                return(propertyEntry);
            }
            Object writeLock = map.GetWriteLock();

            lock (writeLock)
            {
                propertyEntry = map.Get(type);
                if (propertyEntry != null)
                {
                    // Concurrent thread might have been faster
                    return(propertyEntry);
                }

                HashMap <String, HashMap <Type, HashMap <String, MethodInfo> > > sortedMethods = new HashMap <String, HashMap <Type, HashMap <String, MethodInfo> > >();
                MethodInfo[] methods = ReflectUtil.GetDeclaredMethodsInHierarchy(type);

                foreach (MethodInfo method in methods)
                {
                    if (method.DeclaringType.Equals(typeof(Object)))
                    {
                        continue;
                    }
                    if (method.IsStatic)
                    {
                        continue;
                    }
                    try
                    {
                        String propName = GetPropertyNameFor(method);
                        if (propName.Length == 0)
                        {
                            continue;
                        }
                        HashMap <Type, HashMap <String, MethodInfo> > sortedMethod = sortedMethods.Get(propName);
                        if (sortedMethod == null)
                        {
                            sortedMethod = HashMap <Type, HashMap <String, MethodInfo> > .Create(1);

                            sortedMethods.Put(propName, sortedMethod);
                        }

                        ParameterInfo[] parameterInfos = method.GetParameters();
                        Type            propertyType;
                        String          prefix;
                        if (parameterInfos.Length == 1)
                        {
                            propertyType = parameterInfos[0].ParameterType;
                            prefix       = "set";
                        }
                        else if (parameterInfos.Length == 0)
                        {
                            propertyType = method.ReturnType;
                            prefix       = "get";
                        }
                        else
                        {
                            throw new Exception("Method is not an accessor: " + method);
                        }

                        HashMap <String, MethodInfo> methodPerType = sortedMethod.Get(propertyType);
                        if (methodPerType == null)
                        {
                            methodPerType = HashMap <String, MethodInfo> .Create(2);

                            sortedMethod.Put(propertyType, methodPerType);
                        }

                        methodPerType.Put(prefix, method);
                    }
                    catch (Exception e)
                    {
                        throw RuntimeExceptionUtil.Mask(e, "Error occured while processing " + method);
                    }
                }

                HashMap <String, HashMap <String, MethodInfo> > filteredMethods = FilterOverriddenMethods(sortedMethods, type);

                HashMap <String, IPropertyInfo> propertyMap = new HashMap <String, IPropertyInfo>(0.5f);
                foreach (MapEntry <String, HashMap <String, MethodInfo> > propertyData in filteredMethods)
                {
                    String propertyName = propertyData.Key;

                    HashMap <String, MethodInfo> propertyMethods = propertyData.Value;
                    MethodInfo getter = propertyMethods.Get("get");
                    MethodInfo setter = propertyMethods.Get("set");

                    if (isIocMode)
                    {
                        if (setter == null ||
                            (!setter.IsPublic && !AnnotationUtil.IsAnnotationPresent <AutowiredAttribute>(setter, false) &&
                             !AnnotationUtil.IsAnnotationPresent <PropertyAttribute>(setter, false)))
                        {
                            continue;
                        }
                    }
                    MethodPropertyInfo propertyInfo = new MethodPropertyInfo(type, propertyName, getter, setter);
                    propertyMap.Put(propertyInfo.Name, propertyInfo);
                }

                Type[]      interfaces    = type.GetInterfaces();
                List <Type> typesToSearch = new List <Type>(interfaces);
                typesToSearch.Add(type);
                foreach (Type typeToSearch in typesToSearch)
                {
                    PropertyInfo[] properties = typeToSearch.GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Static | BindingFlags.Instance | BindingFlags.Public);
                    foreach (PropertyInfo property in properties)
                    {
                        if (property.GetGetMethod() != null && property.GetGetMethod().GetParameters().Length != 0)
                        {
                            continue;
                        }
                        if (property.GetSetMethod() != null && property.GetSetMethod().GetParameters().Length != 1)
                        {
                            continue;
                        }
                        MethodInfo getter = null;
                        MethodInfo setter = null;

                        MethodPropertyInfo propertyInfo = (MethodPropertyInfo)propertyMap.Get(property.Name);
                        if (propertyInfo != null)
                        {
                            getter = propertyInfo.Getter;
                            setter = propertyInfo.Setter;
                        }
                        if (getter == null)
                        {
                            getter = property.GetGetMethod();
                        }
                        if (setter == null)
                        {
                            setter = property.GetSetMethod();
                        }
                        if (isIocMode && setter == null)
                        {
                            continue;
                        }
                        propertyInfo = new MethodPropertyInfo(type, property.Name, getter, setter);
                        propertyInfo.PutAnnotations(property);
                        propertyMap.Put(propertyInfo.Name, propertyInfo);
                    }
                }

                FieldInfo[] fields = ReflectUtil.GetDeclaredFieldsInHierarchy(type);
                foreach (FieldInfo field in fields)
                {
                    if (field.IsStatic)
                    {
                        continue;
                    }
                    if (isOldIocMode)
                    {
                        if (!AnnotationUtil.IsAnnotationPresent <AutowiredAttribute>(field, false) && !AnnotationUtil.IsAnnotationPresent <PropertyAttribute>(field, false))
                        {
                            continue;
                        }
                    }
                    String        propertyName     = GetPropertyNameFor(field);
                    IPropertyInfo existingProperty = propertyMap.Get(propertyName);
                    if (existingProperty != null && existingProperty.IsWritable)
                    {
                        // Ignore field injection if the already resolved (method-)property is writable
                        continue;
                    }
                    IPropertyInfo propertyInfo = new FieldPropertyInfo(type, propertyName, field);
                    propertyMap.Put(propertyInfo.Name, propertyInfo);
                }
                propertyEntry = new PropertyInfoEntry(propertyMap);
                map.Put(type, propertyEntry);
                return(propertyEntry);
            }
        }