001: /*
002: * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.instance.sra.common;
007:
008: //
009:
010: import com.sun.portal.config.context.*;
011: import com.sun.portal.config.tasks.GWTasks;
012: import com.sun.portal.config.tasks.SRATasksFactory;
013: import com.sun.portal.config.tasks.Tasks;
014: import com.sun.portal.config.tasks.TasksImpl;
015:
016: import java.io.IOException;
017:
018: //
019:
020: public class GatewayInstance extends SRAInstance {
021: //
022: //
023: //
024: protected GWTasks t = null;
025: protected static final String configFilePrefix = "GWConfig";
026:
027: //
028: //
029: //
030: public GatewayInstance(String installLocation) {
031: super (installLocation, configFilePrefix
032: + SRAFileContext.DOT_PROPERTIES);
033: }
034:
035: //
036: //
037: //
038: public SRAPropertyContext getSRAPropertyContext() {
039: SRAPropertyContext result = null;
040:
041: try {
042: validate();
043: result = spc;
044: } catch (IOException ioe) {
045: DebugContext.message("Configuration file is <"
046: + workingConfigurationFile + ">");
047: ioe.printStackTrace();
048: }
049:
050: return result;
051: }
052:
053: public SRAFileContext getSRAFileContext() {
054: SRAFileContext result = null;
055:
056: try {
057: validate();
058: result = sfc;
059: } catch (IOException ioe) {
060: DebugContext.message("Configuration file is <"
061: + workingConfigurationFile + ">");
062: ioe.printStackTrace();
063: }
064:
065: return result;
066: }
067:
068: public Boolean setName(String instanceName) {
069: Boolean result = super .setName(instanceName);
070:
071: try {
072: validate();
073: workingConfigurationFile = sfc
074: .getGWInstanceConfigurationFile(name);
075: if (workingConfigurationFile != null) {
076: gearUp();
077: }
078: } catch (IOException ioe) {
079: DebugContext.message("Configuration file is <"
080: + workingConfigurationFile + ">");
081: ioe.printStackTrace();
082: result = Boolean.FALSE;
083: }
084:
085: return result;
086: }
087:
088: public Boolean create() throws IOException {
089: return t.installGatewayInstance(workingConfigurationFile);
090: }
091:
092: public Boolean remove() throws IOException {
093: return t.uninstallGatewayInstance(workingConfigurationFile);
094: }
095:
096: public String[] list() throws IOException {
097: validate();
098: return sfc.getGWInstanceNames();
099: }
100:
101: //
102: //
103: //
104: private void gearUp() throws IOException {
105: Tasks tasks = new TasksImpl();
106:
107: p = tasks
108: .load(tasks.replaceBackSlash(workingConfigurationFile));
109:
110: spc = new GWPropertyContext(p);
111: sfc = SRAFileContextFactory.createGWFileContext(spc);
112: t = SRATasksFactory.createGWTasks(spc, sfc);
113: }
114:
115: protected void validate() throws IOException {
116: if (workingConfigurationFile != null) {
117: if (p == null) {
118: gearUp();
119: }
120: }
121: }
122:
123: //
124: //
125: //
126: public Boolean updateConfigurationFile(IdentityPropertyContext ipc,
127: SRAPropertyContext spc, String propertiesHeader) {
128: this .spc = spc; // Get modified values. CreateInstance may cause this.spc be out-of-sync.
129: workingConfigurationFile = sfc.getConfigurationDirectory()
130: + SRAFileContext.FORWARD_SLASH + configFilePrefix
131: + SRAFileContext.DASH + spc.getInstanceName()
132: + SRAFileContext.DOT_PROPERTIES;
133: return super .updateConfigurationFile(ipc, propertiesHeader);
134: }
135:
136: //
137: //
138: //
139: }
|