1 /***
2 * Copyright (C) 2008 Jeremy Thomerson (jthomerson@users.sourceforge.net)
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
17 package net.sf.vcaperture.util;
18
19 import java.io.File;
20 import java.io.FileNotFoundException;
21
22 import org.ho.yaml.Yaml;
23
24 public class BeanUtil {
25
26 public static <T> T loadType(File file, Class<T> type) {
27 try {
28 return Yaml.loadType(file, type);
29 } catch (FileNotFoundException ex) {
30 throw new RuntimeException("YAML file not found: " + ex.getMessage(), ex);
31 }
32 }
33
34 public static void save(File file, Object obj) {
35 try {
36 Yaml.dump(obj, file);
37 } catch (FileNotFoundException ex) {
38 throw new RuntimeException("YAML file not found: " + ex.getMessage(), ex);
39 }
40 }
41
42
43 }