source: java/main/src/main/java/com/framsticks/model/f0/Schema.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1package com.framsticks.model.f0;
2
3import java.io.InputStream;
4import java.util.Set;
5
6import com.framsticks.params.*;
7import com.framsticks.params.annotations.AutoAppendAnnotation;
8import com.framsticks.params.annotations.FramsClassAnnotation;
9import com.framsticks.params.annotations.ParamAnnotation;
10import com.framsticks.util.lang.Casting;
11
12
13/**
14 * The Class Schema, which represent f0 schema (it contains all the possible
15 * classes definitions that can be used in f0 representation). Definitions are
16 * loaded from XML stream.
17 *
18 * @author Jarek Szymczak <name.surname@gmail.com>
19 * (please replace name and surname with my personal data)
20 */
21@FramsClassAnnotation(id = "f0classes", name = "f0classes")
22public class Schema {
23
24        protected final Registry registry = new Registry();
25
26        /** The neuro classes (classess representing different types of neurons). */
27        private final Registry framsClasses = new Registry();
28        private final Registry neuroClasses = new Registry();
29        // private DoubleMap<String, FramsClass> framsClasses = new DoubleMap<>();
30        // private DoubleMap<String, NeuroClass> neuroClasses = new DoubleMap<>();
31
32        public static InputStream getDefaultDefinitionAsStream() {
33                //return new FileInputStream(new File(Schema.class.getResource("/parsers/f0def.xml").getPath()));
34                return Schema.class.getResourceAsStream("/parsers/f0def.xml");
35        }
36
37        private static Schema defaultSchema;
38
39        public synchronized static Schema getDefaultSchema() {
40                if (defaultSchema == null) {
41                        defaultSchema = new SchemaBuilder().stream(getDefaultDefinitionAsStream()).finish();
42                }
43                return defaultSchema;
44        }
45
46        public Schema() {
47        }
48
49        @AutoAppendAnnotation
50        public void addClass(FramsClass framsClass) {
51                registry.putFramsClass(framsClass);
52                if (framsClass instanceof NeuroClass) {
53                        neuroClasses.putFramsClass(framsClass);
54                        return;
55                }
56                framsClasses.putFramsClass(framsClass);
57        }
58
59        @AutoAppendAnnotation
60        public void addClass(FramsClassBuilder builder) {
61                addClass(builder.finish());
62        }
63
64        public Set<FramsClass> getNeuroClasses() {
65                return neuroClasses.getFramsClasses();
66        }
67
68        public Set<FramsClass> getFramsClasses() {
69                return framsClasses.getFramsClasses();
70        }
71
72        public NeuroClass getNeuroClass(String identifier) {
73                return Casting.throwCast(NeuroClass.class, neuroClasses.getFramsClass(identifier));
74        }
75
76        public FramsClass getFramsClass(String identifier) {
77                return framsClasses.getFramsClass(identifier);
78        }
79
80        @ParamAnnotation
81        public final Registry getRegistry() {
82                return registry;
83        }
84
85        @ParamAnnotation
86        public final Registry getFramsRegistry() {
87                return framsClasses;
88        }
89
90        @ParamAnnotation
91        public final Registry getNeurosRegistry() {
92                return neuroClasses;
93        }
94
95
96}
Note: See TracBrowser for help on using the repository browser.