001: /**
002: * $Id: WebContainerFactory.java,v 1.6 2006/02/08 11:42:45 fo160993 Exp $
003: * Copyright 2004 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.fabric.tasks;
014:
015: import java.lang.IllegalArgumentException;
016: import java.util.Map;
017: import java.util.logging.Logger;
018: import java.util.logging.Level;
019: import java.util.logging.LogRecord;
020:
021: import com.sun.portal.admin.common.InstanceAttributes;
022: import com.sun.portal.admin.common.util.AdminUtil;
023:
024: import com.sun.portal.log.common.PortalLogger;
025:
026: public class WebContainerFactory {
027:
028: private WebContainerFactory() {
029: }
030:
031: private static Logger logger = PortalLogger
032: .getLogger(WebContainerFactory.class);
033:
034: public static WebContainer getWebContainer(Map attributes,
035: boolean bValidate) throws ConfigurationException,
036: IllegalArgumentException {
037:
038: if (attributes == null) {
039: throw new IllegalArgumentException("attributes=null");
040: }
041:
042: if (logger == null) {
043: throw new IllegalArgumentException("logger=null");
044: }
045:
046: String type = (String) attributes
047: .get(InstanceAttributes.WEB_CONTAINER_TYPE);
048: if ((type == null) || (type.length() <= 0)) {
049: logger.log(Level.SEVERE, "PSFB_CSPFT0331");
050: throw new ConfigurationException(
051: "Invalid Web Container Type=null");
052: }
053:
054: WebContainer wc = null;
055: try {
056:
057: if (type.equals(WebContainer.TYPE_IBMWS5)) {
058: wc = new IBMWAS5Impl(attributes);
059: } else if (type.equals(WebContainer.TYPE_BEAWL8)) {
060: wc = new BEAWL8Impl(attributes);
061: } else if (type.equals(WebContainer.TYPE_JESWS7)) {
062: wc = new JESWS7Impl(attributes);
063: } else if (type.equals(WebContainer.TYPE_JESAS81)) {
064: wc = new JESAS81Impl(attributes);
065: } else if (type.equals(WebContainer.TYPE_JESWS6)) {
066: wc = new JESWS6Impl(attributes);
067: } else {
068: logger.log(Level.SEVERE, "PSFB_CSPFT0332", type);
069: throw new ConfigurationException(
070: "Invalid Web Container Type = " + type);
071: }
072:
073: if (bValidate) {
074:
075: String sHostName = (String) attributes
076: .get(InstanceAttributes.HOST);
077: boolean bIsLocalHost = false;
078:
079: try {
080: bIsLocalHost = AdminUtil.isLocal(sHostName);
081: } catch (java.net.UnknownHostException e) {
082:
083: wc = null;
084: if (logger.isLoggable(Level.SEVERE)) {
085: LogRecord record = new LogRecord(Level.SEVERE,
086: "PSFB_CSPFT0081");
087: record
088: .setParameters(new String[] { sHostName });
089: record.setThrown(e);
090: record.setLoggerName(logger.getName());
091: logger.log(record);
092: }
093:
094: throw new ConfigurationException(e);
095: }
096:
097: if (bIsLocalHost) {
098:
099: wc.validate();
100: } else {
101:
102: logger.log(Level.INFO, "PSFB_CSPFT0080",
103: new String[] { sHostName });
104: }
105: }
106:
107: wc.postValidationInit();
108: } catch (ValidationException e) {
109:
110: wc = null;
111: if (logger.isLoggable(Level.SEVERE)) {
112: LogRecord record = new LogRecord(Level.SEVERE, e
113: .getMessage());
114: record.setThrown(e);
115: record.setLoggerName(logger.getName());
116: logger.log(record);
117: }
118: throw new ConfigurationException(e);
119: }
120:
121: return wc;
122: }
123: }
|