Package com.cloudhopper.commons.util.annotation

Examples of com.cloudhopper.commons.util.annotation.MetaField


                // is this field marked as a MetaField?
                if (f.isAnnotationPresent(MetaField.class)) {

                    // get the annotation
                    MetaField metaField = f.getAnnotation(MetaField.class);

                    // create the new counter info object we'll store
                    // now, this class may actually still represent a class we want to recursively search
                    // we'll create the new info object for now, but this may change
                    MetaFieldInfo info = new MetaFieldInfo();
                   
                    // save the field name
                    info.fieldName = f.getName();
                    // save the field class
                    info.fieldClass = f.getType();
                    // save the level
                    info.level = metaField.level();

                    // is there an annotated name? if not we'll default to the field name
                    info.name = preFieldName + (!metaField.name().equals("") && !ignoreAnnotatedName ? metaField.name() : f.getName()) + postFieldName;

                    // default the recursive pre field names
                    String recursivePreFieldName = preFieldName + f.getName() + ".";
                    String recursivePostFieldName = "";
                   
                    // if this had an actual name, not using the field name, slightly diff format
                    if (!metaField.name().equals("") && !ignoreAnnotatedName) {
                        // only add [ and ] if this is not the first
                        if (!preFieldName.equals("")) {
                            recursivePreFieldName = preFieldName + metaField.name() + "][";
                            recursivePostFieldName = "]";
                        } else {
                            recursivePreFieldName = metaField.name() + "[";
                            recursivePostFieldName = "]";
                        }
                    }

                    // required to read private variables
                    f.setAccessible(true);

                    // read the actual value if the obj isn't null
                    if (obj != null) {
                        // get the actual value
                        try {
                            info.actualValue = f.get(obj);
                        } catch (Exception e) {
                            logger.error("impossible case if run outside of an applet");
                        }

                        //
                        // handle "unwrapping" objects -- AtomicReference
                        //
                        if (info.actualValue != null && f.getType().equals(AtomicReference.class)) {
                            //logger.debug("AtomicReference found, going to unwrap it");
                            AtomicReference ref = (AtomicReference)info.actualValue;
                            // get the actual underlying value
                            info.actualValue = ref.get();
                            // if not null, we can get its type too
                            if (info.actualValue != null) {
                                info.fieldClass = info.actualValue.getClass();
                            }
                        }
                       
                    } else {
                        info.actualValue = null;
                    }

                    // get a proper string value of this counter
                    if (info.actualValue == null) {
                        info.value = stringForNullValues;
                    } else {
                        info.value = info.actualValue.toString();
                    }
                   
                    // add our annotated description
                    info.description = metaField.description();

                    // if this is recursive, we need to check of the subvalues are actually wanted instead...
                    // if the actual value is null though, we know the sub-values are null...
                    if (recursive) {
                        // see if there are any MetaFields in the sub-object
View Full Code Here

TOP

Related Classes of com.cloudhopper.commons.util.annotation.MetaField

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.