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