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
RevLine 
[88]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;
[90]9import com.framsticks.params.annotations.ParamAnnotation;
10import com.framsticks.util.lang.Casting;
[88]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). */
[90]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<>();
[88]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
[97]37        private static Schema defaultSchema;
[88]38
[90]39        public synchronized static Schema getDefaultSchema() {
40                if (defaultSchema == null) {
41                        defaultSchema = new SchemaBuilder().stream(getDefaultDefinitionAsStream()).finish();
[88]42                }
[90]43                return defaultSchema;
[88]44        }
45
46        public Schema() {
47        }
48
[90]49        @AutoAppendAnnotation
[88]50        public void addClass(FramsClass framsClass) {
[90]51                registry.putFramsClass(framsClass);
[88]52                if (framsClass instanceof NeuroClass) {
[90]53                        neuroClasses.putFramsClass(framsClass);
[88]54                        return;
55                }
[90]56                framsClasses.putFramsClass(framsClass);
[88]57        }
58
59        @AutoAppendAnnotation
60        public void addClass(FramsClassBuilder builder) {
61                addClass(builder.finish());
62        }
63
[90]64        public Set<FramsClass> getNeuroClasses() {
65                return neuroClasses.getFramsClasses();
[88]66        }
67
68        public Set<FramsClass> getFramsClasses() {
[90]69                return framsClasses.getFramsClasses();
[88]70        }
71
72        public NeuroClass getNeuroClass(String identifier) {
[90]73                return Casting.throwCast(NeuroClass.class, neuroClasses.getFramsClass(identifier));
[88]74        }
75
76        public FramsClass getFramsClass(String identifier) {
[90]77                return framsClasses.getFramsClass(identifier);
[88]78        }
79
[90]80        @ParamAnnotation
[88]81        public final Registry getRegistry() {
82                return registry;
83        }
84
[90]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
[88]96}
Note: See TracBrowser for help on using the repository browser.