use of com.backendless.exceptions.BackendlessException in project Android-SDK by Backendless.
the class Cache method get.
public <T> void get(final String key, final AsyncCallback<T> callback) {
final Type asyncCallbackType = ReflectionUtil.getCallbackGenericType(callback);
ThreadPoolService.getPoolExecutor().execute(new Runnable() {
@Override
public void run() {
try {
T result = (T) get(key, (Class) asyncCallbackType);
ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<T>(result, callback));
} catch (BackendlessException e) {
ResponseCarrier.getInstance().deliverMessage(new AsyncMessage<T>(new BackendlessFault(e), callback));
}
}
});
}
use of com.backendless.exceptions.BackendlessException in project Android-SDK by Backendless.
the class Persistence method loadRelationsToEntity.
private <E> void loadRelationsToEntity(E entity, E loadedRelations, List<String> relations) {
if (entity.getClass().equals(BackendlessUser.class)) {
BackendlessUser userWithRelations = (BackendlessUser) loadedRelations;
BackendlessUser sourceUser = (BackendlessUser) entity;
sourceUser.putProperties(userWithRelations.getProperties());
} else {
Field[] declaredFields = entity.getClass().getDeclaredFields();
for (Field declaredField : declaredFields) {
if (!relations.contains(declaredField.getName()))
continue;
if (!declaredField.isAccessible())
declaredField.setAccessible(true);
try {
Object fieldValue = declaredField.get(loadedRelations);
declaredField.set(entity, fieldValue);
} catch (IllegalAccessException e) {
// actually, won't be ever thrown because field was set accessible several lines above
String message = String.format(ExceptionMessage.FIELD_NOT_ACCESSIBLE, declaredField.getName()) + ": " + e.getMessage();
throw new BackendlessException(message);
}
}
}
}
use of com.backendless.exceptions.BackendlessException in project Android-SDK by Backendless.
the class UserService method register.
public void register(final BackendlessUser user, final AsyncCallback<BackendlessUser> responder) {
try {
checkUserToBeProper(user);
BackendlessSerializer.serializeUserProperties(user);
Invoker.invokeAsync(USER_MANAGER_SERVER_ALIAS, "register", new Object[] { user.getProperties() }, new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
response.setPassword(user.getPassword());
user.clearProperties();
user.putProperties(response.getProperties());
if (responder != null)
responder.handleResponse(response);
}
@Override
public void handleFault(BackendlessFault fault) {
if (responder != null)
responder.handleFault(fault);
}
}, new AdaptingResponder(BackendlessUser.class, new BackendlessUserAdaptingPolicy()));
} catch (BackendlessException e) {
if (responder != null)
responder.handleFault(new BackendlessFault(e));
}
}
use of com.backendless.exceptions.BackendlessException in project Android-SDK by Backendless.
the class LocationTracker method listenBestProvider.
private void listenBestProvider() {
String bestProvider = locationManager.getBestProvider(criteria != null ? criteria : new Criteria(), true);
if (bestProvider == null)
throw new BackendlessException(ExceptionMessage.NOT_FOUND_PROVIDER);
listenProvider(bestProvider);
}
use of com.backendless.exceptions.BackendlessException in project Android-SDK by Backendless.
the class BackendlessSerializer method serializeToMap.
public Object serializeToMap(Object entity, Map<Object, Map<String, Object>> serializedCache) {
if (entity.getClass().isArray())
return serializeArray(entity, serializedCache);
if (entity.getClass().isEnum())
return ((Enum) entity).name();
Map<String, Object> serializedEntity = new HashMap<String, Object>();
if (entity.getClass() == BackendlessUser.class)
serializedEntity = ((BackendlessUser) entity).getProperties();
else
weborb.util.ObjectInspector.getObjectProperties(entity.getClass(), entity, (HashMap) serializedEntity, new ArrayList(), true, shouldTraverse());
serializedCache.put(entity, serializedEntity);
FootprintsManager.getInstance().Inner.putMissingPropsToEntityMap(entity, serializedEntity);
// put ___class field, otherwise server will not be able to detect class
serializedEntity.put(Persistence.REST_CLASS_FIELD, getSimpleName(entity.getClass()));
// recursively serialize object properties
Iterator<Map.Entry<String, Object>> entityIterator = serializedEntity.entrySet().iterator();
while (entityIterator.hasNext()) {
Map.Entry<String, Object> entityEntry = entityIterator.next();
// ignoring properties which contain $. This occurs in InstantRun in AndroidStudio - it injects $change property.
if (entityEntry.getKey().contains("$")) {
entityIterator.remove();
continue;
}
// http://developer.android.com/reference/android/os/Parcelable.html
if (Backendless.isAndroid() && entityEntry.getKey().equals(Persistence.PARCELABLE_CREATOR_FIELD_NAME)) {
entityIterator.remove();
continue;
}
Object entityEntryValue = entityEntry.getValue();
// ignore null entries and GeoPoints
if (entityEntryValue == null || entityEntryValue instanceof GeoPoint)
continue;
// check for anonymous class entry
if (entityEntryValue.getClass().isAnonymousClass())
throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
// check if entity entry is collection
if (entityEntryValue instanceof List) {
List listEntry = (List) entityEntryValue;
// empty lists should not be sent to the server
if (listEntry.isEmpty()) {
// if there is no object id, remove empty list
if (!serializedEntity.containsKey(Persistence.DEFAULT_OBJECT_ID_FIELD) || serializedEntity.get(Persistence.DEFAULT_OBJECT_ID_FIELD) == null)
entityIterator.remove();
continue;
}
// do nothing with lists of GeoPoints
if (listEntry.iterator().next() instanceof GeoPoint)
continue;
// check for anonymous class entry
if (listEntry.iterator().next().getClass().isAnonymousClass())
throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
List<Object> newCollection = new ArrayList<Object>();
for (Object listEntryItem : listEntry) if (!isBelongsJdk(listEntryItem.getClass()))
newCollection.add(getOrMakeSerializedObject(listEntryItem, serializedCache));
else
newCollection.add(listEntryItem);
entityEntry.setValue(newCollection);
} else if (entityEntryValue instanceof Object[]) {
Object[] arrayEntry = (Object[]) entityEntryValue;
// do nothing with empty arrays and arrays of GeoPoints
if (arrayEntry.length == 0 || arrayEntry[0] instanceof GeoPoint)
continue;
// check for anonymous class entry
if (arrayEntry[0].getClass().isAnonymousClass())
throw new BackendlessException(String.format(ExceptionMessage.ANONYMOUS_CLASSES_PROHIBITED, entityEntry.getKey()));
List<Object> newCollection = new ArrayList<Object>();
for (Object arrayEntryItem : arrayEntry) if (!isBelongsJdk(arrayEntryItem.getClass()))
newCollection.add(getOrMakeSerializedObject(arrayEntryItem, serializedCache));
else
newCollection.add(arrayEntryItem);
entityEntry.setValue(newCollection);
} else // not collection
{
if (!isBelongsJdk(entityEntryValue.getClass()))
entityEntry.setValue(getOrMakeSerializedObject(entityEntryValue, serializedCache));
}
}
return serializedEntity;
}
Aggregations