source: java/main/src/main/java/com/framsticks/core/LocalTree.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.0 KB
RevLine 
[99]1package com.framsticks.core;
2
3import org.apache.log4j.Logger;
4
5import com.framsticks.params.AccessInterface;
6import com.framsticks.params.CompositeParam;
7import com.framsticks.params.EventListener;
8import com.framsticks.params.FramsClass;
9import com.framsticks.params.ParamBuilder;
10import com.framsticks.params.PrimitiveParam;
11import com.framsticks.params.ValueParam;
12import com.framsticks.params.annotations.AutoAppendAnnotation;
13import com.framsticks.params.annotations.FramsClassAnnotation;
14import com.framsticks.params.types.EventParam;
15import com.framsticks.params.types.ProcedureParam;
16import com.framsticks.util.FramsticksException;
17import com.framsticks.util.dispatching.Future;
18
19import static com.framsticks.core.TreeOperations.*;
20
21@FramsClassAnnotation
22public final class LocalTree extends AbstractTree {
23        private static final Logger log = Logger.getLogger(LocalTree.class);
24
25        protected Object rootObject;
26
27        /**
28         *
29         */
30        public LocalTree() {
31                super();
32
33        }
34
35        @AutoAppendAnnotation
36        public void setRootObject(Object object) {
37                final Class<?> javaClass = object.getClass();
38                registry.registerAndBuild(javaClass);
39
40                AccessInterface access = registry.createAccess(javaClass);
41
42                assignRootParam(access.buildParam(new ParamBuilder()).id(getName()).finish(CompositeParam.class));
43                assignRootObject(object);
44        }
45
46        public Object getRootObject() {
47                return getAssignedRoot().getObject();
48        }
49
50        public <T> T getRootObject(Class<T> type) {
51                Object result = getRootObject();
52                if (result == null) {
53                        throw new FramsticksException().msg("object tree is empty").arg("tree", this);
54                }
55                if (!type.isInstance(result)) {
56                        throw new FramsticksException().msg("object tree holds object of different kind").arg("object", result).arg("requested", type).arg("tree", this);
57                }
58                return type.cast(result);
59        }
60
61        @Override
62        public void get(Path path, Future<Path> future) {
63                assert isActive();
64                log.debug("requesting: " + path);
65                path = resolveTopSync(path);
66                future.pass(path);
67        }
68
69        @Override
70        public void get(Path path, ValueParam param, Future<Object> future) {
71                assert isActive();
72                path = resolveTopSync(path);
73                future.pass(bindAccess(path).get(param, Object.class));
74        }
75
76        @Override
77        public void call(Path path, ProcedureParam param, Object[] arguments, Future<Object> future) {
78                assert isActive();
79                try {
80                        future.pass(bindAccess(path).call(param, arguments));
81                } catch (FramsticksException e) {
82                        future.handle(e);
83                }
84        }
85
86        @Override
87        public void info(Path path, Future<FramsClass> future) {
88                assert isActive();
89                Path p = path.tryResolveIfNeeded();
90                Class<?> javaClass = p.getTopObject().getClass();
91                FramsClass framsClass = registry.registerReflectedIfNeeded(javaClass);
92                if (framsClass != null) {
93                        future.pass(framsClass);
94                } else {
95                        future.handle(new FramsticksException().msg("failed to find info for class").arg("java class", javaClass));
96                }
97        }
98
99        protected Path resolveTopSync(Path path) {
100                assert isActive();
101                assert path.isOwner(this);
102                if (path.getTop().getObject() != null) {
103                        return path;
104                }
105                AccessInterface access = bindAccess(path.getUnder());
106                Object object = access.get(path.getTop().getParam(), Object.class);
107                if (object == null) {
108                        throw new FramsticksException().msg("failed to resolve").arg("path", path);
109                }
110                return path.appendResolution(object);
111        }
112
113
114        @Override
115        public void set(Path path, PrimitiveParam<?> param, Object value, final Future<Integer> future) {
116                assert isActive();
117                future.pass(bindAccess(path).set(param, value));
118        }
119
120        public <A> void addListener(Path path, EventParam param, EventListener<A> listener, Class<A> argumentType, Future<Void> future) {
121                assert isActive();
122                try {
123                        bindAccess(path).reg(param, listener);
124                        future.pass(null);
125                } catch (FramsticksException e) {
126                        future.handle(e);
127                }
128        }
129
130        public void removeListener(Path path, EventParam param, EventListener<?> listener, Future<Void> future) {
131                assert isActive();
132                try {
133                        bindAccess(path).regRemove(param, listener);
134                        future.pass(null);
135                } catch (FramsticksException e) {
136                        future.handle(e);
137                }
138        }
139}
Note: See TracBrowser for help on using the repository browser.