Example usage for java.lang IllegalAccessException printStackTrace

List of usage examples for java.lang IllegalAccessException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

public Object getAttribute(String attribute)
        throws AttributeNotFoundException, MBeanException, ReflectionException {
    if (methods == null)
        init();/*from  ww w  . ja  va 2s  . c  o m*/
    Method m = (Method) getAttMap.get(attribute);
    if (m == null)
        throw new AttributeNotFoundException(attribute);

    try {
        if (log.isDebugEnabled())
            log.debug(real.getClass().getName() + " getAttribute " + attribute);
        return m.invoke(real, NO_ARGS_PARAM);
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
        throw new MBeanException(ex);
    } catch (InvocationTargetException ex1) {
        ex1.printStackTrace();
        throw new MBeanException(ex1);
    }
}

From source file:org.apache.tomcat.util.mx.DynamicMBeanProxy.java

public void setAttribute(Attribute attribute)
        throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException {
    if (methods == null)
        init();//from  w w  w .  ja v a  2s  . c o  m
    // XXX Send notification !!!
    Method m = (Method) setAttMap.get(attribute.getName());
    if (m == null)
        throw new AttributeNotFoundException(attribute.getName());

    try {
        log.info(real.getClass().getName() + "setAttribute " + attribute.getName());
        m.invoke(real, new Object[] { attribute.getValue() });
    } catch (IllegalAccessException ex) {
        ex.printStackTrace();
        throw new MBeanException(ex);
    } catch (InvocationTargetException ex1) {
        ex1.printStackTrace();
        throw new MBeanException(ex1);
    }
}

From source file:net.larry1123.elec.util.test.config.AbstractConfigTest.java

protected void assertTest(String fieldName) throws NoSuchMethodException {
    Field field = getField(getConfigBase(), fieldName);
    Type type = field.getGenericType();
    Method method = getTestMethod(fieldName);
    method.setAccessible(true);/*w w w  .ja  v a 2  s .c om*/
    try {
        method.invoke(this, fieldName, field);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    }
}

From source file:cern.c2mon.shared.common.datatag.address.impl.HardwareAddressImpl.java

/**
 * Create a HardwareAddress object from its XML representation.
 *
 * @param pElement DOM element containing the XML representation of a HardwareAddress object, as created by the
 *                 toConfigXML() method.
 * @throws RuntimeException if unable to instantiate the Hardware address
 * @see cern.c2mon.shared.common.datatag.address.HardwareAddress#toConfigXML()
 *//* w w w  .  j  ava 2s .  co m*/
public final synchronized HardwareAddress fromConfigXML(Element pElement) {
    Class hwAddressClass = null;
    HardwareAddressImpl hwAddress = null;

    try {
        hwAddressClass = Class.forName(pElement.getAttribute("class"));
        hwAddress = (HardwareAddressImpl) hwAddressClass.newInstance();
    } catch (ClassNotFoundException cnfe) {
        cnfe.printStackTrace();
        throw new RuntimeException("Exception caught when instantiating a hardware address from XML", cnfe);
    } catch (IllegalAccessException iae) {
        iae.printStackTrace();
        throw new RuntimeException("Exception caught when instantiating a hardware address from XML", iae);
    } catch (InstantiationException ie) {
        ie.printStackTrace();
        throw new RuntimeException("Exception caught when instantiating a hardware address from XML", ie);
    }

    NodeList fields = pElement.getChildNodes();
    Node fieldNode = null;
    int fieldsCount = fields.getLength();
    String fieldName;
    String fieldValueString;
    String fieldTypeName = "";

    for (int i = 0; i < fieldsCount; i++) {
        fieldNode = fields.item(i);
        if (fieldNode.getNodeType() == Node.ELEMENT_NODE) {
            fieldName = fieldNode.getNodeName();

            if (fieldNode.getFirstChild() != null) {
                fieldValueString = fieldNode.getFirstChild().getNodeValue();
            } else {
                fieldValueString = "";
            }
            try {
                Field field = hwAddressClass.getDeclaredField(decodeFieldName(fieldName));
                fieldTypeName = field.getType().getName();

                if (fieldTypeName.equals("short")) {
                    field.setShort(hwAddress, Short.parseShort(fieldValueString));
                } else if (fieldTypeName.equals("java.lang.Short")) {
                    field.set(hwAddress, new Integer(Integer.parseInt(fieldValueString)));
                } else if (fieldTypeName.equals("int")) {
                    field.setInt(hwAddress, Integer.parseInt(fieldValueString));
                } else if (fieldTypeName.equals("java.lang.Integer")) {
                    field.set(hwAddress, new Integer(Integer.parseInt(fieldValueString)));
                } else if (fieldTypeName.equals("float")) {
                    field.setFloat(hwAddress, Float.parseFloat(fieldValueString));
                } else if (fieldTypeName.equals("java.lang.Float")) {
                    field.set(hwAddress, new Float(Float.parseFloat(fieldValueString)));
                } else if (fieldTypeName.equals("double")) {
                    field.setDouble(hwAddress, Double.parseDouble(fieldValueString));
                } else if (fieldTypeName.equals("java.lang.Double")) {
                    field.set(hwAddress, new Double(Double.parseDouble(fieldValueString)));
                } else if (fieldTypeName.equals("long")) {
                    field.setLong(hwAddress, Long.parseLong(fieldValueString));
                } else if (fieldTypeName.equals("java.lang.Long")) {
                    field.set(hwAddress, new Long(Long.parseLong(fieldValueString)));
                } else if (fieldTypeName.equals("byte")) {
                    field.setByte(hwAddress, Byte.parseByte(fieldValueString));
                } else if (fieldTypeName.equals("java.lang.Byte")) {
                    field.set(hwAddress, new Byte(Byte.parseByte(fieldValueString)));
                } else if (fieldTypeName.equals("char")) {
                    field.setChar(hwAddress, fieldValueString.charAt(0));
                } else if (fieldTypeName.equals("java.lang.Character")) {
                    field.set(hwAddress, new Character(fieldValueString.charAt(0)));
                } else if (fieldTypeName.equals("boolean")) {
                    field.setBoolean(hwAddress, Boolean.getBoolean(fieldValueString));
                } else if (fieldTypeName.equals("java.lang.Boolean")) {
                    field.set(hwAddress, new Boolean(Boolean.getBoolean(fieldValueString)));
                } else if (fieldTypeName.equals("java.util.HashMap")) {
                    field.set(hwAddress, SimpleXMLParser.domNodeToMap(fieldNode));
                } else if (field.getType().isEnum()) {
                    Object[] enumConstants = field.getType().getEnumConstants();
                    for (Object enumConstant : enumConstants) {
                        if (enumConstant.toString().equals(fieldValueString)) {
                            field.set(hwAddress, enumConstant);
                        }
                    }
                } else {
                    field.set(hwAddress, fieldValueString);
                }
            } catch (NoSuchFieldException nsfe) {
                String errorMsg = "fromConfigXML(...) - Error occured while parsing XML <HardwareAddress> tag. "
                        + "The following variable does not exist in " + hwAddressClass.toString() + ": \""
                        + decodeFieldName(fieldName) + "\"";
                log.error(errorMsg);
                throw new IllegalArgumentException(errorMsg);
            } catch (IllegalAccessException iae) {
                iae.printStackTrace();
                throw new RuntimeException(iae);
            } catch (NumberFormatException npe) {
                String errorMsg = "fromConfigXML(...) - Error occured while parsing XML <HardwareAddress> tag. Field \""
                        + fieldName + "\" shall not be empty since we expect a \"" + fieldTypeName
                        + "\" value. Please correct the XML configuration for " + hwAddressClass.toString();
                log.error(errorMsg);
                throw new IllegalArgumentException(errorMsg);
            }
        }
    }
    return hwAddress;
}

From source file:com.emergya.persistenceGeo.dao.impl.GeoserverGsManagerDaoImpl.java

private GSLayerEncoder tranformToGSLayerEncoder(GsLayerDescriptor layerDescriptor) {

    GSLayerEncoder encoder = new GSLayerEncoder();
    try {//  w  w  w .  ja va  2  s .c  o  m
        BeanUtils.copyProperties(encoder, layerDescriptor);
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return encoder;
}

From source file:org.opennms.features.reporting.repository.local.LegacyLocalReportRepository.java

/**
 * {@inheritDoc}/*  w ww. j  a va 2s  .c  om*/
 */
@Override
public List<BasicReportDefinition> getReports() {
    List<BasicReportDefinition> resultList = new ArrayList<BasicReportDefinition>();
    for (BasicReportDefinition report : m_localReportsDao.getReports()) {
        BasicReportDefinition resultReport = new LegacyLocalReportDefinition();
        try {
            BeanUtils.copyProperties(resultReport, report);
            resultReport.setId(REPOSITORY_ID + "_" + report.getId());
            // Community reports are allowed by default, no permission restriction
            resultReport.setAllowAccess(true);
        } catch (IllegalAccessException e) {
            logger.error("IllegalAccessException during BeanUtils.copyProperties for BasicReportDefinion '{}'",
                    e.getMessage());
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            logger.error(
                    "InvocationTargetException during BeanUtils.copyProperties for BasicReportDefinion '{}'",
                    e.getMessage());
            e.printStackTrace();
        }
        resultList.add(resultReport);
    }
    return resultList;
}

From source file:org.opennms.features.reporting.repository.local.LegacyLocalReportRepository.java

/**
 * {@inheritDoc}/*from w  ww . ja va 2s  .  c  o  m*/
 */
@Override
public List<BasicReportDefinition> getOnlineReports() {
    List<BasicReportDefinition> resultList = new ArrayList<BasicReportDefinition>();
    for (BasicReportDefinition report : m_localReportsDao.getOnlineReports()) {
        BasicReportDefinition resultReport = new LegacyLocalReportDefinition();
        try {
            BeanUtils.copyProperties(resultReport, report);
            resultReport.setId(REPOSITORY_ID + "_" + report.getId());
            // Community reports are allowed by default, no permission restriction
            resultReport.setAllowAccess(true);
        } catch (IllegalAccessException e) {
            logger.error("IllegalAccessException during BeanUtils.copyProperties for BasicReportDefinion '{}'",
                    e.getMessage());
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            logger.error(
                    "InvocationTargetException during BeanUtils.copyProperties for BasicReportDefinion '{}'",
                    e.getMessage());
            e.printStackTrace();
        }
        resultList.add(resultReport);
    }
    return resultList;
}

From source file:com.aw.swing.mvp.view.IPView.java

private Object getComponentFullScan(String attributeName, Object source) {
    List<Field> forms = new ArrayList();
    Class cls = source.getClass();
    Field[] fields = cls.getFields();
    for (int i = 0; i < fields.length; i++) {
        if (fields[i].getName().equals(attributeName)) {
            JComponent jComponemt;
            try {
                jComponemt = (JComponent) fields[i].get(source);
                if (jComponemt != null) {
                    jComponemt.putClientProperty("Field", fields[i]);
                    return jComponemt;
                } else {
                    System.out.println("Null:<" + source.getClass() + ">- <" + fields[i].getName() + ">");
                }//from w  w  w  .ja  v a2  s .  c  o  m
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                throw new AWSystemException("Error getting teh value of:<" + fields[i].getName() + ">", e);
            }
        }
        if ((fields[i].getType().getSimpleName().startsWith("Frm"))) {
            forms.add(fields[i]);
        }
    }
    if (forms.size() > 0) {
        for (Field field : forms) {
            try {
                Object formToBeChecked = field.get(source);
                if (formToBeChecked != null) {
                    Object cmp = getComponentFullScan(attributeName, formToBeChecked);
                    if (cmp != null) {
                        return cmp;
                    }
                } else {
                    throw new IllegalStateException("FRM NULL:" + field.getName());
                }
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                throw new AWSystemException("Problems getting value for:<" + field.getName() + ">", e);
            }
        }
    }
    logger.debug("Searching - Component " + attributeName + " does not exist in:" + source);
    return null;
}

From source file:com.emergya.persistenceGeo.dao.impl.GeoserverGsManagerDaoImpl.java

/**
 * Utility method for transforming a GsFeatureDescriptor to a
 * GsFeatureTypeEncoder./*from w w w .j a  v a2 s  . com*/
 * 
 * @param descriptor
 * @return
 */
private GSFeatureTypeNativeNameEncoder tranformToGSFeatureTypeEncoder(GsFeatureDescriptor descriptor) {
    GSFeatureTypeNativeNameEncoder encoder = new GSFeatureTypeNativeNameEncoder();
    try {
        BeanUtils.copyProperties(encoder, descriptor);
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    for (String keyword : descriptor.getKeywords()) {
        encoder.addKeyword(keyword);
    }
    BoundingBox llbb = descriptor.getLatLonBoundingBox();
    encoder.setLatLonBoundingBox(llbb.getMinx(), llbb.getMiny(), llbb.getMaxx(), llbb.getMaxy(), llbb.getSrs());

    BoundingBox nbb = descriptor.getNativeBoundingBox();
    encoder.setNativeBoundingBox(nbb.getMinx(), nbb.getMiny(), nbb.getMaxx(), nbb.getMaxy(), nbb.getSrs());

    return encoder;
}

From source file:org.fao.fenix.wds.web.rest.faostat.FAOSTATExporter.java

@POST
@Path("/streamcsv")
public Response streamCSV(final @FormParam("datasource_WQ_csv") String datasource,
        final @FormParam("json_WQ_csv") String json, final @FormParam("cssFilename_WQ_csv") String cssFilename,
        final @FormParam("valueIndex_WQ_csv") String valueIndex,
        final @FormParam("thousandSeparator_WQ_csv") String thousandSeparator,
        final @FormParam("decimalSeparator_WQ_csv") String decimalSeparator,
        final @FormParam("decimalNumbers_WQ_csv") String decimalNumbers,
        final @FormParam("quote_WQ_csv") String quote, final @FormParam("title_WQ_csv") String title,
        final @FormParam("subtitle_WQ_csv") String subtitle) {

    System.out.println("WE ARE IN LOCALHOST");
    System.out.println(valueIndex);
    System.out.println(json);//from   ww w. jav a  2 s.c o  m

    // Initiate the stream
    StreamingOutput stream = new StreamingOutput() {

        @Override
        public void write(OutputStream os) throws IOException, WebApplicationException {

            // compute result
            Gson g = new Gson();
            SQLBean sql = g.fromJson(json, SQLBean.class);
            System.out.println(sql.getQuery());
            System.out.println();
            DatasourceBean db = datasourcePool.getDatasource(datasource.toUpperCase());
            Writer writer = new BufferedWriter(new OutputStreamWriter(os));

            // compute result
            JDBCIterable it = new JDBCIterable();

            try {

                // alter the query to switch from LIMIT to TOP
                if (datasource.toUpperCase().startsWith("FAOSTAT"))
                    sql.setQuery(replaceLimitWithTop(sql));

                System.out.println(Bean2SQL.convert(sql));
                it.query(db, Bean2SQL.convert(sql).toString());

            } catch (IllegalAccessException e) {
                e.printStackTrace();
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'streamCSV' thrown an error: " + e.getMessage()));
            } catch (InstantiationException e) {
                e.printStackTrace();
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'streamCSV' thrown an error: " + e.getMessage()));
            } catch (SQLException e) {
                e.printStackTrace();
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'streamCSV' thrown an error: " + e.getMessage()));
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'streamCSV' thrown an error: " + e.getMessage()));
            } catch (Exception e) {
                e.printStackTrace();
                WDSExceptionStreamWriter.streamException(os,
                        ("Method 'streamCSV' thrown an error: " + e.getMessage()));
            }

            writer.write("\ufeff");

            List<String> cols = it.getColumnNames();
            for (int i = 0; i < cols.size(); i++) {
                writer.write(cols.get(i));
                if (i < cols.size() - 1)
                    writer.write(",");
            }
            writer.write("\n");

            // write the result of the query
            while (it.hasNext()) {
                List<String> l = it.next();
                for (int i = 0; i < l.size(); i++) {
                    writer.write("\"" + l.get(i) + "\"");
                    if (i < l.size() - 1)
                        writer.write(",");
                }
                writer.write("\n");
            }

            writer.write("\n");
            writer.write(createMetadata());
            writer.write("\n");

            // Convert and write the output on the stream
            writer.flush();
            writer.close();

        }

    };

    // Wrap result
    ResponseBuilder builder = Response.ok(stream);
    builder.header("Content-Disposition", "attachment; filename=" + UUID.randomUUID().toString() + ".csv");

    // Stream Excel
    return builder.build();

}