Example usage for java.lang InstantiationError InstantiationError

List of usage examples for java.lang InstantiationError InstantiationError

Introduction

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

Prototype

public InstantiationError(String s) 

Source Link

Document

Constructs an InstantiationError with the specified detail message.

Usage

From source file:com.ebaotech.salesplatform.commons.helper.SimpleSharedPreferences.java

/**
 * <h1><u>Do not use this method</u></h1> <br>
 *//*from ww w  .  j av a  2  s .  co m*/
@Deprecated
@Override
public boolean commit() throws InstantiationError {
    if (mEditor != null) {
        return mEditor.commit();
    }
    throw new InstantiationError("\n ======================================== \nError : " + "Do not call " + tag
            + "'s `commit()`." + "\n This method is not supported directly."
            + " \n ======================================== \n");

}

From source file:org.vietspider.net.client.impl.AnonymousHttpClient.java

@Override
protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    registry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

    ClientConnectionManager connManager = null;
    HttpParams params = getParams();/*from   w  w  w. j  a  va2s. co  m*/

    ClientConnectionManagerFactory factory = null;

    // Try first getting the factory directly as an object.
    factory = (ClientConnectionManagerFactory) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY);
    if (factory == null) { // then try getting its class name.
        String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
        if (className != null) {
            try {
                Class<?> clazz = Class.forName(className);
                factory = (ClientConnectionManagerFactory) clazz.newInstance();
            } catch (ClassNotFoundException ex) {
                throw new IllegalStateException("Invalid class name: " + className);
            } catch (IllegalAccessException ex) {
                throw new IllegalAccessError(ex.getMessage());
            } catch (InstantiationException ex) {
                throw new InstantiationError(ex.getMessage());
            }
        }
    }

    if (factory != null) {
        connManager = factory.newInstance(params, registry);
    } else {
        connManager = new SingleClientConnManager(getParams(), registry);
    }

    return connManager;
}

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

/**
 * Returns a new persistent object/*from w  ww  . ja  v  a  2s .c o  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.kuali.rice.krad.data.platform.MaxValueIncrementerFactory.java

/**
 * Checks the config file for any references to
 * {@code rice.krad.data.platform.incrementer.(DATASOURCE, ex mysql, oracle).(VERSION optional)}.
 *
 * <p>If matching one found attempts to instantiate it to return back to factory for use.</p>
 *
 * @param platformInfo the {@link DatabasePlatformInfo}.
 * @param dataSource the {@link DataSource} for which to retrieve the incrementer.
 * @param incrementerName the name of the incrementer.
 * @param columnName the name of the column to increment.
 * @return a config set customized incrementer that matches and can be used to generate the next incremented value
 *         for the given incrementer against the specified {@link DataSource}
 * @throws InstantiationError if cannot instantiate passed in class.
 *///from   ww w . j av a 2 s  . c o  m
private static DataFieldMaxValueIncrementer getCustomizedIncrementer(DatabasePlatformInfo platformInfo,
        DataSource dataSource, String incrementerName, String columnName) {
    if (platformInfo == null) {
        throw new IllegalArgumentException("DataSource platform must not be null");
    }
    if (ConfigContext.getCurrentContextConfig() == null) {
        return null;
    }
    Map<String, String> incrementerPropToIncrementer = ConfigContext.getCurrentContextConfig()
            .getPropertiesWithPrefix(PLATFORM_INCREMENTER_PREFIX, true);
    String platformNameVersion = platformInfo.getName().toLowerCase() + "." + platformInfo.getMajorVersion();
    String incrementerClassName = "";

    if (incrementerPropToIncrementer.containsKey(platformNameVersion)) {
        incrementerClassName = incrementerPropToIncrementer.get(platformNameVersion);
    } else if (incrementerPropToIncrementer.containsKey(platformInfo.getName().toLowerCase())) {
        incrementerClassName = incrementerPropToIncrementer.get(platformInfo.getName().toLowerCase());
    }

    if (StringUtils.isNotBlank(incrementerClassName)) {
        try {
            Class incrementerClass = Class.forName(incrementerClassName);
            if (AbstractSequenceMaxValueIncrementer.class.isAssignableFrom(incrementerClass)) {
                AbstractSequenceMaxValueIncrementer abstractSequenceMaxValueIncrementer = (AbstractSequenceMaxValueIncrementer) incrementerClass
                        .newInstance();
                abstractSequenceMaxValueIncrementer.setDataSource(dataSource);
                abstractSequenceMaxValueIncrementer.setIncrementerName(incrementerName);
                return abstractSequenceMaxValueIncrementer;

            } else if (AbstractColumnMaxValueIncrementer.class.isAssignableFrom(incrementerClass)) {
                AbstractColumnMaxValueIncrementer abstractColumnMaxValueIncrementer = (AbstractColumnMaxValueIncrementer) incrementerClass
                        .newInstance();
                abstractColumnMaxValueIncrementer.setDataSource(dataSource);
                abstractColumnMaxValueIncrementer.setIncrementerName(incrementerName);
                abstractColumnMaxValueIncrementer.setColumnName(columnName);
                return abstractColumnMaxValueIncrementer;
            } else {
                throw new InstantiationError(
                        "Cannot create incrementer class " + incrementerClassName + " it has to extend "
                                + "AbstractSequenceMaxValueIncrementer or AbstractColumnMaxValueIncrementer");
            }
        } catch (Exception e) {
            throw new InstantiationError("Could not instantiate custom incrementer " + incrementerClassName);
        }
    }
    return null;
}

From source file:hm.binkley.util.XPropsConverter.java

private static <T, E extends Exception> Conversion<T, E> invokeConstructor(final Class<T> token)
        throws NoSuchMethodError {
    try {/*from  w  w w. j  ava 2s.c o  m*/
        final Constructor<T> ctor = token.getConstructor(String.class);
        return value -> {
            try {
                return ctor.newInstance(value);
            } catch (final IllegalAccessException e) {
                final IllegalAccessError x = new IllegalAccessError(e.getMessage());
                x.setStackTrace(e.getStackTrace());
                throw x;
            } catch (final InvocationTargetException e) {
                final Throwable root = getRootCause(e);
                final RuntimeException x = new RuntimeException(root);
                x.setStackTrace(root.getStackTrace());
                throw x;
            } catch (final InstantiationException e) {
                final InstantiationError x = new InstantiationError(e.getMessage());
                x.setStackTrace(e.getStackTrace());
                throw x;
            }
        };
    } catch (final NoSuchMethodException ignored) {
        return null;
    }
}

From source file:com.ebaotech.salesplatform.commons.helper.SimpleSharedPreferences.java

/**
 * <h1><u>Do not use this method</u></h1> <br>
 *///from www  . ja  v a2 s .c o  m
@Deprecated
@Override
public Editor edit() throws InstantiationError {
    if (mEditor != null) {
        return mEditor;
    }

    if (mSharedPreferences == null) {
        throw new InstantiationError("\n ======================================== \nError : " + "Do not call "
                + tag + "'s `edit()`." + "\n This method is not supported directly."
                + " \n ======================================== \n");
    }
    mEditor = mSharedPreferences.edit();
    return mEditor;
}

From source file:org.apache.ambari.server.view.ViewContextImpl.java

private Masker getMasker(ClassLoader cl, ViewConfig viewConfig) {
    try {//from   w ww.  ja va2s  . c o m
        return viewConfig.getMaskerClass(cl).newInstance();
    } catch (Exception e) {
        throw new InstantiationError("Could not create masker instance.");
    }
}

From source file:org.apache.http.impl.client.AbstractHttpClient.java

protected ClientConnectionManager createClientConnectionManager() {
    final SchemeRegistry registry = SchemeRegistryFactory.createDefault();

    ClientConnectionManager connManager = null;
    final HttpParams params = getParams();

    ClientConnectionManagerFactory factory = null;

    final String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
    if (className != null) {
        try {/*from ww  w.  ja  v  a 2  s . c  om*/
            final Class<?> clazz = Class.forName(className);
            factory = (ClientConnectionManagerFactory) clazz.newInstance();
        } catch (final ClassNotFoundException ex) {
            throw new IllegalStateException("Invalid class name: " + className);
        } catch (final IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        } catch (final InstantiationException ex) {
            throw new InstantiationError(ex.getMessage());
        }
    }
    if (factory != null) {
        connManager = factory.newInstance(params, registry);
    } else {
        connManager = new BasicClientConnectionManager(registry);
    }

    return connManager;
}

From source file:org.apache.http2.impl.client.AbstractHttpClient.java

protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = SchemeRegistryFactory.createDefault();

    ClientConnectionManager connManager = null;
    HttpParams params = getParams();/*from   w w  w  .j a v  a  2s . com*/

    ClientConnectionManagerFactory factory = null;

    String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
    if (className != null) {
        try {
            Class<?> clazz = Class.forName(className);
            factory = (ClientConnectionManagerFactory) clazz.newInstance();
        } catch (ClassNotFoundException ex) {
            throw new IllegalStateException("Invalid class name: " + className);
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        } catch (InstantiationException ex) {
            throw new InstantiationError(ex.getMessage());
        }
    }
    if (factory != null) {
        connManager = factory.newInstance(params, registry);
    } else {
        connManager = new BasicClientConnectionManager(registry);
    }

    return connManager;
}

From source file:org.apache.http.impl.client.AbstractStatisticsGatheringHttpClient.java

protected ClientConnectionManager createClientConnectionManager() {
    SchemeRegistry registry = SchemeRegistryFactory.createDefault();

    ClientConnectionManager connManager = null;
    HttpParams params = getParams();/*from  www .  j av  a2  s  . c  om*/

    ClientConnectionManagerFactory factory = null;

    String className = (String) params.getParameter(ClientPNames.CONNECTION_MANAGER_FACTORY_CLASS_NAME);
    if (className != null) {
        try {
            Class<?> clazz = Class.forName(className);
            factory = (ClientConnectionManagerFactory) clazz.newInstance();
        } catch (ClassNotFoundException ex) {
            throw new IllegalStateException("Invalid class name: " + className);
        } catch (IllegalAccessException ex) {
            throw new IllegalAccessError(ex.getMessage());
        } catch (InstantiationException ex) {
            throw new InstantiationError(ex.getMessage());
        }
    }
    if (factory != null) {
        connManager = factory.newInstance(params, registry);
    } else {
        connManager = new SingleClientConnManager(registry);
    }

    return connManager;
}