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.apache.hawq.pxf.plugins.hdfs.utilities.RecordkeyAdapter.java

/**
 * Adds the recordkey to the end of the passed in recFields list.
 * <p>/*from  w ww .ja va  2  s . co  m*/
 * This method also verifies cases in which record keys are not supported by
 * the underlying source type, and therefore "illegally" requested.
 *
 * @param recFields existing list of record (non-key) fields and their
 *            values.
 * @param input all input parameters coming from the client request
 * @param onerow a row object which is used here in order to find out if the
 *            given type supports recordkeys or not.
 * @return 0 if record key not needed, or 1 if record key was appended
 * @throws NoSuchFieldException when the given record type does not support
 *             recordkeys
 */
public int appendRecordkeyField(List<OneField> recFields, InputData input, OneRow onerow)
        throws NoSuchFieldException {

    /*
     * user did not request the recordkey field in the
     * "create external table" statement
     */
    ColumnDescriptor recordkeyColumn = input.getRecordkeyColumn();
    if (recordkeyColumn == null) {
        return 0;
    }

    /*
     * The recordkey was filled in the fileAccessor during execution of
     * method readNextObject. The current accessor implementations are
     * SequenceFileAccessor, LineBreakAccessor and AvroFileAccessor from
     * HdfsSplittableDataAccessor and QuotedLineBreakAccessor from
     * HdfsAtomicDataAccessor. For SequenceFileAccessor, LineBreakAccessor
     * the recordkey is set, since it is returned by the
     * SequenceFileRecordReader or LineRecordReader(for text file). But Avro
     * files do not have keys, so the AvroRecordReader will not return a key
     * and in this case recordkey will be null. If the user specified a
     * recordkey attribute in the CREATE EXTERNAL TABLE statement and he
     * reads from an AvroFile, we will throw an exception since the Avro
     * file does not have keys In the future, additional implementations of
     * FileAccessors will have to set recordkey during readNextObject().
     * Otherwise it is null by default and we will throw an exception here,
     * that is if we get here... a careful user will not specify recordkey
     * in the CREATE EXTERNAL statement and then we will leave this function
     * one line above.
     */
    Object recordkey = onerow.getKey();
    if (recordkey == null) {
        throw new NoSuchFieldException("Value for field \"recordkey\" was requested but the "
                + "queried HDFS resource type does not support key");
    }

    OneField oneField = new OneField();
    oneField.type = recordkeyColumn.columnTypeCode();
    oneField.val = extractVal(recordkey);
    recFields.add(oneField);
    return 1;
}

From source file:com.manydesigns.portofino.reflection.TableAccessor.java

public PropertyAccessor getProperty(String propertyName) throws NoSuchFieldException {
    for (ColumnAccessor current : columnAccessors) {
        if (current.getName().equals(propertyName)) {
            return current;
        }/*w  ww  .j ava2  s . co m*/
    }

    throw new NoSuchFieldException(propertyName);
}

From source file:com.manydesigns.portofino.pageactions.crud.reflection.CrudAccessor.java

public CrudPropertyAccessor getProperty(String propertyName) throws NoSuchFieldException {
    for (CrudPropertyAccessor current : propertyAccessors) {
        //XXX Alessio verificare
        if (current.getName().equalsIgnoreCase(propertyName)) {
            return current;
        }/*from  w  w w.  jav  a2s.c  o m*/
    }

    throw new NoSuchFieldException(propertyName + " (of use case " + getName() + ")");
}

From source file:com.feilong.commons.core.lang.EnumUtil.java

/**
 * fieldName value <br>//from   w  ww .j  a  va 2s  .  c om
 * 
 * <pre>
 * 
 * ?{@link HttpMethodType} ,?:
 * 
 * {@code
 *    EnumUtil.getEnumByField(HttpMethodType.class, "method", "get")
 * }
 * </pre>
 *
 * @param <E>
 *            the element type
 * @param <T>
 *            the generic type
 * @param enumClass
 *            the enum class  {@link HttpMethodType}
 * @param propertyName
 *            ??, {@link HttpMethodType}method,javabean 
 * @param value
 *             post
 * @param ignoreCase
 *            ??
 * @return  enum constant
 * @throws IllegalArgumentException
 *             if Validator.isNullOrEmpty(enumClass) or Validator.isNullOrEmpty(propertyName)
 * @throws NoSuchFieldException
 *             ??
 * @throws BeanUtilException
 *             the bean util exception
 * @see com.feilong.commons.core.bean.BeanUtil#getProperty(Object, String)
 * @since 1.0.8
 */
private static <E extends Enum<?>, T> E getEnumByPropertyValue(Class<E> enumClass, String propertyName, T value,
        boolean ignoreCase) throws IllegalArgumentException, NoSuchFieldException, BeanUtilException {

    if (Validator.isNullOrEmpty(enumClass)) {
        throw new IllegalArgumentException("enumClass is null or empty!");
    }

    if (Validator.isNullOrEmpty(propertyName)) {
        throw new IllegalArgumentException("the fieldName is null or empty!");
    }

    // An enum is a kind of class
    // and an annotation is a kind of interface
    //  Class ? null.
    E[] enumConstants = enumClass.getEnumConstants();

    for (E e : enumConstants) {
        if (log.isDebugEnabled()) {
            log.debug("e:{}", JsonUtil.format(e));
        }

        Object propertyValue = PropertyUtil.getProperty(e, propertyName);

        if (null == propertyValue && null == value) {
            return e;
        }
        if (null != propertyValue && null != value) {
            if (ignoreCase && propertyValue.toString().equalsIgnoreCase(value.toString())) {
                return e;
            } else if (propertyValue.equals(value)) {
                return e;
            }
        }
    }

    throw new NoSuchFieldException("can not found the enum constants,enumClass:[" + enumClass
            + "],propertyName:[" + propertyName + "],value:[" + value + "],ignoreCase:[" + ignoreCase + "]");
}

From source file:com.ett.common.util.ReflectUtil.java

/**
 * @param clazz/*from  w w w  . ja v a 2s.c o m*/
 * @param propertyName
 * @return
 * @throws NoSuchFieldException
 */
public static Field getDeclaredField(Class clazz, String propertyName) throws NoSuchFieldException {
    Assert.notNull(clazz);
    Assert.hasText(propertyName);
    for (Class superClass = clazz; superClass != Object.class; superClass = superClass.getSuperclass()) {
        try {
            return superClass.getDeclaredField(propertyName);
        } catch (NoSuchFieldException e) {
            // Field??17,?
        }
    }
    throw new NoSuchFieldException("No such field: " + clazz.getName() + '.' + propertyName);
}

From source file:com.austin.base.commons.util.ReflectUtil.java

/**
 * @param clazz//from   www.  java2  s  .  co  m
 * @param propertyName
 * @return
 * @throws NoSuchFieldException
 */
public static Field getDeclaredField(Class clazz, String propertyName) throws NoSuchFieldException {
    Assert.notNull(clazz);
    Assert.hasText(propertyName);
    for (Class superClass = clazz; superClass != Object.class; superClass = superClass.getSuperclass()) {
        try {
            return superClass.getDeclaredField(propertyName);
        } catch (NoSuchFieldException e) {
            // Field??17,?
        }
    }
    throw new NoSuchFieldException("No such field: " + clazz.getName() + '.' + propertyName);
}

From source file:edu.utsa.sifter.som.MainSOM.java

void writeVectors(final SequenceFile.Writer file)
        throws IOException, CorruptIndexException, NoSuchFieldException {
    System.out.println("Creating document term vectors");
    final LongWritable id = new LongWritable();
    final IntArrayWritable vec = new IntArrayWritable(TermIndices.size());
    final HashSet<String> idFields = new HashSet();
    idFields.add("ID");

    int max = Reader.maxDoc();
    int noTVs = 0;

    TermsEnum term = null;/*from www.j  ava 2s. com*/
    // iterate docs
    for (int i = 0; i < max; ++i) {
        vec.clear();
        final Document doc = Reader.document(i, idFields);
        final IndexableField idField = doc.getField("ID");
        if (idField == null) {
            throw new NoSuchFieldException("document " + i + " does not have an ID field");
        }
        id.set(Long.parseLong(idField.stringValue()));

        // get term vector for body field
        final Terms terms = Reader.getTermVector(i, "body");
        if (terms != null) {
            // count terms in doc
            int numTerms = 0;
            term = terms.iterator(term);
            int j = 0;
            while (term.next() != null) {
                // System.out.println("doc " + i + " had term '" + term.term().utf8ToString() + "'");
                // System.out.println("doc freq: " + term.docFreq());
                // System.out.println("ord: " + term.ord());
                // System.out.println("totalTermFreq: " + term.totalTermFreq());
                Integer index = TermIndices.get(term.term().utf8ToString());
                if (index != null) {
                    vec.add(index);
                    ++numTerms;
                }
            }
            if (numTerms > 0) {
                // System.out.println("doc " + i + " had " + numTerms + " terms");
                MaxDocTerms = Math.max(MaxDocTerms, numTerms);
                SumDocTerms += numTerms;
            }
        } else {
            ++noTVs;
            // System.err.println("doc " + i + " had no term vector for body");
        }
        if (vec.getLength() == 0) {
            ++NumOutliers;
        }
        file.append(id, vec);
        ++NumDocsWritten;
    }
    System.out.println(noTVs + " docs had no term vectors");
}

From source file:com.manydesigns.elements.reflection.JavaClassAccessor.java

public PropertyAccessor getProperty(String propertyName) throws NoSuchFieldException {
    for (PropertyAccessor current : propertyAccessors) {
        if (current.getName().equals(propertyName)) {
            return current;
        }//  ww  w.  j  a v a2  s  .  co  m
    }
    throw new NoSuchFieldException(propertyName);
}

From source file:com.ms.commons.test.common.ReflectUtil.java

public static Field getDeclaredField(Class<?> clazz, String field)
        throws SecurityException, NoSuchFieldException {
    if (clazz == Object.class) {
        throw new NoSuchFieldException(
                "Field `" + field + "` in class `" + clazz.getName() + "` cannot be found.");
    }//from   ww w . j a  v a2s.co m
    try {
        return clazz.getDeclaredField(field);
    } catch (SecurityException e) {
        throw e;
    } catch (NoSuchFieldException e) {
        return getDeclaredField(clazz.getSuperclass(), field);
    }
}

From source file:net.kamhon.ieagle.util.ReflectionUtil.java

/**
 * different with class.getDeclaredField(does not include the field in super class). this one include the field in
 * super class also./*from   w  w w . j  a va 2s .c o  m*/
 * 
 * @return
 * @throws NoSuchFieldException
 */
public static Field getDeclaredField(Class<?> clazz, String fieldName) throws NoSuchFieldException {

    Field field = null;
    while (clazz != null && field == null) {
        try {
            field = clazz.getDeclaredField(fieldName);
        } catch (Exception e) {
        }
        clazz = clazz.getSuperclass();
    }
    if (clazz == null && field == null)
        throw new NoSuchFieldException(clazz + ". Field name=" + fieldName);
    return field;
}