source: CMDIValidator/trunk/cmdi-validator-core/src/main/java/eu/clarin/cmdi/validator/CMDIValidatorConfig.java @ 5395

Last change on this file since 5395 was 5395, checked in by Oliver Schonefeld, 10 years ago
  • Property svn:eol-style set to native
File size: 4.9 KB
Line 
1/**
2 * This software is copyright (c) 2014 by
3 *  - Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
4 * This is free software. You can redistribute it
5 * and/or modify it under the terms described in
6 * the GNU General Public License v3 of which you
7 * should have received a copy. Otherwise you can download
8 * it from
9 *
10 *   http://www.gnu.org/licenses/gpl-3.0.txt
11 *
12 * @copyright Institut fuer Deutsche Sprache (http://www.ids-mannheim.de)
13 *
14 * @license http://www.gnu.org/licenses/gpl-3.0.txt
15 *  GNU General Public License v3
16 */
17package eu.clarin.cmdi.validator;
18
19import java.io.File;
20import java.io.FileFilter;
21import java.util.ArrayList;
22import java.util.Collections;
23import java.util.List;
24
25
26public class CMDIValidatorConfig {
27    private final File root;
28    private final CMDIValidatorHandler handler;
29    private FileFilter fileFilter = null;
30    private File schemaCacheDirectory = null;
31    private CMDISchemaLoader schemaLoader = null;
32    private File schematronSchemaFile = null;
33    private boolean schematronDisabled = false;
34    private List<CMDIValidatorExtension> extensions = null;
35
36
37    private CMDIValidatorConfig(final File root,
38            final CMDIValidatorHandler handler) {
39        if (root == null) {
40            throw new NullPointerException("root = null");
41        }
42        if (handler == null) {
43            throw new NullPointerException("handler == null");
44        }
45        this.root    = root;
46        this.handler = handler;
47    }
48
49
50    public File getRoot() {
51        return root;
52    }
53
54
55    public FileFilter getFileFilter() {
56        return fileFilter;
57    }
58
59
60    public CMDIValidatorHandler getHandler() {
61        return handler;
62    }
63
64
65    public File getSchemaCacheDirectory() {
66        return schemaCacheDirectory;
67    }
68
69
70    public CMDISchemaLoader getSchemaLoader() {
71        return schemaLoader;
72    }
73
74
75    public File getSchematronSchemaFile() {
76        return schematronSchemaFile;
77    }
78
79
80    public boolean isSchematronDisabled() {
81        return schematronDisabled;
82    }
83
84
85    public List<CMDIValidatorExtension> getExtensions() {
86        if (extensions != null) {
87            return Collections.unmodifiableList(extensions);
88        } else {
89            return null;
90        }
91    }
92
93
94    public static class Builder {
95        private final CMDIValidatorConfig config;
96
97
98        public Builder(final File root, final CMDIValidatorHandler handler) {
99            if (root == null) {
100                throw new NullPointerException("root == null");
101            }
102            if (handler == null) {
103                throw new NullPointerException("handler == null");
104            }
105            this.config = new CMDIValidatorConfig(root, handler);
106        }
107
108
109        public Builder fileFilter(final FileFilter fileFilter) {
110            config.fileFilter = fileFilter;
111            return this;
112        }
113
114
115        public Builder schemaCacheDirectory(final File schemaCacheDirectory) {
116            if (schemaCacheDirectory == null) {
117                throw new NullPointerException("schemaCacheDirectory == null");
118            }
119            if (!schemaCacheDirectory.isDirectory()) {
120                throw new IllegalArgumentException("'" + schemaCacheDirectory +
121                        "'is not a directory");
122            }
123            config.schemaCacheDirectory = schemaCacheDirectory;
124            return this;
125        }
126
127
128        public Builder schemaLoader(final CMDISchemaLoader schemaLoader) {
129            if (schemaLoader == null) {
130                throw new NullPointerException("schemaLoader == null");
131            }
132            config.schemaLoader = schemaLoader;
133            return this;
134        }
135
136
137        public Builder schematronSchemaFile(final File schematronSchemaFile) {
138            if (schematronSchemaFile == null) {
139                throw new NullPointerException("schematronSchemaFile == null");
140            }
141            if (!schematronSchemaFile.isFile()) {
142                throw new IllegalArgumentException("'" + schematronSchemaFile +
143                        "'is not a regular file");
144            }
145            config.schematronSchemaFile = schematronSchemaFile;
146            return this;
147        }
148
149
150        public Builder schematronDisabled(boolean schematronDisabled) {
151            config.schematronDisabled = schematronDisabled;
152            return this;
153        }
154
155
156        public Builder disableSchematron() {
157            config.schematronDisabled = true;
158            return this;
159        }
160
161
162        public Builder extension(final CMDIValidatorExtension extension) {
163            if (extension == null) {
164                throw new NullPointerException("extension == null");
165            }
166            if (config.extensions == null) {
167                config.extensions = new ArrayList<CMDIValidatorExtension>();
168            }
169            config.extensions.add(extension);
170            return this;
171        }
172
173
174        public CMDIValidatorConfig build() {
175            return config;
176        }
177
178    } // class Builder
179
180} // CMDIValidatorFactoryConfig
Note: See TracBrowser for help on using the repository browser.