|
From: <jan...@us...> - 2008-01-21 23:00:33
|
Revision: 715
http://magicmap.svn.sourceforge.net/magicmap/?rev=715&view=rev
Author: jan_fride
Date: 2008-01-21 14:01:28 -0800 (Mon, 21 Jan 2008)
Log Message:
-----------
Added IMagicNode and IMagicNodeModel.
The Controller will return an instance of MagicNodeModel.
Worked with first tests. Index not tested yet ;-)
Modified Paths:
--------------
trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java
trunk/magicmapclient/src/net/sf/magicmap/client/controller/IController.java
trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java
Added Paths:
-----------
trunk/magicmapclient/src/net/sf/magicmap/core/
trunk/magicmapclient/src/net/sf/magicmap/core/model/
trunk/magicmapclient/src/net/sf/magicmap/core/model/URI.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/UnsupportedUriException.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/impl/
trunk/magicmapclient/src/net/sf/magicmap/core/model/impl/URIImpl.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/IMagicNode.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/IMagicNodeModel.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/INodeIndex.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/NodeKeyFunction.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/MagicNode.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/MagicNodeModel.java
trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/NodeIndex.java
Modified: trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java 2008-01-13 23:10:04 UTC (rev 714)
+++ trunk/magicmapclient/src/net/sf/magicmap/client/controller/Controller.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -4,41 +4,29 @@
package net.sf.magicmap.client.controller;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-
import net.sf.magicmap.client.gui.MainGUI;
import net.sf.magicmap.client.gui.utils.GUIUtils;
import net.sf.magicmap.client.gui.views.MapView;
-import net.sf.magicmap.client.interfaces.CreateNewMapCallback;
-import net.sf.magicmap.client.interfaces.CreatePositionCallback;
-import net.sf.magicmap.client.interfaces.DeletePositionCallback;
-import net.sf.magicmap.client.interfaces.MapCallback;
-import net.sf.magicmap.client.interfaces.MapNamesCallback;
-import net.sf.magicmap.client.interfaces.MovePositionCallback;
-import net.sf.magicmap.client.interfaces.PositionCallback;
-import net.sf.magicmap.client.interfaces.ServerConnectCallback;
-import net.sf.magicmap.client.interfaces.ServerDisconnectCallback;
+import net.sf.magicmap.client.interfaces.*;
import net.sf.magicmap.client.measurement.ScannerAllocator;
import net.sf.magicmap.client.measurement.interfaces.AbstractScanResult;
import net.sf.magicmap.client.measurement.interfaces.AbstractScanner;
import net.sf.magicmap.client.measurement.interfaces.AbstractScannerHandler;
import net.sf.magicmap.client.meta.MapInfo;
-import net.sf.magicmap.client.model.node.ClientNode;
-import net.sf.magicmap.client.model.node.GeoPos;
-import net.sf.magicmap.client.model.node.INodeModel;
-import net.sf.magicmap.client.model.node.MapNode;
-import net.sf.magicmap.client.model.node.Node;
-import net.sf.magicmap.client.model.node.NodeModel;
+import net.sf.magicmap.client.model.node.*;
import net.sf.magicmap.client.plugin.PluginManager;
import net.sf.magicmap.client.utils.Settings;
+import net.sf.magicmap.core.model.node.IMagicNodeModel;
+import net.sf.magicmap.core.model.node.impl.MagicNodeModel;
import net.sf.magicmap.server.dto.MapDTO;
import net.sf.magicmap.server.exception.SessionException;
-
import org.apache.log4j.xml.DOMConfigurator;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+
/**
* Kann \xC4nderungen an View und am Modell vornehmen und zieht alle F\xE4den
* der Anwendung.
@@ -65,7 +53,7 @@
/**
* Das Knotenmodel.
*/
- private INodeModel nodeModel; // Model f\xFCr Graphen
+ private IMagicNodeModel nodeModel; // Model f\xFCr Graphen
private ClientNode client; // Ausgezeichneter Knoten
@@ -93,7 +81,7 @@
//
// Das Model der Knoten.
//
- this.nodeModel = new NodeModel();
+ this.nodeModel = new MagicNodeModel(new NodeModel());
this.scannerAllocator = new ScannerAllocator();
this.currentMap = null;
this.serverManager = null;
@@ -129,7 +117,7 @@
*
* @return the node model
*/
- public INodeModel getNodeModel(){
+ public IMagicNodeModel getNodeModel(){
return this.nodeModel;
}
@@ -306,6 +294,7 @@
this.poller = new ServerPoller(this.serverManager, this.pollhandler);
this.serverManager.connect(callback);
+ this.getNodeModel().setServerID(Settings.getServerURL());
this.pluginManager.connect();
}
Modified: trunk/magicmapclient/src/net/sf/magicmap/client/controller/IController.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/client/controller/IController.java 2008-01-13 23:10:04 UTC (rev 714)
+++ trunk/magicmapclient/src/net/sf/magicmap/client/controller/IController.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -1,22 +1,14 @@
package net.sf.magicmap.client.controller;
-import net.sf.magicmap.client.interfaces.CreateNewMapCallback;
-import net.sf.magicmap.client.interfaces.CreatePositionCallback;
-import net.sf.magicmap.client.interfaces.DeletePositionCallback;
-import net.sf.magicmap.client.interfaces.MapCallback;
-import net.sf.magicmap.client.interfaces.MapNamesCallback;
-import net.sf.magicmap.client.interfaces.MovePositionCallback;
-import net.sf.magicmap.client.interfaces.PositionCallback;
-import net.sf.magicmap.client.interfaces.ServerConnectCallback;
-import net.sf.magicmap.client.interfaces.ServerDisconnectCallback;
+import net.sf.magicmap.client.interfaces.*;
import net.sf.magicmap.client.measurement.interfaces.AbstractScanResult;
import net.sf.magicmap.client.measurement.interfaces.AbstractScanner;
import net.sf.magicmap.client.measurement.interfaces.AbstractScannerHandler;
import net.sf.magicmap.client.meta.MapInfo;
import net.sf.magicmap.client.model.node.ClientNode;
import net.sf.magicmap.client.model.node.GeoPos;
-import net.sf.magicmap.client.model.node.INodeModel;
+import net.sf.magicmap.core.model.node.IMagicNodeModel;
/**
* @author Jan Friderici (ja...@fr...)
@@ -35,7 +27,7 @@
*
* @return the node model
*/
- INodeModel getNodeModel();
+ IMagicNodeModel getNodeModel();
/**
* Gibt an ob verbunden oder nicht verbunden
@@ -150,14 +142,18 @@
/**
* Entfernt einen
*
- * @param node
+ * @param name
+ * @param mapname
+ * @param mapname
+ * @param mapname
+ * @param callback
*/
void deletePosition(String name, String mapname, DeletePositionCallback callback);
/**
* @param name
* @param string
- * @param panel
+ * @param callback
*/
void deleteGeoPoint(String name, String string, DeletePositionCallback callback);
Modified: trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java 2008-01-13 23:10:04 UTC (rev 714)
+++ trunk/magicmapclient/src/net/sf/magicmap/client/model/node/NodeModel.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -1,24 +1,16 @@
package net.sf.magicmap.client.model.node;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import net.sf.magicmap.client.gui.MainGUI;
import net.sf.magicmap.client.interfaces.NodeModelListener;
import net.sf.magicmap.client.meta.MapInfo;
import net.sf.magicmap.client.model.location.INodePlacer;
import net.sf.magicmap.client.model.location.jung.JungNodePlacer;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import java.util.*;
+
/**
* Model zur Beschreibung des aktuellen Zustands in der
* Welt der Clients und AccessPoints. Es k\xF6nnen Anfragen
@@ -90,8 +82,7 @@
log.info("Map has Children: " + currentMap.getChildren().size());
}
for (NodeModelListener listener : this.listeners) {
- NodeModelListener l = (NodeModelListener) listener;
- l.nodeAddedEvent(node);
+ listener.nodeAddedEvent(node);
}
}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/URI.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/URI.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/URI.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,42 @@
+package net.sf.magicmap.core.model;
+
+import java.net.URL;
+
+/**
+ * <p>
+ * Class URI ZUSAMMENFASSUNG
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 21.01.2008
+ * Time: 21:52:54
+ */
+public interface URI {
+ /**
+ * Get the protocol.
+ * @return
+ */
+ String getProtocol();
+
+ /**
+ * Return the uri as string....
+ * @return
+ */
+ String toString();
+
+ /**
+ *
+ * @return
+ */
+ java.net.URI toJavaURI();
+
+ /**
+ *
+ * @return
+ * @throws UnsupportedUriException
+ */
+ URL toJavaURL() throws UnsupportedUriException;
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/UnsupportedUriException.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/UnsupportedUriException.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/UnsupportedUriException.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,28 @@
+package net.sf.magicmap.core.model;
+
+/**
+ * <p>
+ * Class UnsupportedUriException ZUSAMMENFASSUNG
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 21.01.2008
+ * Time: 21:53:51
+ */
+public class UnsupportedUriException extends RuntimeException {
+
+ public UnsupportedUriException(String s) {
+ super(s);
+ }
+
+ public UnsupportedUriException(String s, Throwable throwable) {
+ super(s, throwable);
+ }
+
+ public UnsupportedUriException(Throwable throwable) {
+ super(throwable);
+ }
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/impl/URIImpl.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/impl/URIImpl.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/impl/URIImpl.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,67 @@
+package net.sf.magicmap.core.model.impl;
+
+import net.sf.magicmap.core.model.URI;
+import net.sf.magicmap.core.model.UnsupportedUriException;
+
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+
+/**
+ * <p>
+ * Class URIImpl ZUSAMMENFASSUNG
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 13.01.2008
+ * Time: 11:35:41
+ */
+public class URIImpl implements URI {
+ private final String uri;
+
+
+ public URIImpl(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public String getProtocol() {
+ return uri.substring(0, uri.indexOf(":"));
+ }
+
+ public String toString() {
+ return uri;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public java.net.URI toJavaURI() {
+ try {
+ return new java.net.URI(uri);
+ } catch (URISyntaxException e) {
+ throw new UnsupportedUriException(e);
+ }
+ }
+
+ /**
+ *
+ * @return
+ * @throws UnsupportedUriException
+ */
+ public URL toJavaURL() throws UnsupportedUriException {
+ try {
+ return new java.net.URL(uri);
+ } catch (MalformedURLException e) {
+ throw new UnsupportedUriException(e);
+ }
+ }
+
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/node/IMagicNode.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/node/IMagicNode.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/node/IMagicNode.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,38 @@
+package net.sf.magicmap.core.model.node;
+
+import net.sf.magicmap.client.model.node.INode;
+import net.sf.magicmap.client.model.node.Node;
+import net.sf.magicmap.core.model.URI;
+
+/**
+ * <p>
+ * Class IMagicNode ZUSAMMENFASSUNG
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 21.01.2008
+ * Time: 21:51:20
+ */
+public interface IMagicNode extends INode {
+
+ /**
+ * <p>Get the server the nodes is stored.</p>
+ * @return the server id the node is stored with.
+ */
+ URI getServerID();
+
+ /**
+ * <p>The nodes id. This ID will vary depending....</p>
+ * @return a unique id for this node.
+ */
+ URI getNodeID();
+
+ /**
+ * <p>For objects that need the old class.</p>
+ * @return
+ */
+ Node asNode();
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/node/IMagicNodeModel.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/node/IMagicNodeModel.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/node/IMagicNodeModel.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,68 @@
+package net.sf.magicmap.core.model.node;
+
+import net.sf.magicmap.client.model.node.INode;
+import net.sf.magicmap.client.model.node.INodeModel;
+import net.sf.magicmap.core.model.URI;
+
+import java.util.List;
+
+/**
+ * <p>
+ * This interface adds several methods to the old INodeModel.
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 15.01.2008
+ * Time: 22:39:45
+ */
+public interface IMagicNodeModel extends INodeModel {
+
+ /**
+ * <p>return the server this node model is connected with - if any.</p>
+ * @return the uri for the connected server.
+ */
+ URI getServerID();
+
+ /**
+ *
+ * @return the target.
+ */
+ INodeModel getNodeModel();
+
+
+ /**
+ * get an magic node.
+ * @param node the magic node to get.
+ * @return
+ */
+ IMagicNode getMagicNode(INode node);
+
+ /**
+ * <p>Create an index with the given key generating function.</p>
+ * @param function the function to generate the keys.
+ * @return the index
+ */
+ <K, N extends INode>INodeIndex<K,N> createIndex(NodeKeyFunction<K,N> function);
+
+ /**
+ * Remove the index.
+ * @param index
+ * @return
+ */
+ boolean removeIndex(INodeIndex index);
+
+ /**
+ *
+ * @return
+ */
+ List<? extends INodeIndex> getNodeIndexList();
+
+ /**
+ *
+ * @param serverURL
+ */
+ void setServerID(String serverURL);
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/node/INodeIndex.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/node/INodeIndex.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/node/INodeIndex.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,43 @@
+package net.sf.magicmap.core.model.node;
+
+import net.sf.magicmap.client.model.node.INode;
+
+import java.util.Collection;
+
+/**
+ * <p>
+ * Class INodeIndex ZUSAMMENFASSUNG
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 21.01.2008
+ * Time: 21:55:44
+ */
+public interface INodeIndex <K, N extends INode> {
+
+
+ /**
+ *
+ * @param key
+ * @return
+ */
+ N getUnique(K key);
+
+ /**
+ *
+ * @param key
+ * @return
+ */
+ Collection<N> get(K key);
+
+ /**
+ *
+ * @param n
+ * @return
+ */
+ K getKey(N n);
+
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/node/NodeKeyFunction.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/node/NodeKeyFunction.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/node/NodeKeyFunction.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,29 @@
+package net.sf.magicmap.core.model.node;
+
+import net.sf.magicmap.client.model.node.INode;
+
+/**
+ * <p>
+ * Class NodeKeyFunction ZUSAMMENFASSUNG
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 21.01.2008
+ * Time: 22:11:43
+ */
+public interface NodeKeyFunction<K, N extends INode> {
+
+ Class<K> getKeyClass();
+
+ Class<N> getNodeClass();
+
+ /**
+ * Calculate a key for the given node.
+ * @param node the node to create a key for.
+ * @return
+ */
+ K key(INode node);
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/MagicNode.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/MagicNode.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/MagicNode.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,154 @@
+package net.sf.magicmap.core.model.node.impl;
+
+import net.sf.magicmap.client.model.node.Node;
+import net.sf.magicmap.client.model.node.NodeContainer;
+import net.sf.magicmap.core.model.URI;
+import net.sf.magicmap.core.model.impl.URIImpl;
+import net.sf.magicmap.core.model.node.IMagicNode;
+import net.sf.magicmap.core.model.node.IMagicNodeModel;
+
+import java.util.ArrayList;
+
+/**
+ * <p>
+ * Decorates the old nodes.
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 19.01.2008
+ * Time: 14:12:54
+ */
+public class MagicNode implements IMagicNode {
+ private final Node delegate;
+ private final IMagicNodeModel magicNodeModel;
+ private final URI nodeURI;
+
+ public MagicNode(Node delegate, IMagicNodeModel magicNodeModel) {
+ this.delegate = delegate;
+ this.magicNodeModel = magicNodeModel;
+ nodeURI = new URIImpl(
+ magicNodeModel.getServerID().toString()
+ + "/" + delegate.getType()
+ + " /" + delegate.getId());
+ }
+
+
+ public String getDisplayName() {
+ return delegate.getDisplayName();
+ }
+
+ public void setDisplayName(String s) {
+ delegate.setDisplayName(s);
+ }
+
+ public boolean isUpdate() {
+ return delegate.isUpdate();
+ }
+
+ public void setUpdate(boolean b) {
+ delegate.setUpdate(b);
+ }
+
+ public boolean isFix() {
+ return delegate.isFix();
+ }
+
+ public void setFix(boolean b) {
+ delegate.setFix(b);
+ }
+
+ public String getName() {
+ return delegate.getName();
+ }
+
+ public void setName(String s) {
+ delegate.setName(s);
+ }
+
+ public int getX() {
+ return delegate.getX();
+ }
+
+ public int getY() {
+ return delegate.getY();
+ }
+
+ public void setPositionSilent(int i, int i1, int i2) {
+ delegate.setPositionSilent(i, i1, i2);
+ }
+
+ public void setPosition(int i, int i1, int i2) {
+ delegate.setPosition(i, i1, i2);
+ }
+
+ public ArrayList<? extends Node> getNeighbors() {
+ return delegate.getNeighbors();
+ }
+
+ public IMagicNodeModel getModel() {
+ return magicNodeModel;
+ }
+
+ public int getType() {
+ return delegate.getType();
+ }
+
+ public int hashCode() {
+ return delegate.hashCode();
+ }
+
+ public String toString() {
+ return delegate.toString();
+ }
+
+ public long getId() {
+ return delegate.getId();
+ }
+
+ public void setId(long l) {
+ delegate.setId(l);
+ }
+
+ public int getZ() {
+ return delegate.getZ();
+ }
+
+ public void setZ(int i) {
+ delegate.setZ(i);
+ }
+
+ public Node getParentNode() {
+ return delegate.getParentNode();
+ }
+
+ public void setParentNode(Node node) {
+ delegate.setParentNode(node);
+ }
+
+ public boolean isPhysical() {
+ return delegate.isPhysical();
+ }
+
+ public void setPhysical(boolean b) {
+ delegate.setPhysical(b);
+ }
+
+ public NodeContainer getNodeContainer() {
+ return delegate.getNodeContainer();
+ }
+
+ public URI getServerID() {
+ return getModel().getServerID();
+ }
+
+ public URI getNodeID() {
+ return nodeURI;
+ }
+
+ public Node asNode() {
+ return delegate;
+ }
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/MagicNodeModel.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/MagicNodeModel.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/MagicNodeModel.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,236 @@
+package net.sf.magicmap.core.model.node.impl;
+
+import net.sf.magicmap.client.interfaces.NodeModelListener;
+import net.sf.magicmap.client.meta.MapInfo;
+import net.sf.magicmap.client.model.location.INodePlacer;
+import net.sf.magicmap.client.model.node.*;
+import net.sf.magicmap.core.model.URI;
+import net.sf.magicmap.core.model.impl.URIImpl;
+import net.sf.magicmap.core.model.node.IMagicNode;
+import net.sf.magicmap.core.model.node.IMagicNodeModel;
+import net.sf.magicmap.core.model.node.INodeIndex;
+import net.sf.magicmap.core.model.node.NodeKeyFunction;
+
+import java.util.*;
+
+/**
+ * <p>
+ * Uses a decorator pattern to enhance to old information model.
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 18.01.2008
+ * Time: 18:51:39
+ */
+public class MagicNodeModel implements IMagicNodeModel {
+ private final INodeModel delegate;
+ private URI serverID;
+
+ private final WeakHashMap<Node, IMagicNode> nodeMap = new WeakHashMap<Node, IMagicNode>();
+
+ private final List<NodeIndex> nodeInedexList = new LinkedList<NodeIndex>();
+
+ /**
+ * <p>...</p>
+ * @param delegate the old model to use.
+ */
+ public MagicNodeModel(INodeModel delegate) {
+ this.delegate = delegate;
+ }
+
+
+ public void setServerID(String serverURL) {
+ serverID = new URIImpl(serverURL);
+ }
+
+ /**
+ * <p>Create an index to find nodes with a quicknesssssss..</\x9F>
+ * @param function the function to use.
+ * @return
+ */
+ public <K, N extends INode> INodeIndex<K, N> createIndex(NodeKeyFunction<K, N> function) {
+ NodeIndex<K,N> index = new NodeIndex<K,N>(this, function, function.getNodeClass());
+ nodeInedexList.add(index);
+ return index;
+ }
+
+ /**
+ *
+ * @param index
+ * @return
+ */
+ public boolean removeIndex(INodeIndex index) {
+ return nodeInedexList.remove(index);
+ }
+
+
+ public IMagicNode getMagicNode(INode node) {
+ return nodeMap.get(node);
+ }
+
+ /**
+ *
+ * @return
+ */
+ public List<? extends INodeIndex> getNodeIndexList() {
+ return nodeInedexList;
+ }
+
+ /**
+ *
+ * @param node
+ */
+ public void addNode(Node node) {
+ delegate.addNode(node);
+ if (!(node instanceof IMagicNode)) {
+ nodeMap.put(node, new MagicNode(node, this));
+ }
+ }
+
+ /**
+ *
+ * @param node
+ */
+ public void removeNode(Node node) {
+ delegate.removeNode(node);
+ if (!(node instanceof IMagicNode)) {
+ nodeMap.remove(node);
+ }
+ }
+
+ /**
+ *
+ * @return get the id of the server....
+ */
+ public URI getServerID() {
+ return serverID;
+ }
+
+ /**
+ *
+ * @param serverID
+ */
+ public void setServerID(URI serverID) {
+ this.serverID = serverID;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public INodeModel getNodeModel() {
+ return delegate;
+ }
+
+
+ public IMagicNode getMagicNode(Node node) {
+ return nodeMap.get(node);
+ }
+
+
+
+
+
+ public void updateNode(Node node, int i, Object o) {
+ delegate.updateNode(node, i, o);
+ }
+
+ public void rehashNode(Node node, String s) {
+ delegate.rehashNode(node, s);
+ }
+
+ public ArrayList<? extends Node> findNeighbors(Node node) {
+ return delegate.findNeighbors(node);
+ }
+
+ public ArrayList<? extends Node> findNonNeighbors(Node node) {
+ return delegate.findNonNeighbors(node);
+ }
+
+ public void addNodeModelListener(NodeModelListener nodeModelListener) {
+ delegate.addNodeModelListener(nodeModelListener);
+ }
+
+ public void removeNodeModelListener(NodeModelListener nodeModelListener) {
+ delegate.removeNodeModelListener(nodeModelListener);
+ }
+
+ public NodeModelListener[] nodeModelListeners() {
+ return delegate.nodeModelListeners();
+ }
+
+ public Set<AccessPointSeerNode> getAccessPointSeerNodes() {
+ return delegate.getAccessPointSeerNodes();
+ }
+
+ public ArrayList<LocationNode> getLocationsWithAtLeastOneAccessPoint(ArrayList<AccessPointNode> accessPointNodes) {
+ return delegate.getLocationsWithAtLeastOneAccessPoint(accessPointNodes);
+ }
+
+ public ArrayList<LocationNode> getLocationsWithAtLeastOneAccessPoint(ArrayList<AccessPointNode> accessPointNodes, Node node) {
+ return delegate.getLocationsWithAtLeastOneAccessPoint(accessPointNodes, node);
+ }
+
+ public Node findNode(String s) {
+ return delegate.findNode(s);
+ }
+
+ public boolean nodeExists(String s) {
+ return delegate.nodeExists(s);
+ }
+
+ public AccessPointNode findAccessPoint(String s) {
+ return delegate.findAccessPoint(s);
+ }
+
+ public boolean accessPointExists(String s) {
+ return delegate.accessPointExists(s);
+ }
+
+ public ClientNode findClient(String s) {
+ return delegate.findClient(s);
+ }
+
+ public boolean clientExists(String s) {
+ return delegate.clientExists(s);
+ }
+
+ public Collection<Node> getNodes() {
+ return delegate.getNodes();
+ }
+
+ public void clear() {
+ delegate.clear();
+ nodeMap.clear();
+
+ }
+
+ /**
+ *
+ * @param iNodePlacer
+ */
+ public void setNodePlacer(INodePlacer iNodePlacer) {
+ delegate.setNodePlacer(iNodePlacer);
+ }
+
+ /**
+ * Returns the rotigionals node placer.
+ * @return
+ */
+ public INodePlacer getNodePlacer() {
+ return delegate.getNodePlacer();
+ }
+
+ public void setCurrentMap(MapInfo mapInfo) {
+ delegate.setCurrentMap(mapInfo);
+ }
+
+ public MapNode getCurrentMap() {
+ return delegate.getCurrentMap();
+ }
+
+
+}
Added: trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/NodeIndex.java
===================================================================
--- trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/NodeIndex.java (rev 0)
+++ trunk/magicmapclient/src/net/sf/magicmap/core/model/node/impl/NodeIndex.java 2008-01-21 22:01:28 UTC (rev 715)
@@ -0,0 +1,121 @@
+package net.sf.magicmap.core.model.node.impl;
+
+import net.sf.magicmap.client.interfaces.NodeModelListener;
+import net.sf.magicmap.client.model.node.INode;
+import net.sf.magicmap.client.model.node.Node;
+import net.sf.magicmap.core.model.node.IMagicNodeModel;
+import net.sf.magicmap.core.model.node.INodeIndex;
+import net.sf.magicmap.core.model.node.NodeKeyFunction;
+import org.apache.commons.collections15.MultiMap;
+import org.apache.commons.collections15.multimap.MultiHashMap;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * <p>
+ * Class NodeIndex ZUSAMMENFASSUNG
+ * </p>
+ * <p>
+ * DETAILS
+ * </p>
+ *
+ * @author Jan Friderici
+ * Date: 21.01.2008
+ * Time: 22:16:28
+ */
+public class NodeIndex<K, N extends INode> implements INodeIndex<K,N> {
+ private final MultiMap<K,N> nodes = new MultiHashMap<K,N>();
+ private final Map<N,K> keyMap = new HashMap<N,K>();
+ private final NodeKeyFunction<K,N> keyFunction;
+ private final Class<N> nodeClass;
+
+ /**
+ *
+ */
+ private NodeModelListener nodeModelListener = new NodeModelListener() {
+ public void nodeAddedEvent(Node node) {
+ if (nodeClass.isAssignableFrom(node.getClass())) {
+ indexNode((N)node);
+ }
+ }
+
+ public void nodeUpdatedEvent(Node node, int type, Object data) {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void nodeRemovedEvent(Node node) {
+ removeNode(node);
+ }
+ };
+
+
+ /**
+ *
+ * @param node
+ */
+ private void removeNode(Node node) {
+ final K key = keyMap.remove(node);
+ if (key != null) {
+ nodes.get(key).remove((N)node);
+ }
+ }
+
+
+ /**
+ *
+ * @param node
+ */
+ private void indexNode(N node) {
+ final K key = keyFunction.key(node);
+ nodes.put(key, node);
+ keyMap.put(node, key);
+ }
+
+ /**
+ *
+ * @param keyFunction
+ */
+ public NodeIndex(IMagicNodeModel nodeModel, NodeKeyFunction<K, N> keyFunction, Class<N> nodeClass) {
+
+ this.keyFunction = keyFunction;
+ this.nodeClass = nodeClass;
+ nodeModel.addNodeModelListener(nodeModelListener);
+ }
+
+
+ /**
+ *
+ * @param key
+ * @return
+ */
+ public N getUnique(K key) {
+ final Collection<N> nodes = get(key);
+ return nodes == null || nodes.size() == 0 ? null : nodes.iterator().next();
+ }
+
+ /**
+ *
+ * @param key
+ * @return
+ */
+ public Collection<N> get(K key) {
+ return nodes.get(key);
+ }
+
+ /**
+ *
+ * @param n
+ * @return
+ */
+ public K getKey(N n) {
+ return keyMap.get(n);
+ }
+
+ public void clear() {
+ this.nodes.clear();
+ this.keyMap.clear();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|