KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > appclient > AppClientMainClass


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.tools.verifier.tests.appclient;
25
26 import java.lang.reflect.Modifier JavaDoc;
27 import com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor;
28 import com.sun.enterprise.tools.verifier.Result;
29 import com.sun.enterprise.deployment.ApplicationClientDescriptor;
30
31 /**
32  * Application clients start execution at the main method of the class specified
33  * in the Main-Class attribute in the manifest file of the application client’s
34  * JAR file. It must be specified in the MANIFEST file.
35  * @author Sudipto Ghosh
36  */

37 public class AppClientMainClass extends AppClientTest implements AppClientCheck {
38
39     public Result check(ApplicationClientDescriptor descriptor) {
40         Result result = getInitializedResult();
41         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
42
43         String JavaDoc mainClass = descriptor.getMainClassName();
44         if (mainClass != null && mainClass.length() > 0) {
45             try {
46                 Class JavaDoc c = Class.forName(mainClass, false, getVerifierContext().getClassLoader());
47                 if(!Modifier.isPublic(c.getModifiers())) {
48                     addErrorDetails(result, compName);
49                     result.failed(smh.getLocalString(getClass().getName() + ".failed2",
50                             "ERROR: Appclient main-class [ {0} ] as specified in the Manifest file is not public.",
51                             new Object JavaDoc[] {mainClass}));
52                 }
53             } catch (ClassNotFoundException JavaDoc cnfe) {
54                 if(debug)
55                     cnfe.printStackTrace();
56                 addErrorDetails(result, compName);
57                 result.failed(smh.getLocalString(getClass().getName() + ".failed1",
58                         "ERROR: Appclient main-class [ {0} ] as specified in the" +
59                         " Manifest file is not loadable.",
60                         new Object JavaDoc[] {mainClass}));
61             }
62         } else {
63             addErrorDetails(result, compName);
64             result.failed(smh.getLocalString
65                     (getClass().getName() + ".failed",
66                             "Appclient main-class is not found. Please check the " +
67                     "main-class entry of your appclient manifest file."));
68         }
69         if(result.getStatus() != Result.FAILED) {
70             addGoodDetails(result, compName);
71             result.passed(smh.getLocalString(getClass().getName() + ".passed",
72                     "main-class entry is defined properly."));
73         }
74         return result;
75     }
76 }
77
Popular Tags