KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > offline > JavaConfigConfigBeanHelper


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 package com.sun.enterprise.management.offline;
26
27 import java.util.Set JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Arrays JavaDoc;
30
31 import javax.management.AttributeNotFoundException JavaDoc;
32 import javax.management.InvalidAttributeValueException JavaDoc;
33
34 import com.sun.appserv.management.util.misc.StringUtil;
35 import com.sun.appserv.management.util.misc.GSetUtil;
36
37 import com.sun.enterprise.config.ConfigContext;
38 import com.sun.enterprise.config.ConfigBean;
39 import com.sun.enterprise.config.ConfigException;
40
41
42 final class JavaConfigConfigBeanHelper extends StdConfigBeanHelper
43 {
44     static private final String JavaDoc JVM_OPTIONS_ATTR = "JvmOptions";
45     
46         public
47     JavaConfigConfigBeanHelper(
48         final ConfigContext configContext,
49         final ConfigBean configBean )
50     {
51         super( configContext, configBean );
52         
53     }
54     
55     
56        private boolean
57     hasJVMOptions()
58     {
59         return hasValue( JVM_OPTIONS_ATTR );
60     }
61     
62         protected Set JavaDoc<String JavaDoc>
63     _getAttributeNames()
64     {
65         final Set JavaDoc<String JavaDoc> attrNames = super._getAttributeNames();
66         
67         if ( hasJVMOptions() )
68         {
69             attrNames.add( JVM_OPTIONS_ATTR );
70         }
71         
72         return attrNames;
73     }
74     
75       
76         protected Class JavaDoc
77     getAttributeClass( final String JavaDoc attrName )
78     {
79         Class JavaDoc result = null;
80         
81         if ( JVM_OPTIONS_ATTR.equals( attrName ) )
82         {
83             result = String JavaDoc[].class;
84         }
85         else
86         {
87             result = super.getAttributeClass( attrName );
88         }
89         return result;
90     }
91     
92         public Object JavaDoc
93     getAttribute( final String JavaDoc attrName )
94         throws AttributeNotFoundException JavaDoc
95     {
96         Object JavaDoc result = null;
97         
98         if ( JVM_OPTIONS_ATTR.equals( attrName ) )
99         {
100             result = getJVMOptions();
101         }
102         else
103         {
104             result = super.getAttribute( attrName );
105         }
106         return result;
107     }
108     
109         public void
110     setAttribute( final String JavaDoc name, final Object JavaDoc value )
111         throws AttributeNotFoundException JavaDoc, InvalidAttributeValueException JavaDoc
112     {
113         if ( JVM_OPTIONS_ATTR.equals( name ) )
114         {
115             setJVMOptions( (String JavaDoc[])value );
116         }
117         else
118         {
119             super.setAttribute( name, value );
120         }
121     }
122     
123     
124         private com.sun.enterprise.config.serverbeans.JavaConfig
125     getJavaConfigConfigBean()
126     {
127         return (com.sun.enterprise.config.serverbeans.JavaConfig)
128             getConfigBean();
129     }
130     
131         public String JavaDoc[]
132     getJVMOptions()
133     {
134         // presumably spaces are not allowed in a JVM option
135
final String JavaDoc[] result = getJavaConfigConfigBean().getJvmOptions();
136         
137         return result;
138     }
139     
140         public void
141     setJVMOptions( final String JavaDoc[] optionsIn )
142     {
143         // ensure no duplicates
144
final Set JavaDoc<String JavaDoc> optionsSet = GSetUtil.newUnmodifiableStringSet( optionsIn );
145         final String JavaDoc[] options = GSetUtil.toStringArray( optionsSet );
146         Arrays.sort( options );
147         
148         getJavaConfigConfigBean().setJvmOptions( options );
149     }
150     
151 }
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
Popular Tags