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:org.openhab.persistence.jdbc.internal.JdbcConfiguration.java

/**
 * @{inheritDoc//  www.j a v a  2s.c  o m
 */
public void updateConfig(Map<Object, Object> configuration) {
    logger.debug("JDBC::updateConfig: configuration.size = " + configuration.size());

    // Database-Url jdbc:h2:./testH2
    String url = (String) configuration.get("url");
    Properties parsedURL = StringUtilsExt.parseJdbcURL(url);
    logger.debug("JDBC::updateConfig: url={}", url);
    if (StringUtils.isBlank(url) || parsedURL.getProperty("parseValid") == "false") {
        logger.error(
                "JDBC::updateConfig: url The SQL database URL is missing - please configure the jdbc:url parameter in openhab.cfg");
    } else {
        dbName = parsedURL.getProperty("databaseName");
    }

    // Which DB-Type to use
    serviceName = parsedURL.getProperty("dbShortcut"); // derby, h2, hsqldb, mariadb, mysql, postgresql, sqlite
    logger.debug("JDBC::updateConfig: found serviceName = '{}'", serviceName);
    if (StringUtils.isBlank(serviceName) || serviceName.length() < 2) {
        serviceName = "no";
        logger.error(
                "JDBC::updateConfig: url Required database url like 'jdbc:<service>:<host>[:<port>;<attributes>]' - please configure the jdbc:url parameter in openhab.cfg");
    }

    // DB Class
    String ddp = DB_DAO_PACKAGE + serviceName.toUpperCase().charAt(0) + serviceName.toLowerCase().substring(1)
            + "DAO";

    logger.debug("JDBC::updateConfig: Init Data Access Object Class: '{}'", ddp);
    try {

        dBDAO = (JdbcBaseDAO) Class.forName(ddp).newInstance();
        // dBDAO.databaseProps.setProperty("jdbcUrl", url);
        // dBDAO.databaseProps.setProperty("dataSource.url", url);

        logger.debug("JDBC::updateConfig: dBDAO ClassName={}", dBDAO.getClass().getName());
    } catch (InstantiationException e) {
        logger.error("JDBC::updateConfig: InstantiationException: {}", e.getMessage());
    } catch (IllegalAccessException e) {
        logger.error("JDBC::updateConfig: IllegalAccessException: {}", e.getMessage());
    } catch (ClassNotFoundException e) {
        logger.warn(
                "JDBC::updateConfig: no Configuration for serviceName '{}' found. ClassNotFoundException: {}",
                serviceName, e.getMessage());
        logger.debug("JDBC::updateConfig: using default Database Configuration: JdbcBaseDAO !!");
        dBDAO = new JdbcBaseDAO();
        logger.debug("JDBC::updateConfig: dBConfig done");
    }

    @SuppressWarnings("unchecked")
    Enumeration<String> keys = new IteratorEnumeration(configuration.keySet().iterator());

    while (keys.hasMoreElements()) {
        String key = keys.nextElement();

        Matcher matcher = EXTRACT_CONFIG_PATTERN.matcher(key);

        if (!matcher.matches()) {
            continue;
        }

        matcher.reset();
        matcher.find();

        if (!matcher.group(1).equals("sqltype"))
            continue;

        String itemType = matcher.group(2).toUpperCase() + "ITEM";
        String value = (String) configuration.get(key);

        logger.debug("JDBC::updateConfig: set sqlTypes: itemType={} value={}", itemType, value);
        dBDAO.sqlTypes.put(itemType, value);
    }

    String user = (String) configuration.get("user");
    logger.debug("JDBC::updateConfig:  user={}", user);
    if (StringUtils.isBlank(user)) {
        logger.error(
                "JDBC::updateConfig: SQL user is missing - please configure the jdbc:user parameter in openhab.cfg");
    } else {
        dBDAO.databaseProps.setProperty("dataSource.user", user);
    }

    String password = (String) configuration.get("password");
    if (StringUtils.isBlank(password)) {
        logger.error("JDBC::updateConfig: SQL password is missing. Attempting to connect without password. "
                + "To specify a password configure the jdbc:password parameter in openhab.cfg.");
    } else {
        logger.debug("JDBC::updateConfig:  password=<masked> password.length={}", password.length());
        dBDAO.databaseProps.setProperty("dataSource.password", password);
    }

    String et = (String) configuration.get("reconnectCnt");
    if (StringUtils.isNotBlank(et)) {
        errReconnectThreshold = Integer.parseInt(et);
        logger.debug("JDBC::updateConfig: errReconnectThreshold={}", errReconnectThreshold);
    }

    String np = (String) configuration.get("tableNamePrefix");
    if (StringUtils.isNotBlank(np)) {
        dBDAO.databaseProps.setProperty("tableNamePrefix", np);
    }

    String dd = (String) configuration.get("numberDecimalcount");
    if (StringUtils.isNotBlank(dd)) {
        numberDecimalcount = Integer.parseInt(dd);
        logger.debug("JDBC::updateConfig: numberDecimalcount={}", numberDecimalcount);
    }

    String rn = (String) configuration.get("tableUseRealItemNames");
    if (StringUtils.isNotBlank(rn)) {
        tableUseRealItemNames = "true".equals(rn) ? Boolean.parseBoolean(rn) : false;
        logger.debug("JDBC::updateConfig: tableUseRealItemNames={}", tableUseRealItemNames);
    }

    String td = (String) configuration.get("tableIdDigitCount");
    if (StringUtils.isNotBlank(td)) {
        tableIdDigitCount = Integer.parseInt(td);
        logger.debug("JDBC::updateConfig: tableIdDigitCount={}", tableIdDigitCount);
    }

    String rt = (String) configuration.get("rebuildTableNames");
    if (StringUtils.isNotBlank(rt)) {
        rebuildTableNames = "true".equals(rt) ? Boolean.parseBoolean(rt) : false;
        logger.debug("JDBC::updateConfig: rebuildTableNames={}", rebuildTableNames);
    }
    // undocumented
    String ac = (String) configuration.get("maximumPoolSize");
    if (StringUtils.isNotBlank(ac)) {
        dBDAO.databaseProps.setProperty("maximumPoolSize", ac);
    }
    // undocumented
    String ic = (String) configuration.get("minimumIdle");
    if (StringUtils.isNotBlank(ic)) {
        dBDAO.databaseProps.setProperty("minimumIdle", ic);
    }
    // undocumented
    String it = (String) configuration.get("idleTimeout");
    if (StringUtils.isNotBlank(it)) {
        dBDAO.databaseProps.setProperty("idleTimeout", it);
    }
    // undocumented
    String ent = (String) configuration.get("enableLogTime");
    if (StringUtils.isNotBlank(ent)) {
        enableLogTime = "true".equals(ent) ? Boolean.parseBoolean(ent) : false;
    }
    logger.debug("JDBC::updateConfig: enableLogTime {}", enableLogTime);

    // undocumented
    String fd = (String) configuration.get("driverClassName");
    if (StringUtils.isNotBlank(fd)) {
        dBDAO.databaseProps.setProperty("driverClassName", fd);
    }
    // undocumented
    String ds = (String) configuration.get("dataSourceClassName");
    if (StringUtils.isNotBlank(ds)) {
        dBDAO.databaseProps.setProperty("dataSourceClassName", ds);
    }

    driverAvailable = true;
    String dn = dBDAO.databaseProps.getProperty("driverClassName");
    if (dn == null) {
        dn = dBDAO.databaseProps.getProperty("dataSourceClassName");
    } else {
        dBDAO.databaseProps.setProperty("jdbcUrl", url);
    }

    logger.warn("JDBC::updateConfig: try to load JDBC-driverClass: '{}'", dn);
    try {
        Class.forName(dn);
        logger.debug("JDBC::updateConfig: load JDBC-driverClass was successful: '{}'", dn);
    } catch (ClassNotFoundException e) {
        driverAvailable = false;
        logger.error(
                "JDBC::updateConfig: could NOT load JDBC-driverClassName or JDBC-dataSourceClassName ClassNotFoundException: '{}'",
                e.getMessage());
        String warn = ""
                + "\n\n\t!!!\n\tTo avoid this error, place a appropriate JDBC driver file for serviceName '{}' in addons directory.\n"
                + "\tCopy missing JDBC-Driver-jar to your OpenHab/addons Folder.\n\t!!!\n" + "\tDOWNLOAD: \n";
        if (serviceName.equals("derby"))
            warn += "\tDerby:     version >= 10.11.1.1 from          http://mvnrepository.com/artifact/org.apache.derby/derby\n";
        else if (serviceName.equals("h2"))
            warn += "\tH2:        version >= 1.4.189 from            http://mvnrepository.com/artifact/com.h2database/h2\n";
        else if (serviceName.equals("hsqldb"))
            warn += "\tHSQLDB:    version >= 2.3.3 from              http://mvnrepository.com/artifact/org.hsqldb/hsqldb\n";
        else if (serviceName.equals("mariadb"))
            warn += "\tMariaDB:   version >= 1.2.0 from              http://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client\n";
        else if (serviceName.equals("mysql"))
            warn += "\tMySQL:     version >= 5.1.36 from             http://mvnrepository.com/artifact/mysql/mysql-connector-java\n";
        else if (serviceName.equals("postgresql"))
            warn += "\tPostgreSQL:version >= 9.4-1201-jdbc41 from    http://mvnrepository.com/artifact/org.postgresql/postgresql\n";
        else if (serviceName.equals("sqlite"))
            warn += "\tSQLite:    version >= 3.8.11.2 from           http://mvnrepository.com/artifact/org.xerial/sqlite-jdbc\n";
        logger.warn(warn, serviceName);
    }

    logger.debug("JDBC::updateConfig: configuration complete. service={}", getName());
}

From source file:net.sf.joost.trax.TransformerFactoryImpl.java

/**
 * Method creates a new Emitter for stx:message output
 * @param emitterClass the name of the emitter class
 * @return a <code>StxEmitter</code>
 * @throws TransformerConfigurationException in case of errors
 *///from   ww  w. j av  a 2 s. c om
public StxEmitter buildMessageEmitter(String emitterClass) throws TransformerConfigurationException {

    Object emitter = null;
    try {
        emitter = loadClass(emitterClass).newInstance();
        if (!(emitter instanceof StxEmitter)) {
            throw new TransformerConfigurationException(emitterClass + " is not an StxEmitter");
        }
    } catch (InstantiationException ie) {
        throw new TransformerConfigurationException(ie.getMessage(), ie);
    } catch (IllegalAccessException ile) {
        throw new TransformerConfigurationException(ile.getMessage(), ile);
    }

    return (StxEmitter) emitter;
}

From source file:com.apifest.oauth20.AuthorizationServer.java

protected UserDetails callCustomGrantTypeHandler(HttpRequest authRequest) throws AuthenticationException {
    UserDetails userDetails = null;//  w ww. j  av a 2  s .co  m
    ICustomGrantTypeHandler customHandler;
    if (OAuthServer.getCustomGrantTypeHandler() != null) {
        try {
            customHandler = OAuthServer.getCustomGrantTypeHandler().newInstance();
            userDetails = customHandler.execute(authRequest);
        } catch (InstantiationException e) {
            log.error("cannot instantiate custom grant_type class", e);
            throw new AuthenticationException(e.getMessage());
        } catch (IllegalAccessException e) {
            log.error("cannot instantiate custom grant_type class", e);
            throw new AuthenticationException(e.getMessage());
        }
    }
    return userDetails;
}

From source file:nz.co.gregs.dbvolution.datatypes.QueryableDatatypeSyncer.java

/**
 *
 * @param propertyName used in error messages
 * @param internalQdtType internalQdtType
 * @param internalQdtLiteralType internalQdtLiteralType
 * @param externalSimpleType externalSimpleType
 * @param typeAdaptor typeAdaptor typeAdaptor
 *///from  w ww .ja  va  2s. co  m
public QueryableDatatypeSyncer(String propertyName, Class<? extends QueryableDatatype> internalQdtType,
        Class<?> internalQdtLiteralType, Class<?> externalSimpleType,
        DBTypeAdaptor<Object, Object> typeAdaptor) {
    if (typeAdaptor == null) {
        throw new DBRuntimeException("Null typeAdaptor was passed, this is an internal bug");
    }
    this.propertyName = propertyName;
    this.typeAdaptor = typeAdaptor;
    this.internalQdtType = internalQdtType;
    this.toExternalSimpleTypeAdaptor = new SafeOneWaySimpleTypeAdaptor(propertyName, typeAdaptor,
            Direction.TO_EXTERNAL, internalQdtLiteralType, externalSimpleType);

    this.toInternalSimpleTypeAdaptor = new SafeOneWaySimpleTypeAdaptor(propertyName, typeAdaptor,
            Direction.TO_INTERNAL, externalSimpleType, internalQdtLiteralType);

    try {
        this.internalQdt = internalQdtType.newInstance();
    } catch (InstantiationException e) {
        // TODO produce a better error message that is consistent with how this is handled elsewhere
        throw new DBRuntimeException("Instantiation error creating internal " + internalQdtType.getSimpleName()
                + " QDT: " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        // TODO produce a better error message that is consistent with how this is handled elsewhere
        throw new DBRuntimeException(
                "Access error creating internal " + internalQdtType.getSimpleName() + " QDT: " + e.getMessage(),
                e);
    }
}

From source file:com.apifest.oauth20.AuthorizationServer.java

protected UserDetails authenticateUser(String username, String password, HttpRequest authRequest)
        throws AuthenticationException {
    UserDetails userDetails = null;/*  w  ww  .j  a  v  a 2s.  c  o  m*/
    IUserAuthentication ua;
    if (OAuthServer.getUserAuthenticationClass() != null) {
        try {
            ua = OAuthServer.getUserAuthenticationClass().newInstance();
            userDetails = ua.authenticate(username, password, authRequest);
        } catch (InstantiationException e) {
            log.error("cannot instantiate user authentication class", e);
            throw new AuthenticationException(e.getMessage());
        } catch (IllegalAccessException e) {
            log.error("cannot instantiate user authentication class", e);
            throw new AuthenticationException(e.getMessage());
        }
    } else {
        // if no specific UserAuthentication used, always returns customerId - 12345
        userDetails = new UserDetails("12345", null);
    }
    return userDetails;
}

From source file:org.opoo.press.impl.FactoryImpl.java

private Renderer newInstance(Class<Renderer> clazz, Site site) {
    try {//from  w w w .  jav a  2 s .  co m
        Renderer renderer = clazz.newInstance();
        if (renderer instanceof SiteAware) {
            ((SiteAware) renderer).setSite(site);
        }
        if (renderer instanceof ConfigAware) {
            ((ConfigAware) renderer).setConfig(site.getConfig());
        }

        return renderer;
    } catch (InstantiationException e) {
        throw new RuntimeException("error instance" + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException("error instance" + e.getMessage(), e);
    }
}

From source file:com.google.gsa.valve.rootAuth.RootAuthenticationProcess.java

/**
 * Sets the Valve Configuration instance to read the parameters 
 * from there/*from  ww  w.  ja  va  2s  . co  m*/
 * 
 * @param valveConf the Valve configuration instance
 */
public void setValveConfiguration(ValveConfiguration valveConf) {

    this.valveConf = valveConf;

    //Protection. Make sure the Map is empty before proceeding
    authenticationImplementations.clear();

    //Authentication process instance
    AuthenticationProcessImpl authenticationProcess = null;

    String repositoryIds[] = valveConf.getRepositoryIds();

    ValveRepositoryConfiguration repository = null;

    int order = 1;

    for (int i = 0; i < repositoryIds.length; i++) {
        try {

            repository = valveConf.getRepository(repositoryIds[i]);

            //Check if repository has to be included in the authentication process. By default set it to true
            boolean checkAuthN = true;
            try {
                if ((repository.getCheckAuthN() != null) && (!repository.getCheckAuthN().equals(""))) {
                    checkAuthN = new Boolean(repository.getCheckAuthN()).booleanValue();
                }
            } catch (Exception e) {
                logger.error("Error when reading checkAuthN param: " + e.getMessage(), e);
                //protection
                checkAuthN = true;
            }

            if (checkAuthN) {
                logger.info(
                        "Initialising authentication process for " + repository.getId() + " [#" + order + "]");
                authenticationProcess = (AuthenticationProcessImpl) Class.forName(repository.getAuthN())
                        .newInstance();
                authenticationProcess.setValveConfiguration(valveConf);
                //add this authentication process to the Map
                synchronized (authenticationImplementations) {
                    synchronized (authenticationImplementations) {
                        authenticationImplementations.put(repository.getId(), authenticationProcess);
                        authenticationImplementationsOrder.put(new Integer(order), repository.getId());
                        order++;
                    }
                }

            } else {
                logger.debug("Authentication process for repository [" + repository.getId()
                        + "] is not going to be launched");
            }

        } catch (LinkageError le) {
            logger.error(repository.getId()
                    + " - Can't instantiate class [AuthenticationProcess-LinkageError]: " + le.getMessage(),
                    le);
        } catch (InstantiationException ie) {
            logger.error(repository.getId()
                    + " - Can't instantiate class [AuthenticationProcess-InstantiationException]: "
                    + ie.getMessage(), ie);
        } catch (IllegalAccessException iae) {
            logger.error(repository.getId()
                    + " - Can't instantiate class [AuthenticationProcess-IllegalAccessException]: "
                    + iae.getMessage(), iae);
        } catch (ClassNotFoundException cnfe) {
            logger.error(repository.getId()
                    + " - Can't instantiate class [AuthenticationProcess-ClassNotFoundException]: "
                    + cnfe.getMessage(), cnfe);
        } catch (Exception e) {
            logger.error(repository.getId() + " - Can't instantiate class [AuthenticationProcess-Exception]: "
                    + e.getMessage(), e);
        }
    }
    logger.debug(RootAuthenticationProcess.class.getName() + " initialised");
}

From source file:org.apache.gora.dynamodb.store.DynamoDBNativeStore.java

/**
 * Returns a new persistent object/*from ww  w . j  av a2  s.co  m*/
 *
 * @return
 */
@Override
public T newPersistent() {
    T obj = null;
    try {
        obj = persistentClass.newInstance();
    } catch (InstantiationException e) {
        LOG.error("Error instantiating " + persistentClass.getCanonicalName());
        throw new InstantiationError(e.getMessage());
    } catch (IllegalAccessException e) {
        LOG.error("Error instantiating " + persistentClass.getCanonicalName());
        throw new IllegalAccessError(e.getMessage());
    }
    return obj;
}

From source file:org.nuxeo.ecm.platform.ui.web.auth.service.PluggableAuthenticationService.java

@Override
public void registerContribution(Object contribution, String extensionPoint, ComponentInstance contributor) {

    if (extensionPoint.equals(EP_AUTHENTICATOR)) {
        AuthenticationPluginDescriptor descriptor = (AuthenticationPluginDescriptor) contribution;
        if (authenticatorsDescriptors.containsKey(descriptor.getName())) {
            mergeDescriptors(descriptor);
            log.debug("merged AuthenticationPluginDescriptor: " + descriptor.getName());
        } else {//from w w w  .  jav  a 2s.  com
            authenticatorsDescriptors.put(descriptor.getName(), descriptor);
            log.debug("registered AuthenticationPluginDescriptor: " + descriptor.getName());
        }

        // create the new instance
        AuthenticationPluginDescriptor actualDescriptor = authenticatorsDescriptors.get(descriptor.getName());
        try {
            NuxeoAuthenticationPlugin authPlugin = actualDescriptor.getClassName().newInstance();
            authPlugin.initPlugin(actualDescriptor.getParameters());
            authenticators.put(actualDescriptor.getName(), authPlugin);
        } catch (InstantiationException e) {
            log.error("Unable to create AuthPlugin for : " + actualDescriptor.getName() + "Error : "
                    + e.getMessage(), e);
        } catch (IllegalAccessException e) {
            log.error("Unable to create AuthPlugin for : " + actualDescriptor.getName() + "Error : "
                    + e.getMessage(), e);
        }

    } else if (extensionPoint.equals(EP_CHAIN)) {
        AuthenticationChainDescriptor chainContrib = (AuthenticationChainDescriptor) contribution;
        log.debug("New authentication chain powered by " + contributor.getName());
        authChain.clear();
        authChain.addAll(chainContrib.getPluginsNames());
    } else if (extensionPoint.equals(EP_OPENURL)) {
        OpenUrlDescriptor openUrlContrib = (OpenUrlDescriptor) contribution;
        openUrls.add(openUrlContrib);
    } else if (extensionPoint.equals(EP_STARTURL)) {
        StartURLPatternDescriptor startupURLContrib = (StartURLPatternDescriptor) contribution;
        startupURLs.addAll(startupURLContrib.getStartURLPatterns());
    } else if (extensionPoint.equals(EP_PROPAGATOR)) {
        AuthenticationPropagatorDescriptor propagationContrib = (AuthenticationPropagatorDescriptor) contribution;

        // create the new instance
        try {
            propagator = propagationContrib.getClassName().newInstance();
        } catch (InstantiationException e) {
            log.error("Unable to create propagator", e);
        } catch (IllegalAccessException e) {
            log.error("Unable to create propagator", e);
        }
    } else if (extensionPoint.equals(EP_CBFACTORY)) {
        CallbackHandlerFactoryDescriptor cbhfContrib = (CallbackHandlerFactoryDescriptor) contribution;

        // create the new instance
        try {
            cbhFactory = cbhfContrib.getClassName().newInstance();
        } catch (InstantiationException e) {
            log.error("Unable to create callback handler factory", e);
        } catch (IllegalAccessException e) {
            log.error("Unable to create callback handler factory", e);
        }
    } else if (extensionPoint.equals(EP_SESSIONMANAGER)) {
        SessionManagerDescriptor smContrib = (SessionManagerDescriptor) contribution;
        if (smContrib.enabled) {
            try {
                NuxeoAuthenticationSessionManager sm = smContrib.getClassName().newInstance();
                sessionManagers.put(smContrib.getName(), sm);
            } catch (ReflectiveOperationException e) {
                log.error("Unable to create session manager", e);
            }
        } else {
            sessionManagers.remove(smContrib.getName());
        }
    } else if (extensionPoint.equals(EP_SPECIFIC_CHAINS)) {
        SpecificAuthChainDescriptor desc = (SpecificAuthChainDescriptor) contribution;
        specificAuthChains.put(desc.name, desc);
    } else if (extensionPoint.equals(EP_PREFILTER)) {
        AuthPreFilterDescriptor desc = (AuthPreFilterDescriptor) contribution;
        if (preFiltersDesc == null) {
            preFiltersDesc = new HashMap<String, AuthPreFilterDescriptor>();
        }

        if (desc.enabled) {
            preFiltersDesc.put(desc.getName(), desc);
        } else {
            preFiltersDesc.remove(desc.getName());
        }
    } else if (extensionPoint.equals(EP_LOGINSCREEN)) {
        LoginScreenConfig newConfig = (LoginScreenConfig) contribution;
        loginScreenConfigRegistry.addContribution(newConfig);
    }
}

From source file:net.reichholf.dreamdroid.activities.MainActivity.java

@Override
public void showDialogFragment(Class<? extends DialogFragment> fragmentClass, Bundle args, String tag) {
    DialogFragment f = null;//  w  w w  .j  a v a2s. co m
    try {
        f = fragmentClass.newInstance();
        f.setArguments(args);
        showDialogFragment(f, tag);
    } catch (InstantiationException e) {
        Log.e(TAG, e.getMessage());
    } catch (IllegalAccessException e) {
        Log.e(TAG, e.getMessage());
    }
}