comparison src/org/tmatesoft/hg/internal/PropertyMarshal.java @ 456:909306e412e2

Refactor LogFacility and SessionContext, better API for both
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 18 Jun 2012 16:54:00 +0200
parents
children
comparison
equal deleted inserted replaced
454:36fd1fd06492 456:909306e412e2
1 /*
2 * Copyright (c) 2012 TMate Software Ltd
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * For information on how to redistribute this software under
14 * the terms of a license other than GNU General Public License
15 * contact TMate Software at support@hg4j.com
16 */
17 package org.tmatesoft.hg.internal;
18
19 import org.tmatesoft.hg.core.SessionContext;
20
21 /**
22 *
23 * @author Artem Tikhomirov
24 * @author TMate Software Ltd.
25 */
26 public class PropertyMarshal {
27
28 private final SessionContext sessionContext;
29
30 public PropertyMarshal(SessionContext ctx) {
31 sessionContext = ctx;
32 }
33
34 public boolean getBoolean(String propertyName, boolean defaultValue) {
35 // can't use <T> and unchecked cast because got no confidence passed properties are strictly of the kind of my default values,
36 // i.e. if boolean from outside comes as "true", while I pass default as Boolean or vice versa.
37 Object p = sessionContext.getConfigurationProperty(propertyName, defaultValue);
38 return p instanceof Boolean ? ((Boolean) p).booleanValue() : Boolean.parseBoolean(String.valueOf(p));
39 }
40
41 public int getInt(String propertyName, int defaultValue) {
42 Object v = sessionContext.getConfigurationProperty(propertyName, defaultValue);
43 if (false == v instanceof Number) {
44 v = Integer.parseInt(String.valueOf(v));
45 }
46 return ((Number) v).intValue();
47 }
48 }