KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > validation > samples > simple > Application


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.validation.samples.simple;
21
22 import java.io.FileOutputStream JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.text.MessageFormat JavaDoc;
25 import java.util.Collection JavaDoc;
26
27 import org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.*;
28 import org.netbeans.modules.j2ee.sun.validation.util.BundleReader;
29 import org.netbeans.modules.j2ee.sun.validation.util.Display;
30 import org.netbeans.modules.j2ee.sun.validation.util.Utils;
31 import org.netbeans.modules.j2ee.sun.validation.ValidationManager;
32 import org.netbeans.modules.j2ee.sun.validation.ValidationManagerFactory;
33
34
35
36 /**
37  *
38  * @author Rajeshwar Patil
39  * @version %I%, %G%
40  */

41 public class Application {
42     
43     /** Creates a new instance of sample */
44     public Application() {
45     }
46
47
48     /**
49      * @param args the command line arguments
50      */

51     public static void main(String JavaDoc[] args) {
52         RootElement rootElement = null;
53         String JavaDoc fileBeingValidated = "org/netbeans/modules/" + //NOI18N
54
"j2ee/sun/validation/samples/simple/simple.xml"; //NOI18N
55

56         String JavaDoc validationFile = "org/netbeans/modules/" + //NOI18N
57
"j2ee/sun/validation/samples/simple/validation.xml"; //NOI18N
58

59 /// String validationFile = "C:/testframe/tests/org/netbeans/" + //NOI18N
60
/// "modules/j2ee/sun/validation/samples/simple/validation.xml"; //NOI18N
61

62
63 // You should set impl.file to fully qualified file name of the
64
// impl(implementation) file
65
/// String implFile = "com.sun.enterprise.tools." + //NOI18N
66
/// "common.XYZImpl"; //NOI18N
67
/// System.setProperty("impl.file", implFile); //NOI18N
68

69
70 // You can set constraints.file to either absolute or relative path of the
71
// Constraints file
72
/// String cosntriantsFile = "com/sun/enterprise/tools/" + //NOI18N
73
/// "common/testXYZ.xml"; //NOI18N
74
/// String cosntriantsFile = "C:/testframe/src/java/com/sun/" + //NOI18N
75
/// "enterprise/tools/XYZ/testXYZ.xml"; //NOI18N
76
/// System.setProperty("constraints.file", cosntriantsFile); //NOI18N
77

78
79         //Create an InpurtStream object
80
Utils utils = new Utils();
81         InputStream JavaDoc inputStream = utils.getInputStream(fileBeingValidated);
82
83         //Create graph
84
if(inputStream != null) {
85             try {
86                 rootElement = RootElement.createGraph(inputStream);
87             } catch(Exception JavaDoc e) {
88                System.out.println(e.getMessage());
89             }
90         } else {
91             String JavaDoc format =
92                 BundleReader.getValue("MSG_Unable_to_use_file"); //NOI18N
93
Object JavaDoc[] arguments = new Object JavaDoc[]{fileBeingValidated};
94             System.out.println(MessageFormat.format(format, arguments));
95         }
96
97         if(rootElement != null){
98             ValidationManagerFactory validationManagerFactory =
99                 new ValidationManagerFactory();
100
101             //you can pass either absolute or relative path of the validation
102
//file to getValidationManager()
103
ValidationManager validationManager =
104                 validationManagerFactory.getValidationManager(validationFile);
105
106             Collection JavaDoc failures =
107                 validationManager.validate(rootElement);
108
109             Display display = new Display();
110             display.text(failures);
111             display.gui(failures);
112         }
113     }
114 }
115
Popular Tags