Package java.lang.reflect

Examples of java.lang.reflect.Field$FieldData


            return defaultValue;
        }

        Object cnstVal = null;
        try {
            Field fld = klass.getDeclaredField(cnst);
            try {
                cnstVal = fld.get(klass);
            } catch (IllegalAccessException e) {
                conf.warning("Property for object value constant " + key + ", field is not public: " + klassname +
                        "." + cnst);
                return defaultValue;
            }
View Full Code Here


    public static Field getField(final Class clazz, String field_name) {
        if(clazz == null || field_name == null)
            return null;

        Field field=null;
        for(Class curr=clazz; curr != null; curr=curr.getSuperclass()) {
            try {
                return curr.getDeclaredField(field_name);
            }
            catch(NoSuchFieldException e) {
View Full Code Here

                     if(value == null){
                       /*
                       *  Step 5.10.2.4.2: Read property value from object. If value null attempt to get it from default value.
                       */
                       try{
                           Field declaredField = getDeclaredField(clazz,name);
                           XmlElement   xmlElm   =  declaredField.getAnnotation(XmlElement.class);
                             if(xmlElm != null){
                               if(!xmlElm.defaultValue().equals(NULL) && isJSONPrimitive(propertyType)){
                                 value = xmlElm.defaultValue();
                               } else if(!xmlElm.nillable() && createDefaultOnNonNullable){
                                 if(!isJSONPrimitive(propertyType)){
                                   if(!stackNillableInstances.contains(propertyType)){
                                     stackNillableInstances.push(propertyType);
                                     value = getNewInstance(propertyType);
                                     hasData = this.add(name, value, null, hasData, property) || hasData;
                                     stackNillableInstances.pop();
                                   }
                                   continue nextProperty;
                                 }else{
                                   // Primitive don't have any default WHAT TODO . E.g. Integer object can't be instantiated.
                                 }
                               }
                             }
                         }catch(Throwable th){}
                         // Value still null
                         if(value == null && JSONCodec.excludeNullProperties && !this.metaDataMode){
                           continue nextProperty;
                         } else if(this.metaDataMode) {
                       // In meta data mode always get data via meta provider.
                       value = getMetaDataInstance(propertyType, accessor.getAnnotation(JSONWebService.class),
                              getDeclaredField(clazz,name));
                      }
                    }else if(this.metaDataMode && propertyType.isPrimitive()){
                      // Primitive meta data. In case like int value become 0. But it may be from default
                     value = getMetaDataInstance(propertyType, accessor.getAnnotation(JSONWebService.class),
                          getDeclaredField(clazz,name));
                    }
                     
                  /*
                     *  Step 5.10.2.4.3: read property custom config. If it is serializable continue process with specified name if any
                     */
                  JSONWebService properyConfig = accessor.getAnnotation(JSONWebService.class);
                   if (properyConfig != null) {
                         if (!properyConfig.serialize())
                             continue;
                         else if (properyConfig.name().length() > 0)
                             name = properyConfig.name();
                     }else{
                    /*
                     *  Step 5.10.2.4.4: JSON config not present. Then read XML configuration.
                     */   
                       try{
                        // XML annotation present at field level.
                         Field     declaredField   = getDeclaredField(clazz,name);
                         XmlElement   xmlElm       = declaredField.getAnnotation(XmlElement.class);
                          /*
                           *  Step 5.10.2.4.5: If XML transient ignore property.
                           */
                         if (declaredField.isAnnotationPresent(XmlMimeType.class)){
                           if(this.metaDataMode){
                             value  = declaredField.getAnnotation(XmlMimeType.class).value();
                           }else{
                             Map<String,Object> attachment = new HashMap<String, Object>();;
                             attachment .put("name", name);
                             attachment.put("value", value);
                             attachment.put("mimeType",declaredField.getAnnotation(XmlMimeType.class).value());
                             attachments   .add(attachment);
                             continue nextProperty;
                           }
                         } else if(xmlElm != null) {// MAjor hits are here
                           /*
                                *  Step 5.10.2.4.4.2: Xml elements .
                                */
                           if(!xmlElm.name().equals(XML_DEFAULT)){
                             name = xmlElm.name();
                           }
                         }else if(declaredField.isAnnotationPresent(XmlElements.class) && Collection.class.isAssignableFrom(declaredField.getType())
                             && value instanceof Collection){
                           // XML choice list
                             /*
                                *  Step 5.10.2.4.4.1: Is it XML choice list?. If assign find right element name.
                                */
                           XmlElements xmlElms =  declaredField.getAnnotation(XmlElements.class);
                           Collection<?> valueList = (Collection<?>)value;
                           if(!valueList.isEmpty()){
                             // use first object to identify type
                             ArrayList<Map<String,Object>> group = new ArrayList<Map<String,Object>>();
                             for(Object ob : valueList){
                               for(XmlElement elm : xmlElms.value()){
                                 // TODO JAXBElement
                                 if(((Class<?>)elm.type()).isAssignableFrom(ob.getClass())){
                                   Map<String,Object> objectMap = new HashMap<String, Object>();
                                   objectMap.put(elm.name(), ob);
                                   group.add(objectMap);
                                   break;// XmlElement list break
                                 }
                               }
                             }
                             hasData = this.add(name, group, null, hasData, property) || hasData;
                             continue nextProperty;
                           } else {
                             // If choice element id empty, don't print it at all
                             if(!this.metaDataMode){
                               continue nextProperty;
                             } else {
                               name  = "CHOICE";
                               Map<String,Object> choices     = new HashMap<String, Object>();
                               for(XmlElement elm : xmlElms.value()){
                                 try{
                                   choices.put(elm.name(), getMetaDataInstance(elm.type(),null,null));
                                 }catch(Throwable th){
                                   //
                                   choices.put(elm.name(),"object");
                                 }
                               }
                               value = choices;
                             }
                           }
                         }else if(declaredField.isAnnotationPresent(XmlElementRefs.class)
                             && Collection.class.isAssignableFrom(declaredField.getType())
                             && value instanceof Collection){
                           // XML choice list
                             /*
                                *  Step 5.10.2.4.4.1: Is it XML choice list?. If assign find right element name.
                                */
                           XmlElementRefs xmlElms =  declaredField.getAnnotation(XmlElementRefs.class);
                           Collection<?> valueList = (Collection<?>)value;
                           if(!valueList.isEmpty()){
                             // use first object to identify type
                             Map<String,List<Object>> group = new HashMap<String,List<Object>>();
                             for(Object ob : valueList){
                               for(XmlElementRef elm : xmlElms.value()) {
                                 if(ob instanceof JAXBElement<?>) {
                                   JAXBElement<?> element = (JAXBElement<?>)ob;
                                   if(element.getName().getLocalPart().equals(elm.name())){// namespace too
                                     name = elm.name();
                                     if(!group.containsKey(name))
                                       group.put(name, new ArrayList<Object>());
                                     group.get(name).add(element.getValue());
                                     break;// Break element list
                                   }
                                 } else {
                                   if(((Class<?>)elm.type()).isAssignableFrom(ob.getClass())){
                                     name = elm.name();
                                     if(!group.containsKey(name))
                                       group.put(name, new ArrayList<Object>());
                                     group.get(name).add(ob);
                                     break;// Break element list
                                   }
                                 }
                               }
                             }
                             for(Map.Entry<String, List<Object>> entry : group.entrySet()){
                               hasData = this.add(entry.getKey(), entry.getValue(), null, hasData, property) || hasData;
                                       // TODO this.setExprStack(expr);
                             }
                             continue nextProperty;
                           } else {
                             // If choice element id empty, don't print it at all
                             if(!this.metaDataMode){
                               continue nextProperty;
                             } else {
                               name  = "CHOICE";
                               Map<String,Object> choices     = new HashMap<String, Object>();
                               for(XmlElementRef elm : xmlElms.value()){
                                 try{
                                   choices.put(elm.name(), getMetaDataInstance(elm.type(),null,null));
                                 }catch(Throwable th){
                                   //
                                   choices.put(elm.name(),"object");
                                 }
                               }
                               value = choices;
                             }
                           }
                         } else if(declaredField.isAnnotationPresent(XmlAttribute.class)){
                           /*
                                *  Step 5.10.2.4.4.3: Xml attribute.
                                */
                           if(!declaredField.getAnnotation(XmlAttribute.class).name().equals(XML_DEFAULT)){
                             name = declaredField.getAnnotation(XmlAttribute.class).name();
                           }
                            
                         }else if(accessor.isAnnotationPresent(XmlTransient.class) ||
                             (declaredField != null && declaredField.isAnnotationPresent(XmlTransient.class))){
                           /**
                            * XmlTransient contains lower periority than XMLElementX annotation.
                            * Transient fields should not have XMLElement,XMLElements or XmlAttribute
                            */
                           continue nextProperty;
View Full Code Here

      Object object = clazz.newInstance();
      Iterator<Object> iter = props.keySet().iterator();
      while (iter.hasNext())
      {
         Object key = iter.next();
         Field field = getField(clazz, key.toString());
         if (field == null)
            continue;
         setValue(object, field, props.get(key));
      }
      return (Command)object;
View Full Code Here

      return null;
   }

   private Field getField(Class clazz, String name)
   {
      Field field = null;
      try
      {
         field = clazz.getDeclaredField(name);
      }
      catch (Exception e)
View Full Code Here

      // Temporary work around, to fix in MOP and then remove
      ChromatticSession session;
      try
      {
         Field f = ModelImpl.class.getDeclaredField("session");
         f.setAccessible(true);
         session = (ChromatticSession)f.get(model);
      }
      catch (Exception e)
      {
         throw new Error(e);
      }
View Full Code Here

        }
    }

    public static Field getField(final Class clazz, final String fieldName, final boolean accessible)
            throws NoSuchFieldException {
        final Field field;
        try {
            field = AccessController.<Field> doPrivileged(new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    Field f = clazz.getDeclaredField(fieldName);
                    f.setAccessible(accessible);
                    return f;
                }
            });
        } catch (PrivilegedActionException e) {
            throw new AssertionError(e.getCause());
View Full Code Here

            setField(obj, clazz, fieldName, value);
        }
    }

    public static void setField(final Object obj, final Class clazz, final String fieldName, final Object value) {
        final Field field;
        try {
            field = AccessController.<Field> doPrivileged(new PrivilegedExceptionAction<Field>() {
                public Field run() throws NoSuchFieldException {
                    Field f = clazz.getDeclaredField(fieldName);
                    f.setAccessible(true);
                    return f;
                }
            });
        } catch (PrivilegedActionException e) {
            throw new AssertionError(e.getCause());
View Full Code Here

     * @param fieldName the name of the field
     * @return an object representing the value of the field
     */
    public static Object getValue(Object instance, String fieldName) throws IllegalAccessException,
            NoSuchFieldException {
        Field field = _getField(instance.getClass(), fieldName);
        field.setAccessible(true);
        return field.get(instance);
    }
View Full Code Here

        pszPath,
        file.isDirectory() ? 16
            : FILE_ATTRIBUTE_NORMAL, shfi, SHFILEINFO_sizeof, flags
      });
 
      Field fldHIcon = claSHFILEINFO.getField("hIcon");
      if (fldHIcon.getLong(shfi) == 0) {
        return null;
      }
      Image image = null;
      if (useLong) {
        image = (Image) mImage_win32_new.invoke(null, new Object[] {
          null,
          SWT.ICON,
          fldHIcon.getLong(shfi)
        });
      } else {
        image = (Image) mImage_win32_new.invoke(null, new Object[] {
          null,
          SWT.ICON,
          fldHIcon.getInt(shfi)
        });
      }
     
      return image;
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of java.lang.reflect.Field$FieldData

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.