Example usage for java.lang NoSuchFieldException NoSuchFieldException

List of usage examples for java.lang NoSuchFieldException NoSuchFieldException

Introduction

In this page you can find the example usage for java.lang NoSuchFieldException NoSuchFieldException.

Prototype

public NoSuchFieldException(String s) 

Source Link

Document

Constructor with a detail message.

Usage

From source file:gc.david.dfm.ui.activity.MainActivity.java

private void handleGeoSchemeIntent(final Uri uri) {
    final String schemeSpecificPart = uri.getSchemeSpecificPart();
    final Matcher matcher = getMatcherForUri(schemeSpecificPart);
    if (matcher.find()) {
        if (matcher.group(1).equals("0") && matcher.group(2).equals("0")) {
            if (matcher.find()) { // Manage geo:0,0?q=lat,lng(label)
                setDestinationPosition(matcher);
            } else { // Manage geo:0,0?q=my+street+address
                String destination = Uri.decode(uri.getQuery()).replace('+', ' ');
                destination = destination.replace("q=", "");

                // TODO check this ugly workaround
                addressPresenter.searchPositionByName(destination);
                searchMenuItem.collapseActionView();
                mustShowPositionWhenComingFromOutside = true;
            }/*www.  j a va  2  s .co  m*/
        } else { // Manage geo:latitude,longitude or geo:latitude,longitude?z=zoom
            setDestinationPosition(matcher);
        }
    } else {
        final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                "Error al obtener las coordenadas. Matcher = " + matcher.toString());
        DFMLogger.logException(noSuchFieldException);
        toastIt("Unable to parse address", this);
    }
}

From source file:org.jaffa.flexfields.FlexBean.java

/**
 * Get the original value for this field, throw an error if this field has no
 * changed, so you should consider first checking with the  {@link #hasChanged(String)}
 * method/*from w  w  w  . j  av a 2 s  .c o m*/
 *
 * @param name Name of bean property to check
 * @return The object representing the original values. Primitives are return as their
 * Object counterparts.
 * @throws NoSuchFieldException Throw if the property has not been changed, or does not exist.
 */
public Object getOriginalValue(String name) throws NoSuchFieldException {
    if (changes.containsKey(name))
        return changes.get(name);
    else
        throw new NoSuchFieldException(name);
}

From source file:gc.david.dfm.ui.activity.MainActivity.java

private void handleMapsHostIntent(final Uri uri) {
    final String queryParameter = uri.getQueryParameter("q");
    if (queryParameter != null) {
        final Matcher matcher = getMatcherForUri(queryParameter);
        if (matcher.find()) {
            setDestinationPosition(matcher);
        } else {//  ww w  . j ava  2s  .c o m
            final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                    "Error al obtener las coordenadas. Matcher = " + matcher.toString());
            DFMLogger.logException(noSuchFieldException);
            toastIt("Unable to parse address", this);
        }
    } else {
        final NoSuchFieldException noSuchFieldException = new NoSuchFieldException("Query sin parmetro q.");
        DFMLogger.logException(noSuchFieldException);
        toastIt("Unable to parse address", this);
    }
}

From source file:gc.david.dfm.ui.MainActivity.java

/**
 * Handles a send intent with position data.
 *
 * @param intent Input intent with position data.
 *//*ww  w.  ja  v a  2 s .com*/
private void handleViewPositionIntent(final Intent intent) throws Exception {
    Mint.leaveBreadcrumb("MainActivity::handleViewPositionIntent");
    final Uri uri = intent.getData();
    Mint.addExtraData("queryParameter", uri.toString());

    final String uriScheme = uri.getScheme();
    if (uriScheme.equals("geo")) {
        final String schemeSpecificPart = uri.getSchemeSpecificPart();
        final Matcher matcher = getMatcherForUri(schemeSpecificPart);
        if (matcher.find()) {
            if (matcher.group(1).equals("0") && matcher.group(2).equals("0")) {
                if (matcher.find()) { // Manage geo:0,0?q=lat,lng(label)
                    setDestinationPosition(matcher);
                } else { // Manage geo:0,0?q=my+street+address
                    String destination = Uri.decode(uri.getQuery()).replace('+', ' ');
                    destination = destination.replace("q=", "");

                    // TODO check this ugly workaround
                    new SearchPositionByName().execute(destination);
                    mustShowPositionWhenComingFromOutside = true;
                }
            } else { // Manage geo:latitude,longitude or geo:latitude,longitude?z=zoom
                setDestinationPosition(matcher);
            }
        } else {
            final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                    "Error al obtener las coordenadas. Matcher = " + matcher.toString());
            Mint.logException(noSuchFieldException);
            throw noSuchFieldException;
        }
    } else if ((uriScheme.equals("http") || uriScheme.equals("https"))
            && (uri.getHost().equals("maps.google.com"))) { // Manage maps.google.com?q=latitude,longitude

        final String queryParameter = uri.getQueryParameter("q");
        if (queryParameter != null) {
            final Matcher matcher = getMatcherForUri(queryParameter);
            if (matcher.find()) {
                setDestinationPosition(matcher);
            } else {
                final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                        "Error al obtener las coordenadas. Matcher = " + matcher.toString());
                Mint.logException(noSuchFieldException);
                throw noSuchFieldException;
            }
        } else {
            final NoSuchFieldException noSuchFieldException = new NoSuchFieldException(
                    "Query sin parmetro q.");
            Mint.logException(noSuchFieldException);
            throw noSuchFieldException;
        }
    } else {
        final Exception exception = new Exception("Imposible tratar la query " + uri.toString());
        Mint.logException(exception);
        throw exception;
    }
}

From source file:org.jgentleframework.utils.ReflectUtils.java

/**
 * Tm kim v tr v? field tng ng trong mt class ch nh. <br>
 * <br>//from w  w  w .jav a  2 s. com
 * <b>Lu :</b> Hm s t ng tm trong <code>object class</code> ch
 * nh, nu khng c s tm tm tip trong cc <code>SuperClass</code> ca
 * n.
 * 
 * @param cls
 *            i tng <code>object class</code> truy vn
 *            <code>field</code>.
 * @param name
 *            tn ca field cn tm.
 * @return tr v? field tm c.
 * @throws NoSuchFieldException
 *             nm ra ngoi l nu nh khng c field no trong object class
 *             ch nh ng vi tn name cung cp.
 */
public static Field getSupportedField(Class<?> cls, String name) throws NoSuchFieldException {

    if (cls != null) {
        try {
            return cls.getDeclaredField(name);
        } catch (NoSuchFieldException e) {
            return getSupportedField(cls.getSuperclass(), name);
        }
    } else {
        throw new NoSuchFieldException("Could not find the field ['" + name + "'] !");
    }
}

From source file:eu.qualityontime.commons.QPropertyUtilsBean.java

public Object _getMappedProperty(final Object bean, final String name, final String key) throws Exception {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }//from ww w .j a  v a  2  s .c  o m
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }
    if (key == null) {
        throw new IllegalArgumentException(
                "No key specified for property '" + name + "' on bean class " + bean.getClass() + "'");
    }

    Object result = null;

    if (name.startsWith("@")) {
        Object invokeResult = FieldUtils.readField(bean, trimAnnotations(name));
        if (null == invokeResult) {
            if (name.endsWith("?"))
                return null;
            else
                throw new NestedNullException();
        }
        if (invokeResult instanceof java.util.Map) {
            return ((java.util.Map<?, ?>) invokeResult).get(key);
        } else
            throw new NoSuchFieldException("Field '" + name + "' is not mapped in '" + bean.getClass() + "'");
    }
    // Retrieve the property descriptor for the specified property
    final PropertyDescriptor descriptor = getPropertyDescriptor(bean, trimAnnotations(name));
    if (descriptor == null) {
        throw new NoSuchMethodException(
                "Unknown property '" + name + "'+ on bean class '" + bean.getClass() + "'");
    } else if (descriptor instanceof MappedPropertyDescriptor) {
        // Call the keyed getter method if there is one
        Method readMethod = ((MappedPropertyDescriptor) descriptor).getMappedReadMethod();
        readMethod = MethodUtils.getAccessibleMethod(bean.getClass(), readMethod);
        if (readMethod != null) {
            final Object[] keyArray = new Object[1];
            keyArray[0] = key;
            result = invokeMethod(readMethod, bean, keyArray);
        } else {
            throw new NoSuchMethodException("Property '" + name
                    + "' has no mapped getter method on bean class '" + bean.getClass() + "'");
        }
    } else {
        /* means that the result has to be retrieved from a map */
        final Method readMethod = getReadMethod(bean.getClass(), descriptor);
        if (readMethod != null) {
            final Object invokeResult = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
            /* test and fetch from the map */
            if (invokeResult instanceof java.util.Map) {
                result = ((java.util.Map<?, ?>) invokeResult).get(key);
            }
        } else {
            throw new NoSuchMethodException("Property '" + name
                    + "' has no mapped getter method on bean class '" + bean.getClass() + "'");
        }
    }
    return result;

}

From source file:eu.qualityontime.commons.QPropertyUtilsBean.java

public Object _getSimpleProperty(final Object bean, final String name) throws Exception {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }/*ww  w .  j a v a  2s  .  co m*/
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }

    // Validate the syntax of the property name
    if (resolver.hasNested(name)) {
        throw new IllegalArgumentException("Nested property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    } else if (resolver.isIndexed(name)) {
        throw new IllegalArgumentException("Indexed property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    } else if (resolver.isMapped(name)) {
        throw new IllegalArgumentException("Mapped property names are not allowed: Property '" + name
                + "' on bean class '" + bean.getClass() + "'");
    }

    if (name.startsWith("@")) {
        final String fieldName = trimAnnotations(name);
        final Field f = FieldUtils.findField(bean.getClass(), fieldName);
        if (null == f) {
            throw new NoSuchFieldException("field `" + fieldName + "` not found");
        }
        f.setAccessible(true);
        return f.get(bean);
    } else {
        // Retrieve the property getter method for the specified property
        final PropertyDescriptor descriptor = getPropertyDescriptor(bean, trimAnnotations(name));
        if (descriptor == null) {
            throw new NoSuchMethodException(
                    "Unknown property '" + name + "' on class '" + bean.getClass() + "'");
        }
        final Method readMethod = getReadMethod(bean.getClass(), descriptor);
        if (readMethod == null) {
            throw new NoSuchMethodException(
                    "Property '" + name + "' has no getter method in class '" + bean.getClass() + "'");
        }

        // Call the property getter and return the value
        final Object value = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
        return value;
    }

}

From source file:eu.qualityontime.commons.QPropertyUtilsBean.java

public void _setMappedProperty(final Object bean, final String name, final String key, final Object value)
        throws Exception {

    if (bean == null) {
        throw new IllegalArgumentException("No bean specified");
    }/*from w  w  w .  j  av a2  s  .c o m*/
    if (name == null) {
        throw new IllegalArgumentException("No name specified for bean class '" + bean.getClass() + "'");
    }
    if (key == null) {
        throw new IllegalArgumentException(
                "No key specified for property '" + name + "' on bean class '" + bean.getClass() + "'");
    }

    if (name.startsWith("@")) {
        Object f = FieldUtils.readField(bean, name.substring(1));
        if (null == f)
            throw new NestedNullException();
        if (f instanceof Map) {
            final java.util.Map<String, Object> map = toPropertyMap(f);
            map.put(key, value);
            return;
        }
        throw new NoSuchFieldException(
                "Field '" + name + "' is not mapped " + "on bean class '" + bean.getClass() + "'");
    }
    // Retrieve the property descriptor for the specified property
    final PropertyDescriptor descriptor = getPropertyDescriptor(bean, name);
    if (descriptor == null) {
        throw new NoSuchMethodException(
                "Unknown property '" + name + "' on bean class '" + bean.getClass() + "'");
    }

    if (descriptor instanceof MappedPropertyDescriptor) {
        // Call the keyed setter method if there is one
        Method mappedWriteMethod = ((MappedPropertyDescriptor) descriptor).getMappedWriteMethod();
        mappedWriteMethod = MethodUtils.getAccessibleMethod(bean.getClass(), mappedWriteMethod);
        if (mappedWriteMethod != null) {
            final Object[] params = new Object[2];
            params[0] = key;
            params[1] = value;
            if (log.isTraceEnabled()) {
                final String valueClassName = value == null ? "<null>" : value.getClass().getName();
                log.trace("setSimpleProperty: Invoking method " + mappedWriteMethod + " with key=" + key
                        + ", value=" + value + " (class " + valueClassName + ")");
            }
            invokeMethod(mappedWriteMethod, bean, params);
        } else {
            throw new NoSuchMethodException("Property '" + name + "' has no mapped setter method"
                    + "on bean class '" + bean.getClass() + "'");
        }
    } else {
        /* means that the result has to be retrieved from a map */
        final Method readMethod = getReadMethod(bean.getClass(), descriptor);
        if (readMethod != null) {
            final Object invokeResult = invokeMethod(readMethod, bean, EMPTY_OBJECT_ARRAY);
            /* test and fetch from the map */
            if (invokeResult instanceof java.util.Map) {
                final java.util.Map<String, Object> map = toPropertyMap(invokeResult);
                map.put(key, value);
            }
        } else {
            throw new NoSuchMethodException("Property '" + name
                    + "' has no mapped getter method on bean class '" + bean.getClass() + "'");
        }
    }

}

From source file:org.broadleafcommerce.openadmin.server.service.persistence.module.BasicPersistenceModule.java

protected void cleanupFailedPersistenceAttempt(Serializable instance) throws IllegalAccessException {
    //Remove the entity from ORM management - no further attempts to persist
    if (getPersistenceManager().getDynamicEntityDao().getStandardEntityManager().contains(instance)) {
        getPersistenceManager().getDynamicEntityDao().getStandardEntityManager().detach(instance);
    }//from  w w  w .ja  v a2  s  .c  om
    //Remove the id field value, if it's set
    String idFieldName = (String) getPersistenceManager().getDynamicEntityDao()
            .getIdMetadata(instance.getClass()).get("name");
    Field idField = FieldUtils.getField(instance.getClass(), idFieldName, true);
    if (idField == null) {
        throw ExceptionHelper.refineException(new NoSuchFieldException(
                "Entity " + instance.getClass().getName() + " does not contain id field " + idFieldName));
    }
    idField.setAccessible(true);
    if (idField.get(instance) != null) {
        idField.set(instance, null);
    }
}