001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.j2ee.sun.validation.samples.simple;
043:
044: import java.io.FileOutputStream;
045: import java.io.InputStream;
046: import java.text.MessageFormat;
047: import java.util.Collection;
048:
049: import org.netbeans.modules.j2ee.sun.validation.samples.simple.beans.*;
050: import org.netbeans.modules.j2ee.sun.validation.util.BundleReader;
051: import org.netbeans.modules.j2ee.sun.validation.util.Display;
052: import org.netbeans.modules.j2ee.sun.validation.util.Utils;
053: import org.netbeans.modules.j2ee.sun.validation.ValidationManager;
054: import org.netbeans.modules.j2ee.sun.validation.ValidationManagerFactory;
055:
056: /**
057: *
058: * @author Rajeshwar Patil
059: * @version %I%, %G%
060: */
061: public class Application {
062:
063: /** Creates a new instance of sample */
064: public Application() {
065: }
066:
067: /**
068: * @param args the command line arguments
069: */
070: public static void main(String[] args) {
071: RootElement rootElement = null;
072: String fileBeingValidated = "org/netbeans/modules/" + //NOI18N
073: "j2ee/sun/validation/samples/simple/simple.xml"; //NOI18N
074:
075: String validationFile = "org/netbeans/modules/" + //NOI18N
076: "j2ee/sun/validation/samples/simple/validation.xml"; //NOI18N
077:
078: /// String validationFile = "C:/testframe/tests/org/netbeans/" + //NOI18N
079: /// "modules/j2ee/sun/validation/samples/simple/validation.xml"; //NOI18N
080:
081: // You should set impl.file to fully qualified file name of the
082: // impl(implementation) file
083: /// String implFile = "com.sun.enterprise.tools." + //NOI18N
084: /// "common.XYZImpl"; //NOI18N
085: /// System.setProperty("impl.file", implFile); //NOI18N
086:
087: // You can set constraints.file to either absolute or relative path of the
088: // Constraints file
089: /// String cosntriantsFile = "com/sun/enterprise/tools/" + //NOI18N
090: /// "common/testXYZ.xml"; //NOI18N
091: /// String cosntriantsFile = "C:/testframe/src/java/com/sun/" + //NOI18N
092: /// "enterprise/tools/XYZ/testXYZ.xml"; //NOI18N
093: /// System.setProperty("constraints.file", cosntriantsFile); //NOI18N
094:
095: //Create an InpurtStream object
096: Utils utils = new Utils();
097: InputStream inputStream = utils
098: .getInputStream(fileBeingValidated);
099:
100: //Create graph
101: if (inputStream != null) {
102: try {
103: rootElement = RootElement.createGraph(inputStream);
104: } catch (Exception e) {
105: System.out.println(e.getMessage());
106: }
107: } else {
108: String format = BundleReader
109: .getValue("MSG_Unable_to_use_file"); //NOI18N
110: Object[] arguments = new Object[] { fileBeingValidated };
111: System.out.println(MessageFormat.format(format, arguments));
112: }
113:
114: if (rootElement != null) {
115: ValidationManagerFactory validationManagerFactory = new ValidationManagerFactory();
116:
117: //you can pass either absolute or relative path of the validation
118: //file to getValidationManager()
119: ValidationManager validationManager = validationManagerFactory
120: .getValidationManager(validationFile);
121:
122: Collection failures = validationManager
123: .validate(rootElement);
124:
125: Display display = new Display();
126: display.text(failures);
127: display.gui(failures);
128: }
129: }
130: }
|