source: java/main/src/main/java/com/framsticks/examples/GenotypeBrowser.java @ 85

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

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

File size: 2.1 KB
Line 
1package com.framsticks.examples;
2
3import com.framsticks.core.Instance;
4import com.framsticks.core.Node;
5import com.framsticks.dumping.PrintWriterSink;
6import com.framsticks.model.*;
7import com.framsticks.model.Package;
8import com.framsticks.params.*;
9import com.framsticks.parsers.F0Parser;
10import com.framsticks.parsers.F0Writer;
11import com.framsticks.parsers.Schema;
12
13import org.apache.commons.configuration.Configuration;
14import org.apache.log4j.Logger;
15
16import java.io.PrintWriter;
17import java.io.StringWriter;
18import java.util.List;
19
20/**
21 * Author: Piotr Śniegowski
22 */
23public class GenotypeBrowser extends Instance {
24
25        private static final Logger log = Logger
26                        .getLogger(Instance.class.getName());
27        protected Schema schema;
28
29        public GenotypeBrowser() {
30                log.info("model builder created");
31        }
32
33        @Override
34        public void configure(Configuration config) {
35                super.configure(config);
36                try {
37                        schema = new Schema(Schema.getDefaultDefinitionAsStream());
38                } catch (Exception e) {
39                        log.error("failed to load schema: " + e);
40                }
41                this.registry = schema.getRegistry();
42                Package.register(this.getRegistry());
43
44                registry.putInfoIntoCache(new FramsClass("ModelBuilderRoot", "ModelBuilderRoot", null)
45                                .append(Param.build().type("o Model").id("model").name("model"))
46                                .append(Param.build().type("s 1").id("genotype").name("genotype"))
47                );
48                root = new Node((CompositeParam)Param.build().type("o ModelBuilderRoot").id(name).name("Instance").finish(), PropertiesAccess.createPropertiesMap());
49        }
50
51        @Override
52        protected void run() {
53                assert isActive();
54
55                try {
56                        List<AccessInterface> accesses = new F0Parser(schema, GenotypeBrowser.class.getResourceAsStream("/examples/f0_example.txt")).parse();
57                        List<Object> objects = Util.stripAccessInterface(accesses);
58                        Model model = Model.build(objects);
59
60                        AccessInterface rootAccess = bindAccess(this.getRootPath());
61
62                        rootAccess.set("model", model);
63
64                        StringWriter w = new StringWriter();
65                        new F0Writer(schema, model, new PrintWriterSink(new PrintWriter(w))).write();
66                        rootAccess.set("genotype", w.getBuffer().toString());
67
68                } catch (Exception e) {
69                        log.error("exception caught: " + e);
70                }
71                //done();
72        }
73
74}
Note: See TracBrowser for help on using the repository browser.