source: java/main/src/main/java/com/framsticks/params/Registry.java @ 90

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

HIGHLIGHTS:

CHANGELOG:
Make ProcedureParam? hold only ValueParams?.

Use id instead of names when naming gui components internally.

Basic procedure calling in GUI.

The actual procedure call is currently only backed
by the ObjectInstance?.

Add UnimplementedException?.

Improve naming of various gui elements.

Allow easy navigating in FEST Swing testing.

Add optional explicit order attribute to FramsClassAnnotation?.

That's because java reflection does return declared members
in any specific order. That ordering is needed only for
classes that have no representation in framsticks and need
a deterministic ordering of params.

Add ControlOwner? interface.

Add test for procedure calling in Browser.

First version of ParamAnnotation? for procedures.

Development of ProcedureParam?.

Add draft version of ProcedureParam? implementation in ReflectionAccess?.

Allow viewing FramsClasses? in gui Browser.

Extract ResourceBuilder? from ModelBuilder?.

Remove internalId from Param.

It was currently completely not utilised. Whether it is still needed
after introduction of ParamAnnotation? is arguable.

Add remaining param attributes to ParamAnnotation?.

Change AutoBuilder? semantics.

AutoBuilder? returns list of objects that are to be appended
with methods @AutoAppendAnnotation?.

This allows to omit explicit addition of ModelPackage? to instance
if the instance uses ModelBuilder? (registration of ModelPackage? comes
from schema).

Fix params ordering problem in auto created FramsClasses?.

Improve ObjectInstance?.

Several fixes to ModelBuilder?.

Improve test for ObjectInstance? in Browser.

Make initialization of robot static.

With robot recreated for second browser test, the test hanged
deep in AWT.

Add base convenience base test for Browser tests.

More tests to ObjectInstance?.

Rename Dispatcher.invokeLater() to dispatch().

Add assertDispatch.

It allows assertions in other threads, than TestNGInvoker.
Assertions are gathered after each method invocation and rethrown.

Use timeOut annotation attribute for tests involving some waiting.

Remove firstTask method (merge with joinableStart).

Clean up leftovers.

Remove unused FavouritesXMLFactory (the reading part is already
completely done with generic XmlLoader?, and writing part will be done
based on the same approach if needed).
Move UserFavourite? to the com.framsticks.gui.configuration package.

Remove GenotypeBrowser? as to specific.

This functionality will be available in ObjectInstance?.

Add interface ParamsPackage?.

Package containing registration of Java classes meant to use with
ReflectionAccess? may be in Instance using configuration.

Minor changes.

Make Group immutable.

Add AutoBuilder? interface extending Builder - only those would
be used to automatically build from XML.

Fix groups in FramsClass?.

Minor naming cleanup in Registry.

Add ModelComponent? interface.

All class creating the Model are implementing that interface.

Extract Model.build into ModelBuilder?.

ModelBuilder? will be compatible with other builders
and allow using it from configuration.

Fix NeuroConnection?.

Add synchronous get operation for dispatchers.

Rename JoinableMonitor? to Monitor.

Add ObjectInstance?.

This class is mainly for demonstration
and testing purposes.

Improve FramsServer? runner.

  • improve ExternalProcess? runner,
  • runner can kill the server but also react properly, when the server exists on it's own,
  • set default path to search for framsticks server installation,
  • add LoggingOutputListener?.
File size: 4.2 KB
Line 
1package com.framsticks.params;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.params.annotations.FramsClassAnnotation;
6import com.framsticks.params.annotations.ParamAnnotation;
7import com.framsticks.util.DoubleMap;
8import com.framsticks.util.FramsticksException;
9
10import java.util.HashMap;
11import java.util.Map;
12import java.util.Set;
13
14import javax.annotation.Nonnull;
15
16/**
17 * Author: Piotr Śniegowski
18 */
19@FramsClassAnnotation
20public class Registry {
21        private static final Logger log = Logger.getLogger(Registry.class.getName());
22
23        protected final DoubleMap<String, Class<?>> javaClasses = new DoubleMap<>();
24        protected final DoubleMap<String, FramsClass> framsClasses = new DoubleMap<>();
25        protected final Map<Class<?>, FramsClass> javaToFramsAssociation = new HashMap<>();
26
27        /**
28         *
29         */
30        public Registry() {
31                // registerAndBuild(Registry.class);
32                // registerAndBuild(FramsClass.class);
33                // registerAndBuild(Param.class);
34        }
35
36        public void registerReflectedClass(String name, String id, Class<?> javaClass) {
37                javaClasses.put(id, name, javaClass);
38        }
39
40        public void associate(Class<?> javaClass, FramsClass framsClass) {
41                javaToFramsAssociation.put(javaClass, framsClass);
42        }
43
44        public Registry registerAndBuild(Class<?> javaClass) {
45                register(javaClass);
46                associate(javaClass, putFramsClass(FramsClass.build().forClass(javaClass)));
47                return this;
48        }
49
50        public Registry register(Class<?> javaClass) {
51                FramsClassAnnotation a = javaClass.getAnnotation(FramsClassAnnotation.class);
52                if (a == null) {
53                        throw new FramsticksException().msg("class is not annotated").arg("class", javaClass);
54                }
55
56                registerReflectedClass(FramsClassBuilder.getName(a, javaClass), FramsClassBuilder.getId(a, javaClass), javaClass);
57                return this;
58        }
59
60        public @Nonnull ReflectionAccess createAccess(Class<?> javaClass) throws ConstructionException {
61                try {
62                        if (!javaClasses.containsValue(javaClass)) {
63                                throw new FramsticksException().msg("java class is not registered");
64                        }
65                        if (!javaToFramsAssociation.containsKey(javaClass)) {
66                                throw new FramsticksException().msg("java class is not associated with any frams class");
67                        }
68                        return new ReflectionAccess(javaClass, javaToFramsAssociation.get(javaClass));
69                }
70                catch (FramsticksException e) {
71                        throw new FramsticksException().msg("failed to create access for java class").arg("class", javaClass).cause(e);
72                }
73        }
74
75        public @Nonnull AccessInterface createAccess(String name, FramsClass framsClass) throws ConstructionException {
76                // assert framsClasses.containsValue(framsClass);
77                if (javaClasses.containsKey(name)) {
78                        return new ReflectionAccess(javaClasses.get(name), framsClass);
79                }
80                return new PropertiesAccess(framsClass);
81        }
82
83        public FramsClass putFramsClass(FramsClass framsClass) {
84                log.debug("caching info for " + framsClass);
85                framsClasses.put(framsClass.getId(), framsClass.getName(), framsClass);
86                return framsClass;
87        }
88
89        public FramsClass getFramsClass(@Nonnull String identifier) {
90                return framsClasses.get(identifier);
91        }
92
93        public static @Nonnull AccessInterface wrapAccessWithListIfNeeded(@Nonnull CompositeParam param, @Nonnull AccessInterface access) {
94                return param.prepareAccessInterface(access);
95        }
96
97        public @Nonnull AccessInterface prepareAccess(CompositeParam param) throws ConstructionException {
98                return wrapAccessWithListIfNeeded(param, createAccess(param.getContainedTypeName()));
99        }
100
101        public @Nonnull AccessInterface createAccess(@Nonnull String name) throws ConstructionException {
102                try {
103                        FramsClass framsClass = getFramsClass(name);
104                        if (framsClass == null) {
105                                throw new ConstructionException().msg("framsclass is missing");
106                        }
107
108                        return createAccess(name, framsClass);
109                }
110                catch (FramsticksException e) {
111                        throw new FramsticksException().msg("failed to create access for name").arg("name", name).cause(e);
112                }
113        }
114
115        public Set<Class<?>> getReflectedClasses() {
116                return javaClasses.getValues();
117        }
118
119        public Set<FramsClass> getFramsClasses() {
120                return framsClasses.getValues();
121        }
122
123        @ParamAnnotation
124        public Map<String, FramsClass> getFramsClassesById() {
125                return framsClasses.getValuesById();
126        }
127
128        public void takeAllFrom(Registry source) {
129                for (Class<?> javaClass : source.getReflectedClasses()) {
130                        register(javaClass);
131                }
132                for (FramsClass framsClass : source.getFramsClasses()) {
133                        putFramsClass(framsClass);
134                }
135
136        }
137
138}
Note: See TracBrowser for help on using the repository browser.