001: // ***************************************************************
002: // * *
003: // * File:ServiceContainer.java *
004: // * *
005: // * Copyright (c) 2002 Sun Microsystems, Inc. *
006: // * All rights reserved. *
007: // * *
008: // * *
009: // * Date - Jul/16/2002 *
010: // * Author - alejandro.abdelnur@sun.com *
011: // * *
012: // ***************************************************************
013: package com.sun.portal.common.service;
014:
015: import com.sun.portal.common.service.impl.ServiceContainerImpl;
016:
017: /**
018: * A ServiceContainer is a singleton that manages a collection
019: * of ServiceContexts.
020: * <P>
021: * The container implementation class can be specified as a system
022: * property. If it's not specified the default container implementation
023: * will be used, com.sun.portal.common.service.impl.ServiceContainerImpl
024: * <P>
025: * The default container implementation has a DEFAULT_CONTEXT only.
026: * This context initializes all the services described in the service.xml
027: * file that has to be available in the root of the classpath.
028: * <P>
029: *
030: * @author <A HREF="mailto:tucu@sun.com">Alejandro Abdelnur</A>
031: *
032: */
033: public abstract class ServiceContainer {
034:
035: /**
036: * String constant that defined the system propoperty that it
037: * will be queried to obtain the name of the ServiceContainer
038: * class to use.
039: * <P>
040: * It's value is com.sun.portal.common.service.container.class
041: */
042: public static final String SERVICE_CONTAINER_CLASS = "com.sun.portal.common.service.ServiceContainer.class";
043:
044: private static ServiceContainer _container;
045:
046: static {
047: try {
048: String className = System
049: .getProperty(SERVICE_CONTAINER_CLASS);
050: Class clazz = Class.forName(className);
051: _container = (ServiceContainer) clazz.newInstance();
052: } catch (Exception ex) {
053: }
054: if (_container == null) {
055: _container = new ServiceContainerImpl();
056: }
057: }
058:
059: /**
060: * String constant used to retrieve the default context of a
061: * container.
062: * <P>
063: *
064: */
065: public static final String DEFAULT_CONTEXT = "default";
066:
067: /**
068: * Return the ServiceContainer object.
069: * <P>
070: *
071: * @return the ServiceContainer object
072: *
073: */
074: public static ServiceContainer getContainer() {
075: return _container;
076: }
077:
078: /**
079: * Initializes the ServiceContainer object.
080: * <P>
081: * This method must be called before any ServiceContext
082: * can be retrieved from the container.
083: * The init method must complete successfully in order
084: * for the container to be operational.
085: * <P>
086: *
087: * @throws ServiceException if an exception has occurred
088: * that interferes with the container's normal
089: * initialization
090: *
091: */
092: public abstract void init() throws ServiceException;
093:
094: /**
095: * Returns the named ServiceContext of the container.
096: * <P>
097: * If the DEFAULT_CONTEXT constant is used, the default
098: * context must be returned. A container always has a
099: * default context.
100: * <P>
101: *
102: * @param name a String containing the name of the context
103: * to retrieve
104: *
105: * @return the ServiceContext with the given name, or null
106: * if the context does not exist
107: *
108: */
109: public abstract ServiceContext getContext(String name);
110:
111: /**
112: * Destroys the ServiceContainer object.
113: * <P>
114: * This method must be called to take the container out of
115: * service. After this method completes, the container
116: * is not active anymore.
117: * <P>
118: * This method gives the container an opportunity to clean
119: * up any resources that are being held (for example, memory,
120: * file handles, threads).
121: * <P>
122: *
123: */
124: public abstract void destroy();
125:
126: }
|