public static IMethodLevelBehavior <T> Create <A>(Type beanType, AnnotationCache <A> annotationCache, Type behaviourType, IBehaviorTypeExtractor <A, T> behaviourTypeExtractor, IBeanContextFactory beanContextFactory, IServiceContext beanContext) where A : Attribute { BehaviorKey key = new BehaviorKey(beanType, behaviourType); IMethodLevelBehavior <T> behavior = (IMethodLevelBehavior <T>)beanTypeToBehavior.Get(key); if (behavior != null) { if (behavior == noBehavior) { return(null); } return(behavior); } A annotation = annotationCache.GetAnnotation(beanType); if (annotation == null) { beanTypeToBehavior.Put(key, noBehavior); return(null); } T defaultBehaviour = behaviourTypeExtractor.ExtractBehaviorType(annotation); MethodLevelHashMap <T> methodLevelBehaviour = null; MethodInfo[] methods = ReflectUtil.GetMethods(beanType); for (int a = methods.Length; a-- > 0;) { MethodInfo method = methods[a]; A annotationOnMethod = annotationCache.GetAnnotation(method); if (annotationOnMethod != null) { if (methodLevelBehaviour == null) { methodLevelBehaviour = new MethodLevelHashMap <T>(); } T behaviourTypeOnMethod = behaviourTypeExtractor.ExtractBehaviorType(annotationOnMethod); if (behaviourTypeOnMethod != null) { methodLevelBehaviour.Put(method, behaviourTypeOnMethod); } } } if (methodLevelBehaviour == null) { methodLevelBehaviour = new MethodLevelHashMap <T>(0); } behavior = new MethodLevelBehavior <T>(defaultBehaviour, methodLevelBehaviour); beanTypeToBehavior.Put(key, behavior); return(behavior); }
protected PropertyEntry GetPropertyEntry(Type type, IPropertyInfo property) { PropertyEntry entry = propertyToEntryMap.Get(property); if (entry == null) { entry = new PropertyEntry(type, property.Name); propertyToEntryMap.Put(property, entry); } return(entry); }
public ValueHolderContainerEntry GetVhcEntry(Type targetType) { ValueHolderContainerEntry vhcEntry = typeToVhcEntryMap.Get(targetType); if (vhcEntry == null) { IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(targetType); vhcEntry = new ValueHolderContainerEntry(targetType, metaData.RelationMembers, BytecodeEnhancer, PropertyInfoProvider, MemberTypeProvider); typeToVhcEntryMap.Put(targetType, vhcEntry); } return(vhcEntry); }
public static MemberCallDelegate GetMemberCallDelegate(Type type, String memberName, bool tryOnly = false) { GetDelegateKey key = new GetDelegateKey(type, memberName); MemberCallDelegate value = _memberCallDelegates.Get(key); if (value != null) { return(value); } MemberCallDelegate delegates = GetMemberCallDelegateIntern(type, memberName, tryOnly); if (delegates == null) { return(null); } _memberCallDelegates.Put(key, delegates); return(delegates); }
protected EntityFactoryConstructor GetConstructorEntry(Type entityType) { EntityFactoryConstructor constructor = typeToConstructorMap.Get(entityType); if (constructor == null) { try { EntityFactoryWithArgumentConstructor argumentConstructor = AccessorTypeProvider.GetConstructorType <EntityFactoryWithArgumentConstructor>(entityType); constructor = new EntityFactoryToArgumentConstructor(argumentConstructor, Self); } catch (Exception) { constructor = AccessorTypeProvider.GetConstructorType <EntityFactoryConstructor>(entityType); } typeToConstructorMap.Put(entityType, constructor); } return(constructor); }
protected ConstructorInfo GetEmbeddedParamConstructor(Type embeddedType, Type parentObjectType) { ConstructorInfo constructor = typeToEmbbeddedParamConstructorMap.Get(embeddedType); if (constructor == null) { try { constructor = embeddedType.GetConstructor(new Type[] { parentObjectType }); } catch (Exception e) { if (BytecodePrinter != null) { throw RuntimeExceptionUtil.Mask(e, BytecodePrinter.ToPrintableBytecode(embeddedType)); } throw; } typeToEmbbeddedParamConstructorMap.Put(embeddedType, constructor); } return(constructor); }
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); } }