source: java/main/src/main/java/com/framsticks/communication/Request.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.0 KB
Line 
1package com.framsticks.communication;
2
3import java.util.regex.Matcher;
4import java.util.regex.Pattern;
5
6import com.framsticks.communication.queries.*;
7import com.framsticks.util.FramsticksException;
8import com.framsticks.util.lang.Pair;
9
10/**
11 * Class stores information about query sent to manager.
12 */
13public abstract class Request {
14
15        public abstract String getCommand();
16
17        protected abstract StringBuilder construct(StringBuilder buffer);
18
19
20
21
22        public static void quoteValue(StringBuilder builder, String value) {
23                String quote = ((value.indexOf(' ') > 0) || (value.length() == 0) ? "\"" : "");
24                builder.append(quote).append(value).append(quote);
25        }
26
27        public static Request parse(CharSequence type, CharSequence rest) {
28                final Request request = Request.createRequestByTypeString(type.toString());
29                request.parseRest(rest);
30                return request;
31        }
32
33        public static Request createRequestByTypeString(String type) {
34                switch (type) {
35                        case "get": return new GetRequest();
36                        case "set": return new SetRequest();
37                        case "info": return new InfoRequest();
38                        case "call": return new CallRequest();
39                        case "reg": return new RegistrationRequest();
40                        case "use": return new UseRequest();
41                        case "version": return new VersionRequest();
42                }
43                throw new FramsticksException().msg("unknown request type").arg("type", type);
44        }
45
46        public abstract CharSequence parseRest(CharSequence rest);
47
48        @Override
49        public String toString() {
50                // return getCommand();
51                return "request " + stringRepresentation();
52        }
53
54        public String stringRepresentation() {
55                return construct(new StringBuilder().append(getCommand()).append(" ")).toString();
56        }
57
58        public static final Pattern EVENT_PATTERN = Pattern.compile("^\\s*(\\S+)\\s*(\\S+)");
59
60        public static final Pattern STRING_BREAKER_PATTERN = Pattern.compile("^\\s*(?:(?:\\\"([^\"]*)\\\")|([^ ]+))\\s*(.*)$");
61        public static final Pattern IDENTIFIER_BREAKER_PATTERN = Pattern.compile("^\\s*([^ ]+)\\s*(.*)$");
62
63        // public static Matcher match(Pattern pattern, CharSequence line) {
64        //      Matcher matcher = pattern.matcher(line);
65        //      if (!matcher.matches()) {
66        //              return null;
67        //              // throw new FramsticksException().msg("failed to take").arg("pattern", pattern).arg("line", line);
68        //      }
69        //      return matcher;
70        // }
71
72        public static Pair<CharSequence, CharSequence> takeIdentifier(CharSequence line) {
73                Matcher matcher = IDENTIFIER_BREAKER_PATTERN.matcher(line);
74                if (!matcher.matches()) {
75                        return null;
76                }
77                return new Pair<CharSequence, CharSequence>(line.subSequence(matcher.start(1), matcher.end(1)), line.subSequence(matcher.start(2), matcher.end(2)));
78        }
79
80        public static CharSequence takeGroup(CharSequence input, Matcher matcher, int group) {
81                // return (matcher.start(group) == matcher.end(group)) ? null : input.subSequence(matcher.start(group), matcher.end(group));
82                return input.subSequence(matcher.start(group), matcher.end(group));
83        }
84
85        public static Pair<CharSequence, CharSequence> takeString(CharSequence line) {
86                Matcher matcher = STRING_BREAKER_PATTERN.matcher(line);
87                if (!matcher.matches()) {
88                        return null;
89                }
90                assert ((matcher.start(1) == -1) != (matcher.start(2) == -1));
91                return new Pair<CharSequence, CharSequence>(takeGroup(line, matcher, (matcher.start(1) != -1 ? 1 : 2)), takeGroup(line, matcher, 3));
92        }
93
94        protected static final Pattern REQUEST_ID_BREAKER_PATTERN = Pattern.compile("^\\s*([0-9]+)\\s*(.*)$");
95
96        protected final static Pair<Integer, CharSequence> takeRequestId(boolean withId, CharSequence line) {
97                if (withId) {
98                        Matcher matcher = REQUEST_ID_BREAKER_PATTERN.matcher(line);
99                        if (!matcher.matches()) {
100                                return null;
101                        }
102                        return new Pair<Integer, CharSequence>(Integer.valueOf(takeGroup(line, matcher, 1).toString()), takeGroup(line, matcher, 2));
103                }
104                return new Pair<Integer, CharSequence>(null, line);
105        }
106
107        public static StringBuilder quoteArgumentIfNeeded(StringBuilder builder, Object argument) {
108                String r = argument.toString();
109                if (r.indexOf(' ') != -1) {
110                        builder.append('"').append(r).append('"');
111                } else {
112                        builder.append(r);
113                }
114                return builder;
115        }
116
117}
Note: See TracBrowser for help on using the repository browser.