KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > ConfigFileValidator


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema;
5
6 import com.tc.config.schema.setup.ConfigurationSetupException;
7 import com.tc.config.schema.setup.FatalIllegalConfigurationChangeHandler;
8 import com.tc.config.schema.setup.L2TVSConfigurationSetupManager;
9 import com.tc.config.schema.setup.StandardTVSConfigurationSetupManagerFactory;
10
11 /**
12  * Validates a configuration file, and throws an exception if it fails.
13  */

14 public class ConfigFileValidator {
15
16   private String JavaDoc description;
17
18   public void validate(String JavaDoc[] args) throws ConfigurationSetupException {
19     StandardTVSConfigurationSetupManagerFactory factory;
20
21     factory = new StandardTVSConfigurationSetupManagerFactory(args, true, new FatalIllegalConfigurationChangeHandler());
22     L2TVSConfigurationSetupManager manager = factory.createL2TVSConfigurationSetupManager(null);
23     description = manager.describeSources();
24   }
25
26   public String JavaDoc toString() {
27     return this.description;
28   }
29
30   public static void main(String JavaDoc[] args) {
31     ConfigFileValidator validator = new ConfigFileValidator();
32
33     try {
34       validator.validate(args);
35       System.err.println(validator.toString() + ": VALID.");
36       System.exit(0);
37     } catch (ConfigurationSetupException cse) {
38       Throwable JavaDoc exception = cse;
39
40       System.err.println(validator.toString() + ": INVALID.");
41
42       while (exception != null) {
43         System.err.println(exception.getLocalizedMessage());
44         exception = exception.getCause();
45       }
46
47       System.exit(1);
48     }
49   }
50
51 }
52
Popular Tags