FileDocCategorySizeDatePackage
LocationPersistentStorage.javaAPI DocphoneME MR2 API (J2ME)11852Wed May 02 18:00:40 BST 2007com.sun.j2me.location

LocationPersistentStorage

public class LocationPersistentStorage extends Object
This class is an implementation of the persistent storage to store landmarks.

Fields Summary
private static final String
SEPARATOR
private static LocationPersistentStorage
storage
Constructors Summary
private LocationPersistentStorage()

    
Methods Summary
public synchronized voidaddCategory(java.lang.String categoryName, java.lang.String storeName)

        addCategoryImpl(storeName, categoryName);
    
private static native voidaddCategoryImpl(java.lang.String storeName, java.lang.String categoryName)

public synchronized voidaddLandmark(java.lang.String storeName, LandmarkImpl landmark, java.lang.String category)

        try {
            if ((landmark.getRecordId()) > 0 &&
                (landmark.getStoreName() == storeName) &&
                (category != null)) {
                try {
                    updateLandmark(storeName, landmark);
                } catch (LandmarkException ex) {
                    landmark.setRecordId(0);
                }
                if (landmark.getRecordId() > 0) {
                    addLandmarkToCategoryImpl(storeName, landmark.getRecordId(), 
                            category);
                    return;
                }
            }
        } catch (IllegalArgumentException e) {
            // if it is happened, the landmark is deleted from store. 
            // Just continue to add Landmark
        }
        landmark.setRecordId(
                addLandmarkToStoreImpl(storeName, landmark, category));
        landmark.setStoreName(storeName);
    
private static native voidaddLandmarkToCategoryImpl(java.lang.String storeName, int landmarkID, java.lang.String categoryName)

private static native intaddLandmarkToStoreImpl(java.lang.String storeName, LandmarkImpl landmark, java.lang.String categoryName)

public synchronized voidaddStoreName(java.lang.String storeName)

	try {
            createLandmarkStore(storeName);
	} catch (IllegalArgumentException e) {
            throw new IOException(e.getMessage());
	}
    
private static native java.lang.StringcategoryGetNext(int listHandle)

private static native voidcloseCategoryList(int listHandle)

private static native voidcloseLandmarkList(int listHandle)

private static native voidcloseLandmarkStoreList(int listHandle)

private static native voidcreateLandmarkStore(java.lang.String name)

public synchronized voiddeleteCategory(java.lang.String categoryName, java.lang.String storeName)

        deleteCategoryImpl(storeName, categoryName);
    
private static native voiddeleteCategoryImpl(java.lang.String storeName, java.lang.String categoryName)

public synchronized voiddeleteLandmark(java.lang.String storeName, LandmarkImpl lm)


        // If the store names are not the same or
        // they are the same and both are null (for the default LMS)
        // but the landmark does not belong to a LMS
        
        if ((lm.getStoreName() != storeName) || (lm.getRecordId() == 0)) {
            throw new LandmarkException("This landmark belongs to a " +
		"different store: " + lm.getStoreName());
	}
        deleteLandmarkFromStoreImpl(storeName, lm.getRecordId());
        
    
private static native voiddeleteLandmarkFromCategoryImpl(java.lang.String storeName, int landmarkID, java.lang.String category)

private static native voiddeleteLandmarkFromStoreImpl(java.lang.String storeName, int landmarkID)

public synchronized java.util.VectorgetCategories(java.lang.String storeName)

        Vector categories = new Vector();
        int listHandle;
        String category;
        listHandle = openCategoryList(storeName);
        if (listHandle != 0) {
            try {
                while ((category = categoryGetNext(listHandle)) != null) {
                    if (category.length() == 0) {
                        break;
                    }
                    categories.addElement(category);
                }
            } finally {
                closeCategoryList(listHandle);
            }
        }
        return categories;
    
public static com.sun.j2me.location.LocationPersistentStoragegetInstance()


        
        if(storage == null) {
            storage = new LocationPersistentStorage();
        }
        return storage;
    
public java.util.EnumerationgetLandmarksEnumeration(java.lang.String storeName, java.lang.String category, java.lang.String name, double minLatitude, double maxLatitude, double minLongitude, double maxLongitude)

        
        Vector landmarks = new Vector();
        int landmarkID = 0;
        int listHandle;
        listHandle = openLandmarkList(storeName, category);
        if (listHandle != 0) {
            try {
                boolean val = true;
                do {
                    LandmarkImpl landmark = new LandmarkImpl("", null, 
                                                                null, null);
                    landmarkID = landmarkGetNext(listHandle, landmark);
                    if (landmarkID != 0) { 
                        if (name != null) {
                            if (!name.equals(landmark.getName())) {
                                continue;
                            }
                        }
                        if (landmark.getQualifiedCoordinates() != null) {
                            double lat = landmark.getQualifiedCoordinates().
                                    getLatitude();
                            double lon = landmark.getQualifiedCoordinates().
                                    getLongitude();
                            if (minLongitude > maxLongitude) {
                                val = (minLatitude <= lat) && (maxLatitude >= lat)
                                    && ((minLongitude < lon) || (maxLongitude > lon));
                            } else {
                                val = (minLatitude <= lat) && (minLongitude <= lon) &&
                                    (maxLongitude >= lon) && (maxLatitude >= lat);
                            }
                        }
                        if (val) {
                            landmark.setRecordId(landmarkID);
                            landmark.setStoreName(storeName);
                            landmarks.addElement(landmark);
                        }
                    }
                } while (landmarkID != 0);
            } finally {
                closeLandmarkList(listHandle);
            }

            Enumeration en = landmarks.elements();

            if (en.hasMoreElements()) {
                return en;
            }
        }
        
        return null;
    
private static native intlandmarkGetNext(int listHandle, LandmarkImpl landmark)

private static native java.lang.StringlandmarkStoreGetNext(int listHandle)

public static synchronized java.lang.String[]listStoreNames()

        Vector vectStores = new Vector();
        String storeName;
        int hndl = openLandmarkStoreList();
        do {
            storeName = landmarkStoreGetNext(hndl);
            if ((storeName != null) && (storeName.length()>0)) {
                vectStores.addElement(storeName);
            } else {
                closeLandmarkStoreList(hndl);
                storeName = null;
            }
        } while(storeName != null);
        String[] arrStores = null;
        if(vectStores.size()>0) {
            arrStores = new String[vectStores.size()];
            vectStores.copyInto(arrStores);
        }
        return arrStores;
    
private static native intopenCategoryList(java.lang.String name)

private static native intopenLandmarkList(java.lang.String storeName, java.lang.String categoryName)

private static native intopenLandmarkStoreList()

public voidremoveLandmarkFromCategory(java.lang.String storeName, LandmarkImpl lm, java.lang.String category)

        if ((lm.getRecordId() > 0) && (lm.getStoreName() == storeName)) {
            deleteLandmarkFromCategoryImpl(
                    storeName, lm.getRecordId(), category);
        }
    
private static native voidremoveLandmarkStore(java.lang.String name)

public synchronized voidremoveStoreName(java.lang.String storeName)

        // cannot delete default LandmarkStore
        if(storeName == null) {
            throw new 
                    NullPointerException("the default store can't be deleted");
        }

        // remove file with landmarks
        removeLandmarkStore(storeName);
    
public synchronized voidupdateLandmark(java.lang.String storeName, LandmarkImpl landmark)

        if ((landmark.getRecordId()) > 0 &&
            (landmark.getStoreName() == storeName)) {
            try {
                updateLandmarkImpl(storeName, landmark.getRecordId(), 
                        landmark);
            } catch (IllegalArgumentException ex) {
                throw new LandmarkException(ex.getMessage());
            }
            return;
        } else {
            throw new LandmarkException(
                    "Landmark does not belong to this store");
        }
    
private static native voidupdateLandmarkImpl(java.lang.String storeName, int landmarkID, LandmarkImpl landmark)