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

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

HIGHLIGTS:

  • complete events implementation
  • add CLI in Java Framsticks server
  • add automatic registration for events in GUI
  • improve objects fetching (object are never overwritten with new instances)
  • properly react for ListChange? events
  • add ListPanel? with table view
    • columns to be shown may be statically specified in configuration
    • currently modyfying data through tables is not available
  • improve maven configuration
    • configuration file may be specified without touching pom.xml

CHANGELOG:
Extract constants from Flags into ParamFlags? and SetStateFlags?.

Extract flags I/O to FlagsUtils? class.

Configured maven to exec given resource configuration.

For example:
mvn exec:exec -Dframsticks.config=/configs/managed-console.xml

Cleanup pom.xml

Rename ObjectTree? to LocalTree? (also make LocalTree? and RemoteTree? final).

Minor change.

Add maximum number of columns in ListPanelProvider?.

Improve ColumnsConfig? interpretation.

Automatically fill FramsClass?.name if trying to construct empty.

Improve identitifer case mangling in XmlLoader?.

Introduce configurable ColumnsConfig?.

Draft working version of ListPanel?.

Table is being shown (although empty).

More improvements to table building.

Move some functionality from Frame to TreeModel?.

Move tree classes in gui to separate package.

Remove old table related classes.

Add draft implementation of TableModel?.

Redirect ParamBuilder?.forAccess to AccessInterface?.

Optimize ParamBuilder?.forAccess()

Do not clear list when loading.

Do not load fetched values directly.

Implement different AccessInterface? copying policy.

Optimize fetching values routine.

Remove Mode enum (work out get semantics).

Some improvements to ListChange? handling.

Improve UniqueListAccess?.

Add reaction for ListChanges? in the TreeNode?.

EventListeners? are being added in the TreeNode?.

Listeners for ListParams? are now very naive (they download
whole list).

Automatially register on events in GUI.

Events are working in RemoteTree? and Server.

Move listeners to the ClientSideManagedConnection?.

Remove old classes responsible for event subscriptions.

Improve event reading.

Improve events handling at server side.

Add register attribute in FramsClassAnnotation?
to automatically also register other classes.

Registering events works.

Setup for remote listeners registration.

More improvements.

Minor changes.

Add rootTree to the ClientAtServer?.

Moving CLI to the ClientAtServer?.

Fix bug: use Void.TYPE instead of Void.class

More development around CLI.

  • Improve Path resolving.

Add synthetic root to ObjectTree?.

It is needed to allow sybling for the original root
that would containg CLI.

Some work with registering events in RemoteTree?.

Draft implementation of listener registering in RemoteTree?.

Support events registration in the ObjectTree?.

Add events support to ReflectionAccess?.

EventParam? is recognized by ParamCandidate?.

Prepare interface for Events across project.

Add EventListener? and API for listeners in Tree.

File size: 4.8 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                for (Class<?> r : javaClass.getAnnotation(FramsClassAnnotation.class).register()) {
49                        registerAndBuild(r);
50                }
51                return this;
52        }
53
54        public FramsClass registerReflectedIfNeeded(Class<?> javaClass) {
55                if (!javaToFramsAssociation.containsKey(javaClass)) {
56                        registerAndBuild(javaClass);
57                }
58                return javaToFramsAssociation.get(javaClass);
59        }
60
61        public Registry register(Class<?> javaClass) {
62                FramsClassAnnotation a = javaClass.getAnnotation(FramsClassAnnotation.class);
63                if (a == null) {
64                        throw new FramsticksException().msg("class is not annotated").arg("class", javaClass);
65                }
66
67                registerReflectedClass(FramsClassBuilder.getName(a, javaClass), FramsClassBuilder.getId(a, javaClass), javaClass);
68                return this;
69        }
70
71        public @Nonnull ReflectionAccess createAccess(Class<?> javaClass) throws ConstructionException {
72                try {
73                        if (!javaClasses.containsValue(javaClass)) {
74                                throw new FramsticksException().msg("java class is not registered");
75                        }
76                        if (!javaToFramsAssociation.containsKey(javaClass)) {
77                                throw new FramsticksException().msg("java class is not associated with any frams class");
78                        }
79                        return new ReflectionAccess(javaClass, javaToFramsAssociation.get(javaClass));
80                }
81                catch (FramsticksException e) {
82                        throw new FramsticksException().msg("failed to create access for java class").arg("class", javaClass).cause(e);
83                }
84        }
85
86        public @Nonnull AccessInterface createAccess(String name, FramsClass framsClass) throws ConstructionException {
87                // assert framsClasses.containsValue(framsClass);
88                if (javaClasses.containsKey(name)) {
89                        return new ReflectionAccess(javaClasses.get(name), framsClass);
90                }
91                return new PropertiesAccess(framsClass);
92        }
93
94        public FramsClass putFramsClass(FramsClass framsClass) {
95                log.debug("caching info for " + framsClass);
96                framsClasses.put(framsClass.getId(), framsClass.getName(), framsClass);
97                return framsClass;
98        }
99
100        public FramsClass getFramsClass(@Nonnull String identifier) {
101                return framsClasses.get(identifier);
102        }
103
104        public static @Nonnull AccessInterface wrapAccessWithListIfNeeded(@Nonnull CompositeParam param, @Nonnull AccessInterface access) {
105                return param.prepareAccessInterface(access);
106        }
107
108        public @Nonnull AccessInterface prepareAccess(CompositeParam param) throws ConstructionException {
109                return wrapAccessWithListIfNeeded(param, createAccess(param.getContainedTypeName()));
110        }
111
112        public @Nonnull AccessInterface createAccess(@Nonnull String name) throws ConstructionException {
113                try {
114                        Strings.assureNotEmpty(name);
115                        FramsClass framsClass = getFramsClass(name);
116                        if (framsClass == null) {
117                                throw new ConstructionException().msg("framsclass is missing");
118                        }
119
120                        return createAccess(name, framsClass);
121                }
122                catch (FramsticksException e) {
123                        throw new FramsticksException().msg("failed to create access for name").arg("name", name).cause(e);
124                }
125        }
126
127        public FramsClass getFramsClassForJavaClass(Class<?> javaClass) {
128                return javaToFramsAssociation.get(javaClass);
129        }
130
131        public Set<Class<?>> getReflectedClasses() {
132                return javaClasses.getValues();
133        }
134
135        public Set<FramsClass> getFramsClasses() {
136                return framsClasses.getValues();
137        }
138
139        @ParamAnnotation
140        public Map<String, FramsClass> getFramsClassesById() {
141                return framsClasses.getValuesById();
142        }
143
144        public void takeAllFrom(Registry source) {
145                for (Class<?> javaClass : source.getReflectedClasses()) {
146                        register(javaClass);
147                }
148                for (FramsClass framsClass : source.getFramsClasses()) {
149                        putFramsClass(framsClass);
150                }
151
152        }
153
154}
Note: See TracBrowser for help on using the repository browser.