Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright (c) 2010-2011 Oracle and/or its affiliates. All rights reserved.
   *
   * The contents of this file are subject to the terms of either the GNU
   * General Public License Version 2 only ("GPL") or the Common Development
   * and Distribution License("CDDL") (collectively, the "License").  You
   * may not use this file except in compliance with the License.  You can
  * obtain a copy of the License at
  * http://glassfish.java.net/public/CDDL+GPL_1_1.html
  * or packager/legal/LICENSE.txt.  See the License for the specific
  * language governing permissions and limitations under the License.
  *
  * When distributing the software, include this License Header Notice in each
  * file and include the License file at packager/legal/LICENSE.txt.
  *
  * GPL Classpath Exception:
  * Oracle designates this particular file as subject to the "Classpath"
  * exception as provided by Oracle in the GPL Version 2 section of the License
  * file that accompanied this code.
  *
  * Modifications:
  * If applicable, add the following below the License Header, with the fields
  * enclosed by brackets [] replaced by your own identifying information:
  * "Portions Copyright [year] [name of copyright owner]"
  *
  * Contributor(s):
  * If you wish your version of this file to be governed by only the CDDL or
  * only the GPL Version 2, indicate your decision by adding "[Contributor]
  * elects to include this software in this distribution under the [CDDL or GPL
  * Version 2] license."  If you don't indicate a single choice of license, a
  * recipient has the option to distribute your version of this file under
  * either the CDDL, the GPL Version 2 or to extend the choice of license to
  * its licensees as provided above.  However, if you add GPL Version 2 code
  * and therefore, elected the GPL Version 2 license, then the option applies
  * only if the new code is made subject to such option by the copyright
  * holder.
  */
 
 package com.sun.jersey.api.container;
 
 import java.io.File;
 import java.util.List;
 import java.util.Set;

Factory for creating specific HTTP-based containers.

Author(s):
Paul.Sandoz@Sun.Com
 
 public final class ContainerFactory {
     
     private ContainerFactory() {
     }
    
    
Create a container according to the class requested.

The list of service-provider supporting the com.sun.jersey.spi.container.ContainerProvider service-provider will be iterated over until one returns a non-null container instance.

Parameters:
<A> the type of the container.
type the type of the container.
resourceClasses the list of Web resources to be managed by the Web application.
Returns:
the container.
Throws:
ContainerException if there is an error creating the container.
java.lang.IllegalArgumentException if no container provider supports the type.
 
     @SuppressWarnings("unchecked")
     public static <A> A createContainer(Class<A> typeClass<?>... resourceClasses)
         Set<Class<?>> resourceClassesSet = new HashSet<Class<?>>(
                 Arrays.asList(resourceClasses));
         
         return createContainer(typenew DefaultResourceConfig(resourceClassesSet),
                 null);
     }
    
    
Create a container according to the class requested.

The list of service-provider supporting the com.sun.jersey.spi.container.ContainerProvider service-provider will be iterated over until one returns a non-null container instance.

Parameters:
<A> the type of the container.
type the type of the container.
resourceClasses the set of Web resources to be managed by the Web application.
Returns:
the container.
Throws:
ContainerException if there is an error creating the container.
java.lang.IllegalArgumentException if no container provider supports the type.
    @SuppressWarnings("unchecked")
    public static <A> A createContainer(Class<A> typeSet<Class<?>> resourceClasses)
        return createContainer(typenew DefaultResourceConfig(resourceClasses),
                null);
    }
    
    
Create a container according to the class requested.

The list of service-provider supporting the com.sun.jersey.spi.container.ContainerProvider service-provider will be iterated over until one returns a non-null container instance.

Parameters:
<A> the type of the container.
type the type of the container.
resourceConfig the resource configuration containing the set of Web resources to be managed by the Web application.
Returns:
the container.
Throws:
ContainerException if there is an error creating the container.
java.lang.IllegalArgumentException if no container provider supports the type.
    public static <A> A createContainer(Class<A> typeResourceConfig resourceConfig)
        return createContainer(typeresourceConfignull);
    }

    
Create a container according to the class requested.

The list of service-provider supporting the com.sun.jersey.spi.container.ContainerProvider service-provider will be iterated over until one returns a non-null container instance.

Parameters:
<A> the type of the container.
type the type of the container.
resourceConfig the resource configuration containing the set of Web resources to be managed by the Web application.
factory the IoC component provider factory the web application delegates to for obtaining instances of resource and provider classes. May be null if the web application is responsible for instantiating resource and provider classes.
Returns:
the container.
Throws:
ContainerException if there is an error creating the container.
java.lang.IllegalArgumentException if no container provider supports the type.
    @SuppressWarnings("unchecked")
    public static <A> A createContainer(Class<A> typeResourceConfig resourceConfig,
            IoCComponentProviderFactory factory)
        WebApplication wa = WebApplicationFactory.createWebApplication();
        
        // Reverse the order so that applications may override
        LinkedList<ContainerProvidercps = new LinkedList<ContainerProvider>();
        for (ContainerProvider cp : ServiceFinder.find(ContainerProvider.classtrue))
            cps.addFirst(cp);
        
        for (ContainerProvider<A> cp : cps) {
            A c = cp.createContainer(typeresourceConfigwa);
            if (c != null) {
                // Initiate the web application
                if (!wa.isInitiated()) {
                    wa.initiate(resourceConfigfactory);
                }
                // Register a container listener
                Object o = resourceConfig.getProperties().get(
                        .);
                if (o instanceof List) {
                    List list = (Listo;
                    for (Object elem : list) {
                        if (elem instanceof ContainerNotifier &&
                                c instanceof ContainerListener) {
                            ContainerNotifier crf = (ContainerNotifierelem;
                            crf.addListener((ContainerListenerc);
                        }
                    }
                } else if (o instanceof ContainerNotifier &&
                        c instanceof ContainerListener) {
                    ContainerNotifier crf = (ContainerNotifiero;
                    crf.addListener((ContainerListenerc);
                }
                return c;
            }
        }
        
        throw new IllegalArgumentException("No container provider supports the type " + type);
    }
    
    
Create an instance of a container according to the class requested.

Deprecated:
Parameters:
<A> the type of the container.
type the type of the container.
packageName the name of the package where to find the resource configuration class.
Returns:
the HTTP handler, if a handler could not be created then null is returned.
Throws:
ContainerException if the resource configuration class could not be found and instantiated or there is an error creating the container.
java.lang.IllegalArgumentException if no container provider supports the type.
    @Deprecated
    @SuppressWarnings("unchecked")
    public static <A> A createContainer(Class<A> typeString packageName)
        String resourcesClassName = packageName + ".WebResources";
        try {
            Class<?> resourcesClass = ContainerFactory.class.getClassLoader().loadClass(resourcesClassName);
            ResourceConfig config = (ResourceConfigresourcesClass.newInstance();
            return createContainer(typeconfignull);
        } catch (ClassNotFoundException e) {
            throw new ContainerException(e);
        } catch (InstantiationException e) {
            throw new ContainerException(e);
        } catch (IllegalAccessException e) {
            throw new ContainerException(e);
        }
    }
    
    
Create an instance of a container according to the class requested.

All java classpath will be scanned for Root Resource Classes.

Parameters:
<A> the type of the container.
type the type of the container.
Returns:
the HTTP handler, if a handler could not be created then null is returned.
Throws:
java.lang.IllegalArgumentException if no container provider supports the type.
    public static <A> A createContainer(Class<A> type) {
        String classPath = System.getProperty("java.class.path");
        String[] paths = classPath.split(.);
        return createContainer(typepaths);
    }
    
    
Create an instance of a container according to the class requested.

Root Resource Classes will be scanned in paths.

Parameters:
<A> the type of the container.
type the type of the container.
paths a list of paths to be scanned for resource classes.
Returns:
the HTTP handler, if a handler could not be created then null is returned.
Throws:
java.lang.IllegalArgumentException if no container provider supports the type.
    public static <A> A createContainer(Class<A> typeString... paths) {
        ClasspathResourceConfig config = new ClasspathResourceConfig(paths);
        return createContainer(typeconfignull);
    }
    
New to GrepCode? Check out our FAQ X