コード例 #1
0
        private KeyedFastPropertyGetter MakeGetterTwo(String key)
        {
            FastClass  fastClassTwo = FastClass.Create(typeof(SupportBeanCombinedProps.NestedLevOne));
            FastMethod methodTwo    = fastClassTwo.GetMethod("GetMapped", new[] { typeof(string) });

            return(new KeyedFastPropertyGetter(methodTwo, key, SupportEventAdapterService.Service));
        }
コード例 #2
0
        private KeyedFastPropertyGetter MakeGetterOne(int index)
        {
            FastClass  fastClassOne = FastClass.Create(typeof(SupportBeanCombinedProps));
            FastMethod methodOne    = fastClassOne.GetMethod("GetIndexed", new[] { typeof(int) });

            return(new KeyedFastPropertyGetter(methodOne, index, SupportEventAdapterService.Service));
        }
コード例 #3
0
        private ArrayFastPropertyGetter MakeGetter(int index)
        {
            FastClass  fastClass = FastClass.Create(typeof(SupportBeanComplexProps));
            FastMethod method    = fastClass.GetMethod("GetArrayProperty", new Type[0]);

            return(new ArrayFastPropertyGetter(method, index, _container.Resolve <EventAdapterService>()));
        }
コード例 #4
0
        public SignalHandlerDefaultWInvoke(Object target, MethodInfo method)
        {
            Target = target;

            FastClass fastClass = FastClass.Create(target.GetType());

            FastMethod = fastClass.GetMethod(method);
        }
コード例 #5
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="subscriber">is the subscriber to deliver to</param>
        /// <param name="method">the method to invoke</param>
        public ResultDeliveryStrategyObjectArr(String statementName, Object subscriber, MethodInfo method)
        {
            _statementName = statementName;
            _subscriber    = subscriber;
            FastClass fastClass = FastClass.Create(subscriber.GetType());

            _fastMethod = fastClass.GetMethod(method);
        }
コード例 #6
0
        public SignalHandlerDefaultWInvoke(Object target, MethodInfo method, EngineImportService engineImportService)
        {
            Target = target;

            FastClass fastClass = FastClass.Create(target.GetType());

            Method = fastClass.GetMethod(method);
        }
コード例 #7
0
        private static BeanInstantiator ResolveFactoryMethod(BeanEventType beanEventType,
                                                             EngineImportService engineImportService)
        {
            string factoryMethodName = beanEventType.FactoryMethodName;

            int lastDotIndex = factoryMethodName.LastIndexOf('.');

            if (lastDotIndex == -1)
            {
                try
                {
                    MethodInfo method = engineImportService.ResolveMethod(
                        beanEventType.UnderlyingType, factoryMethodName, new Type[0], new bool[0], new bool[0]);
                    if (beanEventType.FastClass != null)
                    {
                        return(new BeanInstantiatorByFactoryFastClass(beanEventType.FastClass.GetMethod(method)));
                    }
                    else
                    {
                        return(new BeanInstantiatorByFactoryReflection(method));
                    }
                }
                catch (EngineImportException e)
                {
                    string message =
                        string.Format(
                            "Failed to resolve configured factory method '{0}' expected to exist for class '{1}'",
                            factoryMethodName, beanEventType.UnderlyingType);
                    Log.Info(message, e);
                    throw new EventBeanManufactureException(message, e);
                }
            }

            string className  = factoryMethodName.Substring(0, lastDotIndex);
            string methodName = factoryMethodName.Substring(lastDotIndex + 1);

            try
            {
                MethodInfo method = engineImportService.ResolveMethod(className, methodName, new Type[0], new bool[0], new bool[0]);
                if (beanEventType.FastClass != null)
                {
                    FastClass fastClassFactory = FastClass.Create(method.DeclaringType);
                    return(new BeanInstantiatorByFactoryFastClass(fastClassFactory.GetMethod(method)));
                }
                else
                {
                    return(new BeanInstantiatorByFactoryReflection(method));
                }
            }
            catch (EngineImportException e)
            {
                String message = "Failed to resolve configured factory method '" + methodName +
                                 "' expected to exist for class '" + className + "'";
                Log.Info(message, e);
                throw new EventBeanManufactureException(message, e);
            }
        }
コード例 #8
0
        public void SetUp()
        {
            _bean     = SupportBeanComplexProps.MakeDefaultBean();
            _theEvent = SupportEventBeanFactory.CreateObject(_bean);
            FastClass  fastClass = FastClass.Create(typeof(SupportBeanComplexProps));
            FastMethod method    = fastClass.GetMethod("GetIndexed", new Type[] { typeof(int) });

            _getter = new KeyedFastPropertyGetter(method, 1, SupportEventAdapterService.Service);
        }
コード例 #9
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="subscriber">is the receiver to method invocations</param>
        /// <param name="method">is the method to deliver to</param>
        public ResultDeliveryStrategyTypeArr(String statementName, Object subscriber, MethodInfo method)
        {
            _statementName = statementName;
            _subscriber    = subscriber;
            FastClass fastClass = FastClass.Create(subscriber.GetType());

            _fastMethod    = fastClass.GetMethod(method);
            _componentType = method.GetParameters()[0].ParameterType.GetElementType();
        }
コード例 #10
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="subscriber">the object to deliver to</param>
        /// <param name="method">the delivery method</param>
        /// <param name="columnNames">the column names for the map</param>
        public ResultDeliveryStrategyMap(String statementName, Object subscriber, MethodInfo method, String[] columnNames)
        {
            _statementName = statementName;
            _subscriber    = subscriber;
            FastClass fastClass = FastClass.Create(subscriber.GetType());

            _fastMethod  = fastClass.GetMethod(method);
            _columnNames = columnNames;
        }
コード例 #11
0
        /// <summary>
        /// Return a writer for writing a single property value.
        /// </summary>
        /// <param name="propertyName">to write to</param>
        /// <returns>
        /// null or writer if writable
        /// </returns>
        public EventPropertyWriter GetWriter(String propertyName)
        {
            if (_writeablePropertyDescriptors == null)
            {
                InitializeWriters();
            }

            var pair = _writerMap.Get(propertyName);

            if (pair != null)
            {
                return(pair.Second);
            }

            var property = PropertyParser.ParseAndWalk(propertyName, false);

            if (property is MappedProperty)
            {
                var mapProp    = (MappedProperty)property;
                var methodName = string.Format("Set{0}", mapProp.PropertyNameAtomic);
                var methodInfo = UnderlyingType.GetMethod(
                    methodName, BindingFlags.Public | BindingFlags.Instance, null,
                    new Type[] { typeof(string), typeof(object) }, null);
                if (methodInfo == null)
                {
                    Log.Info("Failed to find mapped property '" + mapProp.PropertyNameAtomic +
                             "' for writing to property '" + propertyName + "'");
                    return(null);
                }

                var fastMethod = FastClass.GetMethod(methodInfo);
                return(new BeanEventPropertyWriterMapProp(UnderlyingType, fastMethod, mapProp.Key));
            }

            if (property is IndexedProperty)
            {
                var indexedProp = (IndexedProperty)property;
                var methodName  = string.Format("Set{0}", indexedProp.PropertyNameAtomic);
                var methodInfo  = UnderlyingType.GetMethod(
                    methodName, BindingFlags.Public | BindingFlags.Instance, null,
                    new Type[] { typeof(int), typeof(object) }, null);
                if (methodInfo == null)
                {
                    Log.Info("Failed to find mapped property '" + indexedProp.PropertyNameAtomic +
                             "' for writing to property '" + propertyName + "'");
                    return(null);
                }

                var fastMethod = FastClass.GetMethod(methodInfo);
                return(new BeanEventPropertyWriterIndexedProp(UnderlyingType, fastMethod, indexedProp.Index));
            }

            return(null);
        }
コード例 #12
0
        /// <summary>
        /// Ctor.
        /// </summary>
        /// <param name="statementName">Name of the statement.</param>
        /// <param name="subscriber">is the subscriber receiving method invocations</param>
        /// <param name="deliveryConvertor">for converting individual rows</param>
        /// <param name="method">to deliver the insert stream to</param>
        /// <param name="startMethod">to call to indicate when delivery starts, or null if no such indication is required</param>
        /// <param name="endMethod">to call to indicate when delivery ends, or null if no such indication is required</param>
        /// <param name="rStreamMethod">to deliver the remove stream to, or null if no such indication is required</param>
        public ResultDeliveryStrategyImpl(String statementName,
                                          Object subscriber,
                                          DeliveryConvertor deliveryConvertor,
                                          MethodInfo method,
                                          MethodInfo startMethod,
                                          MethodInfo endMethod,
                                          MethodInfo rStreamMethod)
        {
            _statementName     = statementName;
            _subscriber        = subscriber;
            _deliveryConvertor = deliveryConvertor;
            FastClass fastClass = FastClass.Create(subscriber.GetType());

            _updateFastMethod = fastClass.GetMethod(method);

            _startFastMethod = startMethod != null?fastClass.GetMethod(startMethod) : null;

            _endFastMethod = endMethod != null?fastClass.GetMethod(endMethod) : null;

            _updateRStreamFastMethod = rStreamMethod != null?fastClass.GetMethod(rStreamMethod) : null;
        }
コード例 #13
0
 private FastMethod GetFastMethod(Type clazz)
 {
     try
     {
         MethodInfo method         = _engineImportService.ResolveMethod(clazz, _methodName, _parameterTypes, new bool[_parameterTypes.Length], new bool[_parameterTypes.Length]);
         FastClass  declaringClass = FastClass.Create(method.DeclaringType);
         return(declaringClass.GetMethod(method));
     }
     catch (Exception)
     {
         Log.Debug("Not resolved for class '" + clazz.Name + "' method '" + _methodName + "'");
     }
     return(null);
 }
コード例 #14
0
        public void TestGetterSpecial()
        {
            Type      clazz     = typeof(SupportBeanComplexProps);
            FastClass fastClass = FastClass.Create(clazz);

            // set up bean
            SupportBeanComplexProps bean = SupportBeanComplexProps.MakeDefaultBean();

            // try mapped property
            MethodInfo method     = clazz.GetMethod("GetMapped", new Type[] { typeof(string) });
            FastMethod fastMethod = fastClass.GetMethod(method);
            Object     result     = fastMethod.Invoke(bean, new Object[] { "keyOne" });

            Assert.AreEqual("valueOne", result);
            result = fastMethod.Invoke(bean, new Object[] { "keyTwo" });
            Assert.AreEqual("valueTwo", result);

            // try index property
            method     = clazz.GetMethod("GetIndexed", new Type[] { typeof(int) });
            fastMethod = fastClass.GetMethod(method);
            result     = fastMethod.Invoke(bean, new Object[] { 0 });
            Assert.AreEqual(1, result);
            result = fastMethod.Invoke(bean, new Object[] { 1 });
            Assert.AreEqual(2, result);

            // try nested property
            method     = clazz.GetMethod("_GetNested", new Type[] {});
            fastMethod = fastClass.GetMethod(method);
            SupportBeanComplexProps.SupportBeanSpecialGetterNested nested = (SupportBeanComplexProps.SupportBeanSpecialGetterNested)fastMethod.Invoke(bean, new Object[] {});

            Type       nestedClazz     = typeof(SupportBeanComplexProps.SupportBeanSpecialGetterNested);
            MethodInfo methodNested    = nestedClazz.GetMethod("_GetNestedValue", new Type[] {});
            FastClass  fastClassNested = FastClass.Create(nestedClazz);

            fastClassNested.GetMethod(methodNested);
        }
コード例 #15
0
        private DynamicPropertyDescriptor GetPopulateCache(Object obj)
        {
            // Check if the method is already there
            Type target = obj.GetType();

            foreach (DynamicPropertyDescriptor desc in _cache)
            {
                if (desc.GetClazz() == target)
                {
                    return(desc);
                }
            }

            // need to add it
            using (_iLock.Acquire())
            {
                foreach (DynamicPropertyDescriptor desc in _cache)
                {
                    if (desc.GetClazz() == target)
                    {
                        return(desc);
                    }
                }

                // Lookup method to use
                MethodInfo method = DetermineMethod(target);

                // Cache descriptor and create fast method
                DynamicPropertyDescriptor propertyDescriptor;
                if (method == null)
                {
                    propertyDescriptor = new DynamicPropertyDescriptor(target, null, false);
                }
                else
                {
                    FastClass  fastClass  = FastClass.Create(target);
                    FastMethod fastMethod = fastClass.GetMethod(method);
                    propertyDescriptor = new DynamicPropertyDescriptor(target, fastMethod, fastMethod.ParameterCount > 0);
                }
                _cache.Add(propertyDescriptor);
                return(propertyDescriptor);
            }
        }
コード例 #16
0
        private void InitializeWriters()
        {
            var writables = PropertyHelper.GetWritableProperties(FastClass.TargetType);
            var desc      = new EventPropertyDescriptor[writables.Count];
            var writers   = new Dictionary <String, Pair <EventPropertyDescriptor, BeanEventPropertyWriter> >();

            int count = 0;

            foreach (WriteablePropertyDescriptor writable in writables)
            {
                var propertyDesc = new EventPropertyDescriptor(writable.PropertyName, writable.PropertyType, null, false, false, false, false, false);
                desc[count++] = propertyDesc;

                FastMethod fastMethod = FastClass.GetMethod(writable.WriteMethod);
                writers.Put(writable.PropertyName, new Pair <EventPropertyDescriptor, BeanEventPropertyWriter>(propertyDesc, new BeanEventPropertyWriter(UnderlyingType, fastMethod)));
            }

            _writerMap = writers;
            _writeablePropertyDescriptors = desc;
        }
コード例 #17
0
        public EventBeanCopyMethod GetCopyMethod(String[] properties)
        {
            if (_copyMethodName == null)
            {
                if (UnderlyingType.IsSerializable)
                {
                    return(new BeanEventBeanSerializableCopyMethod(this, _eventAdapterService));
                }

                if (UnderlyingType.IsInterface)
                {
                    return(new BeanEventBeanSerializableCopyMethod(this, _eventAdapterService));
                }

                return(null);
            }
            MethodInfo method = null;

            try
            {
                method = UnderlyingType.GetMethod(_copyMethodName);
            }
            catch (AmbiguousMatchException e)
            {
                Log.Error("Configured copy-method for class '" + UnderlyingType.Name + " not found by name '" + _copyMethodName + "': " + e.Message);
            }

            if (method == null)
            {
                if (UnderlyingType.IsSerializable)
                {
                    return(new BeanEventBeanSerializableCopyMethod(this, _eventAdapterService));
                }

                throw new EPException("Configured copy-method for class '" + UnderlyingType.Name + " not found by name '" + _copyMethodName + "' and type is not Serializable");
            }

            return(new BeanEventBeanConfiguredCopyMethod(this, _eventAdapterService, FastClass.GetMethod(method)));
        }
コード例 #18
0
ファイル: PropertyHelper.cs プロジェクト: valmac/nesper
        /// <summary>
        /// Return getter for the given method and CGLIB FastClass.
        /// </summary>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="method">to return getter for</param>
        /// <param name="fastClass">is the CGLIB fast classs to make FastMethod for</param>
        /// <param name="eventAdapterService">factory for event beans and event types</param>
        /// <returns>property getter</returns>
        public static EventPropertyGetter GetGetter(String propertyName, MethodInfo method, FastClass fastClass, EventAdapterService eventAdapterService)
        {
            // Construct the appropriate property getter CGLib or reflect
            if (fastClass != null)
            {
#if true
                var fastProp = fastClass.GetProperty(propertyName);
                if (fastProp != null)
                {
                    return(new CGLibPropertyGetter(fastProp.Target, fastProp, eventAdapterService));
                }
                else
                {
                    return(new CGLibPropertyMethodGetter(method, fastClass.GetMethod(method), eventAdapterService));
                }
#else
                return(new LambdaPropertyGetter(method, eventAdapterService));
#endif
            }
            else
            {
                return(new ReflectionPropMethodGetter(method, eventAdapterService));
            }
        }
コード例 #19
0
        public override EventPropertyGetter GetGetter(BeanEventType eventType, EventAdapterService eventAdapterService)
        {
            FastClass fastClass = eventType.FastClass;
            InternalEventPropDescriptor propertyDesc = eventType.GetIndexedProperty(PropertyNameAtomic);

            if (propertyDesc != null)
            {
                if (fastClass != null)
                {
                    MethodInfo method     = propertyDesc.ReadMethod;
                    FastMethod fastMethod = fastClass.GetMethod(method);
                    return(new KeyedFastPropertyGetter(fastMethod, _index, eventAdapterService));
                }
                else
                {
                    return(new KeyedMethodPropertyGetter(propertyDesc.ReadMethod, _index, eventAdapterService));
                }
            }

            // Try the array as a simple property
            propertyDesc = eventType.GetSimpleProperty(PropertyNameAtomic);
            if (propertyDesc == null)
            {
                return(null);
            }

            Type returnType = propertyDesc.ReturnType;

            if (returnType.IsArray)
            {
                if (propertyDesc.ReadMethod != null)
                {
                    MethodInfo method = propertyDesc.ReadMethod;
                    if (fastClass != null)
                    {
                        FastMethod fastMethod = fastClass.GetMethod(method);
                        return(new ArrayFastPropertyGetter(fastMethod, _index, eventAdapterService));
                    }
                    else
                    {
                        return(new ArrayMethodPropertyGetter(method, _index, eventAdapterService));
                    }
                }
                else
                {
                    FieldInfo field = propertyDesc.AccessorField;
                    return(new ArrayFieldPropertyGetter(field, _index, eventAdapterService));
                }
            }
            else if (returnType.IsImplementsInterface(typeof(IList <object>)))
            {
                if (propertyDesc.ReadMethod != null)
                {
                    MethodInfo method = propertyDesc.ReadMethod;
                    if (fastClass != null)
                    {
                        FastMethod fastMethod = fastClass.GetMethod(method);
                        return(new ListFastPropertyGetter(method, fastMethod, _index, eventAdapterService));
                    }
                    else
                    {
                        return(new ListMethodPropertyGetter(method, _index, eventAdapterService));
                    }
                }
                else
                {
                    FieldInfo field = propertyDesc.AccessorField;
                    return(new ListFieldPropertyGetter(field, _index, eventAdapterService));
                }
            }
            else if (returnType.IsImplementsInterface(typeof(IEnumerable)))
            {
                if (propertyDesc.ReadMethod != null)
                {
                    MethodInfo method = propertyDesc.ReadMethod;
                    if (fastClass != null)
                    {
                        FastMethod fastMethod = fastClass.GetMethod(method);
                        return(new EnumerableFastPropertyGetter(method, fastMethod, _index, eventAdapterService));
                    }
                    else
                    {
                        return(new EnumerableMethodPropertyGetter(method, _index, eventAdapterService));
                    }
                }
                else
                {
                    FieldInfo field = propertyDesc.AccessorField;
                    return(new EnumerableFieldPropertyGetter(field, _index, eventAdapterService));
                }
            }

            return(null);
        }