Package name.pehl.taoki

Source Code of name.pehl.taoki.TestComponent

package name.pehl.taoki;

import org.restlet.Application;
import org.restlet.Component;
import org.restlet.data.Protocol;
import org.restlet.resource.ServerResource;
import org.restlet.routing.Router;

/**
* @author $Author: harald.pehl $
* @version $Date: 2010-12-17 03:25:44 -0600 (Fri, 17 Dec 2010) $ $Revision: 149
*          $
*/
public class TestComponent extends Component
{
    public static final int STARTING_PORT = 10000;
    private static int effectivePort = STARTING_PORT;

    protected Application application;
    protected Router router;


    public TestComponent()
    {
        super();
        effectivePort++;
        getServers().add(Protocol.HTTP, effectivePort);
    }


    protected void initialize()
    {
        if (application == null)
        {
            application = new Application();
        }
        if (router == null)
        {
            router = new Router();
        }
    }


    public void startWith(String path, Class<? extends ServerResource> target) throws Exception
    {
        attach(path, target);
        application.setInboundRoot(router);
        getDefaultHost().attach(application);
        start();
    }


    public void attach(String path, Class<? extends ServerResource> target)
    {
        initialize();
        router.attach(path, target);
    }


    public static String getBaseUrl()
    {
        return "http://localhost:" + effectivePort;
    }
}
TOP

Related Classes of name.pehl.taoki.TestComponent

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.