Search in sources :

Example 1 with NamedObject

use of weborb.reader.NamedObject in project Android-SDK by Backendless.

the class AdaptingResponder method responseHandler.

public final void responseHandler(Object adaptingType) {
    IAdaptingType type = (IAdaptingType) adaptingType;
    IAdaptingType bodyHolder = ((NamedObject) type).getTypedObject();
    if (((IAdaptingType) adaptingType).getDefaultType().equals(ErrMessage.class)) {
        if (nextResponder != null) {
            nextResponder.errorHandler(adaptFault((AnonymousObject) bodyHolder));
        }
    } else {
        IAdaptingType entity = (IAdaptingType) ((AnonymousObject) bodyHolder).getProperties().get("body");
        try {
            adaptingPolicy.adapt(clazz, entity, nextResponder);
        } catch (AdaptingException e) {
            errorHandler(new BackendlessFault(e));
        }
    }
}
Also used : AnonymousObject(weborb.reader.AnonymousObject) IAdaptingType(weborb.types.IAdaptingType) NamedObject(weborb.reader.NamedObject) AdaptingException(weborb.exceptions.AdaptingException) BackendlessFault(com.backendless.exceptions.BackendlessFault)

Example 2 with NamedObject

use of weborb.reader.NamedObject in project Android-SDK by Backendless.

the class BackendlessFileFactory method createObject.

public Object createObject(IAdaptingType argument) {
    if (argument instanceof NamedObject)
        argument = ((NamedObject) argument).getTypedObject();
    if (argument.getClass().getName().equals("weborb.reader.NullType"))
        return null;
    ReferenceCache refCache = ReferenceCache.getInstance();
    if (refCache.hasObject(argument, BackendlessFile.class)) {
        return refCache.getObject(argument, BackendlessFile.class);
    } else {
        if (argument instanceof StringType) {
            StringType stringType = (StringType) argument;
            BackendlessFile file;
            if (Backendless.isAndroid())
                file = new BackendlessFileAndroid(stringType.getValue());
            else
                file = new BackendlessFile(stringType.getValue());
            refCache.addObject(argument, BackendlessFile.class, file);
            return file;
        } else
            throw new RuntimeException("unknown type");
    }
}
Also used : ReferenceCache(weborb.reader.ReferenceCache) StringType(weborb.reader.StringType) NamedObject(weborb.reader.NamedObject)

Example 3 with NamedObject

use of weborb.reader.NamedObject in project Android-SDK by Backendless.

the class BackendlessUserFactory method createObject.

@Override
public Object createObject(IAdaptingType iAdaptingType) {
    if (iAdaptingType instanceof NamedObject)
        iAdaptingType = ((NamedObject) iAdaptingType).getTypedObject();
    if (iAdaptingType.getClass().getName().equals("weborb.reader.NullType"))
        return null;
    ReferenceCache refCache = ReferenceCache.getInstance();
    BackendlessUser backendlessUser;
    if (refCache.hasObject(iAdaptingType, BackendlessUser.class)) {
        return refCache.getObject(iAdaptingType, BackendlessUser.class);
    } else {
        backendlessUser = new BackendlessUser();
        refCache.addObject(iAdaptingType, BackendlessUser.class, backendlessUser);
    }
    HashMap props;
    try {
        props = (HashMap) iAdaptingType.adapt(HashMap.class);
    } catch (Throwable t) {
        props = new HashMap();
    }
    backendlessUser.setProperties(props);
    return backendlessUser;
}
Also used : BackendlessUser(com.backendless.BackendlessUser) ReferenceCache(weborb.reader.ReferenceCache) HashMap(java.util.HashMap) NamedObject(weborb.reader.NamedObject)

Example 4 with NamedObject

use of weborb.reader.NamedObject in project Android-SDK by Backendless.

the class CollectionAdaptingPolicy method adapt.

@Override
public Object adapt(Class<E> clazz, IAdaptingType entity, IResponder nextResponder) {
    List<E> result = null;
    try {
        List<E> list = new ArrayList<>();
        if (entity == null)
            return list;
        ArrayType data = (ArrayType) entity;
        Object[] dataArray = (Object[]) data.getArray();
        if (clazz != null && weborb.types.Types.getMappedClientClass(clazz.getName()) == null) {
            for (Object aDataArray : dataArray) if (aDataArray instanceof NamedObject)
                ((NamedObject) aDataArray).setDefaultType(clazz);
        }
        result = (List<E>) entity.adapt(list.getClass());
        if (nextResponder != null)
            nextResponder.responseHandler(result);
    } catch (AdaptingException e) {
        Fault fault = new Fault("Unable to adapt response to List<" + clazz.getName() + ">", e.getMessage());
        if (nextResponder != null)
            nextResponder.errorHandler(fault);
    }
    return result;
}
Also used : ArrayType(weborb.reader.ArrayType) ArrayList(java.util.ArrayList) NamedObject(weborb.reader.NamedObject) AdaptingException(weborb.exceptions.AdaptingException) NamedObject(weborb.reader.NamedObject) Fault(weborb.client.Fault)

Aggregations

NamedObject (weborb.reader.NamedObject)4 AdaptingException (weborb.exceptions.AdaptingException)2 ReferenceCache (weborb.reader.ReferenceCache)2 BackendlessUser (com.backendless.BackendlessUser)1 BackendlessFault (com.backendless.exceptions.BackendlessFault)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Fault (weborb.client.Fault)1 AnonymousObject (weborb.reader.AnonymousObject)1 ArrayType (weborb.reader.ArrayType)1 StringType (weborb.reader.StringType)1 IAdaptingType (weborb.types.IAdaptingType)1