KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > medor > datasource > lib > BasicDataStore


1 /**
2  * MEDOR: Middleware Enabling Distributed Object Requests
3  *
4  * Copyright (C) 2001-2003 France Telecom R&D
5  * Contact: alexandre.lefebvre@rd.francetelecom.com
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  *
21  * Initial developers: M. Alia, A. Lefebvre
22  */

23
24 package org.objectweb.medor.datasource.lib;
25
26 import org.objectweb.medor.api.DataSourceException;
27 import org.objectweb.medor.datasource.api.DataStore;
28
29 public class BasicDataStore implements DataStore {
30
31     String JavaDoc sourceName;
32     String JavaDoc clientName;
33     short[] capabilities;
34     short type;
35
36     /**
37      * The capacities are restrected...
38      */

39     public BasicDataStore(short dataStoreType,
40                           String JavaDoc sourceName,
41                           short[] capabilities)
42             throws DataSourceException {
43         this.sourceName = sourceName;
44         this.capabilities = capabilities;
45         if (dataStoreType != DataStore.JDBC_STORE &&
46             dataStoreType != DataStore.MEDORTC_STORE)
47             throw new DataSourceException("DataStore type not supported");
48         this.type = dataStoreType;
49     }
50
51     /**
52      * Full capacities evaluation...
53      */

54     public BasicDataStore(short dataStoreType, String JavaDoc sourceName)
55             throws DataSourceException {
56         this.sourceName = sourceName;
57         if (dataStoreType != DataStore.JDBC_STORE &&
58             dataStoreType != DataStore.MEDORTC_STORE)
59             throw new DataSourceException("DataStore type not supported");
60         this.type = dataStoreType;
61     }
62
63     public String JavaDoc getName() {
64         return sourceName;
65     }
66
67     /**
68      * A simple example of an implementation of this method will tests equality
69      * between DataStore name only. Others implemntation will be done later.
70      */

71     public boolean isSameAs(DataStore ds) {
72         return ds.getName().equals(this.sourceName);
73     }
74
75     public boolean isCapable(short operation) {
76         if (capabilities == null)
77             return true;// Full capabilities
78
else {
79             int cpt;
80             for (cpt = 0; (cpt < capabilities.length &&
81                             capabilities[cpt] != operation); cpt++) ;
82             if (cpt == capabilities.length)
83                 return false;
84             else
85                 return true;
86         }
87     }
88
89     public short getDataStoreType() {
90         return type;
91     }
92
93     public String JavaDoc getClientName() {
94         return clientName;
95     }
96
97     public void setClientName(String JavaDoc cName) {
98         clientName = cName;
99     }
100 }
101
Popular Tags