KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > syncclient > spdm > SimpleDeviceManager


1 /**
2  * Copyright (C) 2003-2005 Funambol
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; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.syncclient.spdm;
20
21 /**
22  * This is a simple implementation of <i>DeviceManager</i> that uses the file
23  * system to store and read nodes.
24  * The root of the configuration tree is specified with the system property
25  * <code>spdm.dir.config</code>; if null, the current directory is taken.
26  * <p>
27  * The tree structure is orgnaized in contexts, represented by directories, and
28  * leaf nodes, represented by properties files. Leaf nodes contain the
29  * configuration values.
30  *
31  * @author Fabio Maggi @ Funambol
32  *
33  * @version $Id: SimpleDeviceManager.java,v 1.2 2005/01/19 11:18:36 fabius Exp $
34  */

35
36 public class SimpleDeviceManager extends DeviceManager {
37
38     // --------------------------------------------------------------- Constants
39

40     /**
41      * The system property name for the base directory
42      */

43     public static final String JavaDoc PROP_DM_DIR_BASE = "spdm.dir.base";
44
45
46     //@todo trovare un altro modo per settare la appURI in relazione al JDBC
47
/**
48      * The system property name for the application base uri
49      */

50     //public static final String PROP_DM_APP_BASE = "sp.application.uri";
51

52     // ------------------------------------------------------------ private dara
53

54     private String JavaDoc baseDir = null;
55
56     // ------------------------------------------------------------ Constructors
57

58     /**
59      * Creates a new SimpleDeviceManager
60      */

61     public SimpleDeviceManager() {
62         baseDir = System.getProperty(PROP_DM_DIR_BASE, "./");
63
64         //
65
// Config dir must end with '/'
66
//
67
if (!baseDir.endsWith("/")) {
68             baseDir += '/';
69         }
70     }
71     //----------------------------------------------------------- Public methods
72

73     /**
74      * Factory for SimpleDeviceManager.
75      *
76      * @return the newly created instance
77      */

78     public static DeviceManager getDeviceManager(){
79         return (DeviceManager) new SimpleDeviceManager();
80     }
81
82     /**
83      * Return the management tree given its context
84      *
85      * @param context the node context
86      *
87      * @return the root management node starting at the specified context
88      *
89      */

90     public ManagementNode getManagementTree(String JavaDoc context){
91         return new NodeImpl(null, baseDir + context);
92     }
93
94     /**
95      * The same as <i>getManagementTree("")</i>
96      *
97      * @return <i>getManagementTree("")</i>
98      */

99     public ManagementNode getManagementTree(){
100         return getManagementTree("");
101     }
102
103     public Device getDevice() {
104         return new DeviceImpl(this);
105     }
106     
107 }
Popular Tags