com.google.web.bindery.autobean.shared.AutoBeanCodex Java Examples

The following examples show how to use com.google.web.bindery.autobean.shared.AutoBeanCodex. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Index.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public void add(final String token, final Set<String> keywords, final String description) {
    long id = idCounter++;

    Document document = beanFactory.indexDocument().as();
    document.setId(id);
    document.setToken(token);
    document.setDescription(description);
    document.setKeywords(keywords);
    AutoBean<Document> autoBean = AutoBeanUtils.getAutoBean(document);
    String json = AutoBeanCodex.encode(autoBean).getPayload();
    localStorage.setItem(key(id), json);

    String keywordsValue = null;
    if (keywords != null && !keywords.isEmpty()) {
        StringBuilder builder = new StringBuilder();
        for (Iterator<String> iterator = keywords.iterator(); iterator.hasNext(); ) {
            String keyword = iterator.next();
            builder.append(keyword);
            if (iterator.hasNext()) {
                builder.append(" ");
            }
        }
        keywordsValue = builder.toString();
    }
    addInternal(String.valueOf(id), token, keywordsValue, description);
}
 
Example #2
Source File: Index.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public List<Document> search(final String text) {
    List<Document> results = new ArrayList<Document>();
    JsArray jsonResult = searchInternal(text);
    if (jsonResult != null) {
        for (int i = 0; i < jsonResult.length(); i++) {
            JSONObject json = new JSONObject(jsonResult.get(i));
            JSONString jsonId = json.get("ref").isString();
            if (jsonId != null) {
                long id = Long.parseLong(jsonId.stringValue());
                String documentJson = localStorage.getItem(key(id));
                if (documentJson != null) {
                    AutoBean<Document> autoBean = AutoBeanCodex.decode(beanFactory, Document.class, documentJson);
                    results.add(autoBean.as());
                }
            }
        }
    }
    return results;
}
 
Example #3
Source File: BootstrapServerStore.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public List<BootstrapServer> load() {
    List<BootstrapServer> servers = new ArrayList<BootstrapServer>();
    if (storage != null) {
        //noinspection MismatchedQueryAndUpdateOfCollection
        StorageMap storageMap = new StorageMap(storage);
        if (storageMap.containsKey(KEY)) {
            String json = storageMap.get(KEY);
            if (json != null) {
                JSONValue jsonValue = JSONParser.parseStrict(json);
                if (jsonValue != null) {
                    JSONArray jsonArray = jsonValue.isArray();
                    if (jsonArray != null) {
                        for (int i = 0; i < jsonArray.size(); i++) {
                            AutoBean<BootstrapServer> bean = AutoBeanCodex
                                    .decode(factory, BootstrapServer.class, jsonArray.get(i).toString());
                            servers.add(bean.as());
                        }
                    }
                }
            }
        }
    }
    return servers;
}
 
Example #4
Source File: BootstrapServerStore.java    From core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public BootstrapServer restoreSelection() {
    if (storage != null) {
        //noinspection MismatchedQueryAndUpdateOfCollection
        StorageMap storageMap = new StorageMap(storage);
        if (storageMap.containsKey(KEY)) {
            String json = storageMap.get(SELECTED);
            if (json != null) {
                JSONValue jsonValue = JSONParser.parseStrict(json);
                if (jsonValue != null) {
                    JSONObject jsonObject = jsonValue.isObject();
                    if (jsonObject != null) {
                        AutoBean<BootstrapServer> bean = AutoBeanCodex
                                .decode(factory, BootstrapServer.class, jsonObject.toString());
                        return bean.as();
                    }
                }
            }
        }
    }
    return null;
}
 
Example #5
Source File: AuditLogItemDataProvider.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private AuditLogItem parseItem(final MatchResult match) {
    String date = match.getGroup(1);
    AutoBean<AuditLogItem> itemBean = AutoBeanCodex.decode(beanFactory, AuditLogItem.class, match.getGroup(2));
    AuditLogItem item = itemBean.as();
    item.setId(idCounter++);
    item.setDate(date);
    return item;
}
 
Example #6
Source File: BootstrapServerStore.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private String toJson(List<BootstrapServer> servers) {
    StringBuilder json = new StringBuilder("[");
    for (Iterator<BootstrapServer> iterator = servers.iterator(); iterator.hasNext(); ) {
        BootstrapServer server = iterator.next();
        AutoBean<BootstrapServer> bean = AutoBeanUtils.getAutoBean(server);
        json.append(AutoBeanCodex.encode(bean).getPayload());
        if (iterator.hasNext()) {
            json.append(",");
        }
    }
    json.append("]");
    return json.toString();
}
 
Example #7
Source File: GeoJsonUtils.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static GeoJsonGeometry decodeGeometry(Splittable data) {
	ensureFactory();
	
	return AutoBeanCodex.decode(sFactory, GeoJsonGeometry.class, data).as();
}
 
Example #8
Source File: GeoJsonUtils.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static GeoJsonFeature decodeFeature(Splittable data) {
	ensureFactory();
	
	return AutoBeanCodex.decode(sFactory, GeoJsonFeature.class, data).as();
}
 
Example #9
Source File: GeoJsonUtils.java    From jts with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static GeoJsonFeatureCollection decodeFeatureCollection(Splittable data) {
	ensureFactory();
	
	return AutoBeanCodex.decode(sFactory, GeoJsonFeatureCollection.class, data).as();
}
 
Example #10
Source File: JsonAutoBeanGenerator.java    From requestor with Apache License 2.0 4 votes vote down vote up
private SourceWriter getSourceWriter(TreeLogger logger, GeneratorContext ctx, JClassType intfType) {
    JPackage serviceIntfPkg = intfType.getPackage();
    String packageName = serviceIntfPkg == null ? "" : serviceIntfPkg.getName();
    PrintWriter printWriter = ctx.tryCreate(logger, packageName, getTypeSimpleName());
    if (printWriter == null) {
        return null;
    }

    ClassSourceFileComposerFactory composerFactory =
            new ClassSourceFileComposerFactory(packageName, getTypeSimpleName());

    String[] imports = new String[]{
            // java.util
            ArrayList.class.getCanonicalName(),
            Collection.class.getCanonicalName(),
            List.class.getCanonicalName(),
            Iterator.class.getCanonicalName(),
            Set.class.getCanonicalName(),
            // com.google.gwt.core.client
            GWT.class.getCanonicalName(),
            // com.google.web.bindery.autobean.shared
            AutoBean.class.getCanonicalName(),
            AutoBeanCodex.class.getCanonicalName(),
            AutoBeanFactory.class.getCanonicalName(),
            AutoBeanUtils.class.getCanonicalName(),
            // io.reinert.requestor.serialization
            DeserializationContext.class.getCanonicalName(),
            Deserializer.class.getCanonicalName(),
            HasImpl.class.getCanonicalName(),
            Serdes.class.getCanonicalName(),
            Serializer.class.getCanonicalName(),
            SerializationContext.class.getCanonicalName(),
            UnableToDeserializeException.class.getName(),
            UnableToSerializeException.class.getName(),
            // io.reinert.requestor.serialization.json
            JsonObjectSerdes.class.getCanonicalName(),
            JsonRecordReader.class.getCanonicalName(),
            JsonRecordWriter.class.getCanonicalName(),
    };

    for (String imp : imports) {
        composerFactory.addImport(imp);
    }

    composerFactory.addImplementedInterface(intfType.getErasedType().getQualifiedSourceName());

    return composerFactory.createSourceWriter(ctx, printWriter);
}
 
Example #11
Source File: BootstrapServerStore.java    From core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private String toJson(BootstrapServer server) {
    AutoBean<BootstrapServer> bean = AutoBeanUtils.getAutoBean(server);
    return AutoBeanCodex.encode(bean).getPayload();
}