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.*;
012:
013: import java.io.IOException;
014:
015: //
016:
017: public class RewriterProxyInstance extends SRAInstance {
018: //
019: //
020: //
021: protected RWPTasks t = null;
022: protected static final String configFilePrefix = "RWPConfig";
023:
024: //
025: //
026: //
027: public RewriterProxyInstance(String installLocation) {
028: super (installLocation, configFilePrefix
029: + SRAFileContext.DOT_PROPERTIES);
030: }
031:
032: //
033: //
034: //
035: public SRAPropertyContext getSRAPropertyContext() {
036: SRAPropertyContext result = null;
037:
038: try {
039: validate();
040: result = spc;
041: } catch (IOException ioe) {
042: DebugContext.message("Configuration file is <"
043: + workingConfigurationFile + ">");
044: ioe.printStackTrace();
045: }
046:
047: return result;
048: }
049:
050: public SRAFileContext getSRAFileContext() {
051: SRAFileContext result = null;
052:
053: try {
054: validate();
055: result = sfc;
056: } catch (IOException ioe) {
057: DebugContext.message("Configuration file is <"
058: + workingConfigurationFile + ">");
059: ioe.printStackTrace();
060: }
061:
062: return result;
063: }
064:
065: public Boolean setName(String instanceName) {
066: Boolean result = super .setName(instanceName);
067:
068: try {
069: validate();
070: workingConfigurationFile = sfc
071: .getRWPInstanceConfigurationFile(name);
072: if (workingConfigurationFile != null) {
073: gearUp();
074: }
075: } catch (IOException ioe) {
076: DebugContext.message("Configuration file is <"
077: + workingConfigurationFile + ">");
078: ioe.printStackTrace();
079: result = Boolean.FALSE;
080: }
081:
082: return result;
083: }
084:
085: public Boolean create() throws IOException {
086: return t.installRewriterProxyInstance(workingConfigurationFile);
087: }
088:
089: public Boolean remove() throws IOException {
090: return t
091: .uninstallRewriterProxyInstance(workingConfigurationFile);
092: }
093:
094: public String[] list() throws IOException {
095: validate();
096: return sfc.getRWPInstanceNames();
097: }
098:
099: //
100: //
101: //
102: private void gearUp() throws IOException {
103: Tasks tasks = new TasksImpl();
104:
105: p = tasks
106: .load(tasks.replaceBackSlash(workingConfigurationFile));
107:
108: spc = new RWPPropertyContext(p);
109: sfc = SRAFileContextFactory.createRWPFileContext(spc);
110: t = SRATasksFactory.createRWPTasks(spc, sfc);
111: }
112:
113: protected void validate() throws IOException {
114: if (workingConfigurationFile != null) {
115: if (p == null) {
116: gearUp();
117: }
118: }
119: }
120:
121: //
122: //
123: //
124: public Boolean updateConfigurationFile(IdentityPropertyContext ipc,
125: SRAPropertyContext spc, String propertiesHeader) {
126: this .spc = spc; // Get modified values. CreateInstance may cause this.spc be out-of-sync.
127: workingConfigurationFile = sfc.getConfigurationDirectory()
128: + SRAFileContext.FORWARD_SLASH + configFilePrefix
129: + SRAFileContext.DASH + spc.getInstanceName()
130: + SRAFileContext.DOT_PROPERTIES;
131: return super .updateConfigurationFile(ipc, propertiesHeader);
132: }
133:
134: //
135: //
136: //
137: }
|