1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218
|
import java.util.Vector;
// Referenced classes of package com.sun.kvem.location:
// PortingLayer
public abstract class LocationProviderImpl extends LocationProvider
implements Runnable
{
public LocationProviderImpl()
{
}
public abstract boolean matchesCriteria(Criteria criteria1);
public abstract int getDefaultInterval();
public abstract int getDefaultMaxAge();
public abstract int getDefaultTimeout();
abstract String getName();
public static Location getLastKnownLocation()
{
PortingLayer.getInstance().checkForPermission(36);
return getLastKnownLocationImpl();
}
static Location getLastKnownLocationImpl()
{
return LastKnownLocation;
}
protected static void setLastKnownLocation(Location newLoc)
{
if(newLoc != null)
LastKnownLocation = newLoc;
}
public Location getLocation(int timeout)
throws LocationException, InterruptedException
{
PortingLayer.getInstance().checkForPermission(36);
Location loc = getLocationImpl(timeout);
setLastKnownLocation(loc);
return loc;
}
protected abstract Location getLocationImpl(int i)
throws LocationException, InterruptedException;
public static LocationProvider getInstance(Criteria criteria)
throws LocationException
{
int oos = 0;
LocationProviderImpl found[] = new LocationProviderImpl[3];
if(criteria == null)
criteria = new Criteria();
LocationProviderImpl providers[] = PortingLayer.getInstance().getProviders();
for(int i = 0; i < providers.length; i++)
{
LocationProviderImpl provider = providers[i];
if(provider.matchesCriteria(criteria))
found[provider.getState() - 1] = provider;
if(provider.getState() == 3)
oos++;
}
if(oos == providers.length)
throw new LocationException("All providers are out of service");
Instance = null;
if(found[0] != null)
Instance = found[0];
else
if(found[1] != null)
Instance = found[1];
return Instance;
}
public LocationListener getLocationListener()
{
return locationListener;
}
public void setLocationListener(LocationListener listener, int interval, int timeout, int maxAge)
{
PortingLayer.getInstance().checkForPermission(36);
PortingLayer.getInstance().registerLocationListener(listener, this);
if(listener == null)
{
locationListener = null;
return;
}
if(interval < -1 || interval != -1 && (timeout > interval || maxAge > interval || timeout < 1 && timeout != -1 || maxAge < 1 && maxAge != -1))
throw new IllegalArgumentException();
if(interval == 0)
{
locationListener = listener;
return;
}
if(interval == -1)
{
interval = getDefaultInterval();
maxAge = getDefaultMaxAge();
timeout = getDefaultTimeout();
}
if(maxAge == -1)
maxAge = getDefaultMaxAge();
if(timeout == -1)
timeout = getDefaultTimeout();
locationListener = listener;
this.interval = interval;
this.timeout = timeout;
this.maxAge = maxAge;
initial = true;
synchronized(this)
{
notify();
}
}
public void run()
{
_L2:{
long clock;
long time;
try
{
label0:{
clock = interval * 1000;
if(locationListener == null || interval == 0)
break MISSING_BLOCK_LABEL_176;
if(clock <= 0L)
break MISSING_BLOCK_LABEL_74;
synchronized(this)
{
initialLocationNotification();
wait(clock);
if(locationListener != null && interval != 0)
break label0;
}
continue; /* Loop/switch isn't completed */
}
}
catch(LocationException le)
{
continue; /* Loop/switch isn't completed */
}
catch(Exception e)
{
e.printStackTrace();
}
continue; /* Loop/switch isn't completed */
locationproviderimpl ;
JVM INSTR monitorexit ;
break MISSING_BLOCK_LABEL_74;
locationproviderimpl;
JVM INSTR monitorexit ;
break MISSING_BLOCK_LABEL_74;
exception;
throw exception;
time = System.currentTimeMillis();
if(currentLocation != null)
{
if(System.currentTimeMillis() - currentLocation.getTimestamp() > (long)(maxAge * 1000))
currentLocation = getLocation(timeout);
} else
{
currentLocation = getLocation(timeout);
}
LastKnownLocation = currentLocation;
locationListener.locationUpdated(this, currentLocation);
clock = (long)(interval * 1000) - (System.currentTimeMillis() - time);
continue; /* Loop/switch isn't completed */
synchronized(this)
{
wait();
}
initialLocationNotification();
continue; /* Loop/switch isn't completed */
if(true){
goto _L2;
}
else{
goto _L1;
}
}
_L1:{}
}
private void initialLocationNotification()
throws LocationException, InterruptedException
{
if(initial)
{
currentLocation = getLocation(timeout);
LastKnownLocation = currentLocation;
locationListener.locationUpdated(this, currentLocation);
initial = false;
}
}
private static Vector proximityListeners = new Vector();
private static Location LastKnownLocation;
private static LocationProviderImpl Instance;
protected LocationListener locationListener;
private int interval;
private int timeout;
private int maxAge;
private Location currentLocation;
protected Criteria criteria;
protected Thread locationThread;
private boolean initial;
} |
Partager