KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > common > validation > samples > simple > Application


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  * sample.java May 8, 2003, 11:23 AM
26  */

27
28 package com.sun.enterprise.tools.common.validation.samples.simple;
29
30 import java.io.FileOutputStream JavaDoc;
31 import java.io.InputStream JavaDoc;
32 import java.text.MessageFormat JavaDoc;
33 import java.util.Collection JavaDoc;
34
35 import com.sun.enterprise.tools.common.validation.samples.simple.beans.*;
36 import com.sun.enterprise.tools.common.validation.util.BundleReader;
37 import com.sun.enterprise.tools.common.validation.util.Display;
38 import com.sun.enterprise.tools.common.validation.util.Utils;
39 import com.sun.enterprise.tools.common.validation.ValidationManager;
40 import com.sun.enterprise.tools.common.validation.ValidationManagerFactory;
41
42
43
44 /**
45  *
46  * @author Rajeshwar Patil
47  * @version %I%, %G%
48  */

49 public class Application {
50     
51     /** Creates a new instance of sample */
52     public Application() {
53     }
54
55
56     /**
57      * @param args the command line arguments
58      */

59     public static void main(String JavaDoc[] args) {
60         RootElement rootElement = null;
61         
62         String JavaDoc fileBeingValidated = "com/sun/enterprise/tools/" + //NOI18N
63
"common/validation/samples/simple/simple.xml"; //NOI18N
64

65         String JavaDoc validationFile = "com/sun/enterprise/tools/" + //NOI18N
66
"common/validation/samples/simple/validation.xml"; //NOI18N
67
/// String validationFile = "C:/testframe/tests/com/sun/" + //NOI18N
68
/// "enterprise/tools/common/validation/samples/simple/" + //NOI18N
69
/// "validation.xml"; //NOI18N
70

71
72 // You should set impl.file to fully qualified file name of the
73
// impl(implementation) file
74
/// String implFile = "com.sun.enterprise.tools." + //NOI18N
75
/// "common.XYZImpl"; //NOI18N
76
/// System.setProperty("impl.file", implFile); //NOI18N
77

78
79 // You can set constraints.file to either absolute or relative path of the
80
// Constraints file
81
/// String cosntriantsFile = "com/sun/enterprise/tools/" + //NOI18N
82
/// "common/testXYZ.xml"; //NOI18N
83
/// String cosntriantsFile = "C:/testframe/src/java/com/sun/" + //NOI18N
84
/// "enterprise/tools/XYZ/testXYZ.xml"; //NOI18N
85
/// System.setProperty("constraints.file", cosntriantsFile); //NOI18N
86

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