001: package com.sun.portal.sra.admin.mbeans;
002:
003: import java.util.Properties;
004: import java.util.List;
005:
006: import com.sun.portal.admin.common.context.PSConfigContext;
007: import com.sun.portal.admin.common.PSMBeanException;
008: import com.sun.portal.sra.admin.mbeans.exceptions.NoSuchSraServerTypeException;
009:
010: /**
011: * @version 1.0
012: * @created 04-Mar-2005 9:58:14 PM
013: * @author Sandeep Soni
014: */
015:
016: public class SraServerFactory {
017: public static SraServer createServerInstance(int serviceIdentifier,
018: Properties configProperties, PSConfigContext cc)
019: throws NoSuchSraServerTypeException, PSMBeanException {
020: SraServer server = null;
021: switch (serviceIdentifier) {
022: case SraServer.INSTANCE_TYPE_GATEWAY:
023: server = new Gateway(cc);
024: server.createInstance(configProperties);
025: break;
026: case SraServer.INSTANCE_TYPE_REWRITER_PROXY:
027: server = new RewriterProxy(cc);
028: server.createInstance(configProperties);
029: break;
030: case SraServer.INSTANCE_TYPE_NETLET_PROXY:
031: server = new NetletProxy(cc);
032: server.createInstance(configProperties);
033: break;
034: default:
035: StringBuffer sb = new StringBuffer(
036: "No such SRA Server of type " + serviceIdentifier
037: + " is known.\n");
038: sb
039: .append("Valid values are SraServer.INSTANCE_TYPE_GATEWAY, SraServer.INSTANCE_TYPE_REWRITER_PROXY and SraServer.INSTANCE_TYPE_NETLET_PROXY");
040: throw new NoSuchSraServerTypeException(sb.toString());
041: }
042: return server;
043: }
044:
045: public static boolean deleteServerInstance(int serviceIdentifier,
046: String instanceName, PSConfigContext cc)
047: throws NoSuchSraServerTypeException, Exception {
048: boolean status = false;
049: SraServer server = getServerComponent(serviceIdentifier,
050: instanceName, cc);
051: if (server == null)
052: return status;
053: status = server.deleteInstance();
054: return status;
055: }
056:
057: public static boolean startServerInstance(int serviceIdentifier,
058: String instanceName, PSConfigContext cc)
059: throws NoSuchSraServerTypeException, Exception {
060: boolean status = false;
061: SraServer server = getServerComponent(serviceIdentifier,
062: instanceName, cc);
063: if (server == null)
064: return status;
065: status = server.start();
066: return status;
067: }
068:
069: public static boolean stopServerInstance(int serviceIdentifier,
070: String instanceName, PSConfigContext cc)
071: throws NoSuchSraServerTypeException, Exception {
072: boolean status = false;
073: SraServer server = getServerComponent(serviceIdentifier,
074: instanceName, cc);
075: if (server == null)
076: return status;
077: status = server.stop();
078: return status;
079: }
080:
081: public static boolean isServerInstanceStarted(PSConfigContext cc,
082: int serviceIdentifier, String instanceName,
083: String hostname, int portNumber)
084: throws NoSuchSraServerTypeException, Exception {
085: boolean status = false;
086: SraServer server = getServerComponent(serviceIdentifier,
087: instanceName, cc);
088: if (server == null)
089: return status;
090: return server.isStarted(hostname, portNumber);
091: }
092:
093: public static boolean isServerInstanceStopped(PSConfigContext cc,
094: int serviceIdentifier, String instanceName,
095: String hostname, int portNumber)
096: throws NoSuchSraServerTypeException, Exception {
097: boolean status = false;
098: SraServer server = getServerComponent(serviceIdentifier,
099: instanceName, cc);
100: if (server == null)
101: return status;
102: return server.isStopped(hostname, portNumber);
103: }
104:
105: public static List getInstancesFromProfile(int serviceIdentifier,
106: String instanceName) throws NoSuchSraServerTypeException,
107: Exception {
108: switch (serviceIdentifier) {
109: case SraServer.INSTANCE_TYPE_GATEWAY:
110: return SraServerImpl.getServerInstanceInfoFromProfile(
111: Gateway.COMPONENT_NAME,
112: Gateway.ATTRIBUTE_GATEWAY_LISTS, instanceName);
113: case SraServer.INSTANCE_TYPE_REWRITER_PROXY:
114: return SraServerImpl.getServerInstanceInfoFromProfile(
115: RewriterProxy.COMPONENT_NAME,
116: RewriterProxy.ATTRIBUTE_RWP_LISTS, instanceName);
117: case SraServer.INSTANCE_TYPE_NETLET_PROXY:
118: return SraServerImpl.getServerInstanceInfoFromProfile(
119: NetletProxy.COMPONENT_NAME,
120: NetletProxy.ATTRIBUTE_NLP_LISTS, instanceName);
121: default:
122: StringBuffer sb = new StringBuffer(
123: "No such SRA Server of type " + serviceIdentifier
124: + " is known.\n");
125: sb
126: .append("Valid values are SraServer.INSTANCE_TYPE_GATEWAY, SraServer.INSTANCE_TYPE_REWRITER_PROXY and SraServer.INSTANCE_TYPE_NETLET_PROXY");
127: throw new NoSuchSraServerTypeException(sb.toString());
128: }
129: }
130:
131: /*
132: * Given an instance name and the type of SRA Server to get, this factory
133: * method will create an instance of that server type with all properties of
134: * that instance So for example calling
135: * SraServerComponentFactory.getServerComponent("gateway" , "default" );
136: * will create an object of type Gateway which implements
137: * SraServerComponent. The returned component will have read all confg
138: * values from its corresponding property files and config files and is
139: * guaranteeed to be populated with data you can use.
140: */
141: public static SraServer getServerComponent(int serviceIdentifier,
142: String instanceName, PSConfigContext cc)
143: throws NoSuchSraServerTypeException {
144: SraServer server = null;
145:
146: switch (serviceIdentifier) {
147: case SraServer.INSTANCE_TYPE_GATEWAY:
148: server = new Gateway(instanceName, cc);
149: break;
150: case SraServer.INSTANCE_TYPE_REWRITER_PROXY:
151: server = new RewriterProxy(instanceName, cc);
152: break;
153: case SraServer.INSTANCE_TYPE_NETLET_PROXY:
154: server = new NetletProxy(instanceName, cc);
155: break;
156: default:
157: StringBuffer sb = new StringBuffer(
158: "No such SRA Server of type " + serviceIdentifier
159: + " is known.\n");
160: sb
161: .append("Valid values are SraServer.INSTANCE_TYPE_GATEWAY, SraServer.INSTANCE_TYPE_REWRITER_PROXY and SraServer.INSTANCE_TYPE_NETLET_PROXY");
162: throw new NoSuchSraServerTypeException(sb.toString());
163: }
164: return server;
165: }
166:
167: }
|