Example usage for java.lang InstantiationException getCause

List of usage examples for java.lang InstantiationException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:hsyndicate.hadoop.dfs.HSyndicateUGMonitor.java

private static SyndicateFileSystem createHSyndicateFS(Configuration conf, String address) throws IOException {
    SyndicateFSConfiguration sconf = HSyndicateConfigUtils.createSyndicateConf(conf, address);
    try {//from www. j  a  va2 s .c o  m
        return new SyndicateFileSystem(sconf, conf);
    } catch (InstantiationException ex) {
        throw new IOException(ex.getCause());
    }
}

From source file:info.novatec.testit.livingdoc.util.ClassUtils.java

public static <T> T invoke(Constructor<T> constructor, Object... args) throws Throwable {
    try {//from ww  w . ja  v a 2  s.  co m
        return constructor.newInstance(args);
    } catch (InstantiationException e) {
        throw e.getCause();
    }
}

From source file:org.jsonschema2pojo.Jsonschema2Pojo.java

private static RuleFactory createRuleFactory(GenerationConfig config) {
    Class<? extends RuleFactory> clazz = config.getCustomRuleFactory();

    if (!RuleFactory.class.isAssignableFrom(clazz)) {
        throw new IllegalArgumentException("The class name given as a rule factory  (" + clazz.getName()
                + ") does not refer to a class that implements " + RuleFactory.class.getName());
    }/*  w  ww. j a v  a2s .c  o m*/

    try {
        return clazz.newInstance();
    } catch (InstantiationException e) {
        throw new IllegalArgumentException(
                "Failed to create a rule factory from the given class. An exception was thrown on trying to create a new instance.",
                e.getCause());
    } catch (IllegalAccessException e) {
        throw new IllegalArgumentException(
                "Failed to create a rule factory from the given class. It appears that we do not have access to this class - is both the class and its no-arg constructor marked public?",
                e);
    }
}

From source file:org.kul.xml.ADocument.java

public static ADocument create(final File file, final Class<? extends ADocument> docType)
        throws DocumentException {
    Throwable ex = null;/*from  w ww  .  j a  v  a 2s.  c om*/
    try {
        return docType.getDeclaredConstructor(File.class).newInstance(file);
    } catch (InstantiationException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    } catch (IllegalAccessException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    } catch (IllegalArgumentException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    } catch (InvocationTargetException e) {
        ex = e.getCause();
    } catch (NoSuchMethodException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    } catch (SecurityException e) {
        LOGGER.error(ExceptionUtils.getStackTrace(e));
    }

    if (ex != null) {
        if (DocumentException.class.isAssignableFrom(ex.getClass()))
            throw (DocumentException) ex;
    }

    throw new DocumentException("XML Document creation failed, see stack trace");
}

From source file:hsyndicate.hadoop.dfs.HSyndicateDFS.java

private static SyndicateFileSystem createHSyndicateFS(URI uri, Configuration conf) throws IOException {
    if (uri == null) {
        throw new IllegalArgumentException("uri is null");
    }//from w  w w  . j av  a 2s.c o  m

    SyndicateFSConfiguration sconf = null;
    String ugHost = "";
    if (uri.getHost() != null && !uri.getHost().isEmpty()) {
        ugHost = uri.getHost();

        if (uri.getPort() > 0) {
            ugHost = ugHost + ":" + uri.getPort();
        }

        sconf = HSyndicateConfigUtils.createSyndicateConf(conf, ugHost);
    } else {
        sconf = HSyndicateConfigUtils.createSyndicateConf(conf);
    }

    try {
        return new SyndicateFileSystem(sconf, conf);
    } catch (InstantiationException ex) {
        throw new IOException(ex.getCause());
    }
}

From source file:com.opengamma.util.ReflectionUtils.java

/**
 * Creates an instance of a class from a constructor.
 * /*  w  ww  .  j a  v  a  2s  .c  o m*/
 * @param <T> the type
 * @param constructor  the constructor to call, not null
 * @param args  the arguments, not null
 * @return the constructor, not null
 * @throws RuntimeException if the class cannot be loaded
 */
public static <T> T newInstance(final Constructor<T> constructor, final Object... args) {
    try {
        return constructor.newInstance(args);
    } catch (InstantiationException ex) {
        throw new OpenGammaRuntimeException(ex.getMessage(), ex);
    } catch (IllegalAccessException ex) {
        throw new OpenGammaRuntimeException(ex.getMessage(), ex);
    } catch (InvocationTargetException ex) {
        if (ex.getCause() instanceof RuntimeException) {
            throw (RuntimeException) ex.getCause();
        }
        throw new OpenGammaRuntimeException(ex.getMessage(), ex);
    }
}

From source file:com.mani.cucumber.ReflectionUtils.java

private static Object digInObject(Object target, String field) {
    Method getter = findAccessor(target, field);
    if (getter == null) {
        throw new IllegalStateException(
                "No accessor found for '" + field + "' found in class " + target.getClass().getName());
    }/*from w w  w.  ja va 2  s .c o  m*/

    try {

        Object obj = getter.invoke(target);
        if (obj == null) {
            obj = getter.getReturnType().newInstance();
            Method setter = findMethod(target, "set" + field, obj.getClass());
            setter.invoke(target, obj);
        }

        return obj;

    } catch (InstantiationException exception) {
        throw new IllegalStateException("Unable to create a new instance", exception);

    } catch (IllegalAccessException exception) {
        throw new IllegalStateException("Unable to access getter, setter, or constructor", exception);

    } catch (InvocationTargetException exception) {
        if (exception.getCause() instanceof RuntimeException) {
            throw (RuntimeException) exception.getCause();
        }
        throw new IllegalStateException("Checked exception thrown from getter or setter method", exception);
    }
}

From source file:edu.southampton.wais.crowd.terrier.applications.Indexing.java

/**
 * A constructor that initialised the data structures
 * to use for indexing. /*  w ww .j av a  2s.c o  m*/
 * @param _path Absolute path to where the index should be created
 * @param _prefix Prefix of the index files, usually "data"
 */
public void setTRECIndexing(String _path, String _prefix) {
    path = _path;
    prefix = _prefix;
    //load the appropriate collection
    final String collectionName = MyApplicationSetup.getProperty("trec.collection.class", "TRECCollection");
    collectionTREC = CollectionFactory.loadCollection(collectionName);

    if (collectionTREC == null) {
        logger.fatal("Collection class named " + collectionName + " not found, aborting");
    }

    //load the appropriate indexer
    String indexerName = MyApplicationSetup.getProperty("trec.indexer.class",
            MyApplicationSetup.BLOCK_INDEXING ? "BlockIndexer" : "BasicIndexer");
    if (indexerName.indexOf('.') == -1)
        indexerName = "org.terrier.indexing." + indexerName;
    else if (indexerName.startsWith("uk.ac.gla.terrier"))
        indexerName = indexerName.replaceAll("uk.ac.gla.terrier", "org.terrier");
    try {
        indexer = (Indexer) Class.forName(indexerName).getConstructor(String.class, String.class)
                .newInstance(path, prefix);
    } catch (ClassNotFoundException e) {
        logger.fatal("Indexer class named " + indexerName + " not found", e);
    } catch (InstantiationException ie) {
        logger.fatal("Error while instantiating Indexer class named " + indexerName + " : " + ie.getCause(),
                ie);
    } catch (Exception e) {
        logger.fatal("Indexer class named " + indexerName + "problem", e);
    }
}

From source file:haven.Utils.java

public static <T> T construct(Constructor<T> cons, Object... args) {
    try {//  w  w w . j av a2 s  .  com
        return (cons.newInstance(args));
    } catch (InstantiationException e) {
        throw (new RuntimeException(e));
    } catch (IllegalAccessException e) {
        throw (new RuntimeException(e));
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof RuntimeException)
            throw ((RuntimeException) e.getCause());
        throw (new RuntimeException(e.getCause()));
    }
}

From source file:de.cenote.jasperstarter.Report.java

private Map<String, Object> getCmdLineReportParams() {
    JRParameter[] jrParameterArray = jasperReport.getParameters();
    Map<String, JRParameter> jrParameters = new HashMap<String, JRParameter>();
    Map<String, Object> parameters = new HashMap<String, Object>();
    List<String> params;
    if (config.hasParams()) {
        params = config.getParams();/*from w  w w.  j  av a 2s .  c o m*/
        for (JRParameter rp : jrParameterArray) {
            jrParameters.put(rp.getName(), rp);
        }
        String paramName = null;
        //String paramType = null;
        String paramValue = null;

        for (String p : params) {
            try {
                paramName = p.split("=")[0];
                paramValue = p.split("=", 2)[1];
                if (config.isVerbose()) {
                    System.out.println("Using report parameter: " + paramName + " = " + paramValue);
                }
            } catch (Exception e) {
                throw new IllegalArgumentException("Wrong report param format! " + p, e);
            }
            if (!jrParameters.containsKey(paramName)) {
                throw new IllegalArgumentException("Parameter '" + paramName + "' does not exist in report!");
            }

            JRParameter reportParam = jrParameters.get(paramName);

            try {
                // special parameter handlers must also implemeted in
                // ParameterPanel.java
                if (Date.class.equals(reportParam.getValueClass())) {
                    // Date must be in ISO8601 format. Example 2012-12-31
                    DateFormat dateFormat = new SimpleDateFormat("yy-MM-dd");
                    parameters.put(paramName, (Date) dateFormat.parse(paramValue));
                } else if (Image.class.equals(reportParam.getValueClass())) {
                    Image image = Toolkit.getDefaultToolkit()
                            .createImage(JRLoader.loadBytes(new File(paramValue)));
                    MediaTracker traker = new MediaTracker(new Panel());
                    traker.addImage(image, 0);
                    try {
                        traker.waitForID(0);
                    } catch (Exception e) {
                        throw new IllegalArgumentException("Image tracker error: " + e.getMessage(), e);
                    }
                    parameters.put(paramName, image);
                } else if (Locale.class.equals(reportParam.getValueClass())) {
                    parameters.put(paramName, LocaleUtils.toLocale(paramValue));
                } else {
                    // handle generic parameters with string constructor
                    try {
                        parameters.put(paramName, reportParam.getValueClass().getConstructor(String.class)
                                .newInstance(paramValue));
                    } catch (InstantiationException ex) {
                        throw new IllegalArgumentException("Parameter '" + paramName + "' of type '"
                                + reportParam.getValueClass().getName() + " caused " + ex.getClass().getName()
                                + " " + ex.getMessage(), ex);
                    } catch (IllegalAccessException ex) {
                        throw new IllegalArgumentException("Parameter '" + paramName + "' of type '"
                                + reportParam.getValueClass().getName() + " caused " + ex.getClass().getName()
                                + " " + ex.getMessage(), ex);
                    } catch (InvocationTargetException ex) {
                        Throwable cause = ex.getCause();
                        throw new IllegalArgumentException("Parameter '" + paramName + "' of type '"
                                + reportParam.getValueClass().getName() + " caused "
                                + cause.getClass().getName() + " " + cause.getMessage(), cause);
                    } catch (NoSuchMethodException ex) {
                        throw new IllegalArgumentException("Parameter '" + paramName + "' of type '"
                                + reportParam.getValueClass().getName() + " with value '" + paramValue
                                + "' is not supported by JasperStarter!", ex);
                    }
                }
            } catch (NumberFormatException e) {
                throw new IllegalArgumentException(
                        "NumberFormatException: " + e.getMessage() + "\" in \"" + p + "\"", e);
            } catch (java.text.ParseException e) {
                throw new IllegalArgumentException(e.getMessage() + "\" in \"" + p + "\"", e);
            } catch (JRException e) {
                throw new IllegalArgumentException("Unable to load image from: " + paramValue, e);
            }
        }
    }
    return parameters;
}