KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > persistence > ClassNotFound


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.tools.verifier.tests.persistence;
26
27 import com.sun.enterprise.tools.verifier.tests.VerifierTest;
28 import com.sun.enterprise.tools.verifier.tests.VerifierCheck;
29 import com.sun.enterprise.tools.verifier.Result;
30 import com.sun.enterprise.deployment.Descriptor;
31 import com.sun.enterprise.deployment.PersistenceUnitDescriptor;
32
33 /**
34  * The names of classes specified in persistence.xml must be loadable.
35  * TopLink simply ignores if class could not be loaded. So we need this test.
36  *
37  * @author Sanjeeb.Sahoo@Sun.COM
38  */

39 public class ClassNotFound extends VerifierTest implements VerifierCheck {
40     public Result check(Descriptor descriptor) {
41         Result result = getInitializedResult();
42         addErrorDetails(result, getVerifierContext().getComponentNameConstructor());
43         result.setStatus(Result.PASSED);
44         final PersistenceUnitDescriptor pu = PersistenceUnitDescriptor.class.cast(descriptor);
45         for(String JavaDoc className : pu.getClasses()) {
46             try {
47                 Class.forName(className, false, getVerifierContext().getClassLoader());
48             } catch (ClassNotFoundException JavaDoc e) {
49                 result.failed(smh.getLocalString(getClass().getName() + "failed1",
50                         "Class [ {0} ] could not be loaded", new Object JavaDoc[]{className}));
51             } catch (NoClassDefFoundError JavaDoc e) {
52                 result.failed(smh.getLocalString(getClass().getName() + "failed2",
53                         "Class [ {0} ] could not be loaded " +
54                         "because a dependent class could not be loaded. See reason:\n [ {1} ]",
55                         new Object JavaDoc[]{className,e.getMessage()}));
56             }
57         }
58         return result;
59     }
60 }
61
Popular Tags