1 /*
2 * Copyright 2013 smartics, Kronseder & Reiner GmbH
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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 de.smartics.properties.config.transfer.filesystem;
17
18 import java.io.File;
19 import java.io.IOException;
20
21 import de.smartics.properties.api.config.transfer.PropertySinkFactory;
22 import de.smartics.util.io.FileFunction;
23
24 /**
25 * Creates instances of {@link FileSystemPropertySink}.
26 */
27 public final class Factory implements
28 PropertySinkFactory<FileSystemPropertySink>
29 {
30 // ********************************* Fields *********************************
31
32 // --- constants ------------------------------------------------------------
33
34 // --- members --------------------------------------------------------------
35
36 /**
37 * The name of the folder the properties definitions are written to.
38 */
39 private File targetFolder;
40
41 /**
42 * The format the property definition files will be written to.
43 */
44 private PropertiesFormat outputFormat = PropertiesFormat.NATIVE;
45
46 // ****************************** Initializer *******************************
47
48 // ****************************** Constructors ******************************
49
50 /**
51 * Default constructor.
52 */
53 public Factory()
54 {
55 }
56
57 // ****************************** Inner Classes *****************************
58
59 // ********************************* Methods ********************************
60
61 // --- init -----------------------------------------------------------------
62
63 // --- get&set --------------------------------------------------------------
64
65 /**
66 * Sets the name of the folder the properties definitions are written to.
67 *
68 * @param targetFolder the name of the folder the properties definitions are
69 * written to.
70 */
71 public void setTargetFolder(final String targetFolder)
72 {
73 this.targetFolder = new File(targetFolder);
74 try
75 {
76 FileFunction.provideDirectory(this.targetFolder);
77 }
78 catch (final IOException e)
79 {
80 final String message =
81 String.format("Cannot create target folder '%s'.",
82 this.targetFolder.getAbsolutePath());
83 throw new IllegalArgumentException(message, e);
84 }
85 }
86
87 /**
88 * Sets the format the property definition files will be written to.
89 *
90 * @param outputFormat the format the property definition files will be
91 * written to.
92 */
93 public void setOutputFormat(final String outputFormat)
94 {
95 this.outputFormat = PropertiesFormat.fromString(outputFormat);
96 }
97
98 // --- business -------------------------------------------------------------
99
100 @Override
101 public FileSystemPropertySink create()
102 {
103 return new FileSystemPropertySink(targetFolder, outputFormat);
104 }
105
106 // --- object basics --------------------------------------------------------
107
108 }