Example usage for javax.management RuntimeErrorException RuntimeErrorException

List of usage examples for javax.management RuntimeErrorException RuntimeErrorException

Introduction

In this page you can find the example usage for javax.management RuntimeErrorException RuntimeErrorException.

Prototype

public RuntimeErrorException(java.lang.Error e, String message) 

Source Link

Document

Constructor that allows a specific error message to be specified.

Usage

From source file:org.adorsys.waguia.lightxls.generic.EasyXlsClazzLoader.java

public List<T> loadClazz() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException,
        InstantiationException {//from w  w w.j  a v a  2s  .  c o m
    List<T> result = new ArrayList<T>();

    Field[] declaredFields = clazz.getDeclaredFields();
    int numberOfSheets = workbook.getNumberOfSheets();
    Method[] declaredMethods = clazz.getDeclaredMethods();
    if (classInSheetFinder == null)
        classInSheetFinder = new ClassInSheetFinder();
    List<String> sheetNames = new ArrayList<String>();
    for (int i = 0; i < numberOfSheets; i++) {
        sheetNames.add(workbook.getSheetAt(i).getSheetName());
    }
    int position = classInSheetFinder.find(clazz.getSimpleName(),
            (String[]) sheetNames.toArray(new String[sheetNames.size()]));
    if (position == -1)
        throw new RuntimeErrorException(null, "Unable to find the class's sheet");
    Sheet clazzSheet = workbook.getSheetAt(position);
    // assuming that the first row will contains class's properties. so this is
    // how to get columnNames.
    Row row = clazzSheet.getRow(HEADER_INDEX);
    Iterator<Cell> cellIterator = row.cellIterator();
    List<String> columnNames = new ArrayList<String>();
    while (cellIterator.hasNext()) {
        Cell cell = (Cell) cellIterator.next();
        columnNames.add(cell.getStringCellValue());
    }
    if (this.sheetColumnToClazzFieldMatching == null)
        this.sheetColumnToClazzFieldMatching = new SheetColumnToClazzFieldMatching();

    if (sheetColumnToClazzFieldMatching.checkMatching(
            (String[]) columnNames.toArray(new String[columnNames.size()]), declaredFields,
            declaredMethods) == false)
        throw new RuntimeException("Matching Error. Please recheck matching rules");
    Iterator<Row> rowIterator = clazzSheet.rowIterator();
    if (fieldToColumnComparator == null)
        this.fieldToColumnComparator = new FieldToColumnComparator();
    int numberOfIteration = 0;
    while (rowIterator.hasNext()) {
        Row nextRow = rowIterator.next();
        Object newInstance = clazz.newInstance();
        if (numberOfIteration == HEADER_INDEX) {
            numberOfIteration++;
            continue;
        }
        for (int i = 0; i < declaredFields.length; i++) {
            Field field = declaredFields[i];
            if (!columnNames.contains(field.getName()))
                continue;
            String correspondinMethodName = "set" + StringUtils.capitalize(field.getName());
            for (int j = 0; j < declaredMethods.length; j++) {
                Method method = declaredMethods[j];
                if (!method.getName().equals(correspondinMethodName))
                    continue;
                int index = 0;
                //Find the correct field's range in the list of columns.
                for (String string : columnNames) {
                    if (fieldToColumnComparator.compare(field.getName(), string) == 0) {
                        Class<?> type = field.getType();
                        if (exelPropertyReader == null) {
                            exelPropertyReader = new ExelPropertyReader(field, type, newInstance,
                                    nextRow.getCell(index), method);
                            exelPropertyReader.readProperty();
                        } else {
                            exelPropertyReader.setField(field);
                            exelPropertyReader.setCell(nextRow.getCell(index));
                            exelPropertyReader.setMethod(method);
                            exelPropertyReader.setNewInstance(newInstance);
                            exelPropertyReader.setType(type);
                            exelPropertyReader.readProperty();
                        }
                        index++;
                        continue;
                    }
                    index++;
                }
            }
        }
        result.add((T) newInstance);
        numberOfIteration++;
    }
    return result;
}

From source file:org.buddycloud.channelserver.XMPPAcceptanceTestHelper.java

protected String getValue(Packet p, String xPath, boolean namespaceFeature) throws Exception {
    Object evaluateFirst = getEl(p, xPath, namespaceFeature);
    if (evaluateFirst instanceof Attribute) {
        Attribute attribute = (Attribute) evaluateFirst;
        return attribute.getValue();
    } else if (evaluateFirst instanceof Text) {
        return ((Text) evaluateFirst).getText();
    } else if (evaluateFirst instanceof Element) {
        throw new RuntimeErrorException(null, "XPath maps to element, not attribute");
    }/*from   www.  j  a  va  2  s  .co m*/
    return evaluateFirst == null ? null : ((Attribute) evaluateFirst).getValue();
}