KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > PropertyResolver


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  * Class.java
26  *
27  * Created on November 11, 2003, 1:45 PM
28  */

29
30 package com.sun.enterprise.config.serverbeans;
31
32 import com.sun.enterprise.util.RelativePathResolver;
33
34 import com.sun.enterprise.config.serverbeans.Domain;
35 import com.sun.enterprise.config.serverbeans.Server;
36 import com.sun.enterprise.config.serverbeans.Cluster;
37 import com.sun.enterprise.config.serverbeans.Config;
38
39 import com.sun.enterprise.config.ConfigException;
40 import com.sun.enterprise.config.ConfigContext;
41
42 /**
43  *
44  * @author kebbs
45  */

46 public class PropertyResolver extends RelativePathResolver {
47     
48     private Domain _domain = null;
49     private Cluster _cluster = null;
50     private Server _server = null;
51     private Config _config = null;
52     
53     /** Creates a new instance of Class */
54     public PropertyResolver(ConfigContext configContext, String JavaDoc instanceName)
55         throws ConfigException
56     {
57         _domain = ServerHelper.getDomainConfigBean(configContext);
58         _config = ServerHelper.getConfigForServer(configContext, instanceName);
59         _server = ServerHelper.getServerByName(configContext, instanceName);
60         if (ServerHelper.isServerClustered(configContext, _server)) {
61             _cluster = ClusterHelper.getClusterForInstance(configContext, instanceName);
62         }
63     }
64     
65     /**
66      * Given a propery name, return its corresponding value in the specified
67      * SystemProperty array. Return null if the property is not found.
68      */

69     private String JavaDoc getPropertyValue(String JavaDoc propName, SystemProperty[] props)
70     {
71         String JavaDoc propVal = null;
72         for (int i = 0; i < props.length; i++) {
73             if (props[i].getName().equals(propName)) {
74                 return props[i].getValue();
75             }
76         }
77         return propVal;
78     }
79     
80     /**
81      * Given a propery name, return its corresponding value as defined in
82      * the domain, configuration, cluster, or server element. Return null if the property
83      * is not found. Property values at the server override those at the configuration
84      * which override those at the domain level.
85      */

86     public String JavaDoc getPropertyValue(String JavaDoc propName, boolean bIncludingEnvironmentVariables)
87     {
88         String JavaDoc propVal = null;
89         //First look for a server instance property matching the propName
90
if (_server != null) {
91             propVal = getPropertyValue(propName, _server.getSystemProperty());
92         }
93         if (propVal == null) {
94             if (_cluster != null) {
95                 //If not found in the server instance, look for the propName in the
96
//cluster
97
propVal = getPropertyValue(propName, _cluster.getSystemProperty());
98             }
99             if (propVal == null) {
100                 if (_config != null) {
101                     //If not found in the server instance or cluster, look for the
102
//propName in the config
103
propVal = getPropertyValue(propName, _config.getSystemProperty());
104                     if (propVal == null) {
105                         if (_domain != null) {
106                             //Finally if the property is not found in the server, cluster,
107
//or configuration, look for the propName in the domain
108
propVal = getPropertyValue(propName, _domain.getSystemProperty());
109                         }
110                     }
111                 }
112             }
113         }
114         if (propVal == null) {
115             propVal = super.getPropertyValue(propName, bIncludingEnvironmentVariables);
116         }
117         return propVal;
118     }
119     
120     public String JavaDoc getPropertyValue(String JavaDoc propName)
121     {
122         return getPropertyValue(propName, true);
123     }
124 }
125
Popular Tags