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:org.lareferencia.backend.harvester.OCLCBasedHarvesterImpl.java

private HarvestingEvent createResultFromListRecords(ListRecords listRecords)
        throws TransformerException, NoSuchFieldException {

    HarvestingEvent result = new HarvestingEvent();
    /**//  www. j a  v  a2s . co  m
     * TODO: Podran usarse una lista fija de registros, no persistentes para no crear siempre los
     * objetos de registro, habra que evaluarlo cuidadosamente
     */

    // La obtencin de registros por xpath se realiza de acuerdo al schema correspondiente
    NodeList nodes = null;
    String namespace = null;

    if (listRecords.getSchemaLocation().indexOf(ListRecords.SCHEMA_LOCATION_V2_0) != -1) {
        nodes = listRecords.getNodeList("/oai20:OAI-PMH/oai20:ListRecords/oai20:record");
        namespace = "oai20";
    } else if (listRecords.getSchemaLocation().indexOf(ListRecords.SCHEMA_LOCATION_V1_1_LIST_RECORDS) != -1) {
        namespace = "oai11_ListRecords";
        nodes = listRecords.getNodeList("/oai11_ListRecords:ListRecords/oai11_ListRecords:record");
    } else {
        throw new NoSuchFieldException(listRecords.getSchemaLocation());
    }

    //System.out.println( listRecords.toString() );

    for (int i = 0; i < nodes.getLength(); i++) {

        String identifier = "unknown";
        String metadataString = "unknown";
        String status = "unknown";

        try {
            identifier = listRecords.getSingleString(nodes.item(i),
                    namespace + ":header/" + namespace + ":identifier");
            identifier = identifier.replace("&", "");

            status = listRecords.getSingleString(nodes.item(i), namespace + ":header/@status");

            if (!status.equals(STATUS_DELETED)) {

                metadataString = getMetadataString(nodes.item(i), listRecords.getDocument());

                result.getRecords().add(new OAIRecordMetadata(identifier, metadataString));
            }

        } catch (OAIRecordMetadataParseException e) {
            //TODO: Hay que poder informar estas exceptions individuales para que quede registrada la prdida del registro
            System.err.println("Error en el parseo de registro: " + identifier + '\n' + metadataString);
            result.setRecordMissing(true);
        } catch (Exception e) {
            System.err
                    .println("Error desconocido procesando el registro: " + identifier + '\n' + metadataString);
            System.err.println("Exception:" + e.getMessage());
            result.setRecordMissing(true);
            //e.printStackTrace();
        }
    }

    return result;
}

From source file:org.kuali.rice.core.framework.persistence.jpa.metadata.MetadataManager.java

private static Field getField(Class clazz, String name) throws NoSuchFieldException {
    if (clazz.equals(Object.class)) {
        throw new NoSuchFieldException(name);
    }/* w ww. jav  a 2  s  . c  o  m*/
    Field field = null;
    try {
        field = clazz.getDeclaredField(name);
    } catch (Exception e) {
    }
    if (field == null) {
        field = getField(clazz.getSuperclass(), name);
    }
    return field;
}

From source file:org.fcrepo.http.commons.test.util.TestHelpers.java

private static Field findField(final Class<?> clazz, final String name) throws NoSuchFieldException {
    for (final Field f : clazz.getDeclaredFields()) {
        if (f.getName().equals(name)) {
            return f;
        }/*from  w ww . j a  va  2  s  .c o  m*/
    }
    if (clazz.getSuperclass() == null) {
        throw new NoSuchFieldException("Field " + name + " could not be found");
    }
    return findField(clazz.getSuperclass(), name);
}

From source file:com.madrobot.di.wizard.json.JSONDeserializer.java

private Field getField(final Class<?> userClass, final String jsonKey) throws NoSuchFieldException {

    Field targetField = null;/*from w  w w  .ja v  a  2 s  .  co m*/
    for (Field field : userClass.getDeclaredFields()) {
        if (field.getName().equals(jsonKey)) {
            targetField = field;
            break;
        } else if (field.isAnnotationPresent(SerializedName.class)) {
            SerializedName serializedNameObj = field.getAnnotation(SerializedName.class);
            if (serializedNameObj.value().equals(jsonKey)) {
                targetField = field;
                break;
            }
        }
    }

    if (targetField == null)
        throw new NoSuchFieldException("NoSuchFieldException : " + jsonKey);

    return targetField;
}

From source file:org.overlord.sramp.atom.archive.expand.ZipToSrampArchiveTest.java

/**
 * Finds a field.// w  ww. jav  a 2  s  .c o  m
 * @param j2sramp
 * @throws NoSuchFieldException
 */
protected static Field getJarWorkDirField(ZipToSrampArchive j2sramp) throws NoSuchFieldException {
    boolean found = false;
    Class<?> from = j2sramp.getClass();
    while (!found) {
        try {
            return from.getDeclaredField("jarWorkDir"); //$NON-NLS-1$
        } catch (NoSuchFieldException nsfe) {
            from = from.getSuperclass();
            if (from == null) {
                break;
            }
        }
    }
    throw new NoSuchFieldException("jarWorkDir"); //$NON-NLS-1$
}

From source file:org.lareferencia.backend.harvester.OCLCBasedHarvesterImpl.java

/**
 * @param node//from ww w. j  a  v  a 2  s.co m
 * @param document 
 * @return 
 * @throws TransformerException
 * @throws NoSuchFieldException 
 */
private String getMetadataString(Node node, Document document)
        throws TransformerException, NoSuchFieldException {

    /**
     *  TODO: bsqueda secuencial, puede ser ineficiente pero xpath no esta implementado sobre nodos individaules
     *  en la interfaz listRecords, en necesario construir un DomHelper para Harvester, es sencillo dada la clase
     *  base BaseMetadataDOMHelper
     */

    NodeList childs = node.getChildNodes();
    Node metadataNode = null;
    for (int i = 0; i < childs.getLength(); i++)
        if (childs.item(i).getNodeName().contains(METADATA_NODE_NAME))
            metadataNode = childs.item(i);

    if (metadataNode == null)
        throw new NoSuchFieldException("No existe el nodo: " + METADATA_NODE_NAME + " en la respuesta.\n"
                + MedatadaDOMHelper.Node2XMLString(node));

    // este rename unifica los casos distintos de namespace encontrados en repositorios
    document.renameNode(metadataNode, metadataNode.getNamespaceURI(), METADATA_NODE_NAME);

    // TODO: Ver el tema del char &#56256;
    return MedatadaDOMHelper.Node2XMLString(metadataNode);
}

From source file:com.google.code.siren4j.util.ReflectionUtils.java

public static Field findField(Class<?> clazz, String fieldName) throws NoSuchFieldException {
    Field field = null;/*www .ja va  2  s .  c  o  m*/
    try {
        field = clazz.getDeclaredField(fieldName);
    } catch (NoSuchFieldException e) {

    }
    if (field == null) {
        Class<?> superClazz = clazz.getSuperclass();
        if (superClazz != null) {
            field = findField(superClazz, fieldName);
        }
        if (field == null) {
            throw new NoSuchFieldException("Field: " + fieldName);
        } else {
            return field;
        }
    } else {
        return field;
    }
}

From source file:com.p5solutions.core.jpa.orm.EntityUtility.java

/**
 * Setup attribute overrides./*  ww w . j a va 2 s . c o m*/
 * 
 * @param <T>
 *          the generic type
 * @param entityClass
 *          the entity class
 * @param pbs
 *          the pbs
 */
protected <T> void setupAttributeOverrides(Class<T> entityClass, List<ParameterBinder> pbs) {
    List<AttributeOverride> overrides = findAttributeOverrides(entityClass);

    // not the most efficient way of doing this, but its not overwhelming,
    // and its only done once!
    if (!Comparison.isEmptyOrNull(overrides)) {
        for (AttributeOverride override : overrides) {
            boolean found = false;
            for (ParameterBinder pb : pbs) {
                if (override.name().equals(pb.getFieldName())) {
                    found = true;
                    pb.setOverrideColumn(override.column());
                }
            }

            if (!found) {
                String error = "No override method found when using attribute-override in entity class "
                        + entityClass + " when an attempt was made to match against field name "
                        + override.name();
                logger.error(error);
                throw new RuntimeException(new NoSuchFieldException(error));
            }
        }
    }
}

From source file:com.nestedbird.modules.formparser.FormParse.java

/**
 * For some reason I cannot use Class.getField, as it does not do anything.
 * This method loops over DeclaredFields of the object and all its parents
 *
 * @param objectClass - The object we are searching in
 * @param fieldName   - The fields name we are searching for
 * @return - The field//from  w w  w  .  j av  a  2  s .com
 */
private Optional<Field> getField(final Class objectClass, final String fieldName) {
    Class currentClass = objectClass;
    final Mutable<Field> field = Mutable.of(null);
    do {
        final Field foundField = Arrays.stream(currentClass.getDeclaredFields())
                .filter(e -> e.getName().equals(fieldName)).findFirst().orElse(null);

        field.mutateIf(foundField, foundField != null);

        currentClass = currentClass.getSuperclass();
    } while (currentClass.getSuperclass() != null);

    if (!field.isPresent()) {
        logger.info("[FormParse] [getField] Unable To Find Field", new NoSuchFieldException(fieldName));
    }

    return field.ofNullable();
}

From source file:org.evosuite.testcarver.testcase.EvoTestCaseCodeGenerator.java

private Field getDeclaredField(final Class<?> clazz, final String fieldName) throws NoSuchFieldException {
    if (clazz == null || Object.class.equals(clazz)) {
        throw new NoSuchFieldException(fieldName);
    }/*from  w w  w .j  a  va 2 s.  c  o  m*/

    try {
        final Field field = clazz.getDeclaredField(fieldName);
        field.setAccessible(true);
        return field;
    } catch (final NoSuchFieldException e) {
        return getDeclaredField(clazz.getSuperclass(), fieldName);
    }
}