Exemplo n.º 1
0
        protected ForkStateEntry[] GetForkStateEntries()
        {
            ForkStateEntry[] cachedForkStateEntries = this.cachedForkStateEntries;
            if (cachedForkStateEntries != null)
            {
                return(cachedForkStateEntries);
            }
            Lock writeLock = listeners.GetWriteLock();

            writeLock.Lock();
            try
            {
                // check again: concurrent thread might have been faster
                cachedForkStateEntries = this.cachedForkStateEntries;
                if (cachedForkStateEntries != null)
                {
                    return(cachedForkStateEntries);
                }
                IThreadLocalCleanupBean[] extensions       = listeners.GetExtensions();
                List <ForkStateEntry>     forkStateEntries = new List <ForkStateEntry>(extensions.Length);
                for (int a = 0, size = extensions.Length; a < size; a++)
                {
                    IThreadLocalCleanupBean extension = extensions[a];
                    FieldInfo[]             fields    = ReflectUtil.GetDeclaredFieldsInHierarchy(extension.GetType());
                    foreach (FieldInfo field in fields)
                    {
                        Forkable forkable = AnnotationUtil.GetAnnotation <Forkable>(field, false);
                        if (forkable == null)
                        {
                            continue;
                        }
                        Object valueTL = field.GetValue(extension);
                        if (valueTL == null)
                        {
                            continue;
                        }
                        Type           forkProcessorType = forkable.Processor;
                        IForkProcessor forkProcessor     = null;
                        if (forkProcessorType != null && !typeof(IForkProcessor).Equals(forkProcessorType))
                        {
                            WeakReference   beanContextOfExtensionR = extensionToContextMap.Get(extension);
                            IServiceContext beanContextOfExtension  = beanContextOfExtensionR != null ? (IServiceContext)beanContextOfExtensionR.Target : null;
                            if (beanContextOfExtension == null)
                            {
                                beanContextOfExtension = BeanContext;
                            }
                            forkProcessor = beanContextOfExtension.RegisterBean <IForkProcessor>(forkProcessorType).Finish();
                        }
                        forkStateEntries.Add(new ForkStateEntry(extension, field.Name, valueTL, forkable.Value, forkProcessor));
                    }
                }
                cachedForkStateEntries      = forkStateEntries.ToArray();
                this.cachedForkStateEntries = cachedForkStateEntries;
                return(cachedForkStateEntries);
            }
            finally
            {
                writeLock.Unlock();
            }
        }
Exemplo n.º 2
0
        protected override Attribute LookForAnnotation(MemberInfo method)
        {
            Attribute annotation = base.LookForAnnotation(method);

            if (annotation != null)
            {
                return(annotation);
            }
            NoProxyAttribute noProxy = AnnotationUtil.GetAnnotation <NoProxyAttribute>(method, false);

            if (noProxy != null)
            {
                return(noProxy);
            }
            ProcessAttribute process = AnnotationUtil.GetAnnotation <ProcessAttribute>(method, false);

            if (process != null)
            {
                return(process);
            }
            FindAttribute find = AnnotationUtil.GetAnnotation <FindAttribute>(method, false);

            if (find != null)
            {
                return(find);
            }
            MergeAttribute merge = AnnotationUtil.GetAnnotation <MergeAttribute>(method, false);

            if (merge != null)
            {
                return(merge);
            }
            return(AnnotationUtil.GetAnnotation <RemoveAttribute>(method, false));
        }
Exemplo n.º 3
0
        public String GetPropertyNameFor(MethodInfo method)
        {
            PropertyAccessor propertyAccessor = AnnotationUtil.GetAnnotation <PropertyAccessor>(method, true);

            if (propertyAccessor != null)
            {
                return(propertyAccessor.PropertyName);
            }
            Match matcher = getSetIsPattern.Match(method.Name);

            if (!matcher.Success)
            {
                return("");
            }
            int    paramLength = method.GetParameters().Length;
            String getSetIs    = matcher.Groups[1].Value;

            if (("get_".Equals(getSetIs) || "Get".Equals(getSetIs) || "get".Equals(getSetIs)) && (0 != paramLength || typeof(void).Equals(method.ReturnType)))
            {
                return("");
            }
            else if (("set_".Equals(getSetIs) || "Set".Equals(getSetIs) || "set".Equals(getSetIs)) && 1 != paramLength)
            {
                return("");
            }
            else if (("Is".Equals(getSetIs) || "is".Equals(getSetIs)) && (0 != paramLength || typeof(void).Equals(method.ReturnType)))
            {
                return("");
            }
            String name = matcher.Groups[2].Value;

            return(StringConversionHelper.UpperCaseFirst(name));
        }
Exemplo n.º 4
0
 protected void FillMethodsAnnotatedWith(Type type, IList <MethodInfo> methods, params Type[] annotations)
 {
     if (type == null || typeof(Object).Equals(type))
     {
         return;
     }
     FillMethodsAnnotatedWith(type.BaseType, methods, annotations);
     MethodInfo[] allMethodsOfThisType = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic);
     for (int a = 0, size = allMethodsOfThisType.Length; a < size; a++)
     {
         MethodInfo currentMethod = allMethodsOfThisType[a];
         for (int b = annotations.Length; b-- > 0;)
         {
             if (AnnotationUtil.GetAnnotation(annotations[b], currentMethod, false) == null)
             {
                 continue;
             }
             if (currentMethod.GetParameters().Length != 0)
             {
                 throw new Exception("It is not allowed to annotated methods without " + annotations[b].FullName + " having 0 arguments: "
                                     + currentMethod.ToString());
             }
             methods.Add(currentMethod);
         }
     }
 }
Exemplo n.º 5
0
 protected Object Intercept(IInvocation invocation, String methodName, Attribute annotation, Boolean?isAsyncBegin)
 {
     if (AnnotationUtil.GetAnnotation <ProcessAttribute>(invocation.Method, false) != null)
     {
         return(InterceptApplication(invocation, annotation, isAsyncBegin));
     }
     if (AnnotationUtil.GetAnnotation <MergeAttribute>(invocation.Method, false) != null ||
         methodName.StartsWith("update") ||
         methodName.StartsWith("save") ||
         methodName.StartsWith("merge") ||
         methodName.StartsWith("insert"))
     {
         return(InterceptMerge(invocation, annotation, isAsyncBegin));
     }
     if (AnnotationUtil.GetAnnotation <RemoveAttribute>(invocation.Method, false) != null ||
         methodName.StartsWith("delete") ||
         methodName.StartsWith("remove"))
     {
         return(InterceptDelete(invocation, annotation, isAsyncBegin));
     }
     if (AnnotationUtil.GetAnnotation <FindAttribute>(invocation.Method, false) != null ||
         methodName.StartsWith("retrieve") ||
         methodName.StartsWith("read") ||
         methodName.StartsWith("find") ||
         methodName.StartsWith("get"))
     {
         return(InterceptLoad(invocation, annotation, isAsyncBegin));
     }
     if (methodName.Equals("close") || methodName.Equals("abort"))
     {
         // Intended blank
     }
     return(InterceptApplication(invocation, annotation, isAsyncBegin));
 }
Exemplo n.º 6
0
        protected override Attribute LookForAnnotation(MemberInfo method)
        {
            Attribute annotation = base.LookForAnnotation(method);

            if (annotation != null)
            {
                return(annotation);
            }
            return(AnnotationUtil.GetAnnotation <CachedAttribute>(method, false));
        }
Exemplo n.º 7
0
        public void PutAnnotations(ICustomAttributeProvider obj)
        {
            if (obj is MethodInfo)
            {
                MethodInfo m          = (MethodInfo)obj;
                Type[]     parameters = new Type[m.GetParameters().Length];
                for (int a = m.GetParameters().Length; a-- > 0;)
                {
                    parameters[a] = m.GetParameters()[a].ParameterType;
                }
                Type       baseType         = m.DeclaringType.BaseType;
                MethodInfo overriddenMethod = baseType != null?ReflectUtil.GetDeclaredMethod(true, baseType, m.ReturnType, m.Name, parameters) : null;

                if (overriddenMethod != null)
                {
                    PutAnnotations(overriddenMethod);
                }
            }
            Object[] annotations = obj.GetCustomAttributes(true);
            foreach (Object anno in annotations)
            {
                Attribute annotation = (Attribute)anno;
                AttributeUsageAttribute attributeUsage = AnnotationUtil.GetAnnotation <AttributeUsageAttribute>(annotation.GetType(), true);
                Type type = annotation.GetType();
                if (this.annotations == null)
                {
                    this.annotations = new LinkedHashMap <Type, Attribute[]>();
                }
                Attribute[] existingAttributes = this.annotations.Get(type);
                if (existingAttributes == null)
                {
                    existingAttributes = new Attribute[0];
                }
                Attribute[] newAttributes = new Attribute[existingAttributes.Length + 1];
                Array.Copy(existingAttributes, newAttributes, existingAttributes.Length);
                newAttributes[existingAttributes.Length] = annotation;
                this.annotations.Put(type, newAttributes);
            }
        }
Exemplo n.º 8
0
        public virtual void AfterPropertiesSet()
        {
            if (ClasspathScanner == null)
            {
                if (Log.InfoEnabled)
                {
                    Log.Info("Skipped scanning for XML transfer types. Reason: No instance of " + typeof(IClasspathScanner).FullName + " resolved");
                }
                return;
            }
            IList <Type> rootElementClasses = ClasspathScanner.ScanClassesAnnotatedWith(typeof(DataContractAttribute), typeof(System.Xml.Serialization.XmlTypeAttribute), typeof(XmlTypeAttribute));

            if (Log.InfoEnabled)
            {
                Log.Info("Found " + rootElementClasses.Count + " classes annotated as XML transfer types");
            }
            if (Log.DebugEnabled)
            {
                List <Type> sorted = new List <Type>(rootElementClasses);
                sorted.Sort(delegate(Type left, Type right)
                {
                    return(left.FullName.CompareTo(right.FullName));
                });
                for (int a = 0, size = sorted.Count; a < size; a++)
                {
                    Log.Debug("Xml entity found: " + sorted[a].Namespace + "." + sorted[a].Name);
                }
            }
            for (int a = rootElementClasses.Count; a-- > 0;)
            {
                Type   rootElementClass = rootElementClasses[a];
                String name;
                String namespaceString;

                XmlTypeAttribute genericXmlType = AnnotationUtil.GetAnnotation <XmlTypeAttribute>(rootElementClass, false);
                if (genericXmlType != null)
                {
                    name            = genericXmlType.Name;
                    namespaceString = genericXmlType.Namespace;
                }
                else
                {
                    DataContractAttribute dataContract = AnnotationUtil.GetAnnotation <DataContractAttribute>(rootElementClass, false);
                    if (dataContract != null)
                    {
                        name            = dataContract.Name;
                        namespaceString = dataContract.Namespace;
                    }
                    else
                    {
                        System.Xml.Serialization.XmlTypeAttribute xmlTypeAttribute = AnnotationUtil.GetAnnotation <System.Xml.Serialization.XmlTypeAttribute>(rootElementClass, false);
                        name            = xmlTypeAttribute.TypeName;
                        namespaceString = xmlTypeAttribute.Namespace;
                    }
                }
                if (DefaultNamespace.Equals(namespaceString))
                {
                    namespaceString = null;
                }
                if (name == null)
                {
                    name = rootElementClass.Name;
                }
                XmlTypeExtendable.RegisterXmlType(rootElementClass, name, namespaceString);
                unregisterRunnables.Add(delegate()
                {
                    XmlTypeExtendable.UnregisterXmlType(rootElementClass, name, namespaceString);
                });
            }
            this.rootElementClasses = rootElementClasses;
        }