Exemplo n.º 1
0
 public FieldProperty(Element element, MappingElement parent, string name, ClassName type,
     ClassName implementationClassName, bool nullable, ClassName foreignClass,
     SupportClass.SetSupport foreignKeys, MultiMap metaattribs)
     : base(element, parent)
 {
     InitWith(name, type, implementationClassName, nullable, id, false, foreignClass, foreignKeys, metaattribs);
 }
        public static string GetMetaAsString(SupportClass.ListCollectionSupport meta, string seperator)
        {
            StringBuilder buf = new StringBuilder();
            bool first = true;
            for (IEnumerator iter = meta.GetEnumerator(); iter.MoveNext();)
            {
                if (first)
                    first = false;
                else
                    buf.Append(seperator);

                buf.Append(iter.Current);
            }
            return buf.ToString();
        }
Exemplo n.º 3
0
        public virtual string FieldsAsArguments(SupportClass.ListCollectionSupport fieldslist, ClassMapping classMapping,
            IDictionary class2classmap)
        {
            StringBuilder buf = new StringBuilder();
            bool first = true;
            for (IEnumerator fields = fieldslist.GetEnumerator(); fields.MoveNext();)
            {
                if (first)
                    first = false;
                else
                    buf.Append(", ");

                FieldProperty field = (FieldProperty) fields.Current;
                buf.Append(field.fieldcase);
            }
            return buf.ToString();
        }
Exemplo n.º 4
0
        /// <summary> Returns the last part of type if it is in the set of imports.
        /// e.g. java.util.Date would become Date, if imports contains 
        /// java.util.Date.
        /// 
        /// </summary>
        /// <returns> String
        /// </returns>
        public static string ShortenType(string type, SupportClass.SetSupport imports)
        {
            string result = type;
            if (imports.Contains(type))
            {
                result = type.Substring(type.LastIndexOf(StringHelper.Dot) + 1);
            }
            else if (type.EndsWith("[]"))
            {
                result = ShortenType(type.Substring(0, (type.Length - 2) - (0)), imports) + "[]";
            }
            else if (type.StartsWith("java.lang."))
            {
                result = type.Substring("java.lang.".Length);
            }

            return result;
        }
Exemplo n.º 5
0
 public virtual string FieldsAsParameters(SupportClass.ListCollectionSupport fieldslist, ClassMapping classMapping,
     IDictionary class2classmap)
 {
     StringBuilder buf = new StringBuilder();
     bool first = true;
     for (IEnumerator fields = fieldslist.GetEnumerator(); fields.MoveNext();)
     {
         if (first)
             first = false;
         else
             buf.Append(", ");
         FieldProperty field = (FieldProperty) fields.Current;
         buf.Append(ShortenType(field.FullyQualifiedTypeName, classMapping.Imports) + " " + field.fieldcase);
     }
     return buf.ToString();
 }
Exemplo n.º 6
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;
        }
Exemplo n.º 7
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();
            }
        }
Exemplo n.º 8
0
 protected internal virtual string MakeSupportField(string fieldName, SupportClass.ListCollectionSupport fieldList)
 {
     string suffix = "";
     bool needSuffix = false;
     for (IEnumerator fields = fieldList.GetEnumerator(); fields.MoveNext();)
     {
         string name = ((FieldProperty) fields.Current).FieldName;
         if (name.Equals(fieldName))
             needSuffix = true;
         suffix += name;
     }
     return needSuffix ? fieldName + "_" + suffix : fieldName;
 }
Exemplo n.º 9
0
 protected internal virtual void InitWith(string name, ClassName type, ClassName implementationClassName, bool nullable,
     bool id, bool generated, ClassName foreignClass,
     SupportClass.SetSupport foreignKeys, MultiMap metaattribs)
 {
     this.fieldName = name;
     Type = type;
     this.nullable = nullable;
     this.id = id;
     this.generated = generated;
     this.implementationClassName = implementationClassName;
     this.accessorName = BeanCapitalize(name);
     this.foreignClass = foreignClass;
     this.foreignKeys = foreignKeys;
     MetaAttribs = metaattribs;
     if (fieldName.Substring(0, 1) == fieldName.Substring(0, 1).ToLower())
         log.Warn("Nonstandard naming convention found on " + fieldName);
 }
 internal static bool GetMetaAsBool(SupportClass.ListCollectionSupport c, bool defaultValue)
 {
     if (c == null || c.IsEmpty())
     {
         return defaultValue;
     }
     else
     {
         try
         {
             //return System.Boolean.Parse(c.GetEnumerator().Current.ToString());
             return Convert.ToBoolean(c[0].ToString());
         }
         catch
         {
         }
         return defaultValue;
     }
 }
 internal static string GetMetaAsString(SupportClass.ListCollectionSupport c)
 {
     if (c == null || c.IsEmpty())
     {
         return string.Empty;
     }
     else
     {
         StringBuilder sb = new StringBuilder();
         for (IEnumerator iter = c.GetEnumerator(); iter.MoveNext();)
         {
             Object element = iter.Current;
             sb.Append(element.ToString());
         }
         return sb.ToString();
     }
 }