FileDocCategorySizeDatePackage
LandmarkStore.javaAPI DocphoneME MR2 API (J2ME)11121Wed May 02 18:00:40 BST 2007javax.microedition.location

LandmarkStore

public class LandmarkStore extends Object
This class is defined by the JSR-179 specification Location API for J2ME for J2ME™.

Fields Summary
private static final String
CREATE_LANDMARKSTORE_SUPPORTED
LandmarkStore Create property
private static final String
DELETE_LANDMARKSTORE_SUPPORTED
LandmarkStore Delete property
private static final String
DELETE_CATEGORY_SUPPORTED
Category Delete property
private static final LandmarkStore
defaultStore
The default instance of a store
private static Hashtable
stores
A map of names of stores to actual stores
private static boolean
storesInitialized
Indicates whether landmark stores were loaded
private String
storeName
The name of the record store
Constructors Summary
private LandmarkStore(String storeName)
Constructor is private to prevent user from instanciating this class.

param
storeName name of landmark store


                         
       
        this.storeName = storeName;
    
private LandmarkStore()
Prevent the user from instanciating this class creates default LandmarkStore if it is not exist

        this.storeName = null;
    
Methods Summary
public voidaddCategory(java.lang.String categoryName)

        Util.checkForPermission(Permissions.LANDMARK_CATEGORY);
        if (categoryName == null) {
            throw new NullPointerException("Category name is null");
        }
        // save categories into persistent storage
	LocationPersistentStorage.getInstance().
                addCategory(categoryName, storeName);
    
public voidaddLandmark(Landmark landmark, java.lang.String category)

        Util.checkForPermission(Permissions.LANDMARK_WRITE);
        if (landmark == null) { // NullPointerException should be caused
	    throw new NullPointerException("Landmark is null");
	}
        LocationPersistentStorage.getInstance().addLandmark(storeName,
                landmark.getInstance(), category);
    
public static voidcreateLandmarkStore(java.lang.String storeName)

        if (Configuration.getProperty(CREATE_LANDMARKSTORE_SUPPORTED).
                equals("true")) {
            Util.checkForPermission(Permissions.LANDMARK_MANAGE);
            if (storeName == null) {
                throw new NullPointerException("storeName can not be null");
            }
            // verify that the name is correct and store does not exist
            int storeLen = storeName.length();
            if (storeLen == 0) { 
                throw new IllegalArgumentException("The store: name has " +
                                                   "incorrect length");
            }
            if (getInstance(storeName) != null) {
                throw new IllegalArgumentException("The store: " + storeName + 
                                                   " already exists");
            }
            LocationPersistentStorage.getInstance().addStoreName(storeName);
        } else {
            throw new LandmarkException(
                    "Implementation does not support " + 
                    "creating new landmark stores");
        }
    
public voiddeleteCategory(java.lang.String categoryName)

        if (Configuration.getProperty(DELETE_CATEGORY_SUPPORTED).
                equals("true")) {
            Util.checkForPermission(Permissions.LANDMARK_CATEGORY);
            if (categoryName == null) {
                throw new NullPointerException();
            }
            LocationPersistentStorage.getInstance().
                    deleteCategory(categoryName, storeName);
        } else {
            throw new LandmarkException(
                    "Implementation does not support " + 
                    "deleting categories");
        }
    
public voiddeleteLandmark(Landmark lm)

        Util.checkForPermission(Permissions.LANDMARK_WRITE);
        if (lm == null) {
            throw new NullPointerException();
        }

        LocationPersistentStorage.getInstance().deleteLandmark(
		storeName, lm.getInstance());
    
public static voiddeleteLandmarkStore(java.lang.String storeName)

        if (Configuration.getProperty(DELETE_LANDMARKSTORE_SUPPORTED).
                equals("true")) {
            Util.checkForPermission(Permissions.LANDMARK_MANAGE);
            if (storeName == null) {
                throw new NullPointerException();
            }
            LocationPersistentStorage.getInstance().removeStoreName(storeName);
        } else {
            throw new LandmarkException(
                    "Implementation does not support " + 
                    "deleting landmark stores");
        }
    
public java.util.EnumerationgetCategories()

	try {
	    return getCategoriesVector().elements();
	} catch (IOException e) {
	    return new Vector().elements();
	}
    
private java.util.VectorgetCategoriesVector()

        return LocationPersistentStorage.getInstance().
                getCategories(storeName);
    
public static synchronized javax.microedition.location.LandmarkStoregetInstance(java.lang.String storeName)

        Util.checkForPermission(Permissions.LANDMARK_READ);
        
        LandmarkStore current = null;
	try {
            if (storeName == null) {
                return defaultStore;
            } else {
                String[] storeNames = LocationPersistentStorage.
                                        getInstance().listStoreNames();
                if (storeNames != null) {
                    for (int i = 0; i < storeNames.length; i++) {
                        if (storeNames[i].equals(storeName)) {
                            current = new LandmarkStore(storeName);
                            break;
                        }
                    }
                }
            }
	} catch (IOException e) { // return null
	}
        return current;
    
public java.util.EnumerationgetLandmarks(java.lang.String category, double minLatitude, double maxLatitude, double minLongitude, double maxLongitude)

        if ((minLongitude == 180) || (maxLongitude == 180)) {
            throw new IllegalArgumentException("Longtitude out of range " +
					       "must not equal 180");
        }
        if (minLatitude > maxLatitude) {
            throw new IllegalArgumentException("Minimum latitude cannot be " +
	        "larger than the maximum latitude");
        }
        Util.checkRange(minLatitude, -90, 90,
			"Latitude out of range [-90.0, 90]: ");
        Util.checkRange(maxLatitude, -90, 90,
			"Latitude out of range [-90.0, 90]: ");
        Util.checkRange(maxLongitude, -180, 180,
			"Longitude out of range [-180.0, 180]: ");
        Util.checkRange(minLongitude, -180, 180,
			"Longitude out of range [-180.0, 180]: ");
        
        Enumeration en = LocationPersistentStorage.getInstance().
                             getLandmarksEnumeration(storeName, category, null, 
						 minLatitude, maxLatitude,
						 minLongitude, maxLongitude);
        if (en == null) {
            return null;
        }
        Vector vecLandmarks = new Vector();
        while (en.hasMoreElements()) {
            vecLandmarks.addElement(
                    new Landmark((LandmarkImpl)en.nextElement()));
        }
        return vecLandmarks.elements();
    
public java.util.EnumerationgetLandmarks(java.lang.String category, java.lang.String name)

        Enumeration en = LocationPersistentStorage.getInstance().
                             getLandmarksEnumeration(storeName, category, name, 
						 -90, 90, -180, 180);
        if (en == null) {
            return null;
        }
        Vector vecLandmarks = new Vector();
        while (en.hasMoreElements()) {
            vecLandmarks.addElement(
                    new Landmark((LandmarkImpl)en.nextElement()));
        }
        return vecLandmarks.elements();
    
public java.util.EnumerationgetLandmarks()

        return getLandmarks(null, null);
    
public static java.lang.String[]listLandmarkStores()

        Util.checkForPermission(Permissions.LANDMARK_READ);
        return LocationPersistentStorage.getInstance().listStoreNames();
    
public voidremoveLandmarkFromCategory(Landmark lm, java.lang.String category)

	Util.checkForPermission(Permissions.LANDMARK_WRITE);
        if (lm == null || category == null) {
            throw new NullPointerException();
        }
        LocationPersistentStorage.getInstance().removeLandmarkFromCategory(
                storeName, lm.getInstance(), category);
    
public voidupdateLandmark(Landmark lm)

        Util.checkForPermission(Permissions.LANDMARK_WRITE);
        if (lm == null) {
            throw new NullPointerException();
        }
        LocationPersistentStorage.getInstance().updateLandmark(
                storeName, lm.getInstance());