r1186 - in xwiki-clients/p2pxwiki: . src/main/java/com/xpn/p2pxwiki src/main/java/com/xpn/p2pxwiki/communication src/main/java/com/xpn/p2pxwiki/communication/jxta src/main/java/com/xpn/p2pxwiki/communication/rpc src/main/java/com/xpn/p2pxwiki/registry src/main/java/com/xpn/p2pxwiki/replication src/main/java/com/xpn/p2pxwiki/rpc src/main/java/com/xpn/p2pxwiki/services src/main/java/com/xpn/p2pxwiki/services/file src/test/java/com/xpn/p2pxwiki/communication

Sergiu Dumitriu sdumitriu at users.forge.objectweb.org
Mon Aug 21 21:14:54 CEST 2006


Author: sdumitriu
Date: 2006-08-21 21:14:53 +0200 (Mon, 21 Aug 2006)
New Revision: 1186

Added:
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServer.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServicesApi.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServicesPlugin.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/WikiGroup.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/WikiGroupServices.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileGroup.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileP2PServer.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileWikiGroupServices.java
Modified:
   xwiki-clients/p2pxwiki/.classpath
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/P2PXWikiException.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/ConnectorPlugin.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/jxta/JxtaConnectionFactory.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/jxta/JxtaHandlerManager.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcConnectionFactory.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcHandlerManager.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcNetwork.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/registry/RegistryHandler.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/replication/ReplicationClientApi.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/rpc/ConfluenceRpcHandler.java
   xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/rpc/RpcHandler.java
   xwiki-clients/p2pxwiki/src/test/java/com/xpn/p2pxwiki/communication/ConnectorPluginTest.java
Log:
Uploading the services package

Modified: xwiki-clients/p2pxwiki/.classpath
===================================================================
--- xwiki-clients/p2pxwiki/.classpath	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/.classpath	2006-08-21 19:14:53 UTC (rev 1186)
@@ -1,5 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
+	<classpathentry excluding="**/.svn/" kind="src" path="src/main/java"/>
+	<classpathentry excluding="**/.svn/" kind="src" path="src/test/java"/>
+	<classpathentry excluding="**/.svn/" kind="src" path="src/main/web"/>
 	<classpathentry kind="lib" path="lib/jaxen-core.jar"/>
 	<classpathentry kind="lib" path="lib/jaxen-jdom.jar"/>
 	<classpathentry kind="lib" path="lib/jxl.jxta.jar"/>
@@ -14,14 +17,8 @@
 	</classpathentry>
 	<classpathentry kind="lib" path="lib/p2psockets-scache.jar"/>
 	<classpathentry kind="lib" path="lib/saxpath.jar"/>
-	<classpathentry excluding="**/.svn/" kind="src" path="src/main/java"/>
-	<classpathentry excluding="**/.svn/" kind="src" path="src/main/web"/>
 	<classpathentry combineaccessrules="false" kind="src" path="/xwiki"/>
-	<classpathentry kind="lib" path="/xwiki/lib/portlet.jar"/>
 	<classpathentry kind="lib" path="/xwiki/lib/servlet-api-2.4.jar"/>
-	<classpathentry kind="lib" path="/xwiki/lib/junit-3.8.1.jar"/>
-	<classpathentry kind="lib" path="/xwiki/lib/commons-logging-1.0.4.jar"/>
-	<classpathentry kind="lib" path="/xwiki/lib/commons-logging-api-1.0.4.jar"/>
 	<classpathentry kind="lib" path="/xwiki/lib/velocity-1.4.jar"/>
 	<classpathentry kind="lib" path="/xwiki/lib/hibernate-3.0.3.jar"/>
 	<classpathentry sourcepath="/home/sgm/Work/p2psockets/src/java" kind="lib" path="/xwiki/lib/xmlrpc-1.2.jar"/>
@@ -29,5 +26,8 @@
 	<classpathentry kind="lib" path="/xwiki/lib/org.suigeneris.jrcs.diff-0.3.0.jar"/>
 	<classpathentry kind="lib" path="lib/jdom-1.0.jar"/>
 	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+	<classpathentry kind="lib" path="/xwiki/lib/commons-logging-1.1.jar"/>
+	<classpathentry kind="lib" path="/xwiki/lib/portlet-api-1.0.jar"/>
+	<classpathentry kind="lib" path="/xwiki/lib/junit-4.1.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/P2PXWikiException.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/P2PXWikiException.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/P2PXWikiException.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -6,6 +6,9 @@
     private static final long serialVersionUID = 1106138323477622364L;
 	public static final int ERROR_P2PXWIKI_COMMUNICATION = 30999;
 	public static final int ERROR_P2PXWIKI_REMOTECALL = 30998;
+	public static final int ERROR_P2PXWIKI_NO_SUCH_GROUP = 30997;
+	public static final int ERROR_P2PXWIKI_ACCESSDENIED = 30996;
+	public static final int ERROR_P2PXWIKI_GROUP_NOTALLOWED = 30995;
 	static String module = "P2PXWiki";
 
 	public P2PXWikiException(int code, String message, Throwable e,

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/ConnectorPlugin.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/ConnectorPlugin.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/ConnectorPlugin.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -46,11 +46,12 @@
 /**
  * A Connector has the role of hidding the inter-peer communication technology from
  * the main peer code, by acting as an intermediator. 
- * 
+ *
  * @author sdumitriu
- * TODO: XWikiProperties dynamic network type switcher + PropertyChangedNotifier?
  */
 public class ConnectorPlugin extends XWikiDefaultPlugin implements XWikiPluginInterface{
+//	 TODO: XWikiProperties dynamic network type switcher + PropertyChangedNotifier?
+	public static final String PLUGIN_NAME = "p2pxwikiconnector";
 	public static final String NETWORK_TYPE = "p2pxwiki.connector.network";
 	public static final String DEFAULT_NETWORK_TYPE = "com.xpn.p2pxwiki.communication.jxta.JxtaNetwork";
 	public static final String CONNECTOR_FACTORY = "p2pxwiki.connector.type";
@@ -74,6 +75,12 @@
 	private static String peerName;
 	private static int serverPort;
 
+	/**
+	 * Standard XWiki plugin constructor, called by the plugin manager at startup.
+	 * @param name The standard name guessed by the plugin manager.
+	 * @param className The class name as found in the xwiki.cfg file.
+	 * @param context The XWikiContext available when plugins are initialized.
+	 */
 	public ConnectorPlugin(String name, String className, XWikiContext context) {
 		super(name, className, context);
 		log.debug("constructor");
@@ -82,15 +89,16 @@
 
 	/**
 	 * Obtain the name by which this plugin can be retrieved.
+	 * @return The plugin name.
 	 */
 	public String getName() {
 		log.debug("getName");
-		return "p2pxwikiconnector";
+		return PLUGIN_NAME;
 	}
 
 	/**
 	 * Initializes the plugin.
-	 * @param context The XWikiContext available when plugins are initialized
+	 * @param context The XWikiContext available when plugins are initialized.
 	 */
 	public void init(XWikiContext context) {
 		log.debug("-- init --");
@@ -102,6 +110,7 @@
 			cache = context.getWiki().getCacheService().newLocalCache();
 		}
 		catch(XWikiException ex){
+			// TODO: Handle this better, e.g. use a HashMap
 			log.error("Cannot create cache!", ex);
 		}
 		log.debug("Configuring");
@@ -119,8 +128,7 @@
 		networkType = xwiki.Param(NETWORK_TYPE, DEFAULT_NETWORK_TYPE);
 		// TODO: Retry with default network on failure, if this isn't already the default
 		try{
-			network = (Network)Class.forName(networkType)
-				.getMethod("getInstance", (Class[])null).invoke(null, (Object[])null);
+			network = (Network)Class.forName(networkType).getMethod("getInstance", (Class[])null).invoke(null, (Object[])null);
 		}
 		catch(ClassNotFoundException ex){
 			log.error("Cannot load network type", ex);
@@ -183,7 +191,7 @@
 	 * Returns a stub through which a remote handler can be accessed.
 	 * @param peer The name of the peer to access.
 	 * @return The handler stub for this peer.
-	 * @throws XWikiException if no connection could be established.
+	 * @throws XWikiException If no connection could be established.
 	 */
 	public HandlerStub getConnection(String peer) throws XWikiException{
 		log.debug("Get connection for " + peer);
@@ -220,37 +228,61 @@
 		return connection;
 	}
 
+	/**
+	 * Closes a connection to a remote host. This should be called only when
+	 * there will be no need for another communication with that host, as a
+	 * connection can be reused many times.  
+	 * @param stub The connection being closed.
+	 * @throws XWikiException When the connection could not be closed.
+	 */
 	void closeConnection(HandlerStub stub) throws XWikiException{
 		cache.flushEntry(stub.getPeerName());
 		stub.close();
 	}
 
+	/**
+	 * Register a class as handler for remote calls. 
+	 * @param handler The class being registered. 
+	 * @return True if the class was succesfully registered, false otherwise.
+	 * @throws XWikiException
+	 */
 	public boolean addHandler(Handler handler) throws XWikiException {
 		return handlerManager.addHandler(handler);
 	}
-	
+
+	/**
+	 * Unregister a class as handler for remote calls. 
+	 * @param handler The class being removed. 
+	 * @return True if the class was succesfully unregistered, false otherwise.
+	 * @throws XWikiException
+	 */ 
 	public boolean removeHandler(Handler handler) throws XWikiException {
 		return handlerManager.removeHandler(handler);
 	}
 
 	/**
 	 * Returns an API for using this plugin from scripts.
-	 * @see com.xpn.xwiki.plugin.XWikiDefaultPlugin#getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface, com.xpn.xwiki.XWikiContext)
-	 * @return Scripting API for this plugin
+	 * @see com.xpn.xwiki.plugin.XWikiPluginInterface#getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface, com.xpn.xwiki.XWikiContext) Overridden method.
+	 * @return Scripting API for this plugin.
 	 */
 	public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
+		if(!this.equals(plugin)){
+			log.warn("getPluginApi: different objects! (plugin != this)");
+		}
 		return new ConnectorApi(context, this);
 	}
 
 	/**
-	 * @return the peerName
+	 * Returns the network name of the local host.
+	 * @return The peerName.
 	 */
 	public static String getPeerName() {
 		return peerName;
 	}
 
 	/**
-	 * @param peerName the peerName to set
+	 * Sets the network name of the local host.
+	 * @param peerName The peerName to set
 	 */
 	public static void setPeerName(String peerName) {
 		ConnectorPlugin.peerName = peerName;
@@ -271,7 +303,8 @@
 	}
 
 	/**
-	 * @return the network
+	 * Returns the configured {@link Network Network} helper object. 
+	 * @return The network
 	 */
 	public static Network getNetwork() {
 		return network;

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/jxta/JxtaConnectionFactory.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/jxta/JxtaConnectionFactory.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/jxta/JxtaConnectionFactory.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -24,7 +24,7 @@
 	}
 
 	/**
-	 * @see com.xpn.p2pxwiki.communication.BasicRemoteConnectionFactory#getConnection(java.lang.String)
+	 * @see com.xpn.p2pxwiki.communication.ConnectionFactory#getConnection(java.lang.String)
 	 */
 	public HandlerStub getConnection(String peer) throws P2PXWikiException {
 		log.debug("getConnection");

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/jxta/JxtaHandlerManager.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/jxta/JxtaHandlerManager.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/jxta/JxtaHandlerManager.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -16,7 +16,7 @@
 	
 	protected static JxtaHandlerManager instance = null;
 
-	protected JxtaHandlerManager(String peerName){
+	protected JxtaHandlerManager(){
 		log.debug("constructor");
 		init();
 	}
@@ -34,7 +34,7 @@
 	}
 
 	/**
-	 * @see com.xpn.p2pxwiki.communication.BasicHandlerManager#addHandler(com.xpn.p2pxwiki.communication.Handler)
+	 * @see com.xpn.p2pxwiki.communication.HandlerManager#addHandler(com.xpn.p2pxwiki.communication.Handler)
 	 */
 	public boolean addHandler(Handler handler) throws P2PXWikiException {
 		p2pwebserver.addHandler(handler.getName(), handler);
@@ -42,16 +42,16 @@
 	}
 
 	/**
-	 * @see com.xpn.p2pxwiki.communication.BasicHandlerManager#removeHandler(com.xpn.p2pxwiki.communication.Handler)
+	 * @see com.xpn.p2pxwiki.communication.HandlerManager#removeHandler(com.xpn.p2pxwiki.communication.Handler)
 	 */
 	public boolean removeHandler(Handler handler) throws P2PXWikiException {
 		p2pwebserver.removeHandler(handler.getName());
 		return true;
 	}
 
-	public static JxtaHandlerManager getInstance(String peerName){
+	public static JxtaHandlerManager getInstance(){
 		if(instance == null){
-			instance = new JxtaHandlerManager(peerName);
+			instance = new JxtaHandlerManager();
 		}
 		return instance;
 	}

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcConnectionFactory.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcConnectionFactory.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcConnectionFactory.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -24,7 +24,7 @@
 	}
 
 	/**
-	 * @see com.xpn.p2pxwiki.communication.BasicRemoteConnectionFactory#getConnection(java.lang.String)
+	 * @see com.xpn.p2pxwiki.communication.ConnectionFactory#getConnection(java.lang.String)
 	 */
 	public HandlerStub getConnection(String peer) throws P2PXWikiException {
 		log.debug("getConnection");

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcHandlerManager.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcHandlerManager.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcHandlerManager.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -33,7 +33,7 @@
 	}
 
 	/**
-	 * @see com.xpn.p2pxwiki.communication.BasicHandlerManager#addHandler(com.xpn.p2pxwiki.communication.Handler)
+	 * @see com.xpn.p2pxwiki.communication.HandlerManager#addHandler(com.xpn.p2pxwiki.communication.Handler)
 	 */
 	public boolean addHandler(Handler handler) throws P2PXWikiException {
 		webserver.addHandler(handler.getName(), handler);
@@ -41,7 +41,7 @@
 	}
 
 	/**
-	 * @see com.xpn.p2pxwiki.communication.BasicHandlerManager#removeHandler(com.xpn.p2pxwiki.communication.Handler)
+	 * @see com.xpn.p2pxwiki.communication.HandlerManager#removeHandler(com.xpn.p2pxwiki.communication.Handler)
 	 */
 	public boolean removeHandler(Handler handler) throws P2PXWikiException {
 		webserver.removeHandler(handler.getName());

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcNetwork.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcNetwork.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/communication/rpc/RpcNetwork.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -41,7 +41,7 @@
 	}
 
 	/**
-	 * @see com.xpn.p2pxwiki.communication.BasicNetwork#getCanonicalRemoteName(java.lang.String)
+	 * @see com.xpn.p2pxwiki.communication.Network#getCanonicalRemoteName(java.lang.String)
 	 */
 	public String getCanonicalRemoteName(String peer) {
 		return "http://" + peer + ":" + ConnectorPlugin.getServerPort();

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/registry/RegistryHandler.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/registry/RegistryHandler.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/registry/RegistryHandler.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -102,7 +102,6 @@
 					host = requestURL.getHost();
 				} catch (Exception e) {
 				}
-				;
 
 				log.error("looking for a server document for host: " + host);
 				if (host.equals(""))
@@ -267,7 +266,7 @@
 			e.printStackTrace();
 		} finally {
 			try {
-				if (bTransaction)
+				if (bTransaction && hibstore != null)
 					hibstore.endTransaction(context, false);
 			} catch (Exception e) {
 			}
@@ -359,7 +358,7 @@
 			e.printStackTrace();
 		} finally {
 			try {
-				if (bTransaction) {
+				if (bTransaction && hibstore != null) {
 					hibstore.endTransaction(context, true);
 				}
 			} catch (Exception e) {
@@ -403,7 +402,7 @@
 			e.printStackTrace();
 		} finally {
 			try {
-				if (bTransaction)
+				if (bTransaction && hibstore != null)
 					hibstore.endTransaction(context, false);
 			} catch (Exception e) {
 			}

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/replication/ReplicationClientApi.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/replication/ReplicationClientApi.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/replication/ReplicationClientApi.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -23,7 +23,7 @@
 		return repClient.logout(token, peerserver);
 	}
 
-	/** @TODO: all these calls should take a wikiapp to replicate as an argument */
+	/** TODO: all these calls should take a wikiapp to replicate as an argument */
 
 	public Vector getAllPagesAsXML(String token, String peerserver, String srcwiki) {
 		return repClient.getAllPagesAsXML(token, peerserver, srcwiki);

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/rpc/ConfluenceRpcHandler.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/rpc/ConfluenceRpcHandler.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/rpc/ConfluenceRpcHandler.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -80,6 +80,7 @@
             md5 = MessageDigest.getInstance("MD5");
         } catch (NoSuchAlgorithmException e) {
             System.out.println("Error: " + e);
+            return "";
         }
 
         try {

Modified: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/rpc/RpcHandler.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/rpc/RpcHandler.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/rpc/RpcHandler.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -80,6 +80,7 @@
 			md5 = MessageDigest.getInstance("MD5");
 		} catch (NoSuchAlgorithmException e) {
 			System.out.println("Error: " + e);
+			return "";
 		}
 
 		try {

Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServer.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServer.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServer.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -0,0 +1,55 @@
+package com.xpn.p2pxwiki.services;
+
+import com.xpn.xwiki.XWikiException;
+
+/**
+ * A server hosts wikis; it serves request from clients like reads from and/or
+ * updates to the wikis it hosts.
+ * 
+ * An instance of a class implementing P2PServer represents a peer as part of
+ * all {@link WikiGroup wiki groups}, so implementing classes should be
+ * singletons, and should contain a static method named <tt>getInstance()</tt>. 
+ * 
+ * A server can have the role of <strong>Group Master</strong> for some wiki
+ * groups. A group master is the designated server that coordinates the activity
+ * in a server group. It can have more knowledge about the group than the
+ * other servers, and hosts the authoritative version of the wiki. Only one
+ * master exists in a group at a given time. A server is a master only with
+ * respect to a particular group/wiki, meaning that there is no absolute
+ * master for all wikis.
+ * 
+ * @author sdumitriu
+ */
+public interface P2PServer {
+	/**
+	 * List all the groups this server is part of.
+	 * Equivalent, what wikis does this server host.
+	 * @return The virtual groups.
+	 */
+	WikiGroup[] getGroups() throws XWikiException;
+
+	/**
+	 * List all the groups for which this server has master rights. 
+	 * @return The virtual groups mastered.
+	 */
+	WikiGroup[] getMasteredGroups() throws XWikiException;
+
+	/**
+	 * Try to join a wiki group. 
+	 * @param group The group to join.
+	 * @return True if the server is now part of the group. False if the server
+	 * was already a member of the group. Exception otherwise.
+	 * @throws XWikiException If the server was not part of the group, but
+	 * failed to join.
+	 */
+	boolean joinGroup(WikiGroup group) throws XWikiException;
+
+	/**
+	 * Leave a group.
+	 * @param group The group to leave. 
+	 * @return true if the server succesfully left the group. False if the
+	 * server was not part of the group. Exception otherwise.
+	 * @throws XWikiException If the server could not leave the group.
+	 */
+	boolean leaveGroup(WikiGroup group) throws XWikiException;
+}

Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServicesApi.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServicesApi.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServicesApi.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -0,0 +1,19 @@
+package com.xpn.p2pxwiki.services;
+
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.api.Api;
+
+public class P2PServicesApi extends Api {
+	public P2PServicesApi(XWikiContext context, P2PServicesPlugin plugin) {
+		super(context);
+		this.context = context;
+	}
+
+	public WikiGroupServices getGroupServices() {
+		return P2PServicesPlugin.getGroupServices();
+	}
+
+	public P2PServer getP2PServerServices() {
+		return P2PServicesPlugin.getP2PServerServices();
+	}
+}

Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServicesPlugin.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServicesPlugin.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/P2PServicesPlugin.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -0,0 +1,127 @@
+/**
+ * @author sdumitriu
+ */
+package com.xpn.p2pxwiki.services;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.xpn.xwiki.XWiki;
+import com.xpn.xwiki.XWikiContext;
+import com.xpn.xwiki.api.Api;
+import com.xpn.xwiki.plugin.XWikiDefaultPlugin;
+import com.xpn.xwiki.plugin.XWikiPluginInterface;
+
+/**
+ * 
+ * @author sgm
+ *
+ */
+public class P2PServicesPlugin extends XWikiDefaultPlugin implements XWikiPluginInterface {
+	public static final String SERVER_TYPE = "p2pxwiki.services.server";
+	public static final String DEFAULT_SERVER_TYPE = "com.xpn.p2pxwiki.wiki.file.FileServer";
+	public static final String GROUP_TYPE = "p2pxwiki.services.groupinfo";
+	public static final String DEFAULT_GROUP_TYPE = "com.xpn.p2pxwiki.wiki.file.FileGroupInfoService";
+
+	private static Log log = LogFactory.getFactory().getInstance(P2PServicesPlugin.class);
+	private static P2PServer p2pserverServices;
+	private static WikiGroupServices groupServices;
+	private static String p2pserverServicesType;
+	private static String groupServicesType;
+
+	/**
+	 * Standard XWiki plugin constructor, called by the plugin manager at startup.
+	 * @param name The standard name guessed by the plugin manager.
+	 * @param className The class name as found in the xwiki.cfg file.
+	 * @param context The XWikiContext available when plugins are initialized.
+	 */
+	public P2PServicesPlugin(String name, String className, XWikiContext context) {
+		super(name, className, context);
+		log.debug("constructor");
+		init(context);
+	}
+
+	/**
+	 * Obtain the name by which this plugin can be retrieved.
+	 */
+	public String getName() {
+		log.debug("getName");
+		return "p2pxwikiservices";
+	}
+
+	/**
+	 * Initializes the plugin.
+	 * 
+	 * @param context
+	 *            The XWikiContext available when plugins are initialized.
+	 */
+	public void init(XWikiContext context) {
+		log.debug("-- init --");
+		log.debug("Calling parent init");
+		super.init(context);
+		XWiki xwiki = context.getWiki();
+
+		log.debug("Configuring");
+		log.debug("Configuring p2pserver services");
+		p2pserverServicesType = xwiki.Param(SERVER_TYPE, DEFAULT_SERVER_TYPE);
+		// TODO: Retry with default server services type on failure, if this isn't already
+		// the default
+		try {
+			p2pserverServices = (P2PServer) Class.forName(p2pserverServicesType).getMethod("getInstance", (Class[]) null).invoke(null, (Object[]) null);
+		} catch (ClassNotFoundException ex) {
+			log.error("Cannot load p2pserver services type", ex);
+		} catch (NoSuchMethodException ex) {
+			log.error("Not a p2pserver services type", ex);
+		} catch (InvocationTargetException ex) {
+			log.error("Something fishy going on...", ex);
+		} catch (IllegalAccessException ex) {
+			log.error("Something fishy going on...", ex);
+		}
+		log.debug("Obtained p2pserver services: " + p2pserverServices.getClass().getCanonicalName());
+
+		log.debug("Configuring group services");
+		groupServicesType = xwiki.Param(GROUP_TYPE, DEFAULT_GROUP_TYPE);
+		// TODO: Retry with default group services type on failure, if this isn't already
+		// the default
+		try {
+			groupServices = (WikiGroupServices) Class.forName(groupServicesType).getMethod("getInstance", (Class[]) null).invoke(null, (Object[]) null);
+		} catch (ClassNotFoundException ex) {
+			log.error("Cannot load group services", ex);
+		} catch (NoSuchMethodException ex) {
+			log.error("Not a group services type", ex);
+		} catch (InvocationTargetException ex) {
+			log.error("Something fishy going on...", ex);
+		} catch (IllegalAccessException ex) {
+			log.error("Something fishy going on...", ex);
+		}
+		log.debug("Obtained group services: " + groupServices.getClass().getCanonicalName());
+	}
+
+	/**
+	 * Returns an API for using this plugin from scripts.
+	 * @see com.xpn.xwiki.plugin.XWikiPluginInterface#getPluginApi(com.xpn.xwiki.plugin.XWikiPluginInterface, com.xpn.xwiki.XWikiContext) Overridden method.
+	 * @return Scripting API for this plugin.
+	 */
+	public Api getPluginApi(XWikiPluginInterface plugin, XWikiContext context) {
+		if(!this.equals(plugin)){
+			log.warn("getPluginApi: different objects! (plugin != this)");
+		}
+		return new P2PServicesApi(context, this);
+	}
+
+	/**
+	 * @return the groupServices
+	 */
+	public static WikiGroupServices getGroupServices() {
+		return groupServices;
+	}
+
+	/**
+	 * @return the p2pserverServices
+	 */
+	public static P2PServer getP2PServerServices() {
+		return p2pserverServices;
+	}
+}

Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/WikiGroup.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/WikiGroup.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/WikiGroup.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -0,0 +1,47 @@
+package com.xpn.p2pxwiki.services;
+
+/**
+ * A Wiki group is a virtual group of servers that host the same wiki by means
+ * of replication. The servers in a group are synchronizing and coordinating
+ * between each other.
+ * 
+ * The WikiGroup class is a helper class offering various  
+ * @author sdumitriu
+ */
+public interface WikiGroup {
+	/**
+	 * Returns all the known servers in this group at that moment.
+	 * The resultset contains all servers that are knwon to host htis wiki
+	 * and be online
+	 * 
+	 * @return the list of server names
+	 */
+	String[] getAllServers();
+
+	/**
+	 * Check if this wiki has a master.
+	 * @see com.xpn.p2pxwiki.services.P2PServer for the definition of a wiki master.
+	 * @return true if the group has a master, false otherwise.
+	 */
+	boolean hasMaster();
+
+	/**
+	 * 
+	 * @return
+	 */
+	String getMaster();
+
+	String[] getSlaves();
+
+	boolean hasRegistry();
+
+	String getRegistry();
+
+	boolean acquireMasterRights(P2PServer server);
+
+	boolean releaseMasterRights(P2PServer group);
+
+	int getNumberOfServers();
+
+	boolean isMember(String serverName);
+}

Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/WikiGroupServices.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/WikiGroupServices.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/WikiGroupServices.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -0,0 +1,10 @@
+package com.xpn.p2pxwiki.services;
+
+import com.xpn.p2pxwiki.P2PXWikiException;
+
+public interface WikiGroupServices {
+	String[] getAllGroupsNames() throws P2PXWikiException;
+	WikiGroup[] getAllGroups() throws P2PXWikiException;
+	WikiGroup getWikiGroup(String groupName) throws P2PXWikiException;
+	WikiGroup createWikiGroup(String groupName) throws P2PXWikiException;
+}

Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileGroup.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileGroup.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileGroup.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -0,0 +1,124 @@
+package com.xpn.p2pxwiki.services.file;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import com.xpn.p2pxwiki.P2PXWikiException;
+import com.xpn.p2pxwiki.services.P2PServer;
+import com.xpn.xwiki.XWikiException;
+
+public class FileGroup implements com.xpn.p2pxwiki.services.WikiGroup {
+	private static Log log = LogFactory.getFactory().getInstance(FileGroup.class);
+	private String name;
+	private ArrayList servers = new ArrayList();
+	private String master = null;
+
+	FileGroup(String name) throws P2PXWikiException {
+		log.debug("constructor");
+		Document config;
+		try {
+			log.debug("Reading config file " + name + ".grp.xml");
+			config = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new FileInputStream(name + ".grp.xml"));
+			this.name = name;
+			if (this.name != config.getDocumentElement().getAttribute("name")) {
+				log.warn("The group name inside the file is not equal to the requested group name");
+			}
+			NodeList servers = config.getElementsByTagName("server");
+			for (int i = 0; i < servers.getLength(); ++i) {
+				this.servers.add(((Element) servers.item(i)).getAttribute("name"));
+			}
+			log.debug("Read " + this.servers.size() + " servers");
+			this.master = config.getDocumentElement().getAttribute("master");
+			if ("".equals(this.master)) {
+				log.warn("No specified master node for group \"" + name + "\". Selecting the first server as master.");
+				this.master = (String) this.servers.get(0);
+			}
+			log.debug("Group master: " + this.master);
+		} catch (FileNotFoundException ex) {
+			throw new P2PXWikiException(P2PXWikiException.ERROR_P2PXWIKI_NO_SUCH_GROUP, "Invalid group " + name);
+		} catch (ParserConfigurationException ex) {
+			throw new P2PXWikiException(XWikiException.ERROR_DOC_XML_PARSING, "Error while parsing group definition file for \"" + name + "\"");
+		} catch (IOException ex) {
+			throw new P2PXWikiException(XWikiException.ERROR_DOC_XML_PARSING, "Error while parsing group definition file for \"" + name + "\"");
+		} catch (SAXException ex) {
+			throw new P2PXWikiException(XWikiException.ERROR_DOC_XML_PARSING, "Error while parsing group definition file for \"" + name + "\"");
+		}
+	}
+
+	public boolean acquireMasterRights(P2PServer server) {
+		// This is a static configuration; no changes allowed
+		log.debug(this.name + ": acquireMasterRights");
+		return false;
+	}
+
+	public boolean releaseMasterRights(P2PServer group) {
+		// This is a static configuration; no changes allowed
+		log.debug(this.name + ": releaseMasterRights");
+		return false;
+	}
+
+	public int getNumberOfServers() {
+		log.debug(this.name + ": getNumberOfServers");
+		return this.servers.size();
+	}
+
+	public String[] getAllServers() {
+		log.debug(this.name + ": getAllServers");
+		String[] result = new String[this.getNumberOfServers()];
+		int i = 0;
+		for (Iterator it = this.servers.iterator(); it.hasNext(); ++i) {
+			result[i] = (String) it.next();
+		}
+		return result;
+	}
+
+	public boolean hasMaster() {
+		return true;
+	}
+
+	public String getMaster() {
+		return this.master;
+	}
+
+	public boolean hasRegistry() {
+		// No registry needed
+		return false;
+	}
+
+	public String getRegistry() {
+		// No registry needed
+		return null;
+	}
+
+	public String[] getSlaves() {
+		String[] result = new String[this.getNumberOfServers() - 1];
+		int i = 0;
+		for (Iterator it = this.servers.iterator(); it.hasNext();) {
+			result[i] = (String) it.next();
+			if (!result[i].equals(this.master)) {
+				++i;
+			}
+		}
+		return result;
+	}
+
+	public boolean isMember(String serverName) {
+		if (this.servers.contains(serverName)) {
+			return true;
+		}
+		return false;
+	}
+}

Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileP2PServer.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileP2PServer.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileP2PServer.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -0,0 +1,132 @@
+package com.xpn.p2pxwiki.services.file;
+
+import java.util.ArrayList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import com.xpn.p2pxwiki.P2PXWikiException;
+import com.xpn.p2pxwiki.communication.ConnectorPlugin;
+import com.xpn.p2pxwiki.services.P2PServer;
+import com.xpn.p2pxwiki.services.P2PServicesPlugin;
+import com.xpn.p2pxwiki.services.WikiGroup;
+import com.xpn.xwiki.XWikiException;
+
+/**
+ * 
+ * @author sdumitriu
+ */
+public class FileP2PServer implements P2PServer {
+	private static Log log = LogFactory.getFactory().getInstance(FileP2PServer.class);
+	protected String name;
+
+	protected static P2PServer instance = null;
+
+	protected FileP2PServer() throws P2PXWikiException {
+		log.debug("constructor");
+		init();
+	}
+
+	protected void init() throws P2PXWikiException {
+		log.debug("init");
+		this.name = ConnectorPlugin.getPeerName();
+	}
+
+	/**
+	 * List all the groups this server is part of.
+	 * Equivalent, what wikis does this server host. In order to avoid double
+	 * configuration files, just filter the groups, since they know all their
+	 * members.
+	 * @return The virtual groups.
+	 */
+	public WikiGroup[] getGroups() throws XWikiException {
+		log.debug("getGroups");
+		WikiGroup[] allGroups = P2PServicesPlugin.getGroupServices().getAllGroups();
+		ArrayList myGroups = new ArrayList();
+		for(int i = 0; i < allGroups.length; ++i){
+			if(allGroups[i].isMember(this.name)){
+				myGroups.add(allGroups[i]);
+			}
+		}
+		return (WikiGroup[])myGroups.toArray(new WikiGroup[0]);
+	}
+
+	/**
+	 * List all the groups for which this server has master rights. In order to
+	 * avoid double configuration files, just filter the groups, since they
+	 * know all their members.
+	 * @return The virtual groups mastered.
+	 * @see com.xpn.p2pxwiki.services.P2PServer#getMasteredGroups()
+	 */
+	public WikiGroup[] getMasteredGroups() throws XWikiException {
+		log.debug("getMasteredGroups");
+		WikiGroup[] myGroups = this.getGroups();
+		ArrayList masteredGroups = new ArrayList();
+		for(int i = 0; i < myGroups.length; ++i){
+			if(this.name.equals(myGroups[i].getMaster())){
+				masteredGroups.add(myGroups[i]);
+			}
+		}
+		return (WikiGroup[])masteredGroups.toArray(new WikiGroup[0]);
+	}
+
+	/**
+	 * Join group method. Always fails, since basic file configurations are static.
+	 * @param group The group to join.
+	 * @return False if the server was part of the group. Exception otherwise.
+	 * @throws XWikiException When trying to join a group.
+	 */
+	public boolean joinGroup(WikiGroup group) throws XWikiException {
+		log.debug("joinGroup");
+		if(group.isMember(this.name)){
+			return false;
+		}
+		throw new P2PXWikiException(P2PXWikiException.ERROR_P2PXWIKI_ACCESSDENIED, "Groups cannot be altered under the current policy");
+	}
+
+	/**
+	 * Leave group method. Always fails, since basic file configurations are static.
+	 * @param group The group to leave.
+	 * @return False if the server was not part of the group. Exception otherwise.
+	 * @throws XWikiException When trying to leave a group.
+	 */
+	public boolean leaveGroup(WikiGroup group) throws XWikiException {
+		log.debug("leaveGroup");
+		if(!group.isMember(this.name)){
+			return false;
+		}
+		throw new P2PXWikiException(P2PXWikiException.ERROR_P2PXWIKI_ACCESSDENIED, "Groups cannot be altered under the current policy");
+	}
+
+	/**
+	 * Singleton method. makes sure there is only one instance of this class
+	 * active at any moment.
+	 * @return The singleton instance
+	 */
+	public static P2PServer getInstance() {
+		log.debug("getInstance");
+		if (instance != null) {
+			try {
+				instance = new FileP2PServer();
+			} catch (XWikiException ex) {
+				log.error("Cannot instantiate P2PServer", ex);
+			}
+		}
+		return instance;
+	}
+
+	/**
+	 * @return The peer name.
+	 */
+	public String getName() {
+		return name;
+	}
+
+	/**
+	 * @param name The new name to set.
+	 */
+	public void setName(String name) {
+		this.name = name;
+	}
+	
+}

Added: xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileWikiGroupServices.java
===================================================================
--- xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileWikiGroupServices.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/main/java/com/xpn/p2pxwiki/services/file/FileWikiGroupServices.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -0,0 +1,110 @@
+package com.xpn.p2pxwiki.services.file;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import com.xpn.p2pxwiki.P2PXWikiException;
+import com.xpn.p2pxwiki.services.WikiGroup;
+import com.xpn.p2pxwiki.services.WikiGroupServices;
+import com.xpn.xwiki.XWikiException;
+
+public class FileWikiGroupServices implements WikiGroupServices {
+	private static Log log = LogFactory.getFactory().getInstance(FileWikiGroupServices.class);
+	private static HashMap cache = new HashMap();
+	private ArrayList groups = new ArrayList();
+	private static String configFileName = "groups.xml";
+
+	protected static WikiGroupServices instance = null;
+
+	protected FileWikiGroupServices() throws P2PXWikiException {
+		log.debug("constructor");
+		init();
+	}
+
+	protected void init() throws P2PXWikiException {
+		log.debug("init");
+		Document config;
+		try {
+			log.debug("Reading config file " + configFileName + ".xml");
+			config = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new FileInputStream(configFileName + ".xml"));
+			NodeList groups = config.getElementsByTagName("group");
+			for (int i = 0; i < groups.getLength(); ++i) {
+				this.groups.add(((Element) groups.item(i)).getAttribute("name"));
+			}
+			log.debug("Read " + this.groups.size() + " groups");
+		} catch (FileNotFoundException ex) {
+			throw new P2PXWikiException(XWikiException.ERROR_XWIKI_CONFIG_FILENOTFOUND, "Cannot open groups declaration file " + configFileName);
+		} catch (ParserConfigurationException ex) {
+			throw new P2PXWikiException(XWikiException.ERROR_DOC_XML_PARSING, "Error while parsing groups declaration file");
+		} catch (IOException ex) {
+			throw new P2PXWikiException(XWikiException.ERROR_DOC_XML_PARSING, "Error while parsing groups declaration file");
+		} catch (SAXException ex) {
+			throw new P2PXWikiException(XWikiException.ERROR_DOC_XML_PARSING, "Error while parsing groups declaration file");
+		}
+	}
+
+	public WikiGroup createWikiGroup(String groupName) throws P2PXWikiException {
+		log.debug("createGroup");
+		throw new P2PXWikiException(P2PXWikiException.ERROR_P2PXWIKI_GROUP_NOTALLOWED, "No groups can be created using the current policy");
+	}
+
+	public String[] getAllGroupsNames() throws P2PXWikiException {
+		log.debug("getAllGroupsNames");
+		return (String[]) this.groups.toArray(new String[0]);
+	}
+
+	/**
+	 * @see com.xpn.p2pxwiki.services.WikiGroupServices#getAllGroups()
+	 */
+	public WikiGroup[] getAllGroups() throws P2PXWikiException {
+		String[] groupNames = this.getAllGroupsNames();
+		ArrayList groups = new ArrayList();
+		for (int i = 0; i < groupNames.length; ++i) {
+			try {
+				groups.add(this.getWikiGroup(groupNames[i]));
+			} catch (P2PXWikiException ex) {
+				log.error("Error retrieving group " + groupNames[i], ex);
+			}
+		}
+		return (WikiGroup[]) groups.toArray(new WikiGroup[0]);
+	}
+
+	public WikiGroup getWikiGroup(String groupName) throws P2PXWikiException {
+		log.debug("getGroup: " + groupName);
+		if (!this.groups.contains(groupName)) {
+			throw new P2PXWikiException(P2PXWikiException.ERROR_P2PXWIKI_NO_SUCH_GROUP, "Invalid group " + groupName);
+		}
+		if (cache.containsKey(groupName)) {
+			log.debug("Found group " + groupName + " in cache");
+			return (FileGroup) cache.get(groupName);
+		}
+		log.debug("Inserting group " + groupName + " in cache");
+		FileGroup group = new FileGroup(groupName);
+		cache.put(groupName, group);
+		return group;
+	}
+
+	public static WikiGroupServices getInstance() {
+		if (instance != null) {
+			try {
+				instance = new FileWikiGroupServices();
+			} catch (XWikiException ex) {
+				log.error("Cannot instantiate WikiGroupServices", ex);
+			}
+		}
+		return instance;
+	}
+}

Modified: xwiki-clients/p2pxwiki/src/test/java/com/xpn/p2pxwiki/communication/ConnectorPluginTest.java
===================================================================
--- xwiki-clients/p2pxwiki/src/test/java/com/xpn/p2pxwiki/communication/ConnectorPluginTest.java	2006-08-21 18:01:15 UTC (rev 1185)
+++ xwiki-clients/p2pxwiki/src/test/java/com/xpn/p2pxwiki/communication/ConnectorPluginTest.java	2006-08-21 19:14:53 UTC (rev 1186)
@@ -1,30 +1,22 @@
 package com.xpn.p2pxwiki.communication;
 
-import java.net.URL;
+import junit.framework.TestCase;
 
 import com.xpn.p2pxwiki.mocks.MockNetwork;
 import com.xpn.xwiki.XWiki;
 import com.xpn.xwiki.XWikiConfig;
 import com.xpn.xwiki.XWikiContext;
 import com.xpn.xwiki.XWikiException;
-import com.xpn.xwiki.doc.XWikiDocument;
-import com.xpn.xwiki.objects.BaseObject;
-import com.xpn.xwiki.objects.classes.BaseClass;
-import com.xpn.xwiki.plugin.charts.mocks.MockHttpServletRequest;
 import com.xpn.xwiki.plugin.charts.mocks.MockStore;
-import com.xpn.xwiki.web.XWikiServletRequest;
-import com.xpn.xwiki.web.XWikiServletURLFactory;
 
-import junit.framework.TestCase;
-
 public class ConnectorPluginTest extends TestCase {
 	private ConnectorPlugin plugin;
 	private XWikiContext xcontext;
 	private XWiki xwiki;
-	private BaseClass xclass;
-	private BaseObject xobject;
+	//private BaseClass xclass;
+	//private BaseObject xobject;
+    //private XWikiDocument doc;
     private XWikiConfig config;
-    private XWikiDocument doc;
 	private String pluginName;
     private String localPeer;
     private String remotePeer;





More information about the Xwiki-notifications mailing list