Package com.addthis.codec.reflection

Examples of com.addthis.codec.reflection.CodableClassInfo


                    ConfigObject onlyObject = resolvedConfig.root().withOnlyKey(onlyUnusedKey);
                    if (resolvedConfig.hasPath(primaryFieldName)) {
                        onlyObject = onlyObject.withFallback(
                                resolvedConfig.getValue(primaryFieldName).atKey(onlyUnusedKey));
                    }
                    CodableClassInfo primaryInfo = getOrCreateClassInfo(
                            field.getTypeOrComponentType());
                    PluginMap primaryMap = primaryInfo.getPluginMap();
                    value = hydrateSingleKeyObject(primaryMap, onlyObject);
                    if (value != null) {
                        usedPrimaryField = true;
                    } else {
                        throw new ConfigException.BadPath(config.origin(), "unrecognized key(s) " + unusedKeys.toString());
View Full Code Here


        }
    }

    // like the one in Fields.java, but non-static and using a possibly non-default registry
    CodableClassInfo getOrCreateClassInfo(Class<?> clazz) {
        CodableClassInfo fieldMap = fieldMaps.get(clazz);
        if (fieldMap == null) {
            fieldMap = new CodableClassInfo(clazz, globalConfig, pluginRegistry);
            fieldMaps.put(clazz, fieldMap);
        }
        return fieldMap;
    }
View Full Code Here

    /**
     * Instantiate an object of the requested type using the provided config.
     */
    public <T> T decodeObject(Class<T> type, Config config) {
        CodableClassInfo classInfo = getOrCreateClassInfo(type);
        return hydrateObject(classInfo, classInfo.getPluginMap(), type, config.root());
    }
View Full Code Here

        }
    }

    /** called when the expected type is a non-standard object */
    private <T> T hydrateObject(Class<T> type, ConfigValue configValue) {
        CodableClassInfo info = getOrCreateClassInfo(type);
        PluginMap pluginMap = info.getPluginMap();
        return hydrateObject(info, pluginMap, type, configValue);
    }
View Full Code Here

        }
    }

    // like the one in Fields.java, but non-static and using a possibly non-default registry
    private CodableClassInfo getOrCreateClassInfo(Class<?> clazz) {
        CodableClassInfo fieldMap = fieldMaps.get(clazz);
        if (fieldMap == null) {
            fieldMap = new CodableClassInfo(clazz, globalConfig, pluginRegistry);
            fieldMaps.put(clazz, fieldMap);
        }
        return fieldMap;
    }
View Full Code Here

        if ((type != null) && type.isAssignableFrom(ConfigValue.class)) {
            return ConfigValueFactory.fromAnyRef(config.unwrapped(),
                                                 "unchanged for raw ConfigValue field "
                                                 + config.origin().description());
        }
        CodableClassInfo typeInfo = new CodableClassInfo(type, pluginRegistry.config(), pluginRegistry);
        PluginMap pluginMap = typeInfo.getPluginMap();
        ConfigValue valueOrResolvedRoot = resolveType(type, config, pluginMap);
        if (valueOrResolvedRoot.valueType() != ConfigValueType.OBJECT) {
            return valueOrResolvedRoot;
        }
        ConfigObject root = (ConfigObject) valueOrResolvedRoot;
View Full Code Here

        return expandSugarSkipResolve(type, root, pluginRegistry);
    }

    private static ConfigObject expandSugarSkipResolve(Class<?> type, ConfigObject root,
                                                       PluginRegistry pluginRegistry) {
        CodableClassInfo resolvedTypeInfo = new CodableClassInfo(type, pluginRegistry.config(), pluginRegistry);
        ConfigObject fieldDefaults = resolvedTypeInfo.getFieldDefaults().root();
        for (CodableFieldInfo fieldInfo : resolvedTypeInfo.values()) {
            String fieldName = fieldInfo.getName();
            ConfigValue fieldValue = root.get(fieldName);
            if ((fieldValue == null) && (fieldDefaults.get(fieldName) != null)) {
                ConfigValue fieldDefault = fieldDefaults.get(fieldName);
                fieldValue = ConfigValueFactory.fromAnyRef(
View Full Code Here

        try {
            if (object instanceof SuperCodable) {
                ((SuperCodable) object).preEncode();
            }
            Class objectClass = object.getClass();
            CodableClassInfo classInfo = Fields.getClassFieldMap(objectClass);
            if (objectClass.isArray()) {
                encodeArray(object, objectClass, buf);
            } else if ((classInfo.size() == 0) && !(object instanceof Codable)) {
                encodeNative(object, buf);
            } else {
                buf.out.write(1);
                writeStringHelper(classInfo.getClassName(object), buf.out());
                for (CodableFieldInfo field : classInfo.values()) {
                    encodeField(field.get(object), field, buf);
                }
            }
        } finally {
            if (lock) {
View Full Code Here

    @Nullable private Object decodeObject(Class<?> type, BufferIn buf) throws Exception {
        log.trace("decodeObject: {} {}", type, buf);
        if (Fields.isNative(type)) {
            return decodeNative(type, buf);
        } else {
            CodableClassInfo classInfo = Fields.getClassFieldMap(type);
            return decodeObject(classInfo, null, buf);
        }
    }
View Full Code Here

        try {
            if (object instanceof SuperCodable) {
                ((SuperCodable) object).preEncode();
            }
            Class objectClass = object.getClass();
            CodableClassInfo classInfo = Fields.getClassFieldMap(objectClass);
            if (objectClass.isArray()) {
                encodeArray(object, objectClass, buf);
            } else if (classInfo.size() == 0 && !(object instanceof Codable)) {
                encodeNative(object, buf);
            } else {
                buf.out.write(1);
                writeStringHelper(classInfo.getClassName(object), buf.out());
                for (Iterator<CodableFieldInfo> fields = classInfo.values().iterator(); fields.hasNext();) {
                    CodableFieldInfo field = fields.next();
                    long beginSize = buf.out.size();
                    encodeField(field.get(object), field, buf, statistics);
                    if (statistics != null) {
                        long endSize = buf.out.size();
View Full Code Here

TOP

Related Classes of com.addthis.codec.reflection.CodableClassInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.