Package org.dcm4che3.conf.api.generic

Examples of org.dcm4che3.conf.api.generic.ConfigField


       
        Map<String,Object> cnode = new HashMap<String,Object>();
        for (Field classField : clazz.getDeclaredFields()) {

            // if field is not annotated, skip it
            ConfigField fieldAnno = (ConfigField) classField.getAnnotation(ConfigField.class);
            if (fieldAnno == null)
                continue;

            // read a configuration value using its getter
            Object value;

            try {
                value = PropertyUtils.getSimpleProperty(obj, classField.getName());
            } catch (Exception e) {
                throw new ConfigurationException("Error while writing configuration field " + fieldAnno.name(), e);
            }

            // find typeadapter
            ConfigTypeAdapter customRep = config.lookupTypeAdapter(classField.getType());

            if (customRep != null) {
                Object serialized = customRep.serialize(value, config, classField);
                cnode.put(fieldAnno.name(), serialized);
            } else {
                throw new ConfigurationException("Corresponding 'writer' was not found for field " + fieldAnno.name());
            }

        }
        return cnode;
View Full Code Here


    @Override
    public Map<String,Object> read(ReflectiveConfig config, ConfigReader reader, Field field) throws ConfigurationException {

        // if this object is a property, get a child
        if (field != null && field.getType().equals(clazz)) {
            ConfigField fieldAnno = (ConfigField) field.getAnnotation(ConfigField.class);
            reader = reader.getChildReader(fieldAnno.name());
        }

        Map<String,Object> cnode = new HashMap<String,Object>();
        for (Field classField : clazz.getDeclaredFields()) {

            // if field is not annotated, skip it
            ConfigField fieldAnno = (ConfigField) classField.getAnnotation(ConfigField.class);
            if (fieldAnno == null)
                continue;

            // find typeadapter
            ConfigTypeAdapter customRep = config.lookupTypeAdapter(classField.getType());

            if (customRep != null) {
                try {
                    Object value = customRep.read(config, reader, classField);
                    cnode.put(fieldAnno.name(), value);
                } catch (ConfigurationNotFoundException e) {
                    if (fieldAnno.failIfNotPresent()) throw e;
                }
            } else
                throw new ConfigurationException("Corresponding 'reader' was not found for field " + fieldAnno.name());
        }

        return cnode;
    }
View Full Code Here

            confObj = providedConfObj;

        for (Field classField : clazz.getDeclaredFields()) {

            // if field is not annotated, skip it
            ConfigField fieldAnno = (ConfigField) classField.getAnnotation(ConfigField.class);
            if (fieldAnno == null)
                continue;

            // find typeadapter
            ConfigTypeAdapter customRep = config.lookupTypeAdapter(classField.getType());

            if (customRep != null) {
                try {
                    Object value = customRep.deserialize(serialized.get(fieldAnno.name()), config, classField);

                    // set using a setter, exception is when failIfNotPresent is false and there were no value
                    if (value != null || fieldAnno.failIfNotPresent())
                        PropertyUtils.setSimpleProperty(confObj, classField.getName(), value);
                } catch (Exception e) {
                    throw new ConfigurationException("Error while reading configuration field " + fieldAnno.name(), e);
                }

            } else
                throw new ConfigurationException("Corresponding 'reader' was not found for field " + fieldAnno.name());

        }

        return confObj;
View Full Code Here

    @Override
    public void merge(T prev, T curr, ReflectiveConfig config, ConfigWriter diffwriter, Field field) throws ConfigurationException {

        // if this object is a property, get a child
        if (field != null && field.getType().equals(clazz)) {
            ConfigField fieldAnno = (ConfigField) field.getAnnotation(ConfigField.class);
           
            if (prev == null) {
                write(serialize(curr, config, field), config, diffwriter, field);
                return;
            } else
            if (curr == null) {
                diffwriter.getChildWriter(fieldAnno.name(), field).removeCurrentNode();
                return;
            }

            diffwriter = diffwriter.getChildWriter(fieldAnno.name(), field);

        }

        // look through all fields of the config class, not including
        // superclass fields
        for (Field classField : clazz.getDeclaredFields()) {

            // if field is not annotated, skip it
            ConfigField fieldAnno = (ConfigField) classField.getAnnotation(ConfigField.class);
            if (fieldAnno == null)
                continue;

            try {

                Object prevProp = PropertyUtils.getSimpleProperty(prev, classField.getName());
                Object currProp = PropertyUtils.getSimpleProperty(curr, classField.getName());

                // find adapter
                ConfigTypeAdapter customRep = config.lookupTypeAdapter(classField.getType());

                customRep.merge(prevProp, currProp, config, diffwriter, classField);

            } catch (Exception e) {
                throw new ConfigurationException("Cannot store diff for field " + fieldAnno.name(), e);
            }

        }

        // do actual merge
View Full Code Here

       
        // go through all annotated fields
        for (Field classField : clazz.getDeclaredFields()) {

            // if field is not annotated, skip it
            ConfigField fieldAnno = (ConfigField) classField.getAnnotation(ConfigField.class);
            if (fieldAnno == null)
                continue;

            // save metadata
            Map<String, Object> fieldMetaData = new HashMap<String, Object>();
            classMetaData.put(fieldAnno.name(), fieldMetaData);

            fieldMetaData.put("label", fieldAnno.label());
            fieldMetaData.put("description", fieldAnno.description());
            fieldMetaData.put("optional", fieldAnno.optional());
           
            // find typeadapter
            ConfigTypeAdapter customRep = config.lookupTypeAdapter(classField.getType());

            if (customRep != null) {
View Full Code Here

            return obj;
        }

        @Override
        public void write(T serialized, ReflectiveConfig config, ConfigWriter writer, Field field) throws ConfigurationException {
            ConfigField fieldAnno = field.getAnnotation(ConfigField.class);

            if (!fieldAnno.def().equals("N/A"))
                writer.storeNotDef(fieldAnno.name(), serialized, fieldAnno.def());
            else
                writer.storeNotNull(fieldAnno.name(), serialized);
        }
View Full Code Here

                writer.storeNotNull(fieldAnno.name(), serialized);
        }

        @Override
        public void merge(T prev, T curr, ReflectiveConfig config, ConfigWriter diffwriter, Field field) throws ConfigurationException {
            ConfigField fieldAnno = field.getAnnotation(ConfigField.class);

            T prevSerialized = serialize(prev, config, field);
            T currSerialized = serialize(curr, config, field);

            diffwriter.storeDiff(fieldAnno.name(), prevSerialized, currSerialized);
        }
View Full Code Here

            return false;
        }

        @Override
        public String read(ReflectiveConfig config, ConfigReader reader, Field field) throws ConfigurationException {
            ConfigField fieldAnno = field.getAnnotation(ConfigField.class);
            return reader.asString(fieldAnno.name(), null);
        }
View Full Code Here

            return reader.asString(fieldAnno.name(), null);
        }

        @Override
        public void write(String serialized, ReflectiveConfig config, ConfigWriter writer, Field field) {
            ConfigField fieldAnno = field.getAnnotation(ConfigField.class);
            writer.storeNotNull(fieldAnno.name(), serialized);
        }
View Full Code Here

            writer.storeNotNull(fieldAnno.name(), serialized);
        }

        @Override
        public void merge(T prev, T curr, ReflectiveConfig config, ConfigWriter diffwriter, Field field) throws ConfigurationException {
            ConfigField fieldAnno = field.getAnnotation(ConfigField.class);

            String prevSerialized = serialize(prev, config, field);
            String currSerialized = serialize(curr, config, field);

            diffwriter.storeDiff(fieldAnno.name(), prevSerialized, currSerialized);
        }
View Full Code Here

TOP

Related Classes of org.dcm4che3.conf.api.generic.ConfigField

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.