Example usage for com.google.gson.stream JsonReader nextName

List of usage examples for com.google.gson.stream JsonReader nextName

Introduction

In this page you can find the example usage for com.google.gson.stream JsonReader nextName.

Prototype

public String nextName() throws IOException 

Source Link

Document

Returns the next token, a com.google.gson.stream.JsonToken#NAME property name , and consumes it.

Usage

From source file:org.komodo.rest.relational.json.SavedSearcherSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*ww w  .j  a  v a  2s .co m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoSavedSearcher read(final JsonReader in) throws IOException {
    final KomodoSavedSearcher status = new KomodoSavedSearcher();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoSavedSearcher.NAME_LABEL:
            status.setName(in.nextString());
            break;
        case KomodoSavedSearcher.QUERY_LABEL:
            status.setQuery(in.nextString());
            break;
        case KomodoSavedSearcher.PARAMETER_LABEL:
            final String[] parameters = BUILDER.fromJson(in, String[].class);
            status.setParameters(Arrays.asList(parameters));
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return status;
}

From source file:org.komodo.rest.relational.json.SearcherAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from  w w  w  . jav a2 s .co  m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoSearcherAttributes read(final JsonReader in) throws IOException {
    final KomodoSearcherAttributes searcherAttr = createEntity();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        if (readPath(in, name, searcherAttr) != null)
            continue;

        switch (name) {
        case KomodoSearcherAttributes.SEARCH_NAME_LABEL:
            searcherAttr.setSearchName(in.nextString());
            break;
        case KomodoSearcherAttributes.TYPE_LABEL:
            searcherAttr.setType(in.nextString());
            break;
        case KomodoSearcherAttributes.PARENT_LABEL:
            searcherAttr.setParent(in.nextString());
            break;
        case KomodoSearcherAttributes.ANCESTOR_LABEL:
            searcherAttr.setAncestor(in.nextString());
            break;
        case KomodoSearcherAttributes.CONTAINS_LABEL:
            searcherAttr.setContains(in.nextString());
            break;
        case KomodoSearcherAttributes.OBJECT_NAME_LABEL:
            searcherAttr.setObjectName(in.nextString());
            break;
        case KomodoSearcherAttributes.PARAMETERS_LABEL:
            Map<String, String> parameters = BUILDER.fromJson(in, Map.class);
            for (Map.Entry<String, String> parameter : parameters.entrySet()) {
                searcherAttr.setParameter(parameter.getKey(), parameter.getValue());
            }
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return searcherAttr;
}

From source file:org.komodo.rest.relational.json.StatusObjectSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*w  w w .  j  a  v a 2  s.co m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoStatusObject read(final JsonReader in) throws IOException {
    final KomodoStatusObject status = new KomodoStatusObject();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoStatusObject.TITLE_LABEL:
            status.setTitle(in.nextString());
            break;
        case KomodoStatusObject.INFO_LABEL:
            Map<String, String> attributes = BUILDER.fromJson(in, Map.class);
            status.setAttributes(attributes);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return status;
}

From source file:org.komodo.rest.relational.json.StorageAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*from   w  w  w .  j  ava2 s.  c om*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoStorageAttributes read(final JsonReader in) throws IOException {
    final KomodoStorageAttributes storageAttr = new KomodoStorageAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        if (readContent(in, storageAttr, name) != null)
            continue;

        switch (name) {
        case KomodoStorageAttributes.STORAGE_TYPE_LABEL:
            storageAttr.setStorageType(in.nextString());
            break;
        case KomodoStorageAttributes.ARTIFACT_PATH_LABEL:
            storageAttr.setArtifactPath(in.nextString());
            break;
        case KomodoStorageAttributes.PARAMETERS_LABEL:
            Map<String, String> parameters = BUILDER.fromJson(in, Map.class);
            for (Map.Entry<String, String> parameter : parameters.entrySet()) {
                storageAttr.setParameter(parameter.getKey(), parameter.getValue());
            }
            break;
        case KomodoStorageAttributes.DOCUMENT_TYPE_LABEL:
            String docTypeValue = in.nextString();
            DocumentType docType = DocumentType.documentType(docTypeValue);
            storageAttr.setDocumentType(docType);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageAttr;
}

From source file:org.komodo.rest.relational.json.StorageTypeDescriptorSerializer.java

License:Open Source License

@Override
public RestStorageTypeDescriptor read(JsonReader in) throws IOException {
    final RestStorageTypeDescriptor storageTypeDescriptor = new RestStorageTypeDescriptor();
    in.beginObject();/*ww  w  .  j av a2 s  . c o m*/

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestStorageTypeDescriptor.NAME_LABEL:
            storageTypeDescriptor.setName(in.nextString());
            break;
        case RestStorageTypeDescriptor.DESCRIPTION_LABEL:
            storageTypeDescriptor.setDescription(in.nextString());
            break;
        case RestStorageTypeDescriptor.REQUIRED_LABEL:
            storageTypeDescriptor.setRequired(in.nextBoolean());
            break;
        case RestStorageTypeDescriptor.ENCODED_LABEL:
            storageTypeDescriptor.setEncoded(in.nextBoolean());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageTypeDescriptor;
}

From source file:org.komodo.rest.relational.json.StorageTypeSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*w  w  w .ja v  a  2  s . c o m*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestStorageType read(final JsonReader in) throws IOException {
    final RestStorageType storageType = new RestStorageType();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestStorageType.NAME_LABEL:
            storageType.setName(in.nextString());
            break;
        case RestStorageType.DESCRIPTION_LABEL:
            storageType.setDescription(in.nextString());
            break;
        case RestStorageType.DESCRIPTORS_LABEL:
            RestStorageTypeDescriptor[] descriptors = BUILDER.fromJson(in, RestStorageTypeDescriptor[].class);
            storageType.setDescriptors(descriptors);
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return storageType;
}

From source file:org.komodo.rest.relational.json.TeiidAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//  ww w.j a v  a 2  s .  c om
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoTeiidAttributes read(final JsonReader in) throws IOException {
    final KomodoTeiidAttributes teiidAttrs = new KomodoTeiidAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoTeiidAttributes.ADMIN_USER_LABEL:
            teiidAttrs.setAdminUser(in.nextString());
            break;
        case KomodoTeiidAttributes.ADMIN_PASSWD_LABEL:
            teiidAttrs.setAdminPasswd(in.nextString());
            break;
        case KomodoTeiidAttributes.ADMIN_PORT_LABEL:
            teiidAttrs.setAdminPort(in.nextInt());
            break;
        case KomodoTeiidAttributes.ADMIN_SECURE_LABEL:
            teiidAttrs.setAdminSecure(in.nextBoolean());
            break;
        case KomodoTeiidAttributes.JDBC_USER_LABEL:
            teiidAttrs.setJdbcUser(in.nextString());
            break;
        case KomodoTeiidAttributes.JDBC_PASSWD_LABEL:
            teiidAttrs.setJdbcPasswd(in.nextString());
            break;
        case KomodoTeiidAttributes.JDBC_PORT_LABEL:
            teiidAttrs.setJdbcPort(in.nextInt());
            break;
        case KomodoTeiidAttributes.JDBC_SECURE_LABEL:
            teiidAttrs.setJdbcSecure(in.nextBoolean());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return teiidAttrs;
}

From source file:org.komodo.rest.relational.json.TeiidVdbStatusSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//from ww w . j  av  a 2s.  c  om
 *
 * @see org.komodo.rest.relational.json.AbstractEntitySerializer#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestTeiidVdbStatus read(final JsonReader in) throws IOException {
    final RestTeiidVdbStatus entity = createEntity();

    beginRead(in);

    while (in.hasNext()) {
        final String name = in.nextName();

        if (RestTeiidVdbStatus.VDBS_LABEL.equals(name)) {
            final RestTeiidVdbStatusVdb[] vdbStatuses = BUILDER.fromJson(in, RestTeiidVdbStatusVdb[].class);
            entity.setVdbProperties(Arrays.asList(vdbStatuses));
        } else if (LINKS.equals(name))
            readLinks(in, entity);
        else {
            JsonToken token = in.peek();
            switch (token) {
            case BOOLEAN:
                entity.addTuple(name, in.nextBoolean());
                break;
            case NUMBER:
                entity.addTuple(name, in.nextInt());
                break;
            case STRING:
                entity.addTuple(name, in.nextString());
                break;
            case NULL:
                in.nextNull();
                entity.addTuple(name, null);
                break;
            case BEGIN_ARRAY:
                final String[] value = BUILDER.fromJson(in, String[].class);
                entity.addTuple(name, value);
                break;
            default:
                throw new IOException(Messages.getString(Messages.Error.UNEXPECTED_JSON_TOKEN, name));
            }
        }
    }

    if (!isComplete(entity)) {
        throw new IOException(Messages.getString(INCOMPLETE_JSON, getClass().getSimpleName()));
    }

    endRead(in);
    return entity;
}

From source file:org.komodo.rest.relational.json.TeiidVdbStatusVdbSerializer.java

License:Open Source License

/**
 * {@inheritDoc}//w  w w. j a va2  s. c  o  m
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public RestTeiidVdbStatusVdb read(final JsonReader in) throws IOException {
    final RestTeiidVdbStatusVdb vdb = new RestTeiidVdbStatusVdb();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_NAME:
            vdb.setName(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_DEPLOYED_NAME:
            vdb.setDeployedName(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_VERSION:
            vdb.setVersion(in.nextString());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_ACTIVE:
            vdb.setActive(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_LOADING:
            vdb.setLoading(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_FAILED:
            vdb.setFailed(in.nextBoolean());
            break;
        case RestTeiidVdbStatusVdb.TEIID_VDB_STATUS_ERROR:
            final String[] errors = BUILDER.fromJson(in, String[].class);
            vdb.setErrors(Arrays.asList(errors));
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return vdb;
}

From source file:org.komodo.rest.relational.json.VdbUpdateAttributesSerializer.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  ww  . j ava  2  s .com*/
 *
 * @see com.google.gson.TypeAdapter#read(com.google.gson.stream.JsonReader)
 */
@Override
public KomodoVdbUpdateAttributes read(final JsonReader in) throws IOException {
    final KomodoVdbUpdateAttributes updateAttrs = new KomodoVdbUpdateAttributes();
    in.beginObject();

    while (in.hasNext()) {
        final String name = in.nextName();

        switch (name) {
        case KomodoVdbUpdateAttributes.VDB_NAME_LABEL:
            updateAttrs.setVdbName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.MODEL_NAME_LABEL:
            updateAttrs.setModelName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.TEIID_VDB_NAME_LABEL:
            updateAttrs.setTeiidVdbName(in.nextString());
            break;
        case KomodoVdbUpdateAttributes.TEIID_MODEL_NAME_LABEL:
            updateAttrs.setTeiidModelName(in.nextString());
            break;
        default:
            throw new IOException(Messages.getString(UNEXPECTED_JSON_TOKEN, name));
        }
    }

    in.endObject();

    return updateAttrs;
}