コード例 #1
0
        private void DoFields(SupportClass.ListCollectionSupport fieldList, SupportClass.SetSupport imports,
                              IDictionary class2classmap, StringWriter writer)
        {
            for (IEnumerator fields = fieldList.GetEnumerator(); fields.MoveNext();)
            {
                FieldProperty field = (FieldProperty)fields.Current;

                if (field.GeneratedAsProperty)
                {
                    string fieldScope = GetFieldScope(field, "scope-field", "private");
                    writer.WriteLine("    /// <summary>\n    /// Holder for " +
                                     (field.Nullable && !field.Identifier ? "nullable " : string.Empty) +
                                     (field.Identifier ? "identifier" : "persistent") + " field " + field.FieldName +
                                     "\n    /// </summary>");

                    writer.Write("    " + fieldScope + " " + field.FullyQualifiedTypeName + " " + field.fieldcase);

                    if (field.GetMeta("default-value") != null)
                    {
                        writer.Write(" = " + field.GetMetaAsString("default-value"));
                    }
                    writer.WriteLine(';');
                }
                writer.WriteLine();
            }
        }
コード例 #2
0
        /// <summary> Returns the true name for the given fields class name. By true name is
        /// that it will return the Proxy for the class name if the class was
        /// defined with a proxy attribute.
        /// 
        /// If the Field has an <meta attribute="property-type"></meta> then that
        /// will overrule any other information.
        /// 
        /// </summary>
        /// <param name="field">class name that we use to serach in class2classmap
        /// </param>
        /// <param name="class2classmap">a map from classname to classmappings
        /// </param>
        /// <returns> string return either name or the proxy name of the classmap
        /// </returns>
        public static string GetTrueTypeName(FieldProperty field, IDictionary class2classmap)
        {
            string name = (field.ClassType != null) ? field.ClassType.FullyQualifiedName : field.FullyQualifiedTypeName;

            if (field.GetMeta("property-type") != null)
            {
                name = field.GetMetaAsString("property-type");
            }
            ClassMapping cmap = (ClassMapping) class2classmap[name];

            if (cmap != null)
            {
                if ((Object) cmap.Proxy != null)
                {
                    return cmap.Proxy;
                }
            }
            return name;
        }
コード例 #3
0
ファイル: LanguageTool.cs プロジェクト: knorrus/nhcontrib
        /// <summary> Returns the true name for the given fields class name. By true name is
        /// that it will return the Proxy for the class name if the class was
        /// defined with a proxy attribute.
        ///
        /// If the Field has an <meta attribute="property-type"></meta> then that
        /// will overrule any other information.
        ///
        /// </summary>
        /// <param name="field">class name that we use to serach in class2classmap
        /// </param>
        /// <param name="class2classmap">a map from classname to classmappings
        /// </param>
        /// <returns> string return either name or the proxy name of the classmap
        /// </returns>
        public static string GetTrueTypeName(FieldProperty field, IDictionary class2classmap)
        {
            string name = (field.ClassType != null) ? field.ClassType.FullyQualifiedName : field.FullyQualifiedTypeName;

            if (field.GetMeta("property-type") != null)
            {
                name = field.GetMetaAsString("property-type");
            }
            ClassMapping cmap = (ClassMapping)class2classmap[name];

            if (cmap != null)
            {
                if ((Object)cmap.Proxy != null)
                {
                    return(cmap.Proxy);
                }
            }
            return(name);
        }
コード例 #4
0
        private int DoFields(ClassMapping classMapping, IDictionary class2classmap, StringWriter writer, string vetoSupport,
                             string changeSupport, int fieldTypes, SupportClass.ListCollectionSupport fieldz)
        {
            // field accessors
            for (IEnumerator fields = fieldz.GetEnumerator(); fields.MoveNext();)
            {
                FieldProperty field = (FieldProperty)fields.Current;
                if (field.GeneratedAsProperty)
                {
                    // getter
                    string getAccessScope = GetFieldScope(field, "scope-get", "public");


                    if (field.GetMeta("field-description") != null)
                    {
                        //writer.WriteLine("    /** \n" + languageTool.toJavaDoc(field.getMetaAsString("field-description"), 4) + "     */");
                        writer.WriteLine("    /// <summary>\n" + languageTool.ToJavaDoc(field.GetMetaAsString("field-description"), 4) +
                                         "\n    /// </summary>");
                    }
                    writer.Write("    " + getAccessScope + " virtual " + field.FullyQualifiedTypeName + " " + field.Propcase);
                    if (classMapping.Interface)
                    {
                        writer.WriteLine(";");
                    }
                    else
                    {
                        writer.WriteLine();
                        writer.WriteLine("    {");
                        writer.WriteLine("        get { return this." + field.fieldcase + "; }");
                        //writer.WriteLine("        {");
                        //writer.WriteLine("            return this." + field.FieldName + ";");
                        //writer.WriteLine("        }");
                    }

                    // setter
                    int fieldType = 0;
                    if (field.GetMeta("beans-property-type") != null)
                    {
                        string beansPropertyType = field.GetMetaAsString("beans-property-type").Trim().ToLower();
                        if (beansPropertyType.Equals("constraint"))
                        {
                            fieldTypes = (fieldTypes | CONSTRAINT);
                            fieldType  = CONSTRAINT;
                        }
                        else if (beansPropertyType.Equals("bound"))
                        {
                            fieldTypes = (fieldTypes | BOUND);
                            fieldType  = BOUND;
                        }
                    }
                    string setAccessScope = GetFieldScope(field, "scope-set", "public");
                    writer.Write("        set");
                    writer.Write((fieldType & CONSTRAINT) == CONSTRAINT ? " throws PropertyVetoException " : "");
                    if (classMapping.Interface)
                    {
                        writer.WriteLine(";");
                    }
                    else
                    {
                        writer.WriteLine();
                        writer.WriteLine("        {");
                        if ((fieldType & CONSTRAINT) == CONSTRAINT || (fieldType & BOUND) == BOUND)
                        {
                            writer.WriteLine("            object oldValue = " + GetFieldAsObject(true, field) + ";");
                        }
                        if ((fieldType & CONSTRAINT) == CONSTRAINT)
                        {
                            writer.WriteLine("            " + vetoSupport + ".fireVetoableChange(\"" + field.fieldcase + "\",");
                            writer.WriteLine("                    oldValue,");
                            writer.WriteLine("                    " + GetFieldAsObject(false, field) + ");");
                        }

                        writer.WriteLine("            this." + field.fieldcase + " = value;");
                        if ((fieldType & BOUND) == BOUND)
                        {
                            writer.WriteLine("            " + changeSupport + ".firePropertyChange(\"" + field.fieldcase + "\",");
                            writer.WriteLine("                    oldValue,");
                            writer.WriteLine("                    " + GetFieldAsObject(false, field) + ");");
                        }
                        writer.WriteLine("        }");
                    }
                    writer.WriteLine("    }");
                    writer.WriteLine();

                    // add/remove'rs (commented out for now)

                    /*
                     * if(field.getForeignClass()!=null) {
                     * ClassName foreignClass = field.getForeignClass();
                     *
                     * string trueforeign = getTrueTypeName(foreignClass, class2classmap);
                     * classMapping.addImport(trueforeign);
                     *
                     * // Try to identify the matching set method on the child.
                     * ClassMapping forignMap = (ClassMapping) class2classmap.get(foreignClass.getFullyQualifiedName());
                     *
                     * if(forignMap!=null) {
                     * Iterator foreignFields = forignMap.getFields().iterator();
                     * while (foreignFields.hasNext()) {
                     * Field ffield = (Field) foreignFields.next();
                     * if(ffield.isIdentifier()) {
                     * log.Debug("Trying to match " + ffield.getName() + " with " + field.getForeignKeys());
                     * }
                     * }
                     *
                     * } else {
                     * log.Error("Could not find foreign class's mapping - cannot provide bidirectional setters!");
                     * }
                     *
                     * string addAccessScope = getFieldScope(field, "scope", "scope-add");
                     * writer.println("    " + setAccessScope + " void add" + field.getAsSuffix() + StringHelper.OPEN + shortenType(trueforeign, classMapping.getImports()) + " a" + field.getName() + ") {");
                     * writer.println("        this." + getterType + field.getAsSuffix() + "().add(a" + field.getName() + ");");
                     * writer.println("        a" + field.getName() + ".setXXX(this);");
                     * writer.println("    }");
                     * writer.println();
                     *
                     *
                     * }
                     */
                }
            }
            return(fieldTypes);
        }