Example usage for java.lang InstantiationException getMessage

List of usage examples for java.lang InstantiationException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:br.com.renatoccosta.regexrenamer.element.base.ElementFactory.java

public static Element compile(String alias) throws ElementNotFoundException {
    Element ee = null;//ww w .  ja  v a  2  s  .  c o  m
    try {
        Class<Element> c = ElementsDirectory.getInstance().lookup(alias);

        if (c == null) {
            throw new ElementNotFoundException(alias);
        }

        ee = c.newInstance();

    } catch (InstantiationException ex) {
        LOGGER.error(ex.getMessage(), ex);
    } catch (IllegalAccessException ex) {
        LOGGER.error(ex.getMessage(), ex);
    }

    return ee;
}

From source file:org.wso2.carbon.social.sql.SocialUtil.java

@SuppressWarnings("rawtypes")
public static Object getQueryAdaptorObject(Class cls) throws SocialActivityException {
    Object obj = null;/*ww  w.  j a v  a 2 s  . c o m*/
    String queryAdapterObjectErrorMessage = "Unable to get Query Adapter object";
    try {
        obj = cls.newInstance();
        return obj;
    } catch (InstantiationException e) {
        log.error(queryAdapterObjectErrorMessage + e.getMessage());
        throw new SocialActivityException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        log.error(queryAdapterObjectErrorMessage + e.getMessage());
        throw new SocialActivityException(e.getMessage(), e);
    }

}

From source file:org.jahia.tools.imageprocess.ImageProcess.java

public static boolean save(int type, ImagePlus ip, File outputFile) {
    switch (type) {
    case Opener.TIFF:
        return new FileSaver(ip).saveAsTiff(outputFile.getPath());
    case Opener.GIF:
        return new FileSaver(ip).saveAsGif(outputFile.getPath());
    case Opener.JPEG:
        return new FileSaver(ip).saveAsJpeg(outputFile.getPath());
    case Opener.TEXT:
        return new FileSaver(ip).saveAsText(outputFile.getPath());
    case Opener.LUT:
        return new FileSaver(ip).saveAsLut(outputFile.getPath());
    case Opener.ZIP:
        return new FileSaver(ip).saveAsZip(outputFile.getPath());
    case Opener.BMP:
        return new FileSaver(ip).saveAsBmp(outputFile.getPath());
    case Opener.PNG:
        ImagePlus tempImage = WindowManager.getTempCurrentImage();
        WindowManager.setTempCurrentImage(ip);
        PlugIn p = null;/*w  w w. j a  va  2 s .c om*/
        try {
            p = (PlugIn) Class.forName("ij.plugin.PNG_Writer").newInstance();
        } catch (InstantiationException e) {
            logger.error(e.getMessage(), e);
        } catch (IllegalAccessException e) {
            logger.error(e.getMessage(), e);
        } catch (ClassNotFoundException e) {
            logger.error(e.getMessage(), e);
        }
        p.run(outputFile.getPath());
        WindowManager.setTempCurrentImage(tempImage);
        return true;
    case Opener.PGM:
        return new FileSaver(ip).saveAsPgm(outputFile.getPath());
    }
    return false;
}

From source file:com.flexive.shared.cache.FxBackingCacheProviderFactory.java

/**
 * Factory method to create a new FxBackingCacheProvider
 * <p/>/*from w ww  . ja v a2  s  . c om*/
 * Strategy used in this order in case of failure:
 * <ol>
 * <li>if System property is set try to obtain a new instance of the given class</li>
 * <li>try to get a JNDI TreeCache instance with key "FxJBossTreeCache"</li>
 * <li>create a local TreeCache MBean</li>
 * </ol>
 *
 * @return FxBackingCacheProvider
 */
public static FxBackingCacheProvider createNew() {
    String provider = System.getProperty(KEY);
    FxBackingCacheProvider instance = null;
    try {
        if (provider != null) {
            //try provided class
            try {
                instance = (FxBackingCacheProvider) Class.forName(provider).newInstance();
                return instance;
            } catch (InstantiationException e) {
                LOG.error("Failed to instantiate " + provider + ": " + e.getMessage(), e);
            } catch (IllegalAccessException e) {
                LOG.error(e.getMessage(), e);
            } catch (ClassNotFoundException e) {
                LOG.error("Could not find class " + provider + ": " + e.getMessage(), e);
            }
        }
        try {
            instance = new FxJBossExternalCacheProvider();
            instance.init();
            return instance;
        } catch (FxCacheException e) {
            LOG.info("Failed to instantiate FxJBossExternalCacheProvider: " + e.getMessage());
        }
        try {
            instance = new FxJBossEmbeddedCacheProvider();
            instance.init();
        } catch (FxCacheException e) {
            final String message = "Failed to instantiate embedded cache: " + e.getMessage();
            LOG.error(message, e);
            throw new IllegalStateException(message, e);
        }
    } finally {
        if (instance != null)
            LOG.info("Using FxBackingCacheProvider instance " + instance.getClass().getCanonicalName());
        else
            LOG.fatal("Failed to create a FxBackingCacheProvider instance!");
    }
    return instance;
}

From source file:org.rivalry.core.funcprog.ListUtils.java

/**
 * @param list List.//  w ww  .  j  a  v  a2  s. co  m
 * 
 * @return a new instance of the given type of list.
 */
private static <E> List<E> newInstance(final List<E> list) {
    List<E> answer = null;

    try {
        @SuppressWarnings("unchecked")
        final List<E> newList = list.getClass().newInstance();
        answer = newList;
    } catch (final InstantiationException e) {
        throw new RuntimeException(e.getMessage());
    } catch (final IllegalAccessException e) {
        throw new RuntimeException(e.getMessage());
    }

    return answer;
}

From source file:tk.tomby.tedit.services.PluginManager.java

/**
 * DOCUMENT ME!/*from w  ww  . ja va 2 s.co m*/
 *
 * @param name DOCUMENT ME!
 * @param clazz DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
public static IPlugin createPlugin(IPluginDescriptor descriptor) {
    IPlugin plugin = null;

    try {
        PluginClassLoader loader = new PluginClassLoader(descriptor, PluginManager.class.getClassLoader());

        if (descriptor.getPreferencePage() != null) {
            IPreferencePage pluginPage = new PreferencePageDriver(descriptor.getPluginName(),
                    descriptor.getPreferencePage(), loader).create();

            WorkspaceManager.getPreferences().addPage(pluginPage);
        } else {
            if (descriptor.getPreferences() != null) {
                PreferenceManager.loadCategory(descriptor.getPluginName(), descriptor.getPreferences());
            }

            if (descriptor.getResources() != null) {
                ResourceManager.loadCategory(descriptor.getPluginName(), descriptor.getResources(), loader);
            }
        }

        plugin = loadPlugin(descriptor, loader);
        plugin.init();

        if (descriptor.getPluginType().equals(IPluginDescriptor.PLUGIN_WORKSPACE_TYPE)) {
            WorkspaceManager.addPlugin(WorkspaceManager.PLUGIN_WORKSPACE_POSITION, plugin);
        } else if (descriptor.getPluginType().equals(IPluginDescriptor.PLUGIN_STATUS_TYPE)) {
            WorkspaceManager.addPlugin(WorkspaceManager.PLUGIN_STATUSBAR_POSITION, plugin);
        }

        plugins.put(descriptor.getPluginName(), plugin);
        descriptors.put(descriptor.getPluginName(), descriptor);
        loaders.put(descriptor.getPluginName(), loader);
    } catch (InstantiationException e) {
        log.error(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        log.error(e.getMessage(), e);
    } catch (ClassNotFoundException e) {
        log.error(e.getMessage(), e);
    }

    return plugin;
}

From source file:com.tacitknowledge.util.migration.jdbc.util.SqlUtil.java

/**
 * Established and returns a connection based on the specified parameters.
 *
 * @param driver the JDBC driver to use// w w  w  .jav  a2 s.com
 * @param url    the database URL
 * @param user   the username
 * @param pass   the password
 * @return a JDBC connection
 * @throws ClassNotFoundException if the driver could not be loaded
 * @throws SQLException           if a connnection could not be made to the database
 */
public static Connection getConnection(String driver, String url, String user, String pass)
        throws ClassNotFoundException, SQLException {
    Connection conn = null;
    try {
        Class.forName(driver);
        log.debug("Getting Connection to " + url);
        conn = DriverManager.getConnection(url, user, pass);
    } catch (Exception e) {
        /* work around for DriverManager 'feature'.  
         * In some cases, the jdbc driver jar is injected into a new 
         * child classloader (for example, maven provides different 
         * class loaders for different build lifecycle phases). 
         * 
         * Since DriverManager uses the calling class' loader instead 
         * of the current context's loader, it fails to find the driver.
         * 
         * Our work around is to give the current context's class loader 
         * a shot at finding the driver in cases where DriverManager fails.  
         * This 'may be' a security hole which is why DriverManager implements 
         * things in such a way that it doesn't use the current thread context class loader.
         */
        try {
            Class driverClass = Class.forName(driver, true, Thread.currentThread().getContextClassLoader());
            Driver driverImpl = (Driver) driverClass.newInstance();
            Properties props = new Properties();
            props.put("user", user);
            props.put("password", pass);
            conn = driverImpl.connect(url, props);
        } catch (InstantiationException ie) {
            log.debug(ie);
            throw new SQLException(ie.getMessage());
        } catch (IllegalAccessException iae) {
            log.debug(iae);
            throw new SQLException(iae.getMessage());
        }
    }

    return conn;
}

From source file:org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo.java

/** creates a list of KimAttributeDataBos from attributes, kimTypeId, and assignedToId. */
public static <T extends KimAttributeDataBo> List<T> createFrom(Class<T> type, Map<String, String> attributes,
        String kimTypeId) {//from   w ww .j  a va2s.  co  m
    if (attributes == null) {
        //purposely not using Collections.emptyList() b/c we do not want to return an unmodifiable list.
        return new ArrayList<T>();
    }
    List<T> attrs = new ArrayList<T>();
    for (Map.Entry<String, String> it : attributes.entrySet()) {
        //return attributes.entrySet().collect {
        KimTypeAttribute attr = getKimTypeInfoService().getKimType(kimTypeId)
                .getAttributeDefinitionByName(it.getKey());
        KimType theType = getKimTypeInfoService().getKimType(kimTypeId);
        if (attr != null && StringUtils.isNotBlank(it.getValue())) {
            try {
                T newDetail = type.newInstance();
                newDetail.setKimAttributeId(attr.getKimAttribute().getId());
                newDetail.setKimAttribute(KimAttributeBo.from(attr.getKimAttribute()));
                newDetail.setKimTypeId(kimTypeId);
                newDetail.setKimType(KimTypeBo.from(theType));
                newDetail.setAttributeValue(it.getValue());
                attrs.add(newDetail);
            } catch (InstantiationException e) {
                LOG.error(e.getMessage(), e);
            } catch (IllegalAccessException e) {
                LOG.error(e.getMessage(), e);
            }

        }
    }
    return attrs;
}

From source file:Main.java

/**
 * New instance for the given class name.{@link #forName(String)}
 *
 * @param className/*w  w w.j a v a2  s . c  o m*/
 * @return
 */
public static Object newInstance(String className) {
    try {
        return forName(className).newInstance();
    } catch (InstantiationException e) {
        throw new IllegalStateException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:org.codehaus.grepo.core.validator.GenericValidationUtils.java

/**
 * Validates the given {@code result} using the given {@link ResultValidator} {@code clazz}.
 *
 * @param mpi The method parameter info.
 * @param clazz The validator clazz (must not be null).
 * @param result The result to validate.
 * @throws Exception in case of errors (like validation errors).
 * @throws ValidationException if the given {@link ResultValidator} cannot be instantiated.
 */// www.j  a va  2s.c o m
public static void validateResult(MethodParameterInfo mpi, Class<? extends ResultValidator> clazz,
        Object result) throws Exception, ValidationException {
    if (isValidResultValidator(clazz)) {
        ResultValidator validator = null;
        try {
            logger.debug("Using result validator '{}' for validating result '{}'", clazz, result);
            validator = clazz.newInstance();
        } catch (InstantiationException e) {
            String msg = String.format("Unable to create new instance of '%s': '%s'", clazz.getName(),
                    e.getMessage());
            throw new ValidationException(msg, e);
        } catch (IllegalAccessException e) {
            String msg = String.format("Unable to create new instance of '%s': '%s'", clazz.getName(),
                    e.getMessage());
            throw new ValidationException(msg, e);
        }

        try {
            validator.validate(result);
        } catch (Exception e) {
            logger.debug("Validation error occured: {}", e.getMessage());

            if (mpi.isMethodCompatibleWithException(e)) {
                throw e;
            } else {
                String m = "Exception '%s' is not compatible with  method '%s' (exeptionTypes: %s) "
                        + "- exception will be wrapped in a ValidationException";
                String msg = String.format(m, e.getClass().getName(), mpi.getMethodName(),
                        ArrayUtils.toString(mpi.getMethod().getExceptionTypes()));
                logger.error(msg);
                throw new ValidationException(msg);
            }
        }
    }
}