Exemplo n.º 1
0
        private void Initialize(bool isConfigured, EngineImportService engineImportService)
        {
            PropertyListBuilder propertyListBuilder = PropertyListBuilderFactory.CreateBuilder(_optionalLegacyDef);
            IList<InternalEventPropDescriptor> properties = propertyListBuilder.AssessProperties(_clazz);

            _propertyDescriptors = new EventPropertyDescriptor[properties.Count];
            _propertyDescriptorMap = new Dictionary<string, EventPropertyDescriptor>();
            _propertyNames = new string[properties.Count];
            _simpleProperties = new Dictionary<string, SimplePropertyInfo>();
            _mappedPropertyDescriptors = new Dictionary<string, InternalEventPropDescriptor>();
            _indexedPropertyDescriptors = new Dictionary<string, InternalEventPropDescriptor>();

            if (UsesSmartResolutionStyle)
            {
                _simpleSmartPropertyTable = new Dictionary<string, IList<SimplePropertyInfo>>();
                _mappedSmartPropertyTable = new Dictionary<string, IList<SimplePropertyInfo>>();
                _indexedSmartPropertyTable = new Dictionary<string, IList<SimplePropertyInfo>>();
            }

            if ((_optionalLegacyDef == null) ||
                (_optionalLegacyDef.CodeGeneration != CodeGenerationEnum.DISABLED))
            {
                // get CGLib fast class using current thread class loader
                _fastClass = null;
                try
                {
                    _fastClass = FastClass.Create(_clazz);
                }
                catch (Exception ex)
                {
                    Log.Warn(
                        ".initialize Unable to obtain CGLib fast class and/or method implementation for class " +
                        _clazz.Name + ", error msg is " + ex.Message, ex);
                    Log.Warn(
                        ".initialize Not using the provided class loader, the error msg is: " +
                        ex.Message, ex);
                    _fastClass = null;
                }
            }

            int count = 0;
            foreach (InternalEventPropDescriptor desc in properties)
            {
                string propertyName = desc.PropertyName;
                Type underlyingType;
                Type componentType;
                bool isRequiresIndex;
                bool isRequiresMapkey;
                bool isIndexed;
                bool isMapped;
                bool isFragment;

                if (desc.PropertyType.Equals(EventPropertyType.SIMPLE))
                {
                    EventPropertyGetter getter;
                    Type type;
                    if (desc.ReadMethod != null)
                    {
                        getter = PropertyHelper.GetGetter(desc.PropertyName, desc.ReadMethod, _fastClass, _eventAdapterService);
                        type = desc.ReadMethod.ReturnType;
                    }
                    else
                    {
                        if (desc.AccessorField == null)
                        {
                            // Ignore property
                            continue;
                        }
                        getter = new ReflectionPropFieldGetter(desc.AccessorField, _eventAdapterService);
                        type = desc.AccessorField.FieldType;
                    }

                    underlyingType = type;
                    componentType = null;
                    isRequiresIndex = false;
                    isRequiresMapkey = false;
                    isIndexed = false;
                    isMapped = false;

                    if (type.IsGenericDictionary())
                    {
                        isMapped = true;
                        // We do not yet allow to fragment maps entries.
                        // Type genericType = TypeHelper.GetGenericReturnTypeMap(desc.ReadMethod, desc.AccessorField);
                        isFragment = false;

                        if (desc.ReadMethod != null)
                        {
                            componentType = TypeHelper.GetGenericReturnTypeMap(desc.ReadMethod, false);
                        }
                        else if (desc.AccessorField != null)
                        {
                            componentType = TypeHelper.GetGenericFieldTypeMap(desc.AccessorField, false);
                        }
                        else
                        {
                            componentType = typeof (object);
                        }
                    }
                    else if (type.IsArray)
                    {
                        isIndexed = true;
                        isFragment = TypeHelper.IsFragmentableType(type.GetElementType());
                        componentType = type.GetElementType();
                    }
                    else if (type.IsImplementsInterface(typeof (IEnumerable)))
                    {
                        isIndexed = true;
                        Type genericType = TypeHelper.GetGenericReturnType(desc.ReadMethod, desc.AccessorField, true);
                        isFragment = genericType.IsFragmentableType();
                        if (genericType != null)
                        {
                            componentType = genericType;
                        }
                        else
                        {
                            componentType = typeof (Object);
                        }
                    }
                    else
                    {
                        isMapped = false;
                        isFragment = type.IsFragmentableType();
                    }
                    _simpleProperties.Put(propertyName, new SimplePropertyInfo(type, getter, desc));

                    // Recognize that there may be properties with overlapping case-insentitive names
                    if (UsesSmartResolutionStyle)
                    {
                        // Find the property in the smart property table
                        string smartPropertyName = propertyName.ToLowerInvariant();
                        IList<SimplePropertyInfo> propertyInfoList = _simpleSmartPropertyTable.Get(smartPropertyName);
                        if (propertyInfoList == null)
                        {
                            propertyInfoList = new List<SimplePropertyInfo>();
                            _simpleSmartPropertyTable.Put(smartPropertyName, propertyInfoList);
                        }

                        // Enter the property into the smart property list
                        var propertyInfo = new SimplePropertyInfo(type, getter, desc);
                        propertyInfoList.Add(propertyInfo);
                    }
                }
                else if (desc.PropertyType.Equals(EventPropertyType.MAPPED))
                {
                    _mappedPropertyDescriptors.Put(propertyName, desc);

                    underlyingType = desc.ReturnType;
                    componentType = typeof (Object);
                    isRequiresIndex = false;
                    isRequiresMapkey = desc.ReadMethod.GetParameterTypes().Length > 0;
                    isIndexed = false;
                    isMapped = true;
                    isFragment = false;

                    // Recognize that there may be properties with overlapping case-insentitive names
                    if (UsesSmartResolutionStyle)
                    {
                        // Find the property in the smart property table
                        string smartPropertyName = propertyName.ToLowerInvariant();
                        IList<SimplePropertyInfo> propertyInfoList = _mappedSmartPropertyTable.Get(smartPropertyName);
                        if (propertyInfoList == null)
                        {
                            propertyInfoList = new List<SimplePropertyInfo>();
                            _mappedSmartPropertyTable.Put(smartPropertyName, propertyInfoList);
                        }

                        // Enter the property into the smart property list
                        var propertyInfo = new SimplePropertyInfo(desc.ReturnType, null, desc);
                        propertyInfoList.Add(propertyInfo);
                    }
                }
                else if (desc.PropertyType.Equals(EventPropertyType.INDEXED))
                {
                    _indexedPropertyDescriptors.Put(propertyName, desc);

                    underlyingType = desc.ReturnType;
                    componentType = null;
                    isRequiresIndex = desc.ReadMethod.GetParameterTypes().Length > 0;
                    isRequiresMapkey = false;
                    isIndexed = true;
                    isMapped = false;
                    isFragment = desc.ReturnType.IsFragmentableType();

                    if (UsesSmartResolutionStyle)
                    {
                        // Find the property in the smart property table
                        string smartPropertyName = propertyName.ToLowerInvariant();
                        IList<SimplePropertyInfo> propertyInfoList = _indexedSmartPropertyTable.Get(smartPropertyName);
                        if (propertyInfoList == null)
                        {
                            propertyInfoList = new List<SimplePropertyInfo>();
                            _indexedSmartPropertyTable.Put(smartPropertyName, propertyInfoList);
                        }

                        // Enter the property into the smart property list
                        var propertyInfo = new SimplePropertyInfo(desc.ReturnType, null, desc);
                        propertyInfoList.Add(propertyInfo);
                    }
                }
                else
                {
                    continue;
                }

                _propertyNames[count] = desc.PropertyName;
                var descriptor = new EventPropertyDescriptor(
                    desc.PropertyName, underlyingType, componentType, isRequiresIndex, isRequiresMapkey, isIndexed, isMapped, isFragment);
                _propertyDescriptors[count++] = descriptor;
                _propertyDescriptorMap.Put(descriptor.PropertyName, descriptor);
            }

            // Determine event type super types
            _superTypes = GetSuperTypes(_clazz, _eventAdapterService.BeanEventTypeFactory);
            if (_superTypes != null && _superTypes.Length == 0)
            {
                _superTypes = null;
            }
            if (_metadata != null && _metadata.TypeClass == TypeClass.NAMED_WINDOW)
            {
                _superTypes = null;
            }

            // Determine deep supertypes
            // Get super types (superclasses and interfaces), deep get of all in the tree
            var supers = new HashSet<Type>();
            GetBase(_clazz, supers);
            RemoveLibInterfaces(supers); // Remove "java." super types

            // Cache the supertypes of this event type for later use
            _deepSuperTypes = new HashSet<EventType>();
            foreach (Type superClass in supers)
            {
                EventType superType = _eventAdapterService.BeanEventTypeFactory.CreateBeanType(
                    superClass.Name, superClass, false, false, isConfigured);
                _deepSuperTypes.Add(superType);
            }
        }