/*
* ################################################################
*
* ProActive: The Java(TM) library for Parallel, Distributed,
*            Concurrent computing with Security and Mobility
*
* Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
* Contact: proactive-support@inria.fr
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
* USA
*
*  Initial developer(s):               The ProActive Team
*                        http://www.inria.fr/oasis/ProActive/contacts.html
*  Contributor(s):
*
* ################################################################
*/
package org.objectweb.proactive.ext.util;

import org.apache.log4j.Logger;

import org.objectweb.proactive.ProActive;
import org.objectweb.proactive.core.UniqueID;
import org.objectweb.proactive.core.body.BodyMap;
import org.objectweb.proactive.core.body.UniversalBody;
import org.objectweb.proactive.core.node.NodeFactory;
import org.objectweb.proactive.ext.locationserver.LocationServer;


/**
 * An implementation of a Location Server
 */
public class SimpleLocationServer implements org.objectweb.proactive.RunActive,
    LocationServer {
    static Logger logger = Logger.getLogger(SimpleLocationServer.class.getName());
    private BodyMap table;
    private String url;

    public SimpleLocationServer() {
    }

    public SimpleLocationServer(String url) {
        this.url = normalizeURL(url);
        this.table = new BodyMap();
    }

    /**
 * Update the location for the mobile object s
 * with id
 */
    public void updateLocation(UniqueID i, UniversalBody s) {
        //       System.out.println("Server: updateLocation() " + i + " object = " + s);
        table.updateBody(i, s);
    }

    /**
 * Return a reference to the remote body if available.
 * Return null otherwise
 */
    public UniversalBody searchObject(UniqueID id) {
        return (UniversalBody) table.getBody(id);
    }

    /**
 * First register with the specified url
 * Then wait for request
 */
    public void runActivity(org.objectweb.proactive.Body body) {
        this.register();
        org.objectweb.proactive.Service service = new org.objectweb.proactive.Service(body);
        service.fifoServing();
    }

    protected String normalizeURL(String url) {
        String tmp = url;

        //if it starts with rmi we remove it
        if (url.startsWith("rmi:")) {
            tmp = url.substring(4);
        }
		if (url.startsWith("ibis:")) {
				   tmp = url.substring(5);
			   }

        if (!tmp.startsWith("//")) {
            tmp = "//" + tmp;
        }
        return tmp;
    }

    protected void register() {
        try {
            logger.info("Attempt at binding : " + url);
            ProActive.register(ProActive.getStubOnThis(), url);
            logger.info("Location Server bound in registry : " + url);
        } catch (Exception e) {
            logger.fatal("Cannot bind in registry - aborting " + url);
            e.printStackTrace();
            return;
        }
    }

    public static void main(String[] args) {
        if (args.length < 1) {
            logger.error(
                "usage: java org.objectweb.proactive.ext.util.SimpleLocationServer <server url> [node]");
            System.exit(-1);
        }
        Object[] arg = new Object[1];
        arg[0] = args[0];
        SimpleLocationServer server = null;
        try {
            if (args.length == 2) {
                server = (SimpleLocationServer) ProActive.newActive("org.objectweb.proactive.ext.util.SimpleLocationServer",
                        arg, NodeFactory.getNode(args[1]));
            } else {
                server = (SimpleLocationServer) ProActive.newActive("org.objectweb.proactive.ext.util.SimpleLocationServer",
                        arg);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

@@ -1273,16 +1273,55 @@
 .util;%0A%0A
+import java.net.UnknownHostException;%0A%0A
 import o
@@ -1593,16 +1593,69 @@
 actory;%0A
+import org.objectweb.proactive.core.util.UrlBuilder;%0A
 import o
@@ -3063,222 +3063,208 @@
     
-if (url.startsWith(%22rmi:%22)) %7B%0A            tmp = url.substring(4);%0A        %7D%0A%09%09if (url.startsWith(%22ibis:%22)) %7B%0A%09%09%09%09   tmp = url.substring(5);%0A%09%09%09   %7D%0A%0A        if (!tmp.startsWith(%22//%22)) %7B%0A            tmp = %22//%22 + tmp
+String temp = null;%0A        try %7B%0A            tmp =  UrlBuilder.checkUrl(url);%0A        %7D catch (UnknownHostException e) %7B%0A            // TODO Auto-generated catch block%0A            e.printStackTrace()
 ;%0A  

change normalize url method