예제 #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));
 }
 public string GetTargetName(Type typeToEnhance)
 {
     return(entityType.FullName + "$" + typeof(AbstractPrivilege).Name + "_" + AbstractPrivilege.upperOrLower(create, 'c')
            + AbstractPrivilege.upperOrLower(read, 'r') + AbstractPrivilege.upperOrLower(update, 'u') + AbstractPrivilege.upperOrLower(delete, 'd')
            + AbstractPrivilege.upperOrLower(execute, 'e'));
 }