示例#1
0
        private static void AddWeborbPropertyMapping <T>()
        {
            var entityType       = typeof(T);
            var entityProperties = entityType.GetProperties();

            foreach (var entityProperty in entityProperties)
            {
                switch (entityProperty.Name)
                {
                case DEFAULT_OBJECT_ID_PROPERTY_NAME_DOTNET_STYLE:
                    if (
                        string.IsNullOrEmpty(PropertyRenaming.GetRenamingRule(entityType,
                                                                              DEFAULT_OBJECT_ID_PROPERTY_NAME_DOTNET_STYLE)))
                    {
                        PropertyRenaming.AddRenamingRule(entityType, DEFAULT_OBJECT_ID_PROPERTY_NAME_DOTNET_STYLE,
                                                         DEFAULT_OBJECT_ID_PROPERTY_NAME_JAVA_STYLE);
                    }
                    break;

                case DEFAULT_UPDATED_FIELD_NAME_DOTNET_STYLE:
                    if (
                        string.IsNullOrEmpty(PropertyRenaming.GetRenamingRule(entityType,
                                                                              DEFAULT_UPDATED_FIELD_NAME_DOTNET_STYLE)))
                    {
                        PropertyRenaming.AddRenamingRule(entityType, DEFAULT_UPDATED_FIELD_NAME_DOTNET_STYLE,
                                                         DEFAULT_UPDATED_FIELD_NAME_JAVA_STYLE);
                    }
                    break;

                case DEFAULT_CREATED_FIELD_NAME_DOTNET_STYLE:
                    if (
                        string.IsNullOrEmpty(PropertyRenaming.GetRenamingRule(entityType,
                                                                              DEFAULT_CREATED_FIELD_NAME_DOTNET_STYLE)))
                    {
                        PropertyRenaming.AddRenamingRule(entityType, DEFAULT_CREATED_FIELD_NAME_DOTNET_STYLE,
                                                         DEFAULT_CREATED_FIELD_NAME_JAVA_STYLE);
                    }
                    break;
                }
            }
        }
示例#2
0
        protected virtual ClassDefinition getClassDefinition(String className, Object obj)
        {
#if (FULL_BUILD)
            SerializationConfigHandler serializationConfig = (SerializationConfigHandler)ORBConfig.GetInstance().GetConfig("weborb/serialization");
#endif

            ClassDefinition classDef = new ClassDefinition();

            Type objectClass = obj.GetType();
            IPropertyExclusionAttribute[] propExclusion = (IPropertyExclusionAttribute[])objectClass.GetCustomAttributes(typeof(IPropertyExclusionAttribute), true);

            while (!Object.ReferenceEquals(objectClass, typeof(object)))
            {
                BindingFlags flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static;

                if (serializePrivate)
                {
                    flags |= BindingFlags.NonPublic;
                }

                PropertyInfo[] props = objectClass.GetProperties(flags);

                for (int i = 0; i < props.Length; i++)
                {
                    if (!props[i].CanRead)
                    {
                        continue;
                    }

                    bool skipProperty = false;
                    IPropertyExclusionAttribute[] propExclusionAttr = (IPropertyExclusionAttribute[])props[i].GetCustomAttributes(typeof(IPropertyExclusionAttribute), false);

                    if (propExclusionAttr.Length > 0)
                    {
                        continue;
                    }

                    foreach (IPropertyExclusionAttribute attr in propExclusion)
                    {
                        if (attr.ExcludeProperty(obj, props[i].Name))
                        {
                            skipProperty = true;
                            break;
                        }
                    }

                    if (skipProperty)
                    {
                        continue;
                    }

                    if (props[i].GetGetMethod().IsStatic)
                    {
                        if (!cacheStaticField(className, props[i].Name))
                        {
                            continue;
                        }
                    }

                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])props[i].GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(objectClass, props[i]);
                    }
                    else
                    {
                        memberName = PropertyRenaming.GetRenamingRule(objectClass, props[i].Name);
                    }
#if (FULL_BUILD)
                    if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                    {
                        memberName = serializationConfig.PrefixForKeywords + memberName;
                    }
#endif
                    if (!classDef.ContainsMember(memberName))
                    {
                        //ITypeWriter typeWriter = MessageWriter.getWriter( props[ i ].PropertyType, null, false );
                        classDef.AddMemberInfo(memberName, props[i]);
                    }
                }

                flags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static;

                if (serializePrivate)
                {
                    flags |= BindingFlags.NonPublic;
                }

                FieldInfo[] fields = objectClass.GetFields(flags);

                //Log.log( ORBConstants.INFO, "ObjectWriter.write.before writing fields: " + writer.BaseStream.Length );
                //if( Log.isLogging( LoggingConstants.DEBUG ) )
                //   Log.log( LoggingConstants.DEBUG, "number of fields: " + fields.Length );

                for (int i = 0; i < fields.Length; i++)
                {
                    if (fields[i].IsLiteral || fields[i].IsNotSerialized || fields[i].FieldType == typeof(IntPtr))
                    {
                        continue;
                    }

                    string fieldName = fields[i].Name;

                    if (fields[i].IsStatic)
                    {
                        if (!cacheStaticField(className, fieldName))
                        {
                            continue;
                        }
                    }

                    IMemberRenameAttribute[] renamers = (IMemberRenameAttribute[])fields[i].GetCustomAttributes(typeof(IMemberRenameAttribute), true);
                    string memberName;

                    if (renamers.Length > 0)
                    {
                        memberName = renamers[0].GetClientName(objectClass, fields[i]);
                    }
                    else
                    {
                        memberName = fields[i].Name;
                    }
#if (FULL_BUILD)
                    if (serializationConfig != null && serializationConfig.Keywords.Contains(memberName))
                    {
                        memberName = serializationConfig.PrefixForKeywords + memberName;
                    }
#endif
                    if (!classDef.ContainsMember(memberName))
                    {
                        //ITypeWriter typeWriter = MessageWriter.getWriter( fields[ i ].FieldType, null, false );
                        classDef.AddMemberInfo(memberName, fields[i]);
                    }
                }

                objectClass = objectClass.BaseType;
            }

            IDictionary classStaticsCache = ThreadContext.currentWriterCache();

            if (classStaticsCache != null)
            {
                classStaticsCache.Remove(className);
            }

            classDef.ClassName = className;
            return(classDef);
        }