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

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

HIGHLIGHTS:

CHANGELOG:
Get data also on tree expansion.

Use nice framstick icon for empty nodes.

Update panel after reload if it is current.

Add shallow reload procedure.

Cut Gui prefix from several tree classes.

Bring back counter of GuiTreeNode?.

Use IdentityHashMap? were it is more appriopriate.

Remove TreeListener?.

Do not use TreeListener? in GUI.

Minor change.

Done migration to GuiTreeModel?.

BrowserTest? in that version always crashes frams.linux.

Move rendering implementation into GuiAbstractNode?.

Use hand-crafted list in GuiTreeNode?.

Generally, it would be a great place for WeakIdentityHashMap?
(but there is none in Java Collection Framework).

Remove superfluous logging.

Fix bug in GuiTreeNode?.

Use IdentityHashMap? instead of HashMap?.

Improve structure update.

Filter out invalid uids in UniqueListAccess?.

Improve TreeCellRenderer?.

Add filtering in TrackConsole?.

Improve TreeModel?.

More changes.

More improvements.

More changes.

Remove TreeNode?.

Support MetaNode? in the GuiTreeModel?.

Implement more in GuiTreeModel?.

Add CompositeParam? interface to FramsClass? and AccessInterface?.

Allow access by number to UniqueList?.

Add UidComparator?.

Use TreeMap? as a default accessee in unique list.

It keeps order of keys.

Introduce classes to use with new TreeModel?.

Another step.

Migrate from TreeNode? to Node in many places.

Remove some uses of TreeNode? as DefaultMutableTreeNode?.

Remove Path from TreeNode? interface.

Remove Path from TreeNode?.

Add Path recration from node feature.

Reworking TreeCellRenderer?.

Minor change of TreeOperations? interface.

Remove last methods from TreeNode?.

Another minor step.

Do not store reference to TreeAtFrame? in TreeNode?.

Add proxy exceptionHandler to StatusBar?.

Move panels management to TreeAtFrame?.

Store localChanges in the NodeAtFrame?.

More cleanup.

Move name computing to TreeCellRenderer?.

Move tooltip and icon computations to TreeCellRenderer?.

More dispatches removed.

Remove most dispatching from TreeNode?.

TreeNode? does not actually redispatch tasks.

Make Tree embedded in Browser use SwingDispatcher?.

Make lazy binding of Tree with Dispatcher.

Minor changes.

Organizational change in AbstractTree?.

Make AbstractTree? compose from Thread instead of inherit from it.

Make SwingDispatcher? and AtOnceDispatcher? Joinable compatible.

Add ListPanelProvider?.

Improve Controls readonly and enabled handling.

Properly pass ExceptionHandlers? in more places.

Make Tree.get accept ValueParam?.

  • This is to allow access number of list elements.

Remove not needed get redirection in ClientAtServer?.

Rename tryResolve to tryGet.

Unify tryResolveAndGet into tryResolve.

Remove resolveTop from Tree interface.

Make Tree.get accept Future<Path>.

Use get to implement resolveTop also in ObjectTree?.

Unify resolveTop and get in RemoteTree?.

Another minor step.

More minor changes in tree operations.

Minor organizational changes.

In RemoteTree? first fetch info for root.

Reworking resolving.

Minor changes.

Make ListAccess? return proxy iterators (instead of creating temporary collection).

Let AccessInterface? return Iterable<Param>.

Improve resolving.

More improvements.

First working completion in ManagedConsole?.

Rename resolve to resolveTop.

This reflects the actuall functionality.

Change semantic of tryResolve and tryResolveAndGet.

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