001: /**
002: * $Id: ServiceConfig.java,v 1.6 2007/01/26 03:50:14 portalbld Exp $
003: * Copyright 2005 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.service.common;
014:
015: import java.util.Properties;
016: import java.util.Map;
017: import java.util.HashMap;
018: import java.util.Enumeration;
019:
020: import java.io.FileInputStream;
021: import java.io.IOException;
022: import java.io.FileNotFoundException;
023:
024: import javax.servlet.ServletContext;
025: import com.sun.portal.service.ServiceException;
026: import com.sun.portal.util.ResourceLoader;
027:
028: public class ServiceConfig {
029:
030: public static final String SERVICE_CONFIG_FILE = "service.properties";
031:
032: public static final String SERVICE_REGISTRY_CLASSNAME = "ServiceRegistryClassname";
033:
034: public static final String PORTLET_SERVICE_CLASSNAME = "PortletServiceClassName";
035: public static final String PROVIDER_SERVICE_CLASSNAME = "ProviderServiceClassName";
036: public static final String PROVIDER_PROVISION_SCHEMA_LOCATION = "ProviderProvisionSchemaLocation";
037: public static final String PROVIDER_PROVISION_FILE_NAME = "ProviderProvisionFileName";
038: public static final String IS_VALIDATE_SCHEMA_ON = "IsValidateSchemaOn";
039: //
040: // default values (used when there is none defined in the config file
041: //
042: public static final String DEFAULT_SERVICE_REGISTRY_CLASSNAME = "com.sun.portal.service.serviceregistry.impl.ServiceRegistryImpl";
043:
044: //
045: // default values (used when there is none defined in the config file
046: //
047: public static final String DEFAULT_PORTLET_SERVICE_CLASSNAME = "com.sun.portal.service.portlet.impl.PortletServiceImpl";
048:
049: //
050: // default values (used when there is none defined in the config file
051: //
052: public static final String DEFAULT_PROVIDER_SERVICE_CLASSNAME = "com.sun.portal.service.provider.impl.ProviderServiceImpl";
053: //TODO
054: public static final String DEFAULT_PROVIDER_PROVISION_SCHEMA_LOCATION = "/etc/opt/SUNWportal/dtd";
055:
056: public static final String DEFAULT_PROVIDER_PROVISION_FILE_NAME = "/WEB-INF/providerProvision.xml";
057:
058: public static final String DEFAULT_IS_VALIDATE_SCHEMA_ON = "false";
059:
060: //
061: //
062: // static instance
063: //
064: protected static Properties properties = null;
065:
066: protected static ServiceConfig config = null;
067: private ServletContext _servletContext;
068:
069: protected ServiceConfig() {
070: }
071:
072: public static void init(ServletContext sc) throws ServiceException {
073:
074: init(SERVICE_CONFIG_FILE, null, sc);
075: }
076:
077: private static void init(String filename, String portalId,
078: ServletContext sc) throws ServiceException {
079: config = new ServiceConfig();
080: config._servletContext = sc;
081: if (filename != null && filename.length() > 0) {
082: config.doInit(filename, portalId);
083: } else {
084: throw new ServiceException(
085: "ServiceConfig.init(): properties file name not found.");
086: }
087: }
088:
089: public static ServiceConfig getInstance() {
090: //
091: // we assume that config has been initialized by the time
092: // this gets called
093: //
094: return config;
095: }
096:
097: protected void doInit(String filename, String portalId)
098: throws ServiceException {
099: ResourceLoader resourceLoader = null;
100: if (portalId == null) {
101: resourceLoader = ResourceLoader.getInstance(System
102: .getProperties());
103: } else {
104: resourceLoader = ResourceLoader.getInstance(portalId);
105: }
106: try {
107: properties = resourceLoader.getProperties(filename);
108: } catch (FileNotFoundException fnfe) {
109: throw new ServiceException("ServiceConfig.doInit(): ", fnfe);
110: } catch (IOException ioe) {
111: throw new ServiceException("ServiceConfig.doInit(): ", ioe);
112: }
113:
114: }
115:
116: public String getServiceRegistryClassname() {
117: String mmClassname = properties
118: .getProperty(SERVICE_REGISTRY_CLASSNAME);
119: if (mmClassname == null) {
120: mmClassname = DEFAULT_SERVICE_REGISTRY_CLASSNAME;
121: }
122:
123: return mmClassname;
124: }
125:
126: public String getPortletServiceClassname() {
127: String mmClassname = properties
128: .getProperty(PORTLET_SERVICE_CLASSNAME);
129: if (mmClassname == null) {
130: mmClassname = DEFAULT_PORTLET_SERVICE_CLASSNAME;
131: }
132:
133: return mmClassname;
134: }
135:
136: public String getProviderServiceClassname() {
137: String mmClassname = properties
138: .getProperty(PROVIDER_SERVICE_CLASSNAME);
139: if (mmClassname == null) {
140: mmClassname = DEFAULT_PROVIDER_SERVICE_CLASSNAME;
141: }
142:
143: return mmClassname;
144: }
145:
146: public String getProviderProvisionSchemaLocation() {
147: String x = properties
148: .getProperty(PROVIDER_PROVISION_SCHEMA_LOCATION);
149: if (x == null) {
150: x = DEFAULT_PROVIDER_PROVISION_SCHEMA_LOCATION;
151: }
152:
153: return x;
154: }
155:
156: public String getProviderProvisionFileName() {
157: String x = properties.getProperty(PROVIDER_PROVISION_FILE_NAME);
158: if (x == null) {
159: x = DEFAULT_PROVIDER_PROVISION_FILE_NAME;
160: }
161:
162: return x;
163: }
164:
165: public String isValidateSchemaOn() {
166: String x = properties.getProperty(IS_VALIDATE_SCHEMA_ON);
167: if (x == null) {
168: x = DEFAULT_IS_VALIDATE_SCHEMA_ON;
169: }
170: return x;
171: }
172:
173: public ServletContext getServletContext() {
174: return _servletContext;
175: }
176:
177: }
|