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

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

HIGHLIGHTS:

  • add <include/> to configuration
  • add side notes to tree
    • used to store arbitrary information alongside the tree structure
  • migrate to log4j2
    • supports lazy string evaluation of passed arguments
  • improve GUI tree
    • it stays in synchronization with actual state (even in high load test scenario)
  • improve panel management in GUI
  • make loading objects in GUI more lazy
  • offload parsing to connection receiver thread
    • info parsing
    • first step of objects parsing
  • fix connection parsing bug (eof in long values)
  • support zero-arguments procedure in table view

CHANGELOG:
Implement procedure calls from table view.

Refactorization around procedures in tables.

Add table editor for buttons.

Render buttons in the the list view.

Further improve Columns.

Add Column class for TableModel?.

Accept also non-arguments ProcedureParams? in tableView.

Increase maximal TextAreaControl? size.

Add tooltip to ProcedureControl?.

Fix bug of interpreting eofs in long values by connection reader.

Further rework connection parsing.

Simplify client connection processing.

Test ListChange? modification.

Test ListChange? events with java server.

Add TestChild?.

Fix bug with fast deregistering when connecting to running server.

Another minor refactorization in TreeOperations?.

Fix bug in SimpleAbstractAccess? loading routine.

Another minor improvement.

Minor change.

Make reading of List objects two-phase.

Another minor change.

Dispatch parsing into receiver thread.

Another step.

Enclose passing value in ObjectParam? case in closure.

Minor step.

Minor change on way to offload parsing.

Temporarily comment out single ValueParam? get.

It will be generalized to multi ValueParam?.

Process info in receiver thread.

Add DispatchingExceptionHandler?.

Make waits in browser test longer.

Use FETCHED_MARK.

It is honored in GUI, where it used to decide whether to get values

after user action.

It is set in standard algorithm for processing fetched values.

Add remove operation to side notes.

Make loading more lazy.

Improve loading policy.

On node choose load itself, on node expansion, load children.

Minor improvement.

Fix bug with panel interleaving.

Minor improvements.

Improve panel management.

More cleaning around panels.

Reorganize panels.

Further improve tree.

Fix bug in TreeModel?.

Remove children from TreeNode?.

Implement TreeNode? hashCode and equals.

Make TreeNode? delegate equals and hashcode to internal reference.

Move listeners from TreeNode? to side notes.

Store path.textual as a side note.

Side note params instead of accesses for objects.

More refactorizations.

In TreeNode? bindAccess based on side notes.

Minor step.

Hide createAccess.

Rename AccessInterface? to Access.

Minor changes.

Several improvements in high load scenarios.

Change semantics of ArrayListAccess?.set(index, null);

It now removes the element, making list shorter
(it was set to null before).

Add path remove handler.

Handle exceptions in Connection.

Update .gitignore

Configure logging to file.

Move registration to TreeModel?.

Further refactorization.

Minor refactorization.

Minor improvements.

Use specialized event also for Modify action of ListChange?.

Use remove events.

Use the insertion events for tree.

Further improve tree refreshing.

Further improve reacting on events in GUI.

Fix problem with not adding objects on addition list change.

Migrate to log4j lazy String construction interface.

Migrate imports to log4j2.

Drop dependency on adapter to version 1.2.

Switch log4j implementation to log4j2.

Add dirty mark to the NodeAtFrame?.

Make selecting in AccessInterfaces? type safe.

Ignore containers size settings in Model and Genotype.

Use tree side notes to remember local changes and panels.

Add sideNotes to tree.

They will be used to store various accompanying information
right in the tree.

Use ReferenceIdentityMap? from apache in TreeNode?.

It suits the need perfectly (weak semantics on both key and value).

Make ArrayListParam? do not react size changes.

Guard in TableModel? before not yet loaded objects.

Add <include/> clause and AutoInjector?.

Extract common columns configuration to separate xml,
that can be included by other configurations.

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