Index: modules/http/src/main/java/com/sun/grizzly/http/deployer/Deployer.java =================================================================== --- modules/http/src/main/java/com/sun/grizzly/http/deployer/Deployer.java (revision 0) +++ modules/http/src/main/java/com/sun/grizzly/http/deployer/Deployer.java (revision 0) @@ -0,0 +1,75 @@ +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the license at + * https://glassfish.dev.java.net/public/CDDLv1.0.html or + * glassfish/bootstrap/legal/CDDLv1.0.txt. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at glassfish/bootstrap/legal/CDDLv1.0.txt. + * If applicable, add the following below the CDDL Header, + * with the fields enclosed by brackets [] replaced by + * you own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + */ +package com.sun.grizzly.http.deployer; + +import com.sun.grizzly.http.embed.GrizzlyWebServer; +import com.sun.grizzly.tcp.http11.GrizzlyAdapter; + +import java.util.Map; +import java.util.Set; +import java.net.URI; + +/** + * Deployer abstraction. + * + * @author Hubert Iwaniuk + * @param Type of object deployed by this deployer. + * @since Sep 17, 2009 + */ +public abstract class Deployer { + + /** + * Deploy deployable to gws. + * + * @param gws Grizzly to deploy to. + * @param toDeploy Deployable to be deployed. + * @throws DeployException Error in deployment. + */ + public final void deploy(GrizzlyWebServer gws, V toDeploy) throws DeployException { + Map> map = convert(toDeploy); + if (map == null || map.isEmpty()) { + throw new DeployException("No GrizzlyAdapters created for: " + toDeploy); + } + for (Map.Entry> adapterEntry : map.entrySet()) { + Set mappings = adapterEntry.getValue(); + gws.addGrizzlyAdapter(adapterEntry.getKey(), mappings.toArray(new String[mappings.size()])); + } + } + + /** + * Converts deployable object to {@link Map} of {@link GrizzlyAdapter}s to paths to deploy to. + * + * @param toDeploy Deployable object to be converted. + * @return {@link Map}ping {@link GrizzlyAdapter}s to paths to be deployed under ({@link Set} of {@link String}s). + * @throws DeployException Error while creating adapters. + */ + public abstract Map> convert(V toDeploy) throws DeployException; + + /** + * Create object to deploy from uri. + * + * @param uri of deployable object. + * @return Deployable object. + */ + public abstract V fromURI(URI uri); +} Index: modules/http/src/main/java/com/sun/grizzly/http/deployer/DeployException.java =================================================================== --- modules/http/src/main/java/com/sun/grizzly/http/deployer/DeployException.java (revision 0) +++ modules/http/src/main/java/com/sun/grizzly/http/deployer/DeployException.java (revision 0) @@ -0,0 +1,51 @@ +/* + * The contents of this file are subject to the terms + * of the Common Development and Distribution License + * (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the license at + * https://glassfish.dev.java.net/public/CDDLv1.0.html or + * glassfish/bootstrap/legal/CDDLv1.0.txt. + * See the License for the specific language governing + * permissions and limitations under the License. + * + * When distributing Covered Code, include this CDDL + * Header Notice in each file and include the License file + * at glassfish/bootstrap/legal/CDDLv1.0.txt. + * If applicable, add the following below the CDDL Header, + * with the fields enclosed by brackets [] replaced by + * you own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * Copyright 2007 Sun Microsystems, Inc. All rights reserved. + */ +package com.sun.grizzly.http.deployer; + +/** + * Deploying error. + * + * @author Hubert Iwaniuk + * @since Sep 17, 2009 + */ +public class DeployException extends Exception { + /** {@inheritDoc} */ + public DeployException() { + super(); + } + + /** {@inheritDoc} */ + public DeployException(String message) { + super(message); + } + + /** {@inheritDoc} */ + public DeployException(String message, Throwable cause) { + super(message, cause); + } + + /** {@inheritDoc} */ + public DeployException(Throwable cause) { + super(cause); + } +} Index: modules/http/src/main/java/com/sun/grizzly/http/embed/GrizzlyWebServer.java =================================================================== --- modules/http/src/main/java/com/sun/grizzly/http/embed/GrizzlyWebServer.java (revision 3631) +++ modules/http/src/main/java/com/sun/grizzly/http/embed/GrizzlyWebServer.java (working copy) @@ -29,6 +29,8 @@ import com.sun.grizzly.arp.AsyncHandler; import com.sun.grizzly.http.Management; import com.sun.grizzly.http.SelectorThread; +import com.sun.grizzly.http.deployer.Deployer; +import com.sun.grizzly.http.deployer.DeployException; import com.sun.grizzly.ssl.SSLSelectorThread; import com.sun.grizzly.tcp.Adapter; import com.sun.grizzly.tcp.http11.GrizzlyAdapter; @@ -44,6 +46,7 @@ import java.util.Map.Entry; import java.util.logging.Level; import java.util.logging.Logger; +import java.net.URI; import javax.management.ObjectInstance; import javax.management.ObjectName; @@ -741,4 +744,20 @@ return adapterChains; } } + + /** + * Deploy given uri using provided deployer. + * + * @param uri of object to be deployed. + * @param deployer to be used for deployment. + * @param Type of object to be deployed. + * @throws DeployException Deployment failed. + */ + public void deploy(URI uri, Deployer deployer) throws DeployException { + V toDeploy = deployer.fromURI(uri); + if (toDeploy == null) { + throw new DeployException("Failed to create deployable from " + uri); + } + deployer.deploy(this, toDeploy); + } }