KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > config > serverbeans > validation > tests > ProfilerTest


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 package com.sun.enterprise.config.serverbeans.validation.tests;
25
26 import java.util.Locale JavaDoc;
27 import java.util.logging.Level JavaDoc;
28 import java.io.File JavaDoc;
29 import java.util.Vector JavaDoc;
30
31 import com.sun.enterprise.config.serverbeans.validation.GenericValidator;
32 import com.sun.enterprise.config.serverbeans.validation.ValidationDescriptor;
33 import com.sun.enterprise.config.serverbeans.validation.Result;
34 import com.sun.enterprise.config.serverbeans.ServerTags;
35 import com.sun.enterprise.config.serverbeans.Profiler;
36 import com.sun.enterprise.config.serverbeans.validation.AttrClassName;
37 import com.sun.enterprise.config.serverbeans.validation.tests.StaticTest;
38
39 import com.sun.enterprise.config.ConfigBean;
40 import com.sun.enterprise.config.ConfigContextEvent;
41 import com.sun.enterprise.config.ConfigException;
42
43 /**
44     Custom Test for Profiler Test which calls the Generic Validation before performing custom tests
45
46     @author Srinivas Krishnan
47     @version 2.0
48 */

49
50 public class ProfilerTest extends GenericValidator {
51     
52     public ProfilerTest(ValidationDescriptor desc) {
53         super(desc);
54     }
55     
56     public Result validate(ConfigContextEvent cce) {
57         Result result = super.validate(cce); // Before doing custom validation do basic validation
58

59         if(cce.getChoice().equals(StaticTest.VALIDATE)) {
60             Profiler profiler = (Profiler) cce.getObject();
61             validateAttribute(ServerTags.CLASSPATH, profiler.getClasspath(), result);
62             JvmOptionsTest.validateJvmOptions(profiler.getJvmOptions(), result);
63         }
64         
65         if(cce.getChoice().equals(StaticTest.UPDATE)) {
66             validateAttribute(cce.getName(), (String JavaDoc) cce.getObject(), result);
67         }
68         else if(cce.getChoice().equals(StaticTest.SET)) {
69            final String JavaDoc name = cce.getName();
70            /*
71             * JvmOptions is an element in domain xml. Hence for JvmOptions we
72             * need to use camelized name even thouth it is treated as an
73             * attribute.
74             */

75             if (name.equals("JvmOptions")) {
76                 JvmOptionsTest.validateJvmOptions((String JavaDoc[])cce.getObject(), result);
77             }
78         }
79         return result;
80     }
81     
82     public void validateAttribute(String JavaDoc name, String JavaDoc value, Result result) {
83         
84         if(value == null || value.equals(""))
85             return;
86         if(name.equals(ServerTags.CLASSPATH)) {
87             if(!StaticTest.isClassPathValid(value)) {
88                 result.failed(smh.getLocalString(getClass().getName() + ".invalidProfilerClasspath",
89                    "Attribute:(classpath={0}), Invalid path in classpath", new Object JavaDoc[]{value}));
90             }
91         }
92     }
93 }
94
Popular Tags