KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > servermgmt > RepositoryConfig


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * RepositoryConfig.java
26  *
27  * Created on August 19, 2003, 1:59 PM
28  */

29
30 package com.sun.enterprise.admin.servermgmt;
31
32 import java.util.HashMap JavaDoc;
33
34 import java.io.File JavaDoc;
35
36 import com.sun.enterprise.util.SystemPropertyConstants;
37
38 import com.sun.enterprise.util.io.FileUtils;
39
40 /**
41  * This class represents a repository configuration. A repository can
42  * be either a domain, a node agent, or a server instance. Configuration
43  * specific to each (DomainConfig, AgentConfig, InstanceConfig) is
44  * derived from this class. A repository config consists of the following
45  * attributes:
46  *
47  * 1)repositoryName -- domain or node agent name (e.g. domain1 or agent1)
48  *
49  * 2)repositoryRoot -- the parent directory of the repository (e.g.
50  * $installDir/domains or $installDir/agents)
51  *
52  * 3)instanceName -- the optional server instance name (e.g. server1)
53  *
54  * 4)configurationName -- the optional configuration name of the server
55  * instance (e.g. default-config).
56  *
57  * Using (repositoryName, repositoryRoot, instanceName, configurationName)
58  * syntax. Here are the following permutations:
59  *
60  * 1)For a domain: (domainRootDirectory, domainName, null, null) e.g.
61  * ("/sun/appserver/domains", "domain1", null, null)
62  *
63  * 2)For a node agent: (agentRootDirectory, agentName, "agent", null) e.g
64  * ("/sun/appserver/agents", "agent1", "agent", null). Note that the instance
65  * name of a node agent is always the literal string "agent".
66  *
67  * 3)For a server instance (agentRootDirectory, agentName, instanceName,
68  * configName) e.g.
69  * ("/sun/appserver/agents", "agent1", "server1", "default-config")
70  *
71  * The RepositoryConfig class is an extensible HashMap that can contain
72  * any attributes, but also relies on two system properties being
73  * set:
74  *
75  * 1)com.sun.aas.installRoot -- installation root directory stored under
76  * the K_INSTALL_ROOT key.
77  *
78  * 2)com.sun.aas.configRoot -- configuration root (for locating asenv.conf)
79  * stored under the K_CONFIG_ROOT key.
80  *
81  * @author kebbs
82  */

83 public class RepositoryConfig extends HashMap JavaDoc {
84     
85     public static final String JavaDoc K_INSTALL_ROOT = "install.root";
86     public static final String JavaDoc K_CONFIG_ROOT = "config.root";
87     
88     //Name of the domain or node agent. Cannot be null.
89
private String JavaDoc _repositoryName;
90     
91     //Root directory where the domain or node agent resides. Cannot be null
92
private String JavaDoc _repositoryRoot;
93     
94     //Name of the server instance. May be null
95
private String JavaDoc _instanceName;
96     
97     //Name of the configuration. May be null
98
private String JavaDoc _configurationName;
99     
100     /**
101      * Creates a new instance of RepositoryConfig
102      * The K_INSTALL_ROOT and K_CONFIG_ROOT attributes are implicitly set
103      */

104     public RepositoryConfig(String JavaDoc repositoryName, String JavaDoc repositoryRoot, String JavaDoc instanceName,
105         String JavaDoc configName) {
106         _instanceName = instanceName;
107         _repositoryName = repositoryName;
108         _repositoryRoot = repositoryRoot;
109         _configurationName = configName;
110         put(K_INSTALL_ROOT, getFilePath(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
111         put(K_CONFIG_ROOT, getFilePath(SystemPropertyConstants.CONFIG_ROOT_PROPERTY));
112     }
113
114     public RepositoryConfig(String JavaDoc repositoryName, String JavaDoc repositoryRoot, String JavaDoc instanceName) {
115         this(repositoryName, repositoryRoot, instanceName, null);
116     }
117     
118     public RepositoryConfig(String JavaDoc repositoryName, String JavaDoc repositoryRoot) {
119         this(repositoryName, repositoryRoot, null);
120     }
121     
122     /**
123      * Creates a new instance of RepositoryConfig defined using the
124      * system property com.sun.aas.instanceRoot. It is assumed that this
125      * system property is a directory of the form:
126      * <repositoryRootDirectory>/<repositoryName>/<instanceName>
127      */

128     public RepositoryConfig() {
129         final File JavaDoc instanceRoot = new File JavaDoc(System.getProperty(SystemPropertyConstants.INSTANCE_ROOT_PROPERTY));
130         final File JavaDoc repositoryDir = instanceRoot.getParentFile();
131         _instanceName = instanceRoot.getName();
132         _repositoryName = repositoryDir.getName();
133         _repositoryRoot = FileUtils.makeForwardSlashes(repositoryDir.getParentFile().getAbsolutePath());
134         _configurationName = null;
135         put(K_INSTALL_ROOT, getFilePath(SystemPropertyConstants.INSTALL_ROOT_PROPERTY));
136         put(K_CONFIG_ROOT, getFilePath(SystemPropertyConstants.CONFIG_ROOT_PROPERTY));
137     }
138
139     public String JavaDoc toString()
140     {
141         return ("repositoryRoot " + _repositoryRoot + " repositoryName " + _repositoryName +
142             " instanceName " + _instanceName + " configurationName " + _configurationName);
143     }
144     
145     protected String JavaDoc getFilePath(String JavaDoc propertyName)
146     {
147         File JavaDoc f = new File JavaDoc(System.getProperty(propertyName));
148         return FileUtils.makeForwardSlashes(f.getAbsolutePath());
149     }
150
151     public void setConfigurationName(String JavaDoc configurationName) {
152         _configurationName = configurationName;
153     }
154     
155     public String JavaDoc getConfigurationName() {
156         return _configurationName;
157     }
158    
159     public String JavaDoc getDisplayName() {
160         return getRepositoryName();
161     }
162     
163     public void setInstanceName(String JavaDoc instanceName) {
164         _instanceName = instanceName;
165     }
166     
167     public String JavaDoc getInstanceName() {
168         return _instanceName;
169     }
170     
171     public String JavaDoc getRepositoryName() {
172         return _repositoryName;
173     }
174     
175     protected void setRepositoryRoot(String JavaDoc repositoryRoot) {
176         _repositoryRoot = repositoryRoot;
177     }
178     
179     public String JavaDoc getRepositoryRoot()
180     {
181         return _repositoryRoot;
182     }
183     
184     public String JavaDoc getInstallRoot()
185     {
186         return (String JavaDoc)get(K_INSTALL_ROOT);
187     }
188     
189     public String JavaDoc getConfigRoot()
190     {
191         return (String JavaDoc)get(K_CONFIG_ROOT);
192     }
193 }
194
Popular Tags