source: java/main/src/main/java/com/framsticks/parsers/F0Writer.java @ 88

Last change on this file since 88 was 88, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • loading f0 schema with XmlLoader?
  • use XmlLoader? to load configuration
  • introduce unified fork-join model of various entities

(Instances, Connections, GUI Frames, etc.),
all those entities clean up gracefully on
shutdown, which may be initialized by user
or by some entity

  • basing on above, simplify several organizing classes

(Observer, main class)

(to host native frams server process from Java level)

CHANGELOG:
Remove redundant Observer class.

Clean up in AbstractJoinable?.

Update ExternalProcess? class to changes in joining model.

Another sweep through code with FindBugs?.

Find bug with not joining RemoteInstance?.

Joining almost works.

Much improved joining model.

More improvement to joining model.

Add logging messages around joinable operations.

Rename methods in AbstractJoinable?.

Improve Joinable.

Rewrite of entity structure.

More simplifications with entities.

Further improve joinables.

Let Frame compose from JFrame instead of inheriting.

Add join classes.

Improvements of closing.

Add Builder interface.

Add FramsServerTest?.xml

FramsServer? may be configured through xml.

Make Framsticks main class an Observer of Entities.

Make Observer a generic type.

Remove variables regarding to removed endpoint.

Simplify observer (remove endpoints).

More changes to Observer and Endpoint.

Minor improvements.

Add OutputListener? to ExternalProcess?.

Improve testing of ExternalProcess?.

Add ExternalProcess? runner.

Rename the Program class to Framsticks.

Migrate Program to use XmlLoader? configuration.

First steps with configuration using XmlLoader?.

Fix several bugs.

Move all f0 classes to apriopriate package.

XmlLoader? is able to load Schema.

XmlLoader? is loading classes and props.

Add GroupBuilder?.

File size: 2.3 KB
Line 
1package com.framsticks.parsers;
2
3import com.framsticks.model.Model;
4import com.framsticks.model.f0.Schema;
5import com.framsticks.params.*;
6import com.framsticks.util.Misc;
7import com.framsticks.util.lang.Containers;
8import static com.framsticks.util.lang.Containers.filterInstanceof;
9
10/**
11 * Author: Piotr Śniegowski
12 */
13public class F0Writer {
14
15        protected final Schema schema;
16        protected final SinkInterface sink;
17        protected final Model model;
18        protected boolean omitDefaults = true;
19
20        public F0Writer(Schema schema, Model model, SinkInterface sink) {
21                this.schema = schema;
22                this.model = model;
23                this.sink = sink;
24        }
25
26        public F0Writer setOmitDefaults(boolean omitDefaults) {
27                this.omitDefaults = omitDefaults;
28                return this;
29        }
30
31        protected void write(AccessInterface access) {
32                if (access instanceof ListAccess) {
33                        // TODO
34                        for (ValueParam p : Containers.filterInstanceof(access.getParams(), ValueParam.class)) {
35                                write(schema.getRegistry().prepareAccess((CompositeParam) p).select(access.get(p, Object.class)));
36                        }
37                        return;
38                }
39                StringBuilder line = new StringBuilder();
40                line.append(access.getId()).append(":");
41                boolean placeComma = false;
42                boolean contiguous = true;
43
44                for (ValueParam param : filterInstanceof(access.getParams(), ValueParam.class)) {
45                        if (param instanceof CompositeParam) {
46                                AccessInterface a = schema.getRegistry().prepareAccess((CompositeParam)param);
47                                a.select(access.get((ValueParam) param, Object.class));
48                                write(a);
49                                continue;
50                        }
51                        Object value = access.get(param, Object.class);
52                        if (omitDefaults && (param instanceof PrimitiveParam) && Misc.equals(value, ((PrimitiveParam<?>) param).getDef(Object.class))) {
53                                contiguous = false;
54                                continue;
55                        }
56                        if (value == null) {
57                                contiguous = false;
58                                continue;
59                        }
60
61                        if (placeComma) {
62                                line.append(",");
63                        } else {
64                                placeComma = true;
65                        }
66
67                        if ((!contiguous) || ((param.getFlags() & Flags.CANOMITNAME) == 0)) {
68                                line.append(param.getId()).append("=");
69                                contiguous = true;
70                        }
71                        String printed = value.toString().replace("\"", "\\\"");
72                        if (printed.contains(",")) {
73                                line.append("\"").append(printed).append("\"");
74                        } else {
75                                line.append(value);
76                        }
77                }
78                sink.print(line).breakLine();
79        }
80        public void write() {
81                AccessInterface access = schema.getRegistry().createAccess("m");
82                access.select(model);
83                write(access);
84        }
85
86
87}
Note: See TracBrowser for help on using the repository browser.