Source Code Cross Referenced for LandmarkStore.java in  » 6.0-JDK-Modules » j2me » javax » microedition » location » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » javax.microedition.location 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:        package javax.microedition.location;
027:
028:        import java.io.*;
029:        import java.util.*;
030:
031:        import com.sun.j2me.location.*;
032:        import com.sun.midp.security.Permissions;
033:        import com.sun.midp.main.*;
034:        import com.sun.midp.log.*;
035:
036:        /**
037:         * This class is defined by the JSR-179 specification
038:         * <em>Location API for J2ME for J2ME&trade;.</em>
039:         */
040:        // JAVADOC COMMENT ELIDED
041:        public class LandmarkStore {
042:
043:            /** LandmarkStore Create property */
044:            private static final String CREATE_LANDMARKSTORE_SUPPORTED = "com.sun.j2me.location.CreateLandmarkStoreSupported";
045:
046:            /** LandmarkStore Delete property */
047:            private static final String DELETE_LANDMARKSTORE_SUPPORTED = "com.sun.j2me.location.DeleteLandmarkStoreSupported";
048:
049:            /** Category Delete property */
050:            private static final String DELETE_CATEGORY_SUPPORTED = "com.sun.j2me.location.DeleteCategorySupported";
051:
052:            /** The default instance of a store */
053:            private static final LandmarkStore defaultStore = new LandmarkStore();
054:
055:            /** A map of names of stores to actual stores */
056:            private static Hashtable stores = new Hashtable();
057:
058:            /** Indicates whether landmark stores were loaded */
059:            private static boolean storesInitialized;
060:
061:            /** The name of the record store */
062:            private String storeName;
063:
064:            /**
065:             * Constructor is private to prevent user from instanciating this class.
066:             *
067:             * @param storeName name of landmark store
068:             */
069:            private LandmarkStore(String storeName) {
070:                this .storeName = storeName;
071:            }
072:
073:            /**
074:             * Prevent the user from instanciating this class
075:             * creates default LandmarkStore if it is not exist
076:             */
077:            private LandmarkStore() {
078:                this .storeName = null;
079:            }
080:
081:            // JAVADOC COMMENT ELIDED    
082:            public static synchronized LandmarkStore getInstance(
083:                    String storeName) {
084:                Util.checkForPermission(Permissions.LANDMARK_READ);
085:
086:                LandmarkStore current = null;
087:                try {
088:                    if (storeName == null) {
089:                        return defaultStore;
090:                    } else {
091:                        String[] storeNames = LocationPersistentStorage
092:                                .getInstance().listStoreNames();
093:                        if (storeNames != null) {
094:                            for (int i = 0; i < storeNames.length; i++) {
095:                                if (storeNames[i].equals(storeName)) {
096:                                    current = new LandmarkStore(storeName);
097:                                    break;
098:                                }
099:                            }
100:                        }
101:                    }
102:                } catch (IOException e) { // return null
103:                }
104:                return current;
105:            }
106:
107:            // JAVADOC COMMENT ELIDED
108:            public static void createLandmarkStore(String storeName)
109:                    throws IOException, LandmarkException {
110:                if (Configuration.getProperty(CREATE_LANDMARKSTORE_SUPPORTED)
111:                        .equals("true")) {
112:                    Util.checkForPermission(Permissions.LANDMARK_MANAGE);
113:                    if (storeName == null) {
114:                        throw new NullPointerException(
115:                                "storeName can not be null");
116:                    }
117:                    // verify that the name is correct and store does not exist
118:                    int storeLen = storeName.length();
119:                    if (storeLen == 0) {
120:                        throw new IllegalArgumentException(
121:                                "The store: name has " + "incorrect length");
122:                    }
123:                    if (getInstance(storeName) != null) {
124:                        throw new IllegalArgumentException("The store: "
125:                                + storeName + " already exists");
126:                    }
127:                    LocationPersistentStorage.getInstance().addStoreName(
128:                            storeName);
129:                } else {
130:                    throw new LandmarkException(
131:                            "Implementation does not support "
132:                                    + "creating new landmark stores");
133:                }
134:            }
135:
136:            // JAVADOC COMMENT ELIDED
137:            public static void deleteLandmarkStore(String storeName)
138:                    throws IOException, LandmarkException {
139:                if (Configuration.getProperty(DELETE_LANDMARKSTORE_SUPPORTED)
140:                        .equals("true")) {
141:                    Util.checkForPermission(Permissions.LANDMARK_MANAGE);
142:                    if (storeName == null) {
143:                        throw new NullPointerException();
144:                    }
145:                    LocationPersistentStorage.getInstance().removeStoreName(
146:                            storeName);
147:                } else {
148:                    throw new LandmarkException(
149:                            "Implementation does not support "
150:                                    + "deleting landmark stores");
151:                }
152:            }
153:
154:            // JAVADOC COMMENT ELIDED
155:            public static String[] listLandmarkStores() throws IOException {
156:                Util.checkForPermission(Permissions.LANDMARK_READ);
157:                return LocationPersistentStorage.getInstance().listStoreNames();
158:            }
159:
160:            // JAVADOC COMMENT ELIDED
161:            public void addLandmark(Landmark landmark, String category)
162:                    throws IOException {
163:                Util.checkForPermission(Permissions.LANDMARK_WRITE);
164:                if (landmark == null) { // NullPointerException should be caused
165:                    throw new NullPointerException("Landmark is null");
166:                }
167:                LocationPersistentStorage.getInstance().addLandmark(storeName,
168:                        landmark.getInstance(), category);
169:            }
170:
171:            // JAVADOC COMMENT ELIDED
172:            public Enumeration getLandmarks(String category, String name)
173:                    throws IOException {
174:                Enumeration en = LocationPersistentStorage.getInstance()
175:                        .getLandmarksEnumeration(storeName, category, name,
176:                                -90, 90, -180, 180);
177:                if (en == null) {
178:                    return null;
179:                }
180:                Vector vecLandmarks = new Vector();
181:                while (en.hasMoreElements()) {
182:                    vecLandmarks.addElement(new Landmark((LandmarkImpl) en
183:                            .nextElement()));
184:                }
185:                return vecLandmarks.elements();
186:            }
187:
188:            // JAVADOC COMMENT ELIDED
189:            public Enumeration getLandmarks() throws IOException {
190:                return getLandmarks(null, null);
191:            }
192:
193:            // JAVADOC COMMENT ELIDED
194:            public Enumeration getLandmarks(String category,
195:                    double minLatitude, double maxLatitude,
196:                    double minLongitude, double maxLongitude)
197:                    throws IOException {
198:                if ((minLongitude == 180) || (maxLongitude == 180)) {
199:                    throw new IllegalArgumentException(
200:                            "Longtitude out of range " + "must not equal 180");
201:                }
202:                if (minLatitude > maxLatitude) {
203:                    throw new IllegalArgumentException(
204:                            "Minimum latitude cannot be "
205:                                    + "larger than the maximum latitude");
206:                }
207:                Util.checkRange(minLatitude, -90, 90,
208:                        "Latitude out of range [-90.0, 90]: ");
209:                Util.checkRange(maxLatitude, -90, 90,
210:                        "Latitude out of range [-90.0, 90]: ");
211:                Util.checkRange(maxLongitude, -180, 180,
212:                        "Longitude out of range [-180.0, 180]: ");
213:                Util.checkRange(minLongitude, -180, 180,
214:                        "Longitude out of range [-180.0, 180]: ");
215:
216:                Enumeration en = LocationPersistentStorage.getInstance()
217:                        .getLandmarksEnumeration(storeName, category, null,
218:                                minLatitude, maxLatitude, minLongitude,
219:                                maxLongitude);
220:                if (en == null) {
221:                    return null;
222:                }
223:                Vector vecLandmarks = new Vector();
224:                while (en.hasMoreElements()) {
225:                    vecLandmarks.addElement(new Landmark((LandmarkImpl) en
226:                            .nextElement()));
227:                }
228:                return vecLandmarks.elements();
229:            }
230:
231:            // JAVADOC COMMENT ELIDED
232:            public void removeLandmarkFromCategory(Landmark lm, String category)
233:                    throws IOException {
234:                Util.checkForPermission(Permissions.LANDMARK_WRITE);
235:                if (lm == null || category == null) {
236:                    throw new NullPointerException();
237:                }
238:                LocationPersistentStorage.getInstance()
239:                        .removeLandmarkFromCategory(storeName,
240:                                lm.getInstance(), category);
241:            }
242:
243:            // JAVADOC COMMENT ELIDED
244:            public void updateLandmark(Landmark lm) throws IOException,
245:                    LandmarkException {
246:                Util.checkForPermission(Permissions.LANDMARK_WRITE);
247:                if (lm == null) {
248:                    throw new NullPointerException();
249:                }
250:                LocationPersistentStorage.getInstance().updateLandmark(
251:                        storeName, lm.getInstance());
252:            }
253:
254:            // JAVADOC COMMENT ELIDED
255:            public void deleteLandmark(Landmark lm) throws IOException,
256:                    LandmarkException {
257:                Util.checkForPermission(Permissions.LANDMARK_WRITE);
258:                if (lm == null) {
259:                    throw new NullPointerException();
260:                }
261:
262:                LocationPersistentStorage.getInstance().deleteLandmark(
263:                        storeName, lm.getInstance());
264:            }
265:
266:            // JAVADOC COMMENT ELIDED
267:            public Enumeration getCategories() {
268:                try {
269:                    return getCategoriesVector().elements();
270:                } catch (IOException e) {
271:                    return new Vector().elements();
272:                }
273:            }
274:
275:            // JAVADOC COMMENT ELIDED
276:            private Vector getCategoriesVector() throws IOException {
277:                return LocationPersistentStorage.getInstance().getCategories(
278:                        storeName);
279:            }
280:
281:            // JAVADOC COMMENT ELIDED
282:            public void addCategory(String categoryName)
283:                    throws LandmarkException, IOException {
284:                Util.checkForPermission(Permissions.LANDMARK_CATEGORY);
285:                if (categoryName == null) {
286:                    throw new NullPointerException("Category name is null");
287:                }
288:                // save categories into persistent storage
289:                LocationPersistentStorage.getInstance().addCategory(
290:                        categoryName, storeName);
291:            }
292:
293:            // JAVADOC COMMENT ELIDED
294:            public void deleteCategory(String categoryName)
295:                    throws LandmarkException, IOException {
296:                if (Configuration.getProperty(DELETE_CATEGORY_SUPPORTED)
297:                        .equals("true")) {
298:                    Util.checkForPermission(Permissions.LANDMARK_CATEGORY);
299:                    if (categoryName == null) {
300:                        throw new NullPointerException();
301:                    }
302:                    LocationPersistentStorage.getInstance().deleteCategory(
303:                            categoryName, storeName);
304:                } else {
305:                    throw new LandmarkException(
306:                            "Implementation does not support "
307:                                    + "deleting categories");
308:                }
309:            }
310:
311:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.