KickJava   Java API By Example, From Geeks To Geeks.

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


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  * ConfigBeanInterceptor.java
26  *
27  * Created on January 2, 2004, 2:48 PM
28  */

29
30 package com.sun.enterprise.config.serverbeans;
31
32 import com.sun.enterprise.config.pluggable.ConfigBeanInterceptor;
33 import com.sun.enterprise.config.ConfigBean;
34
35 //The RelativePathResolver is used to translate relative paths containing
36
//embedded system properties (e.g. ${com.sun.aas.instanceRoot}/applications)
37
//into absolute paths
38
import com.sun.enterprise.util.RelativePathResolver;
39
40 import java.io.Serializable JavaDoc;
41
42 /**
43  *
44  * @author sridatta
45  */

46 public class ServerBeanInterceptor implements ConfigBeanInterceptor, Serializable JavaDoc, Cloneable JavaDoc {
47     
48     /** Creates a new instance of ConfigBeanInterceptor */
49     public ServerBeanInterceptor() {
50     }
51     
52  
53           /**
54        * Resolve tokens for an element value that is a string
55        * Broken into a separate method because called in numerous places
56        */

57       public Object JavaDoc resolveTokensForString(Object JavaDoc value) {
58          if (isResolvingPaths() && value != null && value instanceof String JavaDoc) {
59              return resolveStringTokens((String JavaDoc)value);
60          }
61          return value;
62       }
63          
64       /**
65        * General method to resolve tokens for string that are in attributes
66        * and Text elements
67        */

68       public String JavaDoc resolveStringTokens(String JavaDoc string) {
69           return RelativePathResolver.resolvePath(string);
70       }
71
72       public Object JavaDoc postGetValue(ConfigBean cb, String JavaDoc name, Object JavaDoc res) {
73            return resolveTokensForString(res);
74       }
75       
76          /**
77          * The isResolvingPaths boolean when set to false causes getAttributeValue to
78          * return the raw unresolved attribute value.
79          */

80         private boolean _isResolvingPaths = true;
81         
82         public void setResolvingPaths(boolean isResolvingPaths) {
83             _isResolvingPaths = isResolvingPaths;
84         }
85         
86         public boolean isResolvingPaths() {
87             return _isResolvingPaths;
88         }
89         
90         public String JavaDoc postGetAttributeValue(String JavaDoc name, String JavaDoc res) {
91            if (isResolvingPaths()) {
92                 return resolveStringTokens(res);
93             } else {
94                 return res;
95             }
96         }
97         
98         public Object JavaDoc[] postGetValues(String JavaDoc name, Object JavaDoc[] res) {
99             
100          // only needed in one place so don't call separate method
101
if (isResolvingPaths()&& res != null && res instanceof String JavaDoc[]) {
102              // loop through and resolve tokens
103
for(int ii=0; ii < res.length; ii++) {
104                  res[ii]=resolveStringTokens((String JavaDoc)res[ii]);
105              }
106          }
107          return res;
108         }
109         
110         public Object JavaDoc preClone() {
111           boolean orig = isResolvingPaths();
112             setResolvingPaths(false);
113             return new Boolean JavaDoc(orig);
114         }
115         
116         public void postClone(Object JavaDoc o) {
117             setResolvingPaths(((Boolean JavaDoc)o).booleanValue());
118         }
119         
120         public Object JavaDoc clone() {
121             ConfigBeanInterceptor cbiClone = new ServerBeanInterceptor();
122             cbiClone.setResolvingPaths(this.isResolvingPaths());
123             return cbiClone;
124         }
125
126         /**
127          * NOTE: This method returns wrong values sometimes
128          * when a clone is in process
129          */

130         public String JavaDoc toString() {
131             return "{resolvingPaths=" + isResolvingPaths() + "}";
132         }
133 }
134
Popular Tags