01: /*
02: * Copyright 2006-2007 Luca Garulli (luca.garulli@assetdata.it)
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.romaframework.core.schema.config;
17:
18: import java.io.File;
19: import java.io.IOException;
20: import java.io.InputStream;
21:
22: import org.apache.xmlbeans.XmlException;
23: import org.apache.xmlbeans.XmlOptions;
24: import org.romaframework.xml.config.XmlConfigClassDocument;
25:
26: /**
27: * File System implementation of Schema class configuration. It loads the schema from File object located anywhere in the file
28: * system.
29: *
30: * @author Luca Garulli (luca.garulli@assetdata.it)
31: */
32: public class FileSystemSchemaConfiguration extends SchemaConfiguration {
33:
34: protected File fileContrainer;
35: protected String inputFile;
36:
37: public FileSystemSchemaConfiguration(File iFileContainer,
38: String iInputFile) throws XmlException, IOException {
39: fileContrainer = iFileContainer;
40: inputFile = iInputFile;
41: load();
42: }
43:
44: @Override
45: public void load() throws XmlException, IOException {
46: InputStream input = getClass().getResourceAsStream(inputFile);
47: try {
48: XmlConfigClassDocument doc = XmlConfigClassDocument.Factory
49: .parse(input);
50: setType(doc.getClass1());
51: } finally {
52: input.close();
53: }
54: }
55:
56: public void save(XmlConfigClassDocument toSave) throws IOException {
57: XmlOptions options = new XmlOptions();
58: options.setCharacterEncoding("UTF-8");
59: options.setUseDefaultNamespace();
60: options.setSavePrettyPrint();
61:
62: toSave.save(new File(getClass().getResource(inputFile)
63: .getFile()), options);
64: setType(toSave.getClass1());
65: }
66:
67: public File getFile() {
68: return fileContrainer;
69: }
70: }
|