Exemplo n.º 1
0
        public IEntityPrivilegeFactory GetEntityPrivilegeFactory(Type entityType, bool create, bool read, bool update, bool delete, bool execute)
        {
            if (BytecodeEnhancer == null)
            {
                return(ci);
            }
            int index = AbstractPrivilege.CalcIndex(create, read, update, delete, execute);

            IEntityPrivilegeFactory[] factories = typeToConstructorMap.Get(entityType);
            IEntityPrivilegeFactory   factory   = factories != null ? factories[index] : null;

            if (factory != null)
            {
                return(factory);
            }
            Object writeLock = this.writeLock;

            lock (writeLock)
            {
                // concurrent thread might have been faster
                factories = typeToConstructorMap.Get(entityType);
                factory   = factories != null ? factories[index] : null;
                if (factory != null)
                {
                    return(factory);
                }
                try
                {
                    Type enhancedType = BytecodeEnhancer.GetEnhancedType(typeof(AbstractPrivilege), new EntityPrivilegeEnhancementHint(entityType, create, read,
                                                                                                                                       update, delete, execute));

                    if (enhancedType == typeof(AbstractPrivilege))
                    {
                        // Nothing has been enhanced
                        factory = ci;
                    }
                    else
                    {
                        factory = AccessorTypeProvider.GetConstructorType <IEntityPrivilegeFactory>(enhancedType);
                    }
                }
                catch (Exception e)
                {
                    if (Log.WarnEnabled)
                    {
                        Log.Warn(e);
                    }
                    // something serious happened during enhancement: continue with a fallback
                    factory = ci;
                }
                if (factories == null)
                {
                    factories = new IEntityPrivilegeFactory[AbstractPrivilege.ArraySizeForIndex()];
                    typeToConstructorMap.Put(entityType, factories);
                }
                factories[index] = factory;
                return(factory);
            }
        }
 public override int GetHashCode()
 {
     return(GetType().GetHashCode() ^ EntityType.GetHashCode() ^ AbstractPrivilege.CalcIndex(Create, Read, Update, Delete, Execute));
 }