- Timestamp:
- 07/10/13 22:41:02 (11 years ago)
- Location:
- java/main
- Files:
-
- 27 added
- 20 deleted
- 71 edited
Legend:
- Unmodified
- Added
- Removed
-
java/main/pom.xml
r97 r99 17 17 <properties> 18 18 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 19 <framsticks.config>/configs/framsticks.xml</framsticks.config> 19 20 </properties> 20 21 … … 40 41 <scope>compile</scope> 41 42 </dependency> 42 <!-- <dependency> -->43 <!-- <groupId>commons-configuration</groupId> -->44 <!-- <artifactId>commons-configuration</artifactId> -->45 <!-- <version>1.9</version> -->46 <!-- <scope>compile</scope> -->47 <!-- </dependency> -->48 43 <dependency> 49 44 <groupId>commons-collections</groupId> … … 98 93 <scope>test</scope> 99 94 </dependency> 100 <!-- <dependency> -->101 <!-- <groupId>junit</groupId> -->102 <!-- <artifactId>junit</artifactId> -->103 <!-- <version>4.8.1</version> -->104 <!-- <scope>test</scope> -->105 <!-- </dependency> -->106 107 <!--dependency>108 </dependency>109 <dependency>110 </dependency-->111 95 </dependencies> 112 96 <build> … … 154 138 <classpath /> 155 139 <argument>com.framsticks.core.Framsticks</argument> 140 <argument>${framsticks.config}</argument> 156 141 </arguments> 157 142 </configuration> … … 169 154 </programs> 170 155 </configuration> 156 <executions> 157 <execution> 158 <phase>package</phase> 159 <goals> 160 <goal>assemble</goal> 161 </goals> 162 </execution> 163 </executions> 171 164 </plugin> 172 165 </plugins> -
java/main/src/main/java/com/framsticks/communication/ClientSideManagedConnection.java
r98 r99 2 2 3 3 import com.framsticks.communication.queries.ApplicationRequest; 4 import com.framsticks.communication.queries.CallRequest; 4 5 import com.framsticks.communication.queries.ProtocolRequest; 5 import com.framsticks.communication.queries.Regist rationRequest;6 import com.framsticks.communication.queries.RegisterRequest; 6 7 import com.framsticks.communication.queries.UseRequest; 7 8 import com.framsticks.communication.queries.VersionRequest; 8 import com.framsticks.co mmunication.util.LoggingStateCallback;9 import com.framsticks.core.Path; 9 10 import com.framsticks.params.ListSource; 10 11 import com.framsticks.util.*; … … 18 19 import com.framsticks.util.lang.Pair; 19 20 import com.framsticks.util.lang.Strings; 21 import com.framsticks.params.EventListener; 20 22 21 23 import org.apache.log4j.Logger; … … 32 34 private final static Logger log = Logger.getLogger(ClientSideManagedConnection.class); 33 35 34 protected final Map<String, Subscription<?>> subscriptions = new HashMap<>();35 36 36 private final List<Runnable> applicationRequestsBuffer = new LinkedList<>(); 37 37 private boolean isHandshakeDone = false; 38 38 39 39 40 /** … … 93 94 } 94 95 95 private static class EventFire extends InboundMessage { 96 public final Subscription<?> subscription; 97 98 private EventFire(Subscription<?> subscription) { 99 this.subscription = subscription; 100 } 101 102 public void startFile(String path) { 103 assert path == null; 104 initCurrentFile(null); 105 } 106 107 @Override 108 public void eof() { 109 finishCurrentFile(); 110 111 subscription.dispatchCall(getFiles()); 112 } 96 protected List<String> readFileContent() { 97 List<String> content = new LinkedList<String>(); 98 String line; 99 while (!(line = getLine()).startsWith("eof")) { 100 content.add(line); 101 } 102 return content; 113 103 } 114 104 … … 239 229 } 240 230 241 public <C> void subscribe(final String path, final Dispatcher<C> dispatcher, final SubscriptionCallback<? extends C> callback) {242 send(new RegistrationRequest().path(path), AtOnceDispatcher.getInstance(), new ClientSideResponseFuture(callback) {243 @Override244 protected void processOk(Response response) {245 assert response.getFiles().isEmpty();246 Subscription<C> subscription = new Subscription<C>(ClientSideManagedConnection.this, path, response.getComment(), dispatcher);247 log.debug("registered on event: " + subscription);248 synchronized (subscriptions) {249 subscriptions.put(subscription.getRegisteredPath(), subscription);250 }251 subscription.setEventCallback(callback.subscribed(subscription));252 if (subscription.getEventCallback() == null) {253 log.info("subscription for " + path + " aborted");254 subscription.unsubscribe(new LoggingStateCallback(log, "abort subscription"));255 }256 }257 });258 }259 231 260 232 private void sendQueryVersion(final int version, final Future<Void> future) { … … 322 294 Matcher matcher = Request.EVENT_PATTERN.matcher(rest); 323 295 if (!matcher.matches()) { 324 log.error("invalid event line: " + rest); 325 return; 326 } 327 Subscription<?> subscription = subscriptions.get(matcher.group(1)); 328 if (subscription == null) { 329 log.error("non subscribed event: " + matcher.group(1)); 330 return; 331 } 332 EventFire event = new EventFire(subscription); 333 event.startFile(null); 334 processMessage(event); 296 throw new FramsticksException().msg("invalid event line").arg("rest", rest); 297 } 298 String fileLine = getLine(); 299 if (!fileLine.equals("file")) { 300 throw new FramsticksException().msg("expected file line").arg("got", fileLine); 301 } 302 String eventObjectPath = Request.takeGroup(rest, matcher, 1).toString(); 303 String eventCalleePath = Request.takeGroup(rest, matcher, 2).toString(); 304 final File file = new File("", new ListSource(readFileContent())); 305 log.debug("firing event " + eventObjectPath); 306 EventListener<File> listener; 307 synchronized (registeredListeners) { 308 listener = registeredListeners.get(eventObjectPath); 309 } 310 if (listener == null) { 311 throw new FramsticksException().msg("failed to find registered event").arg("event path", eventObjectPath).arg("object", eventCalleePath); 312 } 313 listener.action(file); 335 314 } 336 315 … … 397 376 } 398 377 378 protected final Map<String, EventListener<File>> registeredListeners = new HashMap<>(); 379 380 public <C> void addListener(String path, final EventListener<File> listener, final Dispatcher<C> dispatcher, final Future<Void> future) { 381 send(new RegisterRequest().path(path), dispatcher, new ClientSideResponseFuture(future) { 382 @Override 383 protected void processOk(Response response) { 384 synchronized (registeredListeners) { 385 registeredListeners.put(Path.validateString(response.getComment()), listener); 386 } 387 future.pass(null); 388 } 389 }); 390 } 391 392 public <C> void removeListener(EventListener<File> listener, final Dispatcher<C> dispatcher, final Future<Void> future) { 393 String eventPath = null; 394 synchronized (registeredListeners) { 395 for (Map.Entry<String, EventListener<File>> e : registeredListeners.entrySet()) { 396 if (e.getValue() == listener) { 397 eventPath = e.getKey(); 398 break; 399 } 400 } 401 } 402 if (eventPath == null) { 403 future.handle(new FramsticksException().msg("listener is not registered").arg("listener", listener)); 404 return; 405 } 406 407 final String finalEventPath = eventPath; 408 //TODO add arguments to the exception 409 send(new CallRequest().procedure("remove").path(eventPath), dispatcher, new ClientSideResponseFuture(future) { 410 411 @Override 412 protected void processOk(Response response) { 413 synchronized (registeredListeners) { 414 registeredListeners.remove(finalEventPath); 415 } 416 future.pass(null); 417 } 418 }); 419 } 399 420 } -
java/main/src/main/java/com/framsticks/communication/Request.java
r98 r99 37 37 case "info": return new InfoRequest(); 38 38 case "call": return new CallRequest(); 39 case "reg": return new Regist rationRequest();39 case "reg": return new RegisterRequest(); 40 40 case "use": return new UseRequest(); 41 41 case "version": return new VersionRequest(); -
java/main/src/main/java/com/framsticks/communication/ServerSideManagedConnection.java
r98 r99 68 68 } 69 69 70 protected final void putFile(File file, String outId) { 71 putLine("file" + outId/* + " " + f.getPath()*/); 72 SourceInterface content = file.getContent(); 73 String line; 74 while ((line = content.readLine()) != null) { 75 putLine(line); 76 } 77 putLine("eof"); 78 } 79 80 public final void sendFile(final String header, final File file) { 81 senderThread.dispatch(new RunAt<Connection>(requestHandler) { 82 @Override 83 protected void runAt() { 84 putLine(header); 85 putFile(file, ""); 86 flushOut(); 87 } 88 }); 89 } 90 70 91 protected final void respond(final Response response, final Integer id) { 71 92 senderThread.dispatch(new RunAt<Connection>(requestHandler) { … … 75 96 if (response.getFiles() != null) { 76 97 for (File f : response.getFiles()) { 77 putLine("file" + outId/* + " " + f.getPath()*/); 78 SourceInterface content = f.getContent(); 79 String line; 80 while ((line = content.readLine()) != null) { 81 putLine(line); 82 } 83 putLine("eof"); 98 putFile(f, outId); 84 99 } 85 100 } … … 87 102 statusLine.append(response.getOk() ? "ok" : "error").append(outId); 88 103 if (Strings.notEmpty(response.getComment())) { 89 statusLine.append(" \"").append(response.getComment()).append('"');104 Request.quoteValue(statusLine.append(" "), response.getComment()); 90 105 } 91 106 putLine(statusLine.toString()); -
java/main/src/main/java/com/framsticks/communication/ServerSideResponseFuture.java
r97 r99 11 11 @Override 12 12 public final void handle(FramsticksException e) { 13 result(new Response(false, e.getClass().getCanonicalName() + ": " + e.getM sg(), null));13 result(new Response(false, e.getClass().getCanonicalName() + ": " + e.getMessage(), null)); 14 14 } 15 15 -
java/main/src/main/java/com/framsticks/communication/queries/ApplicationRequest.java
r96 r99 23 23 } 24 24 25 public String getActualPath() { 26 return path; 27 } 28 25 29 26 30 @Override -
java/main/src/main/java/com/framsticks/core/AbstractTree.java
r98 r99 32 32 public abstract class AbstractTree extends AbstractJoinable implements Dispatcher<Tree>, Tree, JoinableParent { 33 33 34 private static final Logger log = Logger.getLogger( Tree.class);34 private static final Logger log = Logger.getLogger(AbstractTree.class); 35 35 36 36 private Node root = null; … … 45 45 } 46 46 root = new Node(this, param, null); 47 log. info("assigned root type: " + root);47 log.debug("assigned root type: " + root); 48 48 } 49 49 … … 57 57 } 58 58 root = new Node(this, root.getParam(), object); 59 log. info("assigned root object: " + root);59 log.debug("assigned root object: " + root); 60 60 } 61 61 … … 177 177 } 178 178 179 /** 180 * @return the registry 181 */ 182 @Override 183 public Registry getRegistry() { 184 return registry; 185 } 186 179 187 @Override 180 188 protected void joinableStart() { -
java/main/src/main/java/com/framsticks/core/Framsticks.java
r97 r99 21 21 public Framsticks() { 22 22 PropertyConfigurator.configure(getClass().getResource("/configs/log4j.properties")); 23 24 // log.info("config is: " + System.getProperties().getProperty("framsticks.config", "/configs/framsticks.xml")); 23 25 } 24 26 -
java/main/src/main/java/com/framsticks/core/Path.java
r98 r99 6 6 import com.framsticks.util.FramsticksException; 7 7 import com.framsticks.util.dispatching.Dispatching; 8 import com.framsticks.util.dispatching.ExceptionResultHandler; 9 import com.framsticks.util.dispatching.IgnoreExceptionHandler; 10 import com.framsticks.util.lang.Pair; 8 11 9 12 import java.util.Iterator; 10 13 import java.util.LinkedList; 11 14 import java.util.List; 15 import java.util.regex.Pattern; 12 16 13 17 import javax.annotation.Nonnull; … … 27 31 final LinkedList<Node> nodes; 28 32 29 protected static Object getKnownChild(Tree tree, AccessInterface access, CompositeParam param ) {33 protected static Object getKnownChild(Tree tree, AccessInterface access, CompositeParam param, ExceptionResultHandler handler) { 30 34 Object child = access.get(param, Object.class); 31 35 if (child == null) { … … 36 40 return child; 37 41 } catch (FramsticksException e) { 42 handler.handle(e); 38 43 } 39 44 return null; … … 130 135 } 131 136 132 133 137 public PathBuilder resolve(@Nonnull Tree tree, String textual) { 138 return resolve(tree, textual, IgnoreExceptionHandler.getInstance()); 139 } 140 141 public PathBuilder resolve(@Nonnull Tree tree, String textual, ExceptionResultHandler handler) { 134 142 135 143 assert nodes.isEmpty(); … … 146 154 String e = i.next(); 147 155 Param p = access.getParam(e); 156 if (p == null) { 157 break; 158 } 148 159 if (!(p instanceof CompositeParam)) { 149 //entries.add(new Entry()); 150 break; 151 } 152 CompositeParam c = (CompositeParam)p; 160 throw new FramsticksException().msg("param is not a composite").arg("param", p).arg("tree", tree).arg("textual", textual).arg("access", access); 161 } 162 CompositeParam c = (CompositeParam) p; 153 163 b.append("/").append(e); 154 164 access.select(current.getObject()); 155 current = new Node(current.getTree(), c, getKnownChild(tree, access, c ));165 current = new Node(current.getTree(), c, getKnownChild(tree, access, c, handler)); 156 166 nodes.add(current); 157 167 } … … 245 255 return Path.build().resolve(tree, "/").finish(); 246 256 } 247 Object child = getKnownChild(tree, TreeOperations.bindAccess(getUnder()), getTop().getParam() );257 Object child = getKnownChild(tree, TreeOperations.bindAccess(getUnder()), getTop().getParam(), IgnoreExceptionHandler.getInstance()); 248 258 if (child == null) { 249 259 return this; … … 274 284 } 275 285 286 public static Path tryTo(@Nonnull Tree tree, String textual) { 287 return Path.build().resolve(tree, textual).finish(); 288 } 289 276 290 public static Path to(@Nonnull Tree tree, String textual) { 277 return Path.build().resolve(tree, textual).finish(); 291 Path path = tryTo(tree, textual); 292 if (path.getTextual().equals(textual)) { 293 return path; 294 } 295 throw new FramsticksException().msg("failed to create path").arg("textual", textual).arg("result", path).arg("tree", tree); 278 296 } 279 297 … … 299 317 } 300 318 319 public static final Pattern pathPattern = Pattern.compile("(\\/)|((\\/[^/]+)+)"); 320 321 public static boolean isValidString(String path) { 322 return pathPattern.matcher(path).matches(); 323 } 324 325 public static String appendString(String path, String element) { 326 if (path.equals("/")) { 327 return path + element; 328 } 329 return path + "/" + element; 330 } 331 332 public static Pair<String, String> removeLastElement(String path) { 333 assert isValidString(path); 334 if (path.equals("/")) { 335 throw new FramsticksException().msg("cannot remove last element from root path"); 336 } 337 int index = path.lastIndexOf('/'); 338 assert index != -1; 339 if (index == 0) { 340 return new Pair<String, String>("/", path.substring(1)); 341 } 342 return new Pair<String, String>(path.substring(0, index), path.substring(index + 1)); 343 } 344 345 public static String validateString(String path) { 346 if (!isValidString(path)) { 347 throw new FramsticksException().msg("path string validation failured").arg("path", path); 348 } 349 return path; 350 } 351 301 352 302 353 // public boolean isEmpty() { -
java/main/src/main/java/com/framsticks/core/Tree.java
r98 r99 5 5 import com.framsticks.params.AccessInterface; 6 6 import com.framsticks.params.CompositeParam; 7 import com.framsticks.params.EventListener; 7 8 import com.framsticks.params.FramsClass; 8 9 import com.framsticks.params.PrimitiveParam; 9 10 import com.framsticks.params.Registry; 10 11 import com.framsticks.params.ValueParam; 12 import com.framsticks.params.types.EventParam; 11 13 import com.framsticks.params.types.ProcedureParam; 12 14 import com.framsticks.util.dispatching.Dispatcher; … … 34 36 * 35 37 */ 36 public void get(Path path, ValueParam param, Mode mode,Future<Object> future);38 public void get(Path path, ValueParam param, Future<Object> future); 37 39 38 public void get(Path path, Mode mode,Future<Path> future);40 public void get(Path path, Future<Path> future); 39 41 40 42 public void call(Path path, ProcedureParam param, Object[] arguments, Future<Object> future); … … 57 59 public JoinableDispatcher<Tree> getDispatcher(); 58 60 61 public <A> void addListener(Path path, EventParam param, EventListener<A> listener, Class<A> argumentType, Future<Void> future); 62 63 public void removeListener(Path path, EventParam param, EventListener<?> listener, Future<Void> future); 64 65 public Registry getRegistry(); 66 59 67 } -
java/main/src/main/java/com/framsticks/core/TreeOperations.java
r98 r99 2 2 3 3 4 import java.util.HashSet; 4 5 import java.util.List; 6 import java.util.Set; 5 7 6 8 import javax.annotation.Nonnull; … … 10 12 import com.framsticks.communication.File; 11 13 import com.framsticks.params.AccessInterface; 12 import com.framsticks.params. CompositeParam;14 import com.framsticks.params.EventListener; 13 15 import com.framsticks.params.FramsClass; 14 16 import com.framsticks.params.ListAccess; 15 17 import com.framsticks.params.Param; 16 18 import com.framsticks.params.PrimitiveParam; 19 import com.framsticks.params.UniqueListAccess; 20 import com.framsticks.params.Util; 21 import com.framsticks.params.types.EventParam; 17 22 import com.framsticks.params.types.ObjectParam; 18 23 import com.framsticks.params.types.ProcedureParam; … … 73 78 74 79 ListAccess listAccess = (ListAccess) bindAccess(node); 75 listAccess.clearValues(); 80 81 Set<String> oldValuesIds = new HashSet<>(); 82 for (Param p : listAccess.getParams()) { 83 oldValuesIds.add(p.getId()); 84 } 85 86 // listAccess.clearValues(); 76 87 77 88 AccessInterface elementAccess = listAccess.getElementAccess(); 89 AccessInterface clonerInterface = elementAccess.cloneAccess(); 90 78 91 loader.addAccessInterface(elementAccess); 79 92 MultiParamLoader.Status status; 93 int number = 0; 80 94 while ((status = loader.go()) != MultiParamLoader.Status.Finished) { 81 95 if (status == MultiParamLoader.Status.AfterObject) { 82 96 AccessInterface accessInterface = loader.getLastAccessInterface(); 83 97 84 String id = listAccess.computeIdentifierFor(accessInterface.getSelected()); 85 //TODO listAccessParam 86 CompositeParam param = Param.build().forAccess(accessInterface).id(id).finish(CompositeParam.class); 87 Object child = accessInterface.getSelected(); 98 String id; 99 if (listAccess instanceof UniqueListAccess) { 100 id = ((UniqueListAccess) listAccess).computeIdentifierFor(accessInterface.getSelected()); 101 } else { 102 id = Integer.toString(number); 103 } 104 ++number; 105 106 Object childTo = listAccess.get(id, Object.class); 107 boolean newOne; 108 if (childTo == null) { 109 childTo = clonerInterface.createAccessee(); 110 newOne = true; 111 } else { 112 assert oldValuesIds.contains(id); 113 newOne = false; 114 } 115 oldValuesIds.remove(id); 116 clonerInterface.select(childTo); 117 Util.takeAllNonNullValues(clonerInterface, accessInterface); 118 if (newOne) { 119 listAccess.set(id, childTo); 120 } 121 122 // listAccess.set(id, accessInterface.getSelected()); 88 123 accessInterface.select(null); 89 assert child != null; 90 bindAccess(node).set(param, child); 124 91 125 } 126 } 127 /** It looks tricky for ArrayListAccess but should also work. 128 * 129 * They should be sorted. 130 */ 131 for (String id : oldValuesIds) { 132 listAccess.set(id, null); 92 133 } 93 134 … … 170 211 } 171 212 172 173 /** This might not be correct. */ 213 public static <A> void addListener(final Path path, final EventParam param, final EventListener<A> listener, final Class<A> argument, final Future<Void> future) { 214 final Tree tree = path.getTree(); 215 216 dispatchIfNotActive(tree, new RunAt<Tree>(future) { 217 @Override 218 protected void runAt() { 219 tree.addListener(path, param, listener, argument, future); 220 } 221 }); 222 } 223 224 public static void removeListener(final Path path, final EventParam param, final EventListener<?> listener, final Future<Void> future) { 225 final Tree tree = path.getTree(); 226 227 dispatchIfNotActive(tree, new RunAt<Tree>(future) { 228 @Override 229 protected void runAt() { 230 tree.removeListener(path, param, listener, future); 231 } 232 }); 233 } 234 235 236 /** 237 * 238 * If StackOverflow occurs in that loop in LocalTree it is probably caused 239 * the by the fact, that get operation may find the object, but Path resolution 240 * cannot. 241 * */ 174 242 public static void tryGet(final Tree tree, final String targetPath, final Future<Path> future) { 175 243 log.debug("resolve textual: " + targetPath + " for " + tree); … … 178 246 @Override 179 247 protected void runAt() { 180 final Path path = Path.to(tree, targetPath); 248 final Path path = Path.tryTo(tree, targetPath).tryResolveIfNeeded(); 249 log.debug("found: " + path); 181 250 if (path.isResolved()) { 182 251 future.pass(path); … … 184 253 } 185 254 186 tree.get(path, Mode.FETCH,new FutureHandler<Path>(future) {255 tree.get(path, new FutureHandler<Path>(future) { 187 256 @Override 188 257 protected void result(Path result) { 258 // if (result.isResolved(targetPath)) { 259 // future.pass(result); 260 // return; 261 // } 262 log.debug("retrying resolve textual: " + targetPath + " for " + tree + " with " + result); 189 263 tryGet(tree, targetPath, future); 190 264 } … … 198 272 return path.getTree().getInfoFromCache(path.getTop().getParam().getContainedTypeName()); 199 273 } 274 200 275 } -
java/main/src/main/java/com/framsticks/gui/Browser.java
r98 r99 4 4 import com.framsticks.gui.console.Console; 5 5 import com.framsticks.gui.console.TrackConsole; 6 import com.framsticks.gui.table.ColumnsConfig; 7 import com.framsticks.gui.table.ListPanelProvider; 6 8 import com.framsticks.params.annotations.AutoAppendAnnotation; 7 9 import com.framsticks.params.annotations.FramsClassAnnotation; … … 57 59 } 58 60 61 protected final StandardPanelProvider standardPanelProvider; 62 protected final ListPanelProvider listPanelProvider; 63 59 64 public Browser() { 60 65 setName("browser"); 61 66 JPopupMenu.setDefaultLightWeightPopupEnabled(false); 62 addPanelProvider(new StandardPanelProvider()); 67 addPanelProvider(standardPanelProvider = new StandardPanelProvider()); 68 addPanelProvider(listPanelProvider = new ListPanelProvider()); 63 69 64 70 mainFrame = new MainFrame(Browser.this); … … 116 122 117 123 @AutoAppendAnnotation 124 public void addColumnsConfig(ColumnsConfig columnsConfig) { 125 listPanelProvider.addColumnsConfig(columnsConfig); 126 } 127 128 @AutoAppendAnnotation 118 129 public void addPopupMenuEntryProvider(PopupMenuEntryProvider popupMenuEntryProvider) { 119 130 popupMenuEntryProviders.add(popupMenuEntryProvider); … … 122 133 @AutoAppendAnnotation 123 134 public void addTree(Tree tree) { 124 log. info("adding tree: " + tree);135 log.debug("adding tree: " + tree); 125 136 tree.setDispatcher(new SwingDispatcher<Tree>()); 126 137 trees.add(tree); … … 155 166 } 156 167 157 public void createTreeNodeForChild(final Path path) {158 assert !isActive();159 //assert tree.isActive();160 161 /*162 final TreeNode parentTreeNode = (TreeNode) child.getParent().getUserObject();163 if (parentTreeNode == null) {164 Dispatching.invokeDispatch(this, manager, new Runnable() {165 @Override166 public void run() {167 createTreeNodeForChild(child);168 }169 });170 return;171 }172 log.debug(child.getClass().getSimpleName() + " created: " + child);173 174 175 invokeLater(new Runnable() {176 @Override177 public void run() {178 parentTreeNode.getOrCreateChildTreeNodeFor(child);179 }180 });181 */182 }183 184 168 @Override 185 169 protected void joinableStart() { … … 288 272 } 289 273 290 // final protected Map<EventParam, Subscription<?>> userSubscriptions = new HashMap<>();291 // public boolean hasSubscribed(EventParam param) {292 // assert frame.isActive();293 // return userSubscriptions.containsKey(param);294 // }295 296 // public void unsubscribe(EventParam eventParam) {297 // assert frame.isActive();298 // if (!hasSubscribed(eventParam)) {299 // log.error("could not unsubscribe from " + eventParam);300 // return;301 // }302 // userSubscriptions.get(eventParam).unsubscribe(new LoggingStateCallback(log, "unsubscribed " + eventParam));303 // userSubscriptions.remove(eventParam);304 // }305 306 307 308 309 274 } -
java/main/src/main/java/com/framsticks/gui/Frame.java
r98 r99 38 38 import org.apache.log4j.Logger; 39 39 40 import com.framsticks.core.Mode;41 40 import com.framsticks.core.Path; 42 41 import com.framsticks.core.Tree; 43 import com.framsticks.core.TreeOperations; 44 import com.framsticks.gui.view.TreeCellRenderer; 45 import com.framsticks.params.AccessInterface; 42 import com.framsticks.gui.tree.MetaNode; 43 import com.framsticks.gui.tree.TreeCellRenderer; 44 import com.framsticks.gui.tree.TreeModel; 45 import com.framsticks.gui.tree.TreeNode; 46 46 import com.framsticks.util.dispatching.Dispatching; 47 47 import com.framsticks.util.dispatching.FutureHandler; … … 126 126 @Override 127 127 public void valueChanged(TreeSelectionEvent e) { 128 chooseTreeNode(e.getNewLeadSelectionPath());128 treeModel.chooseTreeNode(e.getNewLeadSelectionPath()); 129 129 } 130 130 }); … … 139 139 @Override 140 140 public void treeExpanded(TreeExpansionEvent e) { 141 loadChildren(treeModel.convertToPath(e.getPath()), false);141 // loadChildren(treeModel.convertToPath(e.getPath()), false); 142 142 } 143 143 }); … … 243 243 public void actionPerformed(ActionEvent actionEvent) { 244 244 245 loadPath(treeModel.convertToPath(jtree.getSelectionPath()), true);245 treeModel.loadPath(treeModel.convertToPath(jtree.getSelectionPath()), true); 246 246 } 247 247 }); … … 258 258 Tree tree = path.getTree(); 259 259 260 log. info("trying mount: " + path);260 log.debug("trying mount: " + path); 261 261 if (!tree.getAssignedRoot().isResolved()) { 262 tree.get(path, Mode.FETCH,new FutureHandler<Path>(this) {262 tree.get(path, new FutureHandler<Path>(this) { 263 263 264 264 @Override … … 275 275 treeAtFrames.put(tree, e); 276 276 277 rootNode.getChildren().add(new TreeNode( tree.getAssignedRoot()));277 rootNode.getChildren().add(new TreeNode(e, Path.to(tree, "/"))); 278 278 e.rootNode = tree.getAssignedRoot(); 279 279 treeModel.nodeStructureChanged(new TreePath(rootNode)); … … 311 311 } 312 312 313 public void loadChildren(Path path, boolean reload) { 314 if (path == null) { 315 return; 313 public void updatePanelIfIsLeadSelection(TreePath treePath, Path path) { 314 assert isActive(); 315 if (treePath.equals(jtree.getSelectionPath())) { 316 treeAtFrames.get(path.getTree()).useOrCreatePanel(treePath); 316 317 } 317 AccessInterface access = TreeOperations.bindAccess(path); 318 319 int count = access.getCompositeParamCount(); 320 for (int i = 0; i < count; ++i) { 321 Path childPath = path.appendParam(access.getCompositeParam(i)).tryFindResolution(); 322 loadPath(childPath, reload); 323 } 324 325 } 326 327 public void loadPath(Path path, boolean reload) { 328 if (path == null) { 329 return; 330 } 331 if (path.isResolved() && !reload) { 332 return; 333 } 334 path.getTree().get(path, Mode.FETCH, new FutureHandler<Path>(this) { 335 @Override 336 protected void result(Path result) { 337 final TreePath treePath = treeModel.convertToTreePath(result); 338 339 treeModel.nodeStructureChanged(treePath); 340 if (treePath.equals(jtree.getSelectionPath())) { 341 treeAtFrames.get(result.getTree()).useOrCreatePanel(treePath); 342 } 343 } 344 }); 345 } 346 347 public void chooseTreeNode(final TreePath treePath) { 348 assert isActive(); 349 if (treePath == null) { 350 return; 351 } 352 if (treeModel.isChanging()) { 353 return; 354 } 355 356 Path path = treeModel.convertToPath(treePath); 357 if (path == null) { 358 return; 359 } 360 path = path.assureResolved(); 361 final Tree tree = path.getTree(); 362 363 treeAtFrames.get(tree).useOrCreatePanel(treePath); 364 loadChildren(path, false); 365 366 } 318 } 319 367 320 368 321 … … 420 373 421 374 /** 375 * @return the jtree 376 */ 377 public JTree getJtree() { 378 return jtree; 379 } 380 381 /** 422 382 * @return the treeModel 423 383 */ … … 426 386 } 427 387 388 /** 389 * @return the rootNode 390 */ 391 public MetaNode getRootNode() { 392 return rootNode; 393 } 394 395 /** 396 * @return the treeAtFrames 397 */ 398 public Map<Tree, TreeAtFrame> getTreeAtFrames() { 399 return treeAtFrames; 400 } 401 428 402 } -
java/main/src/main/java/com/framsticks/gui/Gui.java
r97 r99 101 101 102 102 public static <P extends Param, C extends Control> void fillWithControls(ControlOwner owner, Collection<P> params, Map<P, C> components, Class<C> controlType) { 103 JPanel panel = owner.getPanel ();103 JPanel panel = owner.getPanelForControls(); 104 104 for (P param : params) { 105 105 if (param.isUserHidden()) { -
java/main/src/main/java/com/framsticks/gui/ModifiablePanel.java
r98 r99 20 20 * Pane to which components will be added. 21 21 */ 22 protected JPanel contentPanel;23 22 24 final protected JLabel label; 25 final protected JButton applyButton; 23 protected final JLabel label; 24 protected final JButton applyButton; 25 protected final JPanel centerPanel; 26 27 protected Component contentComponent; 26 28 27 29 public ModifiablePanel(Panel.Parameters parameters) { … … 30 32 31 33 32 contentPanel = new JPanel();33 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS));34 JScrollPane scroll = new JScrollPane(contentPanel);35 //scroll.setBorder(BorderFactory.createEtchedBorder());36 34 37 35 JPanel pageEndPanel = new JPanel(); … … 53 51 54 52 label = new JLabel(); 55 JPanelcenterPanel = new JPanel();53 centerPanel = new JPanel(); 56 54 centerPanel.setLayout(new BorderLayout()); 57 55 centerPanel.add(Box.createHorizontalStrut(10), BorderLayout.LINE_START); 58 56 centerPanel.add(Box.createHorizontalStrut(10), BorderLayout.LINE_END); 59 57 centerPanel.add(label, BorderLayout.PAGE_START); 60 centerPanel.add(scroll, BorderLayout.CENTER); 58 59 61 60 centerPanel.add(pageEndPanel, BorderLayout.PAGE_END); 62 61 … … 68 67 protected abstract void applyChanges(); 69 68 69 protected void setupContentComponent(Component contentComponent) { 70 this.contentComponent = contentComponent; 71 centerPanel.add(contentComponent, BorderLayout.CENTER); 72 } 73 70 74 } -
java/main/src/main/java/com/framsticks/gui/ObjectPanel.java
r98 r99 29 29 final protected Map<ValueParam, ValueControl> valueControls = new IdentityHashMap<ValueParam, ValueControl>(); 30 30 31 protected final JPanel contentPanel; 32 protected final JScrollPane scrollPane; 33 31 34 public ObjectPanel(Panel.Parameters parameters, Collection<Param> params) { 32 35 super(parameters); 36 37 contentPanel = new JPanel(); 38 scrollPane = new JScrollPane(contentPanel); 39 contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS)); 40 setupContentComponent(scrollPane); 33 41 34 42 Gui.fillWithControls(this, params, components, Control.class); … … 102 110 103 111 @Override 104 public JPanel getPanel () {112 public JPanel getPanelForControls() { 105 113 return contentPanel; 106 114 } -
java/main/src/main/java/com/framsticks/gui/Panel.java
r98 r99 22 22 public final TreeAtFrame treeAtFrame; 23 23 public final CompositeParam param; 24 25 /** Contained type FramsClass. */ 24 26 public final FramsClass framsClass; 25 27 -
java/main/src/main/java/com/framsticks/gui/TreeAtFrame.java
r98 r99 8 8 import com.framsticks.core.TreeOperations; 9 9 import com.framsticks.gui.controls.ValueControl; 10 import com.framsticks.gui.tree.TreeNode; 10 11 import com.framsticks.params.CompositeParam; 11 12 import com.framsticks.params.FramsClass; -
java/main/src/main/java/com/framsticks/gui/console/ManagedConsole.java
r98 r99 10 10 import com.framsticks.communication.Response; 11 11 import com.framsticks.communication.queries.ApplicationRequest; 12 import com.framsticks.core.Mode;13 12 import com.framsticks.core.Path; 14 13 import static com.framsticks.core.TreeOperations.*; … … 143 142 144 143 if (path.getTop().getParam() instanceof ListParam) { 145 tree.get(path, Mode.FETCH,new FutureHandler<Path>(ManagedConsole.this) {144 tree.get(path, new FutureHandler<Path>(ManagedConsole.this) { 146 145 @Override 147 146 protected void result(Path result) { -
java/main/src/main/java/com/framsticks/gui/controls/Control.java
r98 r99 6 6 import javax.swing.JPanel; 7 7 8 import com.framsticks.params. Flags;8 import com.framsticks.params.ParamFlags; 9 9 import com.framsticks.params.Param; 10 10 import com.framsticks.util.FramsticksException; … … 57 57 58 58 public final boolean isReadonly() { 59 return !userEnabled || param.hasFlag( Flags.READONLY);59 return !userEnabled || param.hasFlag(ParamFlags.READONLY); 60 60 } 61 61 -
java/main/src/main/java/com/framsticks/gui/controls/ControlOwner.java
r98 r99 9 9 public interface ControlOwner extends ExceptionResultHandler { 10 10 11 public JPanel getPanel ();11 public JPanel getPanelForControls(); 12 12 public TreePath getCurrentTreePath(); 13 13 public Frame getFrame(); -
java/main/src/main/java/com/framsticks/gui/controls/ProcedureControl.java
r98 r99 86 86 87 87 @Override 88 public JPanel getPanel () {88 public JPanel getPanelForControls() { 89 89 return this; 90 90 } -
java/main/src/main/java/com/framsticks/gui/controls/ValueControl.java
r98 r99 4 4 5 5 import com.framsticks.params.CastFailure; 6 import com.framsticks.params. Flags;6 import com.framsticks.params.ParamFlags; 7 7 import com.framsticks.params.PrimitiveParam; 8 8 import com.framsticks.params.ReassignResult; 9 import com.framsticks.params.SetStateFlags; 9 10 import com.framsticks.util.FramsticksException; 11 import com.framsticks.util.lang.FlagsUtil; 10 12 import com.framsticks.util.swing.TooltipConstructor; 11 13 … … 33 35 .append("min", primitiveParam.getMin(Object.class)) 34 36 .append("max", primitiveParam.getMax(Object.class)) 35 .append("flags", Flags .write(primitiveParam.getFlags(), null))37 .append("flags", FlagsUtil.write(ParamFlags.class, primitiveParam.getFlags(), null)) 36 38 .append("group", primitiveParam.getGroup()) 37 39 .append("extra", primitiveParam.getExtra()) … … 70 72 ReassignResult<?> res = getParam().reassign(candidate, oldValue); 71 73 if (res.getFlags() != 0) { 72 log.warn("filter of param " + param + " failed: " + Flags .write(res.getFlags(), "0"));74 log.warn("filter of param " + param + " failed: " + FlagsUtil.write(SetStateFlags.class, res.getFlags(), "0")); 73 75 } 74 76 return res.getValue(); -
java/main/src/main/java/com/framsticks/hosting/ClientAtServer.java
r98 r99 8 8 import com.framsticks.communication.queries.GetRequest; 9 9 import com.framsticks.communication.queries.InfoRequest; 10 import com.framsticks.communication.queries.RegisterRequest; 10 11 import com.framsticks.communication.queries.SetRequest; 12 import com.framsticks.core.LocalTree; 11 13 import com.framsticks.core.Tree; 12 14 import com.framsticks.core.Path; 13 15 import com.framsticks.params.*; 16 import com.framsticks.params.types.EventParam; 14 17 import com.framsticks.params.types.ProcedureParam; 15 18 import com.framsticks.parsers.Savers; 16 19 import com.framsticks.util.FramsticksException; 20 import com.framsticks.util.Misc; 17 21 import com.framsticks.util.dispatching.AbstractJoinable; 18 22 import com.framsticks.util.dispatching.Dispatching; … … 22 26 import com.framsticks.util.dispatching.JoinableParent; 23 27 import com.framsticks.util.dispatching.JoinableState; 28 import com.framsticks.util.lang.FlagsUtil; 29 import com.framsticks.util.lang.Strings; 30 24 31 import static com.framsticks.core.TreeOperations.*; 25 32 26 33 import java.net.Socket; 27 import java.util.LinkedList;28 import java.util.List;29 34 30 35 /** … … 34 39 35 40 protected final Server server; 36 protected final Tree tree; 41 protected final Tree contentTree; 42 protected final Object treeRootObject; 37 43 protected final ServerSideManagedConnection connection; 44 45 protected final Cli cliObject; 46 protected final LocalTree rootTree; 47 48 49 protected final FramsClass rootFramsClass; 50 protected final Object root; 51 protected final String contentPrefix; 38 52 39 53 public ClientAtServer(Server server, Socket socket) { 40 54 this.server = server; 41 this. tree = server.hosted;55 this.contentTree = server.hosted; 42 56 this.connection = new ServerSideManagedConnection(socket, this); 57 58 treeRootObject = contentTree.getAssignedRoot().getObject(); 59 Misc.throwIfNull(treeRootObject); 60 61 cliObject = new Cli(this); 62 rootTree = new LocalTree(); 63 // rootTree.setDispatcher(new AtOnceDispatcher<Tree>()); 64 rootTree.setDispatcher(server.getHosted().getDispatcher()); 65 assert rootTree.getDispatcher() != null; 66 67 final FramsClass framsClass = bindAccess(contentTree.getAssignedRoot()).getFramsClass(); 68 final String id = Strings.uncapitalize(framsClass.getName()); 69 contentPrefix = "/" + id; 70 final String rootFramsClassId = id + "Root"; 71 72 rootFramsClass = FramsClass.build() 73 .idAndName(rootFramsClassId) 74 .param(Param.build().id(id).name(framsClass.getName()).type("o " + framsClass.getId())) 75 .param(Param.build().id("cli").name("CLI").type("o Cli")) 76 .finish(); 77 78 // rootTree.putInfoIntoCache(rootFramsClass); 79 rootTree.getRegistry().putFramsClass(rootFramsClass); 80 rootTree.getRegistry().registerAndBuild(Cli.class); 81 rootTree.getRegistry().registerAndBuild(CliEvent.class); 82 83 AccessInterface access = new PropertiesAccess(rootFramsClass); 84 85 root = access.createAccessee(); 86 access.select(root); 87 access.set(id, treeRootObject); 88 access.set("cli", cliObject); 89 90 rootTree.assignRootParam(access.buildParam(new ParamBuilder()).name(rootFramsClassId).finish(CompositeParam.class)); 91 rootTree.assignRootObject(root); 92 43 93 } 44 94 … … 52 102 assureNotEmpty(request.getPath()); 53 103 54 tryGet(tree, request.getPath(), new FutureHandler<Path>(responseCallback) { 104 if (request.getPath().startsWith(contentPrefix)) { 105 String p = request.getPath().substring(contentPrefix.length()); 106 request.path(p.equals("") ? "/" : p); 107 handleInTree(contentTree, request, responseCallback, contentPrefix); 108 return; 109 } 110 111 handleInTree(rootTree, request, responseCallback, ""); 112 } 113 114 public static File printToFile(String path, AccessInterface access) { 115 ListSink sink = new ListSink(); 116 access.save(sink); 117 return new File(path, new ListSource(sink.getOut())); 118 } 119 120 protected void handleInTree(final Tree tree, final ApplicationRequest request, final ServerSideResponseFuture responseCallback, final String usedPrefix) { 121 122 tryGet(tree, request.getActualPath(), new FutureHandler<Path>(responseCallback) { 55 123 @Override 56 124 protected void result(final Path path) { 57 125 58 if (!path.getTextual().equals(request.get Path())) {59 throw new FramsticksException().msg("invalid path").arg("path", request.get Path());126 if (!path.getTextual().equals(request.getActualPath())) { 127 throw new FramsticksException().msg("invalid path").arg("path", request.getActualPath()); 60 128 } 61 129 62 130 // final AccessInterface access = tree.prepareAccess(path); 63 131 final AccessInterface access = bindAccess(path); 132 133 if (request instanceof GetRequest) { 134 Object result = path.getTopObject(); 135 if (result != access.getSelected()) { 136 throw new FramsticksException().msg("mismatch objects during fetch").arg("path", path); 137 } 138 responseCallback.pass(new Response(true, "", File.single(printToFile(path.getTextual(), access)))); 139 140 return; 141 } 64 142 65 143 if (request instanceof SetRequest) { … … 69 147 @Override 70 148 protected void result(Integer flag) { 71 responseCallback.pass(new Response(true, Flags .write(flag, null), null));149 responseCallback.pass(new Response(true, FlagsUtil.write(SetStateFlags.class, flag, null), null)); 72 150 73 151 } … … 76 154 } 77 155 78 if (request instanceof GetRequest) {79 Object result = path.getTopObject();80 if (result != access.getSelected()) {81 throw new FramsticksException().msg("mismatch objects during fetch").arg("path", path);82 }83 List<File> files = new LinkedList<File>();84 ListSink sink = new ListSink();85 access.save(sink);86 files.add(new File(path.getTextual(), new ListSource(sink.getOut())));87 responseCallback.pass(new Response(true, "", files));88 89 return;90 }91 156 if (request instanceof CallRequest) { 92 157 final CallRequest callRequest = (CallRequest) request; … … 107 172 return; 108 173 } 174 109 175 if (request instanceof InfoRequest) { 110 176 FramsClass framsClass = getInfo(path); … … 116 182 } 117 183 184 if (request instanceof RegisterRequest) { 185 RegisterRequest register = (RegisterRequest) request; 186 187 cliObject.addListener(path, access.getFramsClass().getParamEntry(register.getEventName(), EventParam.class), usedPrefix, responseCallback); 188 return; 189 } 190 118 191 throw new FramsticksException().msg("invalid request type: " + request.getCommand()); 119 192 } … … 148 221 @Override 149 222 public void handle(FramsticksException exception) { 150 tree.handle(exception); 223 contentTree.handle(exception); 224 } 225 226 /** 227 * @return the tree 228 */ 229 public Tree getTree() { 230 return contentTree; 151 231 } 152 232 -
java/main/src/main/java/com/framsticks/model/Model.java
r90 r99 59 59 public List<NeuroConnection> getNeuroConnections() { return neuroConnections; } 60 60 61 @Override 62 public String toString() { 63 return "Model{" + parts.size() + ":" + joints.size() + ":" + neuroDefinitions.size() + ":" + neuroConnections.size() + "}"; 64 65 } 66 61 67 } -
java/main/src/main/java/com/framsticks/params/AccessInterface.java
r98 r99 2 2 3 3 4 import com.framsticks.params.types.EventParam; 4 5 import com.framsticks.params.types.ProcedureParam; 5 6 … … 39 40 <T> int set(ValueParam param, T value); 40 41 42 void reg(EventParam param, EventListener<?> listener); 43 44 void regRemove(EventParam param, EventListener<?> listener); 45 41 46 void setDefault(boolean numericOnly); 42 47 … … 50 55 51 56 void setMax(int i); 52 53 void copyFrom(AccessInterface src);54 57 55 58 void save(SinkInterface sink); … … 80 83 CompositeParam getCompositeParam(int number); 81 84 85 ParamBuilder buildParam(ParamBuilder builder); 86 82 87 83 88 } -
java/main/src/main/java/com/framsticks/params/ArrayListAccess.java
r98 r99 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.params.types.ArrayListParam; 3 4 import com.framsticks.util.UnimplementedException; 4 5 import com.framsticks.util.lang.Numbers; … … 15 16 16 17 List<Object> list; 18 17 19 18 20 public ArrayListAccess(AccessInterface elementAccess) { … … 35 37 return null; 36 38 } 37 return Param.build().id(Integer.toString(i)).forAccess(elementAccess).finish(CompositeParam.class);39 return paramBuilder.id(Integer.toString(i)).finish(CompositeParam.class); 38 40 } 39 41 … … 109 111 } 110 112 111 @Override112 public String computeIdentifierFor(Object selected) {113 return Integer.toString(list.size());114 }115 113 116 114 @Override … … 131 129 @Override 132 130 public Param next() { 133 Param param = Param.build().id(Integer.toString(internal.nextIndex())).forAccess(elementAccess).finish();131 Param param = paramBuilder.id(Integer.toString(internal.nextIndex())).finish(CompositeParam.class); 134 132 internal.next(); 135 133 return param; … … 156 154 } 157 155 156 @Override 157 public ParamBuilder buildParam(ParamBuilder builder) { 158 return builder.name(containedTypeName + " list").type(ArrayListParam.class).containedTypeName(containedTypeName); 159 } 158 160 159 161 } -
java/main/src/main/java/com/framsticks/params/FramsClass.java
r98 r99 5 5 import com.framsticks.util.FramsticksException; 6 6 import com.framsticks.util.lang.Containers; 7 import com.framsticks.util.lang.Strings; 7 8 // import com.framsticks.util.FramsticksException; 8 9 … … 60 61 61 62 this.id = builder.getId(); 62 this.name = builder.getName();63 this.name = Strings.toStringEmptyProof(builder.getName(), this.id); 63 64 this.description = builder.getDescription(); 64 65 this.groups = Containers.build(builder.groupBuilders); -
java/main/src/main/java/com/framsticks/params/FramsClassBuilder.java
r98 r99 40 40 41 41 public static ParamBuilder induceParamType(ParamBuilder builder, Type type) { 42 // if (type.equals(Void.TYPE)) { 43 // throw new ConstructionException().msg("void is not a valid type"); 44 // } 42 45 43 46 if (type instanceof ParameterizedType) { … … 47 50 //TODO make implementation here 48 51 boolean map = false; 52 StringBuilder b = new StringBuilder(); 49 53 if (rawType.equals(Map.class)) { 50 54 containedType = p.getActualTypeArguments()[1]; 51 55 map = true; 56 b.append("l"); 52 57 } else if (rawType.equals(List.class)) { 53 58 containedType = p.getActualTypeArguments()[0]; 59 b.append("l"); 60 } else if (rawType.equals(EventListener.class)) { 61 containedType = p.getActualTypeArguments()[0]; 62 b.append("e"); 54 63 } 55 64 if (!(containedType instanceof Class)) { 56 65 return builder; 57 66 } 67 b.append(" "); 68 58 69 Class<?> containedClass = (Class<?>) containedType; 59 StringBuilder b = new StringBuilder();60 b.append("l ");61 70 FramsClassAnnotation fca = containedClass.getAnnotation(FramsClassAnnotation.class); 62 71 if (fca == null) { 63 log.error("the class is not annotated: " + containedClass); 64 return builder; 72 throw new ConstructionException().msg("the contained class is not annotated").arg("class", containedClass); 65 73 } 66 74 b.append(getName(fca, containedClass)); 75 //TODO parametrize this 67 76 if (map) { 68 77 b.append(" name"); … … 109 118 return builder; 110 119 } 120 111 121 112 122 // builder.type("o " + (cl).getCanonicalName()); … … 174 184 } 175 185 if (argsNum == 1) { 176 return n.startsWith("set") ? Strings.uncapitalize(n.substring(3)) : n; 186 if (n.startsWith("set")) { 187 return Strings.uncapitalize(n.substring(3)); 188 } 189 if (n.startsWith("add")) { 190 return Strings.uncapitalize(n.substring(3)); 191 } 192 if (n.startsWith("remove")) { 193 return Strings.uncapitalize(n.substring(6)); 194 } 195 return n; 177 196 } 178 197 log.error("invalid number of arguments"); -
java/main/src/main/java/com/framsticks/params/InvalidOperationException.java
r90 r99 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.util. FramsticksException;3 import com.framsticks.util.UnsupportedOperationException; 4 4 5 5 @SuppressWarnings("serial") 6 public class InvalidOperationException extends FramsticksException {6 public class InvalidOperationException extends UnsupportedOperationException { 7 7 8 8 } -
java/main/src/main/java/com/framsticks/params/ListAccess.java
r97 r99 5 5 import static com.framsticks.util.lang.Containers.filterInstanceof; 6 6 7 import com.framsticks.params.types.EventParam; 7 8 import com.framsticks.params.types.ProcedureParam; 8 9 … … 13 14 14 15 final AccessInterface elementAccess; 16 final String containedTypeName; 17 18 protected final ParamBuilder paramBuilder; 15 19 16 20 public ListAccess(AccessInterface elementAccess) { 17 21 this.elementAccess = elementAccess; 22 this.containedTypeName = elementAccess.getId(); 23 paramBuilder = elementAccess.buildParam(new ParamBuilder()); 18 24 } 19 25 … … 48 54 49 55 @Override 50 public void copyFrom(AccessInterface src) {51 }52 53 @Override54 56 public void save(SinkInterface sink) { 55 57 for (CompositeParam p : filterInstanceof(getParams(), CompositeParam.class)) { … … 70 72 } 71 73 72 public abstract String computeIdentifierFor(Object selected); 74 /** 75 * @return the containedTypeName 76 */ 77 public String getContainedTypeName() { 78 return containedTypeName; 79 } 73 80 74 81 @Override … … 85 92 @Override 86 93 public Object call(String id, Object[] arguments) { 87 throw new InvalidOperationException().msg("list access does not support calling methods").arg("id", id) ;94 throw new InvalidOperationException().msg("list access does not support calling methods").arg("id", id).arg("access", this); 88 95 } 89 96 90 97 @Override 91 98 public Object call(ProcedureParam param, Object[] arguments) { 92 throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param) ;99 throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param).arg("access", this); 93 100 } 94 101 102 @Override 103 public void reg(EventParam param, EventListener<?> listener) { 104 throw new InvalidOperationException().msg("list access does not support registering events").arg("param", param).arg("access", this); 105 } 106 107 @Override 108 public void regRemove(EventParam param, EventListener<?> listener) { 109 throw new InvalidOperationException().msg("list access does not support registering events").arg("param", param).arg("access", this); 110 } 111 112 113 @Override 114 public String toString() { 115 StringBuilder b = new StringBuilder(); 116 b.append("list of ").append(containedTypeName); 117 if (getSelected() != null) { 118 b.append("[").append(getParamCount()).append("]"); 119 } 120 return b.toString(); 121 } 95 122 }; -
java/main/src/main/java/com/framsticks/params/Param.java
r96 r99 97 97 98 98 public boolean isUserHidden() { 99 return (flags & Flags.USERHIDDEN) != 0;99 return (flags & ParamFlags.USERHIDDEN) != 0; 100 100 } 101 101 -
java/main/src/main/java/com/framsticks/params/ParamBuilder.java
r97 r99 7 7 import com.framsticks.util.FramsticksException; 8 8 import com.framsticks.util.Misc; 9 import com.framsticks.util.lang.FlagsUtil; 9 10 import com.framsticks.util.lang.Strings; 10 11 … … 66 67 private int extra = 0; 67 68 68 String containedTypeName; 69 protected String containedTypeName; 70 71 protected String eventArgumentTypeName; 69 72 70 73 protected Class<?> storageType; … … 116 119 } 117 120 121 public ParamBuilder containedTypeName(String containedTypeName) { 122 this.containedTypeName = containedTypeName; 123 return this; 124 } 125 118 126 /** 119 127 * @return the resultType … … 160 168 public String getUid() { 161 169 return uid; 170 } 171 172 public ParamBuilder uid(String uid) { 173 this.uid = uid; 174 return this; 162 175 } 163 176 … … 322 335 case 'e': { 323 336 type(EventParam.class); 324 break; 325 } 326 case 'l': { 327 containedTypeName = second; 328 if (third != null) { 329 type(UniqueListParam.class); 330 uid = third; 331 } else { 332 type(ArrayListParam.class); 333 } 334 break; 335 } 336 default:{ 337 log.error("unknown type: " + first); 338 return this; 339 } 340 } 337 eventArgumentTypeName(second); 338 break; 339 } 340 case 'l': { 341 containedTypeName = second; 342 if (third != null) { 343 type(UniqueListParam.class); 344 uid = third; 345 } else { 346 type(ArrayListParam.class); 347 } 348 break; 349 } 350 default: { 351 log.error("unknown type: " + first); 352 return this; 353 } 354 } 355 return this; 356 } 357 358 public ParamBuilder eventArgumentTypeName(String eventArgumentTypeName) { 359 this.eventArgumentTypeName = eventArgumentTypeName; 341 360 return this; 342 361 } … … 438 457 id(paramEntryValues[0]); 439 458 group(Integer.valueOf(paramEntryValues[1])); 440 flags(Flags .read(paramEntryValues[2]));459 flags(FlagsUtil.read(ParamFlags.class, paramEntryValues[2])); 441 460 name(paramEntryValues[3]); 442 461 type(paramEntryValues[4]); … … 464 483 break; 465 484 case FLAGS_FIELD: 466 flags(Flags .read(value));485 flags(FlagsUtil.read(ParamFlags.class, value)); 467 486 break; 468 487 case HELP_FIELD: … … 492 511 } 493 512 513 /** 514 * @return the eventArgumentTypeName 515 */ 516 public String getEventArgumentTypeName() { 517 return eventArgumentTypeName; 518 } 519 494 520 public Class<?> getStorageType() { 495 521 return storageType; 496 }497 498 public ParamBuilder forAccess(AccessInterface access) {499 return name(access.getId()).type("o " + access.getId());500 522 } 501 523 -
java/main/src/main/java/com/framsticks/params/ParamCandidate.java
r90 r99 73 73 protected final OneTime<Method> getter = new OneTime<>("getter"); 74 74 protected final OneTime<Method> caller = new OneTime<>("caller"); 75 protected final OneTime<Method> adder = new OneTime<>("adder"); 76 protected final OneTime<Method> remover = new OneTime<>("remover"); 75 77 76 78 protected final List<ParamAnnotation> annotations = new LinkedList<>(); … … 142 144 143 145 /** 146 * @return the getter 147 */ 148 public Method getAdder() { 149 return adder.get(); 150 } 151 152 /** 153 * @return the getter 154 */ 155 public Method getRemover() { 156 return remover.get(); 157 } 158 159 /** 144 160 * @return the annotations 145 161 */ … … 150 166 void validate() throws ConstructionException { 151 167 try { 168 if (adder.has() != remover.has()) { 169 throw new ConstructionException().msg("only one of event manipulator methods is defined"); 170 } 171 if (adder.has() && remover.has()) { 172 return; 173 } 152 174 if (caller.has()) { 153 175 if (!isPublic(caller)) { … … 174 196 throw new ConstructionException().msg("missing getter or field"); 175 197 } 198 if (getter.has() || field.has() || setter.has()) { 199 if (type.get().equals(Void.TYPE)) { 200 throw new ConstructionException().msg("type of field is void"); 201 } 202 } 176 203 } catch (ConstructionException e) { 177 204 throw e.arg("in", this); … … 183 210 return false; 184 211 } 212 if (adder.has() || remover.has()) { 213 return false; 214 } 185 215 if (Collection.class.isAssignableFrom(getRawType())) { 186 216 return false; … … 197 227 boolean isReadOnly() { 198 228 if (caller.has()) { 229 return false; 230 } 231 if (adder.has() || remover.has()) { 199 232 return false; 200 233 } … … 229 262 } 230 263 Type[] ps = m.getGenericParameterTypes(); 264 Class<?>[] pts = m.getParameterTypes(); 231 265 if (ps.length == 0) { 266 if (m.getReturnType().equals(Void.TYPE)) { 267 throw new ConstructionException().msg("failed to add getter of void return type"); 268 } 232 269 getter.set(m); 233 270 setType(m.getGenericReturnType()); … … 235 272 } 236 273 if (ps.length == 1) { 274 if (pts[0].equals(EventListener.class)) { 275 if (member.getName().startsWith("add")) { 276 adder.set(m); 277 setType(ps[0]); 278 return; 279 } 280 if (member.getName().startsWith("remove")) { 281 remover.set(m); 282 setType(ps[0]); 283 return; 284 } 285 throw new ConstructionException().msg("invalid name of event manipulator").arg("method", m).arg("in", this); 286 } 237 287 setter.set(m); 238 288 setType(ps[0]); … … 251 301 int f = 0; 252 302 if (isReadOnly()) { 253 f |= Flags.READONLY;303 f |= ParamFlags.READONLY; 254 304 } 255 305 return f; -
java/main/src/main/java/com/framsticks/params/PropertiesAccess.java
r96 r99 4 4 import java.util.Map; 5 5 6 import com.framsticks.params.types.EventParam; 6 7 import com.framsticks.params.types.ProcedureParam; 7 8 … … 97 98 @Override 98 99 public Object call(String id, Object[] arguments) { 99 throw new InvalidOperationException().msg(" listaccess does not support calling methods").arg("id", id);100 throw new InvalidOperationException().msg("properties access does not support calling methods").arg("id", id); 100 101 } 101 102 102 103 @Override 103 104 public Object call(ProcedureParam param, Object[] arguments) { 104 throw new InvalidOperationException().msg("list access does not support calling methods").arg("param", param); 105 throw new InvalidOperationException().msg("properties access does not support calling methods").arg("param", param); 106 } 107 108 @Override 109 public void reg(EventParam param, EventListener<?> listener) { 110 throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this); 111 } 112 113 @Override 114 public void regRemove(EventParam param, EventListener<?> listener) { 115 throw new InvalidOperationException().msg("properties access does not support registering events").arg("param", param).arg("access", this); 105 116 } 106 117 -
java/main/src/main/java/com/framsticks/params/ReflectionAccess.java
r98 r99 17 17 18 18 import com.framsticks.params.annotations.AutoAppendAnnotation; 19 import com.framsticks.params.types.EventParam; 19 20 import com.framsticks.params.types.ProcedureParam; 20 21 import com.framsticks.util.FramsticksException; … … 57 58 } 58 59 60 public interface ReflectedAdder{ 61 public void reg(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException; 62 } 63 64 public interface ReflectedRemover{ 65 public void regRemove(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException; 66 } 67 59 68 protected final Map<ValueParam, ReflectedSetter> setters = new IdentityHashMap<>(); 60 69 protected final Map<ValueParam, ReflectedGetter> getters = new IdentityHashMap<>(); 61 70 protected final Map<ProcedureParam, ReflectedCaller> callers = new IdentityHashMap<>(); 71 protected final Map<EventParam, ReflectedAdder> adders = new IdentityHashMap<>(); 72 protected final Map<EventParam, ReflectedRemover> removers = new IdentityHashMap<>(); 73 62 74 protected final List<Method> autoAppendMethods = new ArrayList<>(); 63 75 … … 100 112 } 101 113 114 for (final EventParam ep : filterInstanceof(framsClass.getParamEntries(), EventParam.class)) { 115 if (!candidates.containsKey(ep.getId())) { 116 log.trace("java class does not implement the event param " + ep); 117 continue; 118 } 119 ParamCandidate ec = candidates.get(ep.getId()); 120 final Method adder = ec.getAdder(); 121 final Method remover = ec.getRemover(); 122 123 backend.adders.put(ep, new ReflectedAdder() { 124 125 @Override 126 public void reg(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { 127 adder.invoke(object, listener); 128 } 129 }); 130 131 backend.removers.put(ep, new ReflectedRemover() { 132 133 @Override 134 public void regRemove(Object object, EventListener<?> listener) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { 135 remover.invoke(object, listener); 136 } 137 }); 138 } 139 102 140 for (final ValueParam vp : filterInstanceof(framsClass.getParamEntries(), ValueParam.class)) { 103 141 if (!candidates.containsKey(vp.getId())) { … … 105 143 } 106 144 ParamCandidate pc = candidates.get(vp.getId()); 107 if (pc.isReadOnly() && !vp.hasFlag( Flags.READONLY)) {145 if (pc.isReadOnly() && !vp.hasFlag(ParamFlags.READONLY)) { 108 146 throw new ConstructionException().msg("readonly state conflict").arg("param", vp); 109 147 } … … 200 238 } 201 239 202 public ReflectionAccess(Class<?> reflectedClass) throws ConstructionException {203 this(reflectedClass, FramsClass.build().forClass(reflectedClass));204 }205 206 240 public static boolean typeMatch(Class<?> a, Class<?> b) { 207 assert !b.isPrimitive(); 241 if (b.isPrimitive()) { 242 throw new FramsticksException().msg("failed to match type, right argument is primitive").arg("left", a).arg("right", b); 243 } 208 244 if (!a.isPrimitive()) { 209 245 return a.equals(b); … … 219 255 return b.equals(Boolean.class); 220 256 } 221 assert false; 222 return false; 223 } 224 225 public ReflectionAccess(Class<?> reflectedClass, FramsClass framsClass) throws ConstructionException { 257 throw new FramsticksException().msg("failed to match types").arg("left", a).arg("right", b); 258 } 259 260 261 262 263 public ReflectionAccess(Class<?> javaClass) throws ConstructionException { 264 this(javaClass, FramsClass.build().forClass(javaClass)); 265 } 266 267 268 public ReflectionAccess(Class<?> javaClass, FramsClass framsClass) throws ConstructionException { 269 this(javaClass, framsClass, Backend.getOrCreateFor(javaClass, framsClass)); 270 } 271 272 protected ReflectionAccess(Class<?> javaClass, FramsClass framsClass, Backend backend) throws ConstructionException { 226 273 super(framsClass); 227 this.javaClass = reflectedClass; 228 this.backend = Backend.getOrCreateFor(reflectedClass, framsClass); 229 } 230 274 this.javaClass = javaClass; 275 this.backend = backend; 276 } 277 278 @Override 279 public ReflectionAccess cloneAccess() throws ConstructionException { 280 return new ReflectionAccess(javaClass, framsClass, backend); 281 } 231 282 232 283 @Override … … 268 319 } catch (FramsticksException e) { 269 320 throw e.arg("param", param).arg("value", value).arg("access", this); 321 } 322 } 323 324 @Override 325 public void reg(EventParam param, EventListener<?> listener) { 326 try { 327 try { 328 if (object == null) { 329 throw new FramsticksException().msg("no object set"); 330 } 331 332 backend.adders.get(param).reg(object, listener); 333 return; 334 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 335 throw new FramsticksException().msg("failed to add listener").cause(e); 336 } 337 } catch (FramsticksException e) { 338 throw e.arg("param", param).arg("access", this); 339 } 340 } 341 342 @Override 343 public void regRemove(EventParam param, EventListener<?> listener) { 344 try { 345 try { 346 if (object == null) { 347 throw new FramsticksException().msg("no object set"); 348 } 349 350 backend.removers.get(param).regRemove(object, listener); 351 return; 352 } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 353 throw new FramsticksException().msg("failed to remove listener").cause(e); 354 } 355 } catch (FramsticksException e) { 356 throw e.arg("param", param).arg("access", this); 270 357 } 271 358 } … … 352 439 } 353 440 354 @Override355 public ReflectionAccess cloneAccess() throws ConstructionException {356 return new ReflectionAccess(javaClass, framsClass);357 }358 441 359 442 @Override … … 368 451 } 369 452 370 @Override371 public String toString() {372 StringBuilder b = new StringBuilder();373 b.append(framsClass);374 if (object != null) {375 b.append("(").append(object).append(")");376 }377 return b.toString();378 }379 453 380 454 @Override -
java/main/src/main/java/com/framsticks/params/Registry.java
r98 r99 46 46 register(javaClass); 47 47 associate(javaClass, putFramsClass(FramsClass.build().forClass(javaClass))); 48 for (Class<?> r : javaClass.getAnnotation(FramsClassAnnotation.class).register()) { 49 registerAndBuild(r); 50 } 48 51 return this; 49 52 } … … 122 125 } 123 126 127 public FramsClass getFramsClassForJavaClass(Class<?> javaClass) { 128 return javaToFramsAssociation.get(javaClass); 129 } 130 124 131 public Set<Class<?>> getReflectedClasses() { 125 132 return javaClasses.getValues(); -
java/main/src/main/java/com/framsticks/params/SimpleAbstractAccess.java
r98 r99 6 6 import org.apache.log4j.Logger; 7 7 8 import com.framsticks.util.UnimplementedException; 8 import com.framsticks.params.types.ObjectParam; 9 import com.framsticks.util.FramsticksException; 10 import static com.framsticks.params.SetStateFlags.*; 9 11 10 12 /** … … 105 107 @Override 106 108 public <T> int set(ValueParam param, T value) { 107 int flags = 0;108 109 109 110 //String id = param.getEffectiveId(); … … 115 116 internalSet(param, casted); 116 117 } 117 flags =result.getFlags();118 return result.getFlags(); 118 119 } catch (CastFailure e) { 119 log.error("casting failure while set: ", e); 120 } 121 return flags; 120 throw new FramsticksException() 121 .msg("casting failure while set") 122 .arg("param", param) 123 .arg("value", value) 124 .arg("value's type", (value == null ? "<null>" : value.getClass().getCanonicalName())) 125 .arg("in", this).cause(e); 126 } 122 127 } 123 128 … … 167 172 set(i, max); 168 173 } 169 }170 171 @Override172 public void copyFrom(AccessInterface src) {173 throw new UnimplementedException();174 // clearValues();175 //TODO: iterate over self, and pull from src176 /*177 for (int i = 0; i < src.getFramsClass().size(); i++) {178 this.set(i, src.get(i, Object.class));179 }180 */181 174 } 182 175 … … 257 250 continue; 258 251 } 259 if ((param.getFlags() & Flags.DONTLOAD) != 0) {252 if ((param.getFlags() & ParamFlags.DONTLOAD) != 0) { 260 253 log.debug("DontLoad flag was set - not loading..."); 261 254 } else { 262 255 int retFlags = this.set((ValueParam) param, entry.value); 263 if ((retFlags & ( Flags.PSET_HITMIN | Flags.PSET_HITMAX)) != 0) {264 String which = ((retFlags & Flags.PSET_HITMIN) != 0) ? "small" : "big";256 if ((retFlags & (PSET_HITMIN | PSET_HITMAX)) != 0) { 257 String which = ((retFlags & PSET_HITMIN) != 0) ? "small" : "big"; 265 258 log.warn("value of key '" + entry.key + "' was too " + which + ", adjusted"); 266 259 } … … 304 297 }*/ 305 298 299 @Override 300 public String toString() { 301 StringBuilder b = new StringBuilder(); 302 b.append(framsClass); 303 if (getSelected() != null) { 304 b.append("(").append(getSelected()).append(")"); 305 } 306 return b.toString(); 307 } 308 309 @Override 310 public ParamBuilder buildParam(ParamBuilder builder) { 311 return builder.name(getId()).type(ObjectParam.class).containedTypeName(getId()); 312 } 306 313 307 314 } -
java/main/src/main/java/com/framsticks/params/UniqueListAccess.java
r98 r99 1 1 package com.framsticks.params; 2 2 3 import com.framsticks.params.types.UniqueListParam; 3 4 import com.framsticks.util.FramsticksException; 4 5 import com.framsticks.util.UnimplementedException; … … 80 81 return null; 81 82 } 82 return Param.build().id(Integer.toString(i)).forAccess(elementAccess).finish(CompositeParam.class); 83 Iterator<Map.Entry<String, Object>> iterator = map.entrySet().iterator(); 84 while (i > 0 && iterator.hasNext()) { 85 iterator.next(); 86 --i; 87 } 88 if (i > 0) { 89 return null; 90 } 91 if (!iterator.hasNext()) { 92 return null; 93 } 94 return paramBuilder.id(getUidOf(iterator.next().getValue())).finish(CompositeParam.class); 83 95 } 84 96 … … 96 108 return null; 97 109 } 98 return Param.build().id(id).forAccess(elementAccess).finish(CompositeParam.class);110 return paramBuilder.id(id).finish(CompositeParam.class); 99 111 } 100 112 … … 148 160 String uid = elementAccess.get(uidName, String.class); 149 161 elementAccess.select(tmp); 150 if (uid == null) {151 return null;152 }153 162 return uid; 154 163 } … … 233 242 } 234 243 235 @Override236 244 public String computeIdentifierFor(Object selected) { 237 245 String uid = getUidOf(selected); … … 260 268 @Override 261 269 public Param next() { 262 return Param.build().id(internal.next().getKey()).forAccess(elementAccess).finish();270 return paramBuilder.id(internal.next().getKey()).finish(); 263 271 } 264 272 … … 282 290 return getParam(number); 283 291 } 292 293 @Override 294 public ParamBuilder buildParam(ParamBuilder builder) { 295 return builder.name(containedTypeName + " list").type(UniqueListParam.class).containedTypeName(containedTypeName).uid(uidName); 296 } 297 284 298 } -
java/main/src/main/java/com/framsticks/params/Util.java
r90 r99 36 36 } 37 37 38 public static int copyParams(AccessInterface to, AccessInterface from) { 38 public static int takeAllNonNullValues(AccessInterface to, AccessInterface from) { 39 int copied = 0; 40 for (ValueParam f : filterInstanceof(from.getParams(), ValueParam.class)) { 41 Object v = from.get(f, Object.class); 42 if (v == null) { 43 continue; 44 } 45 to.set(f, v); 46 ++copied; 47 } 48 return copied; 49 } 50 51 public static int copyExistingParamsTypeSafe(AccessInterface to, AccessInterface from) { 39 52 int copied = 0; 40 53 for (ValueParam f : filterInstanceof(from.getParams(), ValueParam.class)) { -
java/main/src/main/java/com/framsticks/params/annotations/FramsClassAnnotation.java
r90 r99 13 13 14 14 String[] order() default {}; 15 Class<?>[] register() default {}; 15 16 } -
java/main/src/main/java/com/framsticks/params/types/EventParam.java
r87 r99 12 12 public class EventParam extends Param { 13 13 14 protected final String eventArgumentTypeName; 14 15 15 16 … … 19 20 public EventParam(ParamBuilder builder) { 20 21 super(builder); 22 eventArgumentTypeName = builder.getEventArgumentTypeName(); 21 23 } 22 24 23 25 @Override 24 26 public Class<?> getStorageType() { 25 return Void. class;27 return Void.TYPE; 26 28 } 27 29 28 30 @Override 29 31 public String getFramsTypeName() { 30 return "e";32 return eventArgumentTypeName != null ? "e " + eventArgumentTypeName : "e"; 31 33 } 32 34 } -
java/main/src/main/java/com/framsticks/params/types/NumberParam.java
r87 r99 2 2 3 3 import com.framsticks.params.CastFailure; 4 import com.framsticks.params.Flags;5 4 import com.framsticks.params.ParamBuilder; 6 5 import com.framsticks.params.PrimitiveParam; … … 10 9 11 10 import javax.annotation.concurrent.Immutable; 11 import static com.framsticks.params.SetStateFlags.*; 12 12 13 13 /** … … 40 40 } 41 41 if (min != null && v.compareTo(getMin(type)) < 0) { 42 return new ReassignResult<T>(getMin(type), Flags.PSET_HITMIN);42 return new ReassignResult<T>(getMin(type), PSET_HITMIN); 43 43 } 44 44 if (max != null && v.compareTo(getMax(type)) > 0) { 45 return new ReassignResult<T>(getMax(type), Flags.PSET_HITMAX);45 return new ReassignResult<T>(getMax(type), PSET_HITMAX); 46 46 } 47 47 return ReassignResult.create(v); -
java/main/src/main/java/com/framsticks/params/types/ProcedureParam.java
r97 r99 54 54 @Override 55 55 public Class<?> getStorageType() { 56 return Void. class;56 return Void.TYPE; 57 57 } 58 58 -
java/main/src/main/java/com/framsticks/parsers/F0Parser.java
r98 r99 14 14 import static com.framsticks.params.SimpleAbstractAccess.*; 15 15 16 import com.framsticks.params.Flags;17 16 import com.framsticks.params.Param; 18 17 import com.framsticks.params.PrimitiveParam; … … 26 25 import com.framsticks.params.FramsClass; 27 26 import com.framsticks.params.AccessInterface; 27 import static com.framsticks.params.ParamFlags.*; 28 import static com.framsticks.params.SetStateFlags.*; 28 29 29 30 /** … … 205 206 } 206 207 } else { 207 if (nextParamNumber == null || ((params[nextParamNumber].getFlags() & Flags.CANOMITNAME) == 0)) {208 if (nextParamNumber == null || ((params[nextParamNumber].getFlags() & CANOMITNAME) == 0)) { 208 209 nextParamNumber = null; 209 210 throw new Exception( … … 220 221 PrimitiveParam<?> vp = (PrimitiveParam<?>) currentParam; 221 222 int setFlag = access.set(vp, pair.value); 222 if ((setFlag & Flags.PSET_HITMIN) != 0) {223 exceptions.add(createBoundaryHitException(access, vp, pair.value, Flags.PSET_HITMIN));224 } 225 226 if ((setFlag & Flags.PSET_HITMAX) != 0) {227 exceptions.add(createBoundaryHitException(access, vp, pair.value, Flags.PSET_HITMAX));228 } 229 230 if ((setFlag & Flags.PSET_RONLY) != 0) {223 if ((setFlag & PSET_HITMIN) != 0) { 224 exceptions.add(createBoundaryHitException(access, vp, pair.value, PSET_HITMIN)); 225 } 226 227 if ((setFlag & PSET_HITMAX) != 0) { 228 exceptions.add(createBoundaryHitException(access, vp, pair.value, PSET_HITMAX)); 229 } 230 231 if ((setFlag & PSET_RONLY) != 0) { 231 232 throw (new Exception("tried to set a read-only attribute \"" 232 233 + currentParam.getId() … … 250 251 251 252 private static Exception createBoundaryHitException(AccessInterface access, PrimitiveParam<?> param, String value, int flag) { 252 boolean minimum = (flag & Flags.PSET_HITMIN) != 0;253 boolean minimum = (flag & PSET_HITMIN) != 0; 253 254 String boundary = (minimum ? param.getMin(Object.class) : param.getMax(Object.class)).toString(); 254 255 String name = (minimum ? "minimum" : "maximum"); -
java/main/src/main/java/com/framsticks/parsers/F0Writer.java
r90 r99 7 7 import com.framsticks.util.lang.Containers; 8 8 import static com.framsticks.util.lang.Containers.filterInstanceof; 9 import static com.framsticks.params.ParamFlags.*; 9 10 10 11 /** … … 65 66 } 66 67 67 if ((!contiguous) || ((param.getFlags() & Flags.CANOMITNAME) == 0)) {68 if ((!contiguous) || ((param.getFlags() & CANOMITNAME) == 0)) { 68 69 line.append(param.getId()).append("="); 69 70 contiguous = true; -
java/main/src/main/java/com/framsticks/parsers/GenotypeLoader.java
r87 r99 6 6 7 7 import org.apache.log4j.Logger; 8 import static com.framsticks.params.ParamFlags.*; 8 9 9 10 public class GenotypeLoader extends MultiParamLoader { … … 24 25 .param(Param.build().id("genotype").group(0).name("Genotype").type(StringParam.class).min(1)) 25 26 .param(Param.build().id("info").group(0).name("Info").type(StringParam.class).min(1).help("Additional information or comments")) 26 .param(Param.build().id("simi").group(1).flags( Flags.READONLY | Flags.DONTSAVE).name("Similarity").type(FloatParam.class))27 .param(Param.build().id("energ0").group(1).flags( Flags.READONLY | Flags.DONTSAVE).name("Starting energy").type(FloatParam.class))28 .param(Param.build().id("strsiz").group(1).flags( Flags.READONLY | Flags.DONTSAVE | Flags.USERHIDDEN).name("Body parts (deprecated; use numparts)").type(FloatParam.class))29 .param(Param.build().id("strjoints").group(1).flags( Flags.READONLY | Flags.DONTSAVE | Flags.USERHIDDEN).name("Body joints (deprecated; use numjoints)").type(FloatParam.class))30 .param(Param.build().id("nnsiz").group(1).flags( Flags.READONLY | Flags.DONTSAVE | Flags.USERHIDDEN).name("Brain size (deprecated; use numneurons)").type(FloatParam.class))31 .param(Param.build().id("nncon").group(1).flags( Flags.READONLY | Flags.DONTSAVE | Flags.USERHIDDEN).name("Brain connections (deprecated; use numconnections)").type(FloatParam.class))32 .param(Param.build().id("numparts").group(1).flags( Flags.READONLY | Flags.DONTSAVE).name("Body parts").type(FloatParam.class))33 .param(Param.build().id("numjoints").group(1).flags( Flags.READONLY | Flags.DONTSAVE).name("Body joints").type(FloatParam.class))34 .param(Param.build().id("numneurons").group(1).flags( Flags.READONLY | Flags.DONTSAVE).name("Brain size").type(FloatParam.class))35 .param(Param.build().id("numconnections").group(1).flags( Flags.READONLY | Flags.DONTSAVE).name("Brain connections").type(FloatParam.class))27 .param(Param.build().id("simi").group(1).flags(READONLY | DONTSAVE).name("Similarity").type(FloatParam.class)) 28 .param(Param.build().id("energ0").group(1).flags(READONLY | DONTSAVE).name("Starting energy").type(FloatParam.class)) 29 .param(Param.build().id("strsiz").group(1).flags(READONLY | DONTSAVE | USERHIDDEN).name("Body parts (deprecated; use numparts)").type(FloatParam.class)) 30 .param(Param.build().id("strjoints").group(1).flags(READONLY | DONTSAVE | USERHIDDEN).name("Body joints (deprecated; use numjoints)").type(FloatParam.class)) 31 .param(Param.build().id("nnsiz").group(1).flags(READONLY | DONTSAVE | USERHIDDEN).name("Brain size (deprecated; use numneurons)").type(FloatParam.class)) 32 .param(Param.build().id("nncon").group(1).flags(READONLY | DONTSAVE | USERHIDDEN).name("Brain connections (deprecated; use numconnections)").type(FloatParam.class)) 33 .param(Param.build().id("numparts").group(1).flags(READONLY | DONTSAVE).name("Body parts").type(FloatParam.class)) 34 .param(Param.build().id("numjoints").group(1).flags(READONLY | DONTSAVE).name("Body joints").type(FloatParam.class)) 35 .param(Param.build().id("numneurons").group(1).flags(READONLY | DONTSAVE).name("Brain size").type(FloatParam.class)) 36 .param(Param.build().id("numconnections").group(1).flags(READONLY | DONTSAVE).name("Brain connections").type(FloatParam.class)) 36 37 .param(Param.build().id("num").group(2).name("Ordinal number").type(DecimalParam.class)) 37 38 .param(Param.build().id("gnum").group(2).name("Generation").type(DecimalParam.class)) 38 .param(Param.build().id("popsiz").group(2).flags( Flags.USERHIDDEN).name("Deprecated; use entities").type(DecimalParam.class))39 .param(Param.build().id("entities").group(2).flags( Flags.DONTSAVE).name("Instances").type(DecimalParam.class).help("Copies of this genotype"))39 .param(Param.build().id("popsiz").group(2).flags(USERHIDDEN).name("Deprecated; use entities").type(DecimalParam.class)) 40 .param(Param.build().id("entities").group(2).flags(DONTSAVE).name("Instances").type(DecimalParam.class).help("Copies of this genotype")) 40 41 .param(Param.build().id("lifespan").group(2).name("Life span").type(FloatParam.class).help("Average life span")) 41 42 .param(Param.build().id("velocity").group(2).name("Velocity").type(FloatParam.class).help("Average velocity")) … … 43 44 .param(Param.build().id("vertvel").group(2).name("Vertical velocity").type(FloatParam.class)) 44 45 .param(Param.build().id("vertpos").group(2).name("Vertical position").type(FloatParam.class)) 45 .param(Param.build().id("fit").group(3).flags( Flags.READONLY | Flags.DONTSAVE).name("Fitness").type(FloatParam.class))46 .param(Param.build().id("fit2").group(3).flags( Flags.READONLY | Flags.DONTSAVE).name("Final fitness").type(FloatParam.class).help("Fitness shifted by (avg-n*stddev)"))47 .param(Param.build().id("f0genotype").group(4).flags( Flags.READONLY | Flags.DONTSAVE).name("f0 genotype").type(StringParam.class).min(1).help("converted to f0 genotype"))46 .param(Param.build().id("fit").group(3).flags(READONLY | DONTSAVE).name("Fitness").type(FloatParam.class)) 47 .param(Param.build().id("fit2").group(3).flags(READONLY | DONTSAVE).name("Final fitness").type(FloatParam.class).help("Fitness shifted by (avg-n*stddev)")) 48 .param(Param.build().id("f0genotype").group(4).flags(READONLY | DONTSAVE).name("f0 genotype").type(StringParam.class).min(1).help("converted to f0 genotype")) 48 49 .param(Param.build().id("user1").group(2).name("User field 1").type(UniversalParam.class)) 49 50 .param(Param.build().id("user2").group(2).name("User field 2").type(UniversalParam.class)) 50 51 .param(Param.build().id("user3").group(2).name("User field 3").type(UniversalParam.class)) 51 .param(Param.build().id("isValid").group(0).flags( Flags.READONLY | Flags.DONTSAVE | Flags.USERHIDDEN).name("Valid").type(DecimalParam.class).min(0).max(1))52 .param(Param.build().id("uid").group(0).flags( Flags.READONLY | Flags.USERHIDDEN).name("#").type("s").help("Unique identifier"))52 .param(Param.build().id("isValid").group(0).flags(READONLY | DONTSAVE | USERHIDDEN).name("Valid").type(DecimalParam.class).min(0).max(1)) 53 .param(Param.build().id("uid").group(0).flags(READONLY | USERHIDDEN).name("#").type("s").help("Unique identifier")) 53 54 .finish(); 54 55 -
java/main/src/main/java/com/framsticks/parsers/XmlLoader.java
r97 r99 19 19 import com.framsticks.util.AutoBuilder; 20 20 import com.framsticks.util.FramsticksException; 21 import com.framsticks.util.lang.Strings; 21 22 22 23 public class XmlLoader { … … 47 48 } 48 49 50 public String mangleName(String name) { 51 return useLowerCase ? name.toLowerCase() : name; 52 } 53 54 public String mangleAttribute(String name) { 55 return useLowerCase ? name.toLowerCase() : Strings.uncapitalize(name); 56 } 57 49 58 public Object processElement(Element element) { 50 String name = element.getNodeName(); 51 if (useLowerCase) { 52 name = name.toLowerCase(); 53 } 59 final String name = mangleName(element.getNodeName()); 54 60 if (name.equals("import")) { 55 61 String className = element.getAttribute("class"); … … 71 77 for (int i = 0; i < attributes.getLength(); ++i) { 72 78 Node attributeNode = attributes.item(i); 73 access.set( attributeNode.getNodeName().toLowerCase(), attributeNode.getNodeValue());79 access.set(mangleAttribute(attributeNode.getNodeName()), attributeNode.getNodeValue()); 74 80 } 75 81 -
java/main/src/main/java/com/framsticks/remote/RecursiveFetcher.java
r98 r99 3 3 import static com.framsticks.core.TreeOperations.*; 4 4 5 import com.framsticks.core.Mode;6 5 import com.framsticks.core.Node; 7 6 import com.framsticks.core.Path; … … 67 66 } 68 67 ++dispatched; 69 tree.get(childPath, Mode.FETCH,new FutureHandler<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) {68 tree.get(childPath, new FutureHandler<Path>(Logging.logger(log, "resolve", RecursiveFetcher.this)) { 70 69 @Override 71 70 protected void result(Path result) { … … 83 82 84 83 protected void fetch(final Path path) { 85 tree.get(path, Mode.FETCH,new Future<Path>() {84 tree.get(path, new Future<Path>() { 86 85 87 86 @Override -
java/main/src/main/java/com/framsticks/remote/RemoteTree.java
r98 r99 7 7 import com.framsticks.communication.queries.SetRequest; 8 8 import com.framsticks.core.AbstractTree; 9 import com.framsticks.core.Mode;10 import com.framsticks.core.ListChange;11 9 import com.framsticks.core.Path; 12 10 import com.framsticks.params.*; 11 import com.framsticks.params.EventListener; 13 12 import com.framsticks.params.annotations.AutoAppendAnnotation; 14 13 import com.framsticks.params.annotations.FramsClassAnnotation; … … 28 27 import com.framsticks.util.dispatching.ThrowExceptionHandler; 29 28 import com.framsticks.util.lang.Casting; 30 import com.framsticks.util.lang.Pair;31 29 import com.framsticks.util.dispatching.RunAt; 32 30 import static com.framsticks.core.TreeOperations.*; … … 42 40 */ 43 41 @FramsClassAnnotation 44 public class RemoteTree extends AbstractTree implements JoinableParent {42 public final class RemoteTree extends AbstractTree implements JoinableParent { 45 43 46 44 private final static Logger log = Logger.getLogger(RemoteTree.class); 47 45 48 46 protected ClientSideManagedConnection connection; 49 50 protected final Set<Pair<Path, Subscription<?>>> subscriptions = new HashSet<>();51 52 public Pair<Path, Subscription<?>> getSubscription(Path path) {53 for (Pair<Path, Subscription<?>> s : subscriptions) {54 if (s.first.isTheSameObjects(path)) {55 return s;56 }57 }58 return null;59 }60 47 61 48 public RemoteTree() { … … 88 75 89 76 @Override 90 public void get(final Path path, final ValueParam param, Mode mode,final Future<Object> future) {77 public void get(final Path path, final ValueParam param, final Future<Object> future) { 91 78 assert isActive(); 92 79 assert param != null; … … 166 153 167 154 @Override 168 public void get(final Path path, final Mode mode, finalFuture<Path> future) {155 public void get(final Path path, final Future<Path> future) { 169 156 assert isActive(); 170 157 … … 187 174 } 188 175 189 190 @Override191 protected void tryRegisterOnChangeEvents(final Path path) {192 assert isActive();193 AccessInterface access = bindAccess(path);194 if (!(access instanceof ListAccess)) {195 return;196 }197 198 assert path.size() >= 2;199 FramsClass underFramsClass = getInfoFromCache(path.getUnder().getParam().getContainedTypeName());200 201 EventParam changedEvent;202 try {203 changedEvent = underFramsClass.getParamEntry(path.getTop().getParam().getId() + "_changed", EventParam.class);204 } catch (FramsticksException e) {205 return;206 }207 208 log.debug("registering for " + changedEvent);209 if (getSubscription(path) != null) {210 return;211 }212 213 final Pair<Path, Subscription<?>> temporary = new Pair<>(path, null);214 subscriptions.add(temporary);215 216 connection.subscribe(path.getTextual() + "_changed", this, new SubscriptionCallback<Tree>() {217 @Override218 public EventCallback subscribed(final Subscription<? super Tree> subscription) {219 if (subscription == null) {220 log.error("failed to subscribe for change event for " + path);221 return null;222 }223 log.debug("subscribed for change event for " + path);224 // subscription.setDispatcher(RemoteInstance.this);225 RemoteTree.this.dispatch(new RunAt<Tree>(this) {226 @Override227 protected void runAt() {228 subscriptions.remove(temporary);229 subscriptions.add(new Pair<Path, Subscription<?>>(path, subscription));230 }231 });232 return new EventCallback() {233 @Override234 public void call(List<File> files) {235 assert isActive();236 assert files.size() == 1;237 final MultiParamLoader loader = new MultiParamLoader();238 loader.setNewSource(files.get(0).getContent());239 loader.addBreakCondition(MultiParamLoader.Status.AfterObject);240 loader.addListener(MultiParamLoader.Status.OnComment, new MultiParamLoader.StatusListener() {241 242 @Override243 public void onStatusChange() {244 throw new FramsticksException().msg("multi param loader error").arg("line", loader.getCurrentLine());245 }246 });247 ReflectionAccess access = new ReflectionAccess(ListChange.class, FramsClass.build().forClass(ListChange.class));248 loader.addAccessInterface(access);249 250 MultiParamLoader.Status status;251 while ((status = loader.go()) != MultiParamLoader.Status.Finished) {252 if (status == MultiParamLoader.Status.AfterObject) {253 AccessInterface accessInterface = loader.getLastAccessInterface();254 reactToChange(path, (ListChange) accessInterface.getSelected());255 }256 }257 }258 };259 }260 });261 }262 263 protected Future<Path> futureListChanger(final ListChange listChange, final String path) {264 return new FutureHandler<Path>(Logging.logger(log, "failed to " + listChange, path)) {265 @Override266 protected void result(Path result) {267 log.debug(listChange + ": " + result);268 }269 };270 }271 272 protected void reactToChange(final Path path, final ListChange listChange) {273 assert isActive();274 log.debug("reacting to change " + listChange + " in " + path);275 AccessInterface access = bindAccess(path);276 assert access != null;277 278 if ((listChange.getAction() == ListChange.Action.Modify) && (listChange.getPosition() == -1)) {279 final String p = path.getTextual();280 tryGet(this, p, futureListChanger(listChange, p));281 return;282 }283 284 CompositeParam childParam = Casting.tryCast(CompositeParam.class, access.getParam(listChange.getBestIdentifier()));285 assert childParam != null;286 switch (listChange.getAction()) {287 case Add: {288 final String p = path.getTextual() + "/" + childParam.getId();289 tryGet(this, p, futureListChanger(listChange, p));290 break;291 }292 case Remove: {293 access.set(childParam, null);294 break;295 }296 case Modify: {297 final String p = path.getTextual() + "/" + childParam.getId();298 tryGet(this, p, futureListChanger(listChange, p));299 break;300 }301 }302 }303 304 176 @Override 305 177 public void set(final Path path, final PrimitiveParam<?> param, final Object value, final Future<Integer> future) { … … 380 252 } 381 253 382 // @Override 383 // public Path create(Path path) { 384 // assert isActive(); 385 // assert !path.isResolved(); 386 // Path resolved = path.tryFindResolution(); 387 // if (!resolved.isResolved()) { 388 // log.debug("creating: " + path); 389 // //TODO: access parent here, check if it is valid, only then create 390 // AccessInterface access = registry.prepareAccess(path.getTop().getParam()); 391 // assert access != null; 392 // Object child = access.createAccessee(); 393 // assert child != null; 394 // if (path.size() == 1) { 395 // setRoot(new Node(getRoot().getParam(), child)); 396 // } else { 397 // bindAccess(this, path.getUnder()).set(path.getTop().getParam(), child); 398 // } 399 // resolved = path.appendResolution(child); 400 // } 401 // tryRegisterOnChangeEvents(resolved); 402 // return resolved; 403 // } 254 protected final Map<EventListener<?>, EventListener<File>> proxyListeners = new IdentityHashMap<>(); 255 256 public <A> void addListener(Path path, EventParam param, final EventListener<A> listener, final Class<A> argumentType, final Future<Void> future) { 257 assert isActive(); 258 assert path.isResolved(); 259 if ((!argumentType.equals(Object.class)) && (null == registry.getFramsClassForJavaClass(argumentType))) { 260 registry.registerAndBuild(argumentType); 261 } 262 263 final EventListener<File> proxyListener = new EventListener<File>() { 264 265 @Override 266 public void action(final File file) { 267 Dispatching.dispatchIfNotActive(RemoteTree.this, new RunAt<RemoteTree>(RemoteTree.this) { 268 269 @Override 270 protected void runAt() { 271 assert isActive(); 272 if (argumentType.equals(Object.class)) { 273 listener.action(Casting.tryCast(argumentType, file)); 274 return; 275 } 276 AccessInterface access = registry.createAccess(argumentType); 277 Object argument = access.createAccessee(); 278 access.select(argument); 279 if (!argumentType.isInstance(argument)) { 280 throw new FramsticksException().msg("created argument is of wrond type").arg("expected", argumentType).arg("created", argument.getClass()); 281 } 282 A typedArgument = argumentType.cast(argument); 283 284 // log.info("executing event with argument " + argumentType); 285 MultiParamLoader loader = new MultiParamLoader(); 286 loader.setNewSource(file.getContent()); 287 loader.addBreakCondition(MultiParamLoader.Status.AfterObject); 288 loader.addAccessInterface(access); 289 loader.go(); 290 291 listener.action(typedArgument); 292 } 293 }); 294 } 295 }; 296 297 proxyListeners.put(listener, proxyListener); 298 299 connection.addListener(Path.appendString(path.getTextual(), param.getId()), proxyListener, this, future); 300 } 301 302 public void removeListener(Path path, EventParam param, EventListener<?> listener, Future<Void> future) { 303 assert isActive(); 304 EventListener<File> proxyListener = proxyListeners.get(listener); 305 connection.removeListener(proxyListener, this, future); 306 } 404 307 405 308 } -
java/main/src/main/java/com/framsticks/test/TestClass.java
r97 r99 1 1 package com.framsticks.test; 2 3 import java.util.LinkedList; 4 import java.util.List; 2 5 3 6 import org.apache.log4j.Logger; 4 7 8 import com.framsticks.params.EventListener; 5 9 import com.framsticks.params.annotations.FramsClassAnnotation; 6 10 import com.framsticks.params.annotations.ParamAnnotation; 7 11 import com.framsticks.params.types.ProcedureParam; 8 12 9 @FramsClassAnnotation(order = {"name", "history", " appendHistory", "resetHistory"})13 @FramsClassAnnotation(order = {"name", "history", "history_changed", "appendHistory", "resetHistory"}, register = {ChangeEvent.class}) 10 14 public class TestClass { 11 15 private static final Logger log = … … 15 19 protected String name = "test"; 16 20 protected String history = "initial|"; 21 protected final List<EventListener<ChangeEvent>> historyListeners = new LinkedList<>(); 17 22 18 23 /** … … 52 57 log.debug("appending '" + line + "'"); 53 58 history = history + line + "|"; 59 fireHistoryChange(); 54 60 return history.length(); 55 61 } … … 59 65 log.debug("reseting"); 60 66 history = ""; 67 fireHistoryChange(); 68 } 69 70 protected void fireHistoryChange() { 71 for (EventListener<ChangeEvent> l : historyListeners) { 72 ChangeEvent event = new ChangeEvent(); 73 event.history = history; 74 l.action(event); 75 } 76 } 77 78 @ParamAnnotation(id = "history_changed") 79 public void addHistoryListener(EventListener<ChangeEvent> listener) { 80 historyListeners.add(listener); 81 } 82 83 @ParamAnnotation(id = "history_changed") 84 public void removeHistoryListener(EventListener<ChangeEvent> listener) { 85 historyListeners.remove(listener); 86 } 87 88 @Override 89 public String toString() { 90 return "test class " + history; 61 91 } 62 92 -
java/main/src/main/java/com/framsticks/util/dispatching/AtOnceDispatcher.java
r98 r99 5 5 * @author Piotr Sniegowski 6 6 */ 7 public class AtOnceDispatcher<C> implementsDispatcher<C> {7 public class AtOnceDispatcher<C> extends AbstractJoinable implements JoinableDispatcher<C> { 8 8 9 9 @SuppressWarnings("rawtypes") … … 25 25 } 26 26 27 @Override 28 public String getName() { 29 return "atonce"; 30 } 31 32 @Override 33 protected void joinableStart() { 34 35 } 36 37 @Override 38 protected void joinableInterrupt() { 39 finish(); 40 } 41 42 @Override 43 protected void joinableFinish() { 44 45 } 46 47 @Override 48 protected void joinableJoin() throws InterruptedException { 49 50 } 51 27 52 } -
java/main/src/main/java/com/framsticks/util/dispatching/Dispatching.java
r98 r99 224 224 225 225 protected final double timeOut; 226 protected final ExceptionResultHandler handler; 226 227 227 228 /** 228 229 * @param timeOut 229 230 */ 230 public Waiter(double timeOut ) {231 public Waiter(double timeOut, ExceptionResultHandler handler) { 231 232 this.timeOut = timeOut; 233 this.handler = handler; 232 234 } 233 235 … … 247 249 } 248 250 if (!done) { 249 throw new FramsticksException().msg("waiter timed out"); 250 } 251 handler.handle(new FramsticksException().msg("waiter timed out")); 252 } 253 } 254 255 public <T> Future<T> passInFuture(Class<T> type) { 256 return new FutureHandler<T>(handler) { 257 @Override 258 protected void result(T result) { 259 Waiter.this.pass(); 260 } 261 }; 251 262 } 252 263 } … … 254 265 255 266 public static <C> void synchronize(Dispatcher<C> dispatcher, double seconds) { 256 final Waiter waiter = new Waiter(seconds );267 final Waiter waiter = new Waiter(seconds, ThrowExceptionHandler.getInstance()); 257 268 dispatcher.dispatch(new RunAt<C>(ThrowExceptionHandler.getInstance()) { 258 269 @Override -
java/main/src/main/java/com/framsticks/util/dispatching/FutureHandler.java
r97 r99 17 17 } 18 18 19 public static <T> FutureHandler<T> doNothing(Class<T> type, ExceptionResultHandler handler) { 20 return new FutureHandler<T>(handler) { 21 22 @Override 23 protected void result(T result) { 24 25 } 26 }; 27 } 28 19 29 } -
java/main/src/main/java/com/framsticks/util/dispatching/Thread.java
r98 r99 73 73 } 74 74 try { 75 task.run At();75 task.run(); 76 76 } catch (Exception e) { 77 77 if (exceptionHandler != null) { … … 122 122 @Override 123 123 protected void runAt() { 124 runnable.run At();124 runnable.run(); 125 125 } 126 126 }); -
java/main/src/main/java/com/framsticks/util/lang/Casting.java
r84 r99 6 6 */ 7 7 public abstract class Casting { 8 9 10 11 12 13 14 8 public static <T> T tryCast(Class<T> class_, Object object) { 9 try { 10 return class_.cast(object); 11 } catch (ClassCastException ignored) { 12 return null; 13 } 14 } 15 15 16 17 18 19 20 21 22 23 16 public static <T> T assertCast(Class<T> class_, Object object) { 17 try { 18 return class_.cast(object); 19 } catch (ClassCastException ignored) { 20 assert false; 21 return null; 22 } 23 } 24 24 25 26 27 28 29 30 25 public static <T> T throwCast(Class<T> class_, Object object) { 26 if (object == null) { 27 throw new NullPointerException(); 28 } 29 return class_.cast(object); 30 } 31 31 } -
java/main/src/main/java/com/framsticks/util/lang/Strings.java
r97 r99 36 36 } 37 37 38 public static String toStringEmptyProof(Object object, Object def) { 39 if (object == null) { 40 return def.toString(); 41 } 42 String v = object.toString(); 43 return notEmpty(v) ? v : def.toString(); 44 } 45 38 46 public static String collapse(String s) { 39 47 if (s == null) { -
java/main/src/main/resources/configs/framsticks.xml
r98 r99 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Framsticks> 3 <!-- <import class="com.framsticks.gui.console.ManagedConsole" /> -->4 <!-- <import class="com.framsticks.remote.RemoteTree" /> -->5 <!-- <ManagedConsole> -->6 <!-- <RemoteTree name="remote" address="localhost:9009" /> -->7 <!-- </ManagedConsole> -->8 9 <!-- <import class="com.framsticks.gui.console.DirectConsole" /> -->10 <!-- <import class="com.framsticks.communication.ClientSideRawConnection" /> -->11 <!-- <DirectConsole> -->12 <!-- <ClientSideRawConnection address="localhost:9009" /> -->13 <!-- </DirectConsole> -->14 15 3 <import class="com.framsticks.gui.Browser" /> 16 4 <import class="com.framsticks.remote.RemoteTree" /> 17 <import class="com.framsticks.remote.SimulatorTree" />18 5 <import class="com.framsticks.model.ModelPackage" /> 19 6 <import class="com.framsticks.model.ModelBuilder" /> 20 7 <import class="com.framsticks.model.f0.SchemaBuilder" /> 21 <import class="com.framsticks.core. ObjectTree" />8 <import class="com.framsticks.core.LocalTree" /> 22 9 <import class="com.framsticks.hosting.Server" /> 23 10 <import class="com.framsticks.test.TestClass" /> 11 <import class="com.framsticks.gui.table.ColumnsConfig" /> 24 12 <Browser> 25 < SimulatorTree name="localhost:9009" address="localhost:9009">13 <RemoteTree name="localhost:9009" address="localhost:9009"> 26 14 <ModelPackage /> 27 </ SimulatorTree>28 <!-- < ObjectTree name="model"> -->15 </RemoteTree> 16 <!-- <LocalTree name="model"> --> 29 17 <!-- <ModelBuilder resource="/examples/f0_example.txt" /> --> 30 <!-- </ ObjectTree> -->31 <!-- < ObjectTree name="f0schema"> -->18 <!-- </LocalTree> --> 19 <!-- <LocalTree name="f0schema"> --> 32 20 <!-- <SchemaBuilder /> --> 33 <!-- </ObjectTree> --> 34 <!-- <RemoteTree name="remote" address="localhost:9007" /> --> 21 <!-- </LocalTree> --> 22 <RemoteTree name="remote" address="localhost:9007" /> 23 <ColumnsConfig className="Genotype" columnsNames="uid name" /> 35 24 </Browser> 36 < !-- <Server name="server" port="9007"> -->37 <!-- <ObjectTree name="test"> -->38 <!-- <TestClass /> -->39 <!-- </ObjectTree> -->40 < !-- </Server> -->25 <Server name="server" port="9007"> 26 <LocalTree name="test"> 27 <TestClass /> 28 </LocalTree> 29 </Server> 41 30 </Framsticks> -
java/main/src/main/resources/configs/log4j.properties
r98 r99 29 29 30 30 log4j.logger.com.framsticks=INFO 31 # log4j.logger.com.framsticks.gui.table=DEBUG 31 32 # log4j.logger.com.framsticks.gui.Panel=DEBUG 32 33 # log4j.logger.com.framsticks.remote.RemoteTree=DEBUG -
java/main/src/test/java/com/framsticks/communication/RequestTest.java
r96 r99 7 7 import com.framsticks.communication.queries.GetRequest; 8 8 import com.framsticks.communication.queries.InfoRequest; 9 import com.framsticks.communication.queries.RegisterRequest; 9 10 import com.framsticks.communication.queries.SetRequest; 10 11 import com.framsticks.communication.queries.UseRequest; … … 46 47 { SetRequest.class, "set /test field value"}, 47 48 { SetRequest.class, "set /test field \"value with spaces\""}, 49 { RegisterRequest.class, "reg /test/field_changed"}, 48 50 { VersionRequest.class, "version 4"}, 49 51 { InfoRequest.class, "info /some/path"}, -
java/main/src/test/java/com/framsticks/core/PathTest.java
r87 r99 8 8 9 9 import org.testng.annotations.BeforeClass; 10 import org.testng.annotations.DataProvider; 10 11 import org.testng.annotations.Test; 11 12 12 13 import com.framsticks.test.TestConfiguration; 14 import com.framsticks.util.lang.Pair; 15 16 import static org.fest.assertions.Assertions.*; 13 17 14 18 @Test … … 25 29 } 26 30 27 @Test 28 public void testPath() { 31 @Test(dataProvider = "pathValidationProvider") 32 public void pathValidation(String path, boolean ok) { 33 assertThat(Path.isValidString(path)).describedAs(path).isEqualTo(ok); 34 } 35 36 @Test(dataProvider = "pathSplitingProvider") 37 public void pathSpliting(String path, String prefix, String suffix) { 38 Pair<String, String> p = Path.removeLastElement(path); 39 assertThat(p.first).isEqualTo(prefix); 40 assertThat(p.second).isEqualTo(suffix); 41 } 42 43 @DataProvider 44 public Object[][] pathValidationProvider() { 45 return new Object[][] { 46 { "/", true }, 47 { "/path", true }, 48 { "path", false }, 49 { "/path/to/", false }, 50 { "/path/to", true }, 51 { "/testClass/history_changed", true }, 52 { "/cli/events/e0", true } 53 54 }; 55 } 56 57 @DataProvider 58 public Object[][] pathSplitingProvider() { 59 return new Object[][] { 60 { "/event", "/", "event" }, 61 { "/path/event", "/path", "event" } 62 }; 29 63 } 30 64 -
java/main/src/test/java/com/framsticks/gui/BrowserBaseTest.java
r98 r99 50 50 protected void clickAndExpandPath(String path) { 51 51 tree.clickPath(path); 52 Dispatching.sleep( 1.0);52 Dispatching.sleep(2.0); 53 53 tree.expandPath(path); 54 54 robot.waitForIdle(); -
java/main/src/test/java/com/framsticks/gui/BrowserTest.java
r98 r99 12 12 13 13 import com.framsticks.model.ModelPackage; 14 import com.framsticks.remote. SimulatorTree;14 import com.framsticks.remote.RemoteTree; 15 15 import com.framsticks.util.dispatching.Dispatching; 16 16 … … 19 19 private static final Logger log = Logger.getLogger(BrowserTest.class); 20 20 21 SimulatorTree localhost;21 RemoteTree localhost; 22 22 23 23 @Override … … 25 25 browser = new Browser(); 26 26 27 localhost = new SimulatorTree();27 localhost = new RemoteTree(); 28 28 localhost.setName("localhost"); 29 29 localhost.setAddress("localhost:9009"); … … 37 37 public void testShow() { 38 38 Dispatching.synchronize(localhost, 1.0); 39 // Dispatching.sleep(0.5);39 Dispatching.sleep(2.0); 40 40 log.info("testing"); 41 tree.clickRow(0).expandRow(0); 42 robot.waitForIdle(); 41 clickAndExpandPath("localhost"); 42 // tree.clickRow(0).expandRow(0); 43 // robot.waitForIdle(); 43 44 44 tree.clickRow(1).expandRow(1); 45 robot.waitForIdle(); 45 clickAndExpandPath("localhost/simulator"); 46 // tree.clickRow(1).expandRow(1); 47 // robot.waitForIdle(); 46 48 assertThat(tree.valueAt(1)).isEqualTo("simulator"); 47 49 robot.waitForIdle(); -
java/main/src/test/java/com/framsticks/gui/ProcedureBrowserTest.java
r97 r99 7 7 import org.testng.annotations.Test; 8 8 9 import com.framsticks.core.Path; 9 10 import com.framsticks.core.Tree; 10 import com.framsticks.core. ObjectTree;11 import com.framsticks.core.LocalTree; 11 12 import com.framsticks.params.AccessInterface; 13 import com.framsticks.params.EventListener; 12 14 import com.framsticks.params.FramsClass; 13 15 import com.framsticks.params.ReflectionAccess; 16 import com.framsticks.params.types.EventParam; 14 17 import com.framsticks.params.types.StringParam; 15 18 import com.framsticks.parsers.XmlLoader; 19 import com.framsticks.test.ChangeEvent; 16 20 import com.framsticks.test.TestClass; 21 import com.framsticks.util.dispatching.FutureHandler; 17 22 // import com.framsticks.util.dispatching.Dispatching; 18 23 import com.framsticks.util.dispatching.RunAt; … … 22 27 public class ProcedureBrowserTest extends BrowserBaseTest { 23 28 24 ObjectTree tree;29 LocalTree tree; 25 30 26 31 @Override … … 29 34 30 35 assertThat(browser.getTrees().size()).isEqualTo(1); 31 assertThat(browser.getTrees().get("test")).isInstanceOf( ObjectTree.class);36 assertThat(browser.getTrees().get("test")).isInstanceOf(LocalTree.class); 32 37 33 tree = ( ObjectTree) browser.getTrees().get("test");38 tree = (LocalTree) browser.getTrees().get("test"); 34 39 } 35 40 … … 60 65 assertThat(access).isInstanceOf(ReflectionAccess.class); 61 66 FramsClass framsClass = access.getFramsClass(); 62 assertThat(framsClass.getParamCount()).isEqualTo( 4);67 assertThat(framsClass.getParamCount()).isEqualTo(5); 63 68 assertThat(framsClass.getParam(0).getId()).isEqualTo("name"); 64 69 assertThat(framsClass.getParam(1).getId()).isEqualTo("history"); 65 assertThat(framsClass.getParam(2).getId()).isEqualTo("appendHistory"); 66 assertThat(framsClass.getParam(3).getId()).isEqualTo("resetHistory"); 70 assertThat(framsClass.getParam(2).getId()).isEqualTo("history_changed"); 71 assertThat(framsClass.getParam(3).getId()).isEqualTo("appendHistory"); 72 assertThat(framsClass.getParam(4).getId()).isEqualTo("resetHistory"); 67 73 68 74 assertThat(access.get("history", String.class)).isEqualTo("initial|"); … … 77 83 waitForIdle(); 78 84 85 final EventListener<ChangeEvent> listener = new EventListener<ChangeEvent>() { 86 87 @Override 88 public void action(ChangeEvent argument) { 89 assertThat(argument.history).isEqualTo(""); 90 } 91 }; 79 92 80 93 tree.dispatch(new RunAt<Tree>(failOnException) { 81 94 @Override 82 95 protected void runAt() { 83 assertThat(bindAccess(tree, "/").get("history", String.class)).isEqualTo("initial|Żółw|"); 96 AccessInterface access = bindAccess(tree, "/"); 97 assertThat(access.get("history", String.class)).isEqualTo("initial|Żółw|"); 98 99 tree.addListener(Path.to(tree, "/"), access.getFramsClass().getParamEntry("history_changed", EventParam.class), listener, ChangeEvent.class, FutureHandler.doNothing(Void.class, failOnException)); 84 100 } 85 101 }); … … 91 107 @Override 92 108 protected void runAt() { 93 assertThat(bindAccess(tree, "/").get("history", String.class)).isEqualTo(""); 109 AccessInterface access = bindAccess(tree, "/"); 110 assertThat(access.get("history", String.class)).isEqualTo(""); 111 112 tree.removeListener(Path.to(tree, "/"), access.getFramsClass().getParamEntry("history_changed", EventParam.class), listener, FutureHandler.doNothing(Void.class, failOnException)); 94 113 } 95 114 }); -
java/main/src/test/java/com/framsticks/hosting/ServerTest.java
r98 r99 2 2 3 3 // import org.apache.log4j.Logger; 4 import java.util.Arrays; 5 import java.util.LinkedList; 6 import java.util.List; 7 4 8 import org.testng.annotations.Test; 5 9 6 import com.framsticks.core.Mode; 7 import com.framsticks.core.ObjectTree; 10 import com.framsticks.core.LocalTree; 8 11 import com.framsticks.core.Path; 12 import com.framsticks.core.TreeOperations; 9 13 import com.framsticks.core.XmlBasedTest; 10 14 import com.framsticks.remote.RemoteTree; 11 15 16 import com.framsticks.test.ChangeEvent; 12 17 import com.framsticks.test.TestClass; 13 18 import com.framsticks.core.Tree; 14 19 import com.framsticks.params.FramsClass; 15 import com.framsticks.util.dispatching.Dispatching;16 20 import com.framsticks.params.AccessInterface; 21 import com.framsticks.params.EventListener; 17 22 import com.framsticks.params.PrimitiveParam; 18 23 import com.framsticks.params.PropertiesAccess; 24 import com.framsticks.params.types.EventParam; 25 // import com.framsticks.params.types.EventParam; 19 26 import com.framsticks.params.types.ProcedureParam; 20 27 import com.framsticks.util.dispatching.Dispatching.Waiter; … … 34 41 35 42 protected Server server; 36 protected ObjectTree hosted;43 protected LocalTree hosted; 37 44 protected TestClass hostedObject; 45 protected EventListener<ChangeEvent> listener; 46 protected List<String> listenerArguments = new LinkedList<>(); 38 47 39 48 @Override … … 50 59 server = (Server) framsticks.get("test"); 51 60 remote = (RemoteTree) framsticks.get("remote"); 52 assertThat(server.getHosted()).isInstanceOf( ObjectTree.class);53 hosted = ( ObjectTree) server.getHosted();61 assertThat(server.getHosted()).isInstanceOf(LocalTree.class); 62 hosted = (LocalTree) server.getHosted(); 54 63 assertThat(hosted.getRootObject()).isInstanceOf(TestClass.class); 55 64 hostedObject = hosted.getRootObject(TestClass.class); … … 58 67 @Test(dependsOnMethods = "runServer") 59 68 public void fetchInfo() { 60 remote.dispatch(new RunAt<Tree>(failOnException) { 69 final Waiter waiter = produceWaiter(1.0); 70 71 TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) { 61 72 @Override 62 protected void runAt() { 63 remote.info(Path.to(remote, "/"), new FutureHandler<FramsClass>(failOnException) { 64 @Override 65 protected void result(FramsClass result) { 66 remoteTestFramsClass = result; 67 assertThat(result.getId()).isEqualTo("TestClass"); 68 } 69 }); 73 protected void result(Path path) { 74 assertThat(path.isResolved()).isTrue(); 75 remoteTestFramsClass = bindAccess(path).getFramsClass(); 76 assertThat(remoteTestFramsClass.getName()).isEqualTo("TestClass"); 77 waiter.pass(); 70 78 } 71 79 }); 72 80 73 Dispatching.synchronize(remote, 1.0);74 81 } 75 82 … … 78 85 final Waiter waiter = produceWaiter(1.0); 79 86 80 remote.dispatch(new RunAt<Tree>(failOnException) {87 TreeOperations.tryGet(remote, "/testClass", new FutureHandler<Path>(failOnException) { 81 88 @Override 82 protected void runAt() { 83 final Path path = Path.to(remote, "/"); 84 assertThat(path.isResolved()).isFalse(); 85 86 remote.get(path, Mode.FETCH, new FutureHandler<Path>(failOnException) { 87 @Override 88 protected void result(Path path) { 89 assertThat(path.isResolved()).isTrue(); 90 remotePath = path; 91 AccessInterface access = bindAccess(path); 92 assertThat(access).isInstanceOf(PropertiesAccess.class); 93 assertThat(access.get("name", String.class)).isEqualTo("a test name"); 94 waiter.pass(); 95 } 96 }); 89 protected void result(Path path) { 90 assertThat(path.isResolved()).isTrue(); 91 remotePath = path; 92 AccessInterface access = bindAccess(path); 93 assertThat(access).isInstanceOf(PropertiesAccess.class); 94 assertThat(access.get("name", String.class)).isEqualTo("a test name"); 95 waiter.pass(); 97 96 } 98 97 }); … … 120 119 121 120 @Test(dependsOnMethods = "setValueName") 121 public void registerListener() { 122 final Waiter waiter = produceWaiter(1.0); 123 listener = new EventListener<ChangeEvent>() { 124 125 @Override 126 public void action(ChangeEvent argument) { 127 listenerArguments.add(argument.history); 128 } 129 }; 130 131 TreeOperations.tryGet(remote, "/cli/events", new FutureHandler<Path>(failOnException) { 132 @Override 133 protected void result(Path path) { 134 waiter.pass(); 135 } 136 }); 137 138 addListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, ChangeEvent.class, produceWaiter(1.0).passInFuture(Void.class)); 139 } 140 141 @Test(dependsOnMethods = "registerListener") 122 142 public void callMethod() { 123 final Waiter firstWaiter = produceWaiter(2.0);124 143 final Waiter waiter = produceWaiter(2.0); 125 144 126 call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, new FutureHandler<Object>(failOnException) { 127 @Override 128 protected void result(Object result) { 129 firstWaiter.pass(); 130 } 131 }); 145 call(remotePath, remoteTestFramsClass.getParamEntry("resetHistory", ProcedureParam.class), new Object[] {}, produceWaiter(2.0).passInFuture(Object.class)); 132 146 133 147 call(remotePath, remoteTestFramsClass.getParamEntry("appendHistory", ProcedureParam.class), new Object[] {"next word"}, new FutureHandler<Object>(failOnException) { … … 143 157 } 144 158 }); 159 } 145 160 161 162 @Test(dependsOnMethods = "callMethod") 163 public void deregisterListener() { 164 removeListener(remotePath, remoteTestFramsClass.getParamEntry("history_changed", EventParam.class), listener, produceWaiter(1.0).passInFuture(Void.class)); 165 166 assertThat(listenerArguments).isEqualTo(Arrays.asList("", "next word|")); 146 167 } 147 168 -
java/main/src/test/java/com/framsticks/params/FramsClassBuilderTest.java
r97 r99 6 6 import org.testng.annotations.Test; 7 7 8 import com.framsticks.params.types.EventParam; 8 9 import com.framsticks.params.types.ProcedureParam; 9 10 import com.framsticks.params.types.StringParam; 10 11 import com.framsticks.parsers.Savers; 12 import com.framsticks.test.ChangeEvent; 11 13 import com.framsticks.test.TestClass; 12 14 import com.framsticks.test.TestConfiguration; 15 import com.framsticks.util.lang.Holder; 16 13 17 import static org.fest.assertions.Assertions.*; 14 18 … … 30 34 @Test 31 35 public void checkProcedureParams() { 32 assertThat(framsClass.getParamCount()).isEqualTo( 4);36 assertThat(framsClass.getParamCount()).isEqualTo(5); 33 37 34 38 assertThat(framsClass.getParam("name")).isInstanceOf(StringParam.class); 35 39 assertThat(framsClass.getParam("history")).isInstanceOf(StringParam.class); 40 assertThat(framsClass.getParam("history_changed")).isInstanceOf(EventParam.class); 36 41 37 42 assertThat(framsClass.getParam("appendHistory")).isInstanceOf(ProcedureParam.class); … … 62 67 "", 63 68 "prop:", 69 "id:history_changed", 70 "name:HistoryListener", 71 "type:e ChangeEvent", 72 "", 73 "prop:", 64 74 "id:appendHistory", 65 75 "name:AppendHistory", … … 75 85 } 76 86 87 @Test(dependsOnMethods = "print") 88 public void createAccess() { 89 access = new ReflectionAccess(TestClass.class, framsClass); 90 access.select(test); 91 } 77 92 78 @Test(dependsOnMethods = " print")93 @Test(dependsOnMethods = "createAccess") 79 94 public void callProcedures() { 80 access = new ReflectionAccess(TestClass.class, framsClass);81 82 access.select(test);83 95 84 96 assertThat(access.get("history", String.class)).isEqualTo("initial|first|"); … … 93 105 94 106 assertThat(access.get("history", String.class)).isEqualTo(""); 107 } 95 108 109 @Test(dependsOnMethods = "callProcedures") 110 public void listeners() { 111 112 final Holder<String> called = new Holder<>(); 113 114 final EventListener<ChangeEvent> listener = new EventListener<ChangeEvent>() { 115 116 @Override 117 public void action(ChangeEvent argument) { 118 called.set(argument.history); 119 } 120 }; 121 122 final EventParam eventParam = access.getFramsClass().getParamEntry("history_changed", EventParam.class); 123 access.reg(eventParam, listener); 124 125 final String currentHistory = access.get("history", String.class); 126 final String addition = "test"; 127 128 access.call("appendHistory", new Object[] { addition }); 129 130 String expected = currentHistory + addition + "|"; 131 assertThat(access.get("history", String.class)).isEqualTo(expected); 132 assertThat(called.get()).isEqualTo(expected); 133 access.regRemove(eventParam, listener); 96 134 } 97 135 -
java/main/src/test/java/com/framsticks/test/TestConfiguration.java
r98 r99 17 17 import com.framsticks.util.dispatching.ExceptionResultHandler; 18 18 19 import static org.fest.assertions.Assertions.*;19 // import static org.fest.assertions.Assertions.*; 20 20 21 21 public class TestConfiguration { … … 31 31 private final List<AssertionError> asyncAssertions = new LinkedList<>(); 32 32 33 public static AssertionError wrapInAssertion(Throwable throwable) { 34 if (throwable instanceof AssertionError) { 35 return (AssertionError) throwable; 36 } 37 38 AssertionError ae = new AssertionError(); 39 ae.initCause(throwable); 40 return ae; 41 } 42 43 public void addAsyncAssertion(Throwable throwable) { 44 synchronized (asyncAssertions) { 45 asyncAssertions.add(wrapInAssertion(throwable)); 46 } 47 } 48 33 49 public ExceptionHandler createExceptionHandler() { 34 50 return new ExceptionHandler() { 35 51 @Override 36 52 public boolean handle(Dispatcher<?> dispatcher, Throwable throwable) { 37 AssertionError ae; 38 if (AssertionError.class.isInstance(throwable)) { 39 ae = AssertionError.class.cast(throwable); 40 } else { 41 ae = new AssertionError(); 42 ae.initCause(throwable); 43 } 44 synchronized (asyncAssertions) { 45 asyncAssertions.add(ae); 46 } 53 addAsyncAssertion(throwable); 47 54 return true; 48 55 } … … 83 90 84 91 protected Dispatching.Waiter produceWaiter(double timeOut) { 85 Waiter waiter = new Waiter(timeOut );92 Waiter waiter = new Waiter(timeOut, failOnException); 86 93 waiters.add(waiter); 87 94 return waiter; 88 95 } 89 96 90 public staticfinal ExceptionResultHandler failOnException = new ExceptionResultHandler() {97 public final ExceptionResultHandler failOnException = new ExceptionResultHandler() { 91 98 @Override 92 99 public void handle(FramsticksException e) { 93 e.printStackTrace();94 a ssertThat(e).isNull();100 log.error("passing exception as assertion in " + TestConfiguration.this.getClass(), e); 101 addAsyncAssertion(e); 95 102 } 96 103 }; -
java/main/src/test/resources/configs/ProcedureBrowserTest.xml
r97 r99 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <Browser> 3 <import class="com.framsticks.core. ObjectTree" />3 <import class="com.framsticks.core.LocalTree" /> 4 4 <import class="com.framsticks.test.TestClass" /> 5 < ObjectTree name="test">5 <LocalTree name="test"> 6 6 <TestClass /> 7 </ ObjectTree>7 </LocalTree> 8 8 </Browser> -
java/main/src/test/resources/configs/ServerTest.xml
r97 r99 3 3 <import class="com.framsticks.hosting.Server" /> 4 4 <import class="com.framsticks.remote.RemoteTree" /> 5 <import class="com.framsticks.core. ObjectTree" />5 <import class="com.framsticks.core.LocalTree" /> 6 6 <import class="com.framsticks.test.TestClass" /> 7 7 <import class="com.framsticks.running.LoggingOutputListener" /> 8 8 <Server name="server" port="9007"> 9 < ObjectTree name="test">9 <LocalTree name="test"> 10 10 <TestClass name="a test name" /> 11 </ ObjectTree>11 </LocalTree> 12 12 </Server> 13 13 <RemoteTree name="remote" address="localhost:9007" /> -
java/main/src/test/resources/configs/test.xml
r97 r99 2 2 <Framsticks> 3 3 <import class="com.framsticks.gui.Browser" /> 4 <import class="com.framsticks.remote. SimulatorTree" />4 <import class="com.framsticks.remote.RemoteTree" /> 5 5 <Browser name="browser"> 6 < SimulatorTree name="localhost:9009" address="localhost:9009" />6 <RemoteTree name="localhost:9009" address="localhost:9009" /> 7 7 </Browser> 8 8 </Framsticks> -
java/main/src/test/resources/log4j.properties
r98 r99 28 28 log4j.logger.com.framsticks=WARN 29 29 log4j.logger.com.framsticks.test.TestConfiguration=INFO 30 # log4j.logger.com.framsticks. core.TreeOperations=DEBUG30 # log4j.logger.com.framsticks.hosting.Cli=DEBUG 31 31 # log4j.logger.com.framsticks.core.AbstractTree=DEBUG 32 32 # log4j.logger.com.framsticks.remote.RemoteTree=DEBUG
Note: See TracChangeset
for help on using the changeset viewer.