Projekt

Obecné

Profil

Stáhnout (3.23 KB) Statistiky
| Větev: | Tag: | Revize:
1
package jdeserialize;
2

    
3
import java.util.*;
4

    
5
/**
6
 * Represents an instance of a non-enum, non-Class, non-ObjectStreamClass,
7
 * non-array class, including the non-transient field values, for all classes in
8
 * its hierarchy and inner classes.
9
 */
10
public class instance extends contentbase {
11
    /**
12
     * Collection of field data, organized by class description.
13
     */
14
    public Map<classdesc, Map<field, Object>> fielddata;
15

    
16
    /**
17
     * Class description for this instance.
18
     */
19
    public classdesc classdesc;
20

    
21
    /**
22
     * Constructor.
23
     */
24
    public instance() {
25
        super(contenttype.INSTANCE);
26
        this.fielddata = new HashMap<classdesc, Map<field, Object>>();
27
    }
28

    
29
    public @Override String toJson(String indentation, Map<classdesc, Map<field, Object>> fielddata)
30
    {
31
        StringBuffer sb = new StringBuffer();
32
        String val = "";
33
        
34
        indentation += "\t";
35

    
36
        // ClassName
37
        sb.append("{\n").append(indentation).append("class ").append(classdesc.name);
38
        // extends
39
        if (classdesc.superclass != null) {
40
            sb.append(" extends ").append(classdesc.superclass.name);
41
        }
42
        // implements
43
        if (classdesc.interfaces != null) {
44
            sb.append(" implements ");
45
            for (String str : classdesc.interfaces) {
46
                sb.append(str);
47
            }
48
        }
49
        sb.append(" : {"); // ending of first line
50
        
51
        indentation += "\t";
52

    
53
        for (field f : classdesc.fields) {
54
            // v this.fielddata najit element, jehoz key == classdesc
55
            // v tomto prvku fielddata najdu value (element) podle key == f
56
            // jeho value je chtena hodnota
57
            var locVal = this.fielddata.get(classdesc).get(f);
58

    
59
            if(locVal instanceof content)
60
            {
61
                val = ((content)locVal).toJson(indentation, this.fielddata);
62
            }
63
            else {
64
                val = locVal.toString();
65
            }
66

    
67
            sb.append("\n").append(indentation);
68
            sb.append("\"").append(f.name).append("\"");
69
            sb.append(" : ");
70
            sb.append(val);
71

    
72
            if (!f.equals(classdesc.fields[classdesc.fields.length - 1])) {
73
                sb.append(", ");
74
            }
75
        }
76
        indentation = indentation.substring(0, indentation.length() - 1);
77

    
78
        sb.append("\n").append(indentation).append("}");
79
        
80

    
81
        if(classdesc.superclass != null)
82
        {
83
            sb.append(",\n");
84
            sb.append(classdesc.superclass.toJson(indentation, this.fielddata));
85
        }
86
        
87
        indentation = indentation.substring(0, indentation.length() - 1);
88
        sb.append(indentation).append("\n}");
89

    
90
        return sb.toString();
91
    }
92

    
93
    public String toString() {
94
        StringBuffer sb = new StringBuffer();
95
        sb.append(classdesc.name).append(' ').append("_h").append(jdeserialize.hex(handle))
96
            .append(" = r_").append(jdeserialize.hex(classdesc.handle)).append(";  ");
97
        //sb.append("// [instance " + jdeserialize.hex(handle) + ": " + jdeserialize.hex(classdesc.handle) + "/" + classdesc.name).append("]");
98
        return sb.toString();
99
    }
100

    
101
    /**
102
     * Object annotation data.
103
     */
104
    public Map<classdesc, List<content>> annotations;
105
}
(18-18/20)