Exemplo n.º 1
0
        public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                             IList <IBytecodeBehavior> cascadePendingBehaviors)
        {
            if (state.GetContext <EntityEnhancementHint>() == null && state.GetContext <EmbeddedEnhancementHint>() == null && state.GetContext <ImplementAbstractObjectEnhancementHint>() == null)
            {
                return(visitor);
            }
            ListUtil.AddAll(cascadePendingBehaviors, 0, remainingPendingBehaviors);
            remainingPendingBehaviors.Clear();

            HashMap <String, IPropertyInfo> allProperties = new HashMap <String, IPropertyInfo>();

            IPropertyInfo[] properties = PropertyInfoProvider.GetProperties(state.CurrentType);
            foreach (IPropertyInfo pi in properties)
            {
                allProperties.Put(pi.Name, pi);
            }
            properties = PropertyInfoProvider.GetProperties(state.OriginalType);
            foreach (IPropertyInfo pi in properties)
            {
                // Only add property if it is not already declared by the current type
                allProperties.PutIfNotExists(pi.Name, pi);
            }
            visitor = new DefaultPropertiesMethodVisitor(visitor, allProperties.ToArray());
            if (state.OriginalType.IsInterface)
            {
                visitor = new InterfaceAdder(visitor, state.OriginalType);
            }
            return(visitor);
        }
 public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                      IList <IBytecodeBehavior> cascadePendingBehaviors)
 {
     // NotifyPropertyChangedBehavior executes in this cascade
     // add IPropertyChanged
     visitor = new InterfaceAdder(visitor, typeof(INotifyPropertyChanged), typeof(INotifyPropertyChangedSource),
                                  typeof(IPropertyChangedEventHandler), typeof(INotifyCollectionChangedListener), typeof(IPropertyChangeConfigurable));
     visitor = BeanContext.RegisterWithLifecycle(new NotifyPropertyChangedClassVisitor(visitor, MetaData, null)).Finish();
     return(visitor);
 }
Exemplo n.º 3
0
 public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                      IList <IBytecodeBehavior> cascadePendingBehaviors)
 {
     if (state.GetContext <EmbeddedEnhancementHint>() == null)
     {
         return(visitor);
     }
     visitor = new InterfaceAdder(visitor, typeof(IEmbeddedType));
     visitor = new EmbeddedTypeVisitor(visitor);
     return(visitor);
 }
Exemplo n.º 4
0
            public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                                 IList <IBytecodeBehavior> cascadePendingBehaviors)
            {
                ListUtil.AddAll(cascadePendingBehaviors, 0, remainingPendingBehaviors);
                remainingPendingBehaviors.Clear();

                // Add this interface only for real entities, not for embedded types
                if (implementValueHolderContainerInterface)
                {
                    visitor = new InterfaceAdder(visitor, typeof(IValueHolderContainer));
                }
                visitor = new RelationsGetterVisitor(visitor, metaData, ValueHolderContainerHelper, PropertyInfoProvider);
                visitor = new SetCacheModificationMethodCreator(visitor);
                return(visitor);
            }
Exemplo n.º 5
0
            public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                                 IList <IBytecodeBehavior> cascadePendingBehaviors)
            {
                visitor = new InterfaceAdder(visitor, typeof(IDataObject), typeof(INotifyCollectionChangedListener));
                visitor = new DataObjectVisitor(visitor, metaData, PropertyInfoProvider);
                visitor = new SetCacheModificationMethodCreator(visitor);

                // ToBeUpdated & ToBeDeleted have to fire PropertyChange-Events by themselves
                String[] properties = { DataObjectVisitor.template_p_toBeUpdated.Name, DataObjectVisitor.template_p_toBeDeleted.Name };

                CascadeBehavior2 cascadeBehavior2 = BeanContext.RegisterWithLifecycle(new CascadeBehavior2(metaData, properties)).Finish();

                cascadePendingBehaviors.Add(cascadeBehavior2);

                return(visitor);
            }
Exemplo n.º 6
0
 public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                      IList <IBytecodeBehavior> cascadePendingBehaviors)
 {
     if ((state.GetContext <EntityEnhancementHint>() == null && state.GetContext <EmbeddedEnhancementHint>() == null))
     {
         return(visitor);
     }
     if (state.GetContext <EntityEnhancementHint>() != null)
     {
         IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(state.OriginalType);
         visitor = new InterfaceAdder(visitor, typeof(IEntityMetaDataHolder));
         visitor = new EntityMetaDataHolderVisitor(visitor, metaData);
     }
     visitor = new InterfaceAdder(visitor, typeof(IEnhancedType));
     visitor = new GetBaseTypeMethodCreator(visitor);
     return(visitor);
 }
Exemplo n.º 7
0
        public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                             IList <IBytecodeBehavior> cascadePendingBehaviors)
        {
            if (state.GetContext <EntityEnhancementHint>() == null)
            {
                return(visitor);
            }
            IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(state.OriginalType, true);

            if (metaData == null)
            {
                return(visitor);
            }
            visitor = new InterfaceAdder(visitor, typeof(IParentCacheValueHardRef));
            visitor = new ParentCacheHardRefVisitor(visitor);
            return(visitor);
        }
        /**
         * {@inheritDoc}
         */
        public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                             IList <IBytecodeBehavior> cascadePendingBehaviors)
        {
            Type keyType = state.OriginalType;

            if (!IsActive(GetContext(state.Context), keyType))
            {
                // behavior not applied
                return(visitor);
            }
            Type[] interfaceTypes = ImplementAbstractObjectFactory.GetInterfaceTypes(keyType);

            ListUtil.AddAll(cascadePendingBehaviors, 0, remainingPendingBehaviors);
            remainingPendingBehaviors.Clear();

            cascadePendingBehaviors.Add(new InnerBehavior(interfaceTypes, this));

            // implements interfaces
            visitor = new InterfaceAdder(visitor, interfaceTypes);

            return(visitor);
        }
Exemplo n.º 9
0
        public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                             IList <IBytecodeBehavior> cascadePendingBehaviors)
        {
            if (state.GetContext <EntityEnhancementHint>() == null)
            {
                return(visitor);
            }
            IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(state.OriginalType, true);

            if (metaData == null)
            {
                return(visitor);
            }
            if (!IsAnnotationPresent <EntityEqualsAspect>(state.CurrentType))
            {
                return(visitor);
            }
            visitor = new InterfaceAdder(visitor, typeof(IEntityEquals), typeof(IPrintable));
            visitor = new GetIdMethodCreator(visitor, metaData);
            visitor = new GetBaseTypeMethodCreator(visitor);
            visitor = new EntityEqualsVisitor(visitor);
            return(visitor);
        }
Exemplo n.º 10
0
        public override IClassVisitor Extend(IClassVisitor visitor, IBytecodeBehaviorState state, IList <IBytecodeBehavior> remainingPendingBehaviors,
                                             IList <IBytecodeBehavior> cascadePendingBehaviors)
        {
            Type entityType = EntityUtil.GetEntityType(state.Context);

            if (entityType == null)
            {
                return(visitor);
            }
            IEntityMetaData metaData = EntityMetaDataProvider.GetMetaData(entityType, true);

            if (metaData == null)
            {
                return(visitor);
            }
            visitor = new FlattenDebugHierarchyVisitor(visitor, metaData.RelationMembers.Length != 0);
            bool addValueHolderContainer;

            if (EmbeddedEnhancementHint.HasMemberPath(state.Context))
            {
                foreach (RelationMember member in metaData.RelationMembers)
                {
                    if (!(member is IEmbeddedMember))
                    {
                        continue;
                    }
                    Member             cMember = ((IEmbeddedMember)member).ChildMember;
                    MethodPropertyInfo prop    = (MethodPropertyInfo)PropertyInfoProvider.GetProperty(cMember.DeclaringType, cMember.Name);
                    if ((prop.Getter != null && state.HasMethod(new MethodInstance(prop.Getter))) || (prop.Setter != null && state.HasMethod(new MethodInstance(prop.Setter))))
                    {
                        // Handle this behavior in the next iteration
                        cascadePendingBehaviors.Add(this);
                        return(visitor);
                    }
                }
                addValueHolderContainer = false;
            }
            else
            {
                foreach (RelationMember member in metaData.RelationMembers)
                {
                    if (member is IEmbeddedMember)
                    {
                        continue;
                    }
                    MethodPropertyInfo prop = (MethodPropertyInfo)PropertyInfoProvider.GetProperty(member.DeclaringType, member.Name);
                    if ((prop.Getter != null && state.HasMethod(new MethodInstance(prop.Getter))) || (prop.Setter != null && state.HasMethod(new MethodInstance(prop.Setter))))
                    {
                        // Handle this behavior in the next iteration
                        cascadePendingBehaviors.Add(this);
                        return(visitor);
                    }
                }
                // Add this interface only for real entities, not for embedded types
                addValueHolderContainer = true;
                visitor = new EntityMetaDataHolderVisitor(visitor, metaData);
            }
            visitor = new SetCacheModificationMethodCreator(visitor);
            cascadePendingBehaviors.Add(WaitForApplyBehavior.Create(BeanContext, delegate(IClassVisitor visitor2, IBytecodeBehaviorState state2, IList <IBytecodeBehavior> remainingPendingBehaviors2,
                                                                                          IList <IBytecodeBehavior> cascadePendingBehaviors2)
            {
                if (addValueHolderContainer)
                {
                    visitor2 = new InterfaceAdder(visitor2, typeof(IValueHolderContainer));
                }
                visitor2 = new RelationsGetterVisitor(visitor2, metaData, ValueHolderContainerHelper, PropertyInfoProvider);
                return(visitor2);
            }));
            return(visitor);
        }