Example usage for java.lang InstantiationException InstantiationException

List of usage examples for java.lang InstantiationException InstantiationException

Introduction

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

Prototype

public InstantiationException(String s) 

Source Link

Document

Constructs an InstantiationException with the specified detail message.

Usage

From source file:de.xaniox.heavyspleef.core.i18n.YMLControl.java

@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader,
        boolean reload) throws IllegalAccessException, InstantiationException, IOException {
    Validate.notNull(baseName);/*from   w  w w .  jav  a2  s .  c om*/
    Validate.notNull(locale);
    Validate.notNull(format);
    Validate.notNull(loader);

    ResourceBundle bundle = null;

    if (YML_FORMAT.equals(format)) {
        String bundleName = toBundleName(baseName, locale);
        String resourceName = toResourceName(bundleName, format);

        URL url = null;

        if (mode == LoadingMode.CLASSPATH) {
            //The mode forces us to load the resource from classpath
            url = getClass().getResource(classpathDir + resourceName);
        } else if (mode == LoadingMode.FILE_SYSTEM) {
            //If we use the file system mode, try to load the resource from file first
            //and load it from classpath if it fails
            File resourceFile = new File(localeDir, resourceName);

            if (resourceFile.exists() && resourceFile.isFile()) {
                url = resourceFile.toURI().toURL();
            } else {
                url = getClass().getResource(classpathDir + resourceName);
            }
        }

        if (url == null) {
            return null;
        }

        URLConnection connection = url.openConnection();
        if (reload) {
            connection.setUseCaches(false);
        }

        InputStream stream = connection.getInputStream();

        if (stream != null) {
            Reader reader = new InputStreamReader(stream, I18N.UTF8_CHARSET);
            YamlConfiguration config = new YamlConfiguration();

            StringBuilder builder;

            try (BufferedReader bufferedReader = new BufferedReader(reader)) {
                builder = new StringBuilder();

                String read;
                while ((read = bufferedReader.readLine()) != null) {
                    builder.append(read);
                    builder.append('\n');
                }
            }

            try {
                config.loadFromString(builder.toString());
            } catch (InvalidConfigurationException e) {
                throw new InstantiationException(e.getMessage());
            }

            bundle = new YMLResourceBundle(config);
        }
    } else {
        bundle = super.newBundle(baseName, locale, format, loader, reload);
    }

    return bundle;
}

From source file:ORG.oclc.os.SRW.DSpaceLucene.LuceneQueryResult.java

public LuceneQueryResult(QueryArgs qArgs) throws InstantiationException {
    this.qArgs = qArgs;
    try {/*from  w  ww.  ja  v  a 2  s .c om*/
        dspaceContext = new Context();
        if (log.isDebugEnabled()) {
            Exception e = new Exception("in LuceneQueryResult constructor called by:");
            log.debug(e, e);
            log.debug("dspaceContext.isValid()=" + dspaceContext.isValid());
            log.debug("getPageSize=" + qArgs.getPageSize() + ", getQuery=" + qArgs.getQuery() + ", getStart="
                    + qArgs.getStart());
            //                new Exception().printStackTrace();
        }
        result = DSQuery.doQuery(dspaceContext, qArgs);
        if (log.isDebugEnabled())
            log.debug(result.getHitHandles().size() + " handles found");

        // now instantiate the results and put them in their buckets
        Integer myType;
        List collectionHandles = new ArrayList(), communityHandles = new ArrayList(),
                itemHandles = new ArrayList();
        String myHandle;
        for (int i = 0; i < result.getHitHandles().size(); i++) {
            myHandle = (String) result.getHitHandles().get(i);
            myType = (Integer) result.getHitTypes().get(i);

            // add the handle to the appropriate lists
            switch (myType.intValue()) {
            case Constants.ITEM:
                itemHandles.add(myHandle);
                break;

            case Constants.COLLECTION:
                collectionHandles.add(myHandle);
                break;

            case Constants.COMMUNITY:
                communityHandles.add(myHandle);
                break;
            }
        }

        int numItems = itemHandles.size();
        if (log.isDebugEnabled())
            log.debug(numItems + " items found");
        resultItems = new Item[numItems];
        for (int i = 0; i < numItems; i++) {
            myHandle = (String) itemHandles.get(i);
            if (log.isDebugEnabled())
                log.debug("about to resolveToObject");
            Object o = HandleManager.resolveToObject(dspaceContext, myHandle);
            if (log.isDebugEnabled())
                log.debug("did resolveToObject");

            resultItems[i] = (Item) o;
            if (resultItems[i] == null)
                throw new RemoteException(
                        "Query \"" + qArgs.getQuery() + "\" returned unresolvable handle: " + myHandle);
        }

        int postings = result.getHitCount();
        //            int postings=itemHandles.size();
        if (log.isDebugEnabled())
            log.debug("'" + qArgs.getQuery() + "'==> " + postings);
    } catch (Exception e) {
        if (dspaceContext != null)
            dspaceContext.abort();
        throw new InstantiationException(e.getMessage());
    }
}

From source file:gda.hrpd.data.ExcelReader.java

/**
 * constructor that creates an multimap object for holding sample information loaded in from an Excel spreadsheet
 * file specified. If full path name is not specified, it is expecting the sample information file resides in the
 * data directory specified by java property {@code gda.data.scan.datawriter.datadir}.
 * //from   w  w w . j a va 2s .com
 * @param filename
 * @throws InstantiationException
 */
public ExcelReader(String filename) throws InstantiationException {
    if (filename.startsWith("/")) {
        // full path is provided.
        this.filename = filename;
    } else {
        // check if the data directory has been defined
        dataDir = PathConstructor.createFromProperty("gda.data.scan.datawriter.datadir");

        if (this.dataDir == null) {
            // this java property is compulsory - stop the scan
            String error = "java property gda.data.scan.datawriter.datadir not defined - please load your sample information file there.";
            logger.error(error);
            throw new InstantiationException(error);
        }
        // construct full path to the sample information file
        this.filename = dataDir + File.separator + filename;
    }
    try {
        fin = new FileInputStream(this.filename);
    } catch (FileNotFoundException e) {
        logger.warn("Cannot find sample information file {}.", filename);
        JythonServerFacade.getInstance().print("please specify the sample information file name.");
    }
    openSpreadsheet(null);
    mvm = new MultiValueMap();
    readData();
}

From source file:org.nuxeo.opensocial.servlet.GuiceContextListener.java

private Module getModuleInstance(String moduleName) throws InstantiationException {
    try {//from  w w w  . j  av  a 2  s  . c om
        return (Module) Class.forName(moduleName).newInstance();
    } catch (IllegalAccessException e) {
        InstantiationException ie = new InstantiationException("IllegalAccessException: " + e.getMessage());
        ie.setStackTrace(e.getStackTrace());
        throw ie;
    } catch (ClassNotFoundException e) {
        InstantiationException ie = new InstantiationException("ClassNotFoundException: " + e.getMessage());
        ie.setStackTrace(e.getStackTrace());
        throw ie;
    }
}

From source file:org.xmlactions.mapping.bean_to_xml.MapperAttribute.java

private Element useAction(BeanToXml beanToXml, List<KeyValue> keyvalues, String actionName, Element parent,
        Object object, String propertyName)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    log.debug(actionName + " - " + object + propertyName);

    Class clas = Class.forName(actionName);
    Object p = clas.newInstance();
    if (!(p instanceof PopulateXmlFromClassInterface)) {
        throw new InstantiationException(
                actionName + " does not implement " + PopulateXmlFromClassInterface.class.getSimpleName());
    }//from w  w  w  .jav  a2 s  .c o m
    PopulateXmlFromClassInterface pc = (PopulateXmlFromClassInterface) p;
    return pc.performAttributeAction(keyvalues, beanToXml, parent, object, prefix, name, null);

}

From source file:hsyndicate.rest.client.SyndicateUGHttpClient.java

public SyndicateUGHttpClient(String host, int port, String sessionName, String sessionKey)
        throws InstantiationException {
    if (host == null) {
        throw new IllegalArgumentException("host is null");
    }/*from ww  w .  j ava2  s . c  o  m*/

    if (port <= 0) {
        throw new IllegalArgumentException("port is illegal");
    }

    try {
        URI serviceURI = new URI(String.format("http://%s:%d/", host, port));
        initialize(serviceURI, sessionName, sessionKey, API_CALL_DEFAULT);
    } catch (URISyntaxException ex) {
        LOG.error("exception occurred", ex);
        throw new InstantiationException(ex.getMessage());
    }
}

From source file:com.wso2telco.claims.RemoteClaimsRetriever.java

public Map<String, Object> getTotalClaims(String operatorName, CustomerInfo customerInfo)
        throws IllegalAccessException, InstantiationException, ClassNotFoundException {

    Map<String, Object> totalClaims;

    try {//from  ww w. jav  a  2 s . c  om
        totalClaims = getRemoteTotalClaims(operatorName, customerInfo);
    } catch (ClassNotFoundException e) {
        log.error("Class Not Found Exception occurred when calling operator'd endpoint - " + operatorName + ":"
                + e);
        throw new ClassNotFoundException(e.getMessage(), e);
    } catch (InstantiationException e) {
        log.error("Instantiation Exception occurred when calling operator'd endpoint - " + operatorName + ":"
                + e);
        throw new InstantiationException(e.getMessage());
    } catch (IllegalAccessException e) {
        log.error("Illegal Access Exception occurred when calling operator'd endpoint - " + operatorName + ":"
                + e);
        throw new IllegalAccessException(e.getMessage());
    }
    return totalClaims;
}

From source file:org.apache.torque.adapter.AdapterFactory.java

/**
 * Creates a new instance of the Torque database adapter associated
 * with the specified JDBC driver or adapter key.
 *
 * @param key The fully-qualified name of the JDBC driver
 *        or a shorter form adapter key.
 * @return An instance of a Torque database adapter, or null if
 *         no adapter exists for the given key.
 * @throws InstantiationException throws if the adapter could not be
 *         instantiated/*from  w ww  .java  2  s. c  o  m*/
 */
public static Adapter create(String key) throws InstantiationException {
    Class<? extends Adapter> adapterClass = adapters.get(key);

    if (adapterClass == null) {
        return null;
    }

    try {
        Adapter adapter = adapterClass.newInstance();
        return adapter;
    } catch (IllegalAccessException e) {
        throw new InstantiationException("Could not instantiate adapter for key : " + key
                + ": Assure that adapter classes are in your classpath");
    }
}

From source file:it.uniroma2.sag.kelp.data.representation.structure.StructureElementFactory.java

/**
 * Initializes and returns the structureElement described in
 * <code>structureElementBody</code>
 * /* w  w w .ja va  2  s .co  m*/
 * @param structureElementType
 *            the identifier of the structureElement class to be
 *            instantiated
 * @param structureElementBody
 *            the the textual description of the structureElement to be
 *            instantiated
 * @return the structureElement described in
 *         <code>structureElementBody</code>
 */
protected StructureElement parseStructureElement(String structureElementType, String structureElementBody)
        throws InstantiationException {

    Class<? extends StructureElement> structureElementClass = this.structureElementImplementations
            .get(structureElementType);
    if (structureElementClass == null) {
        throw new IllegalArgumentException("unrecognized structureElement " + structureElementType);
    }

    try {
        StructureElement structureElement = structureElementClass.newInstance();
        structureElement.setDataFromText(structureElementBody);
        return structureElement;
    } catch (Exception e) {
        e.printStackTrace();
        throw new InstantiationException("Cannot initialize " + structureElementType + " structureElements: "
                + " missing empty constructor of the class " + structureElementClass.getSimpleName());
    }

}

From source file:de.matzefratze123.heavyspleef.core.i18n.YMLControl.java

@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format, ClassLoader loader,
        boolean reload) throws IllegalAccessException, InstantiationException, IOException {
    Validate.notNull(baseName);// www .  j  a  va  2 s.  c  o  m
    Validate.notNull(locale);
    Validate.notNull(format);
    Validate.notNull(loader);

    ResourceBundle bundle = null;

    if (YML_FORMAT.equals(format)) {
        String bundleName = toBundleName(baseName, locale);
        String resourceName = toResourceName(bundleName, format);

        URL url = null;

        if (classpath) {
            url = getClass().getResource(classpathDir + resourceName);
        } else {
            File resourceFile = new File(localeDir, resourceName);

            if (resourceFile.exists() && resourceFile.isFile()) {
                url = resourceFile.toURI().toURL();
            } else {
                url = getClass().getResource(classpathDir + resourceName);
            }
        }

        URLConnection connection = url.openConnection();
        if (reload) {
            connection.setUseCaches(false);
        }

        InputStream stream = connection.getInputStream();

        if (stream != null) {
            Reader reader = new InputStreamReader(stream, I18N.UTF8_CHARSET);
            YamlConfiguration config = new YamlConfiguration();

            StringBuilder builder;

            try (BufferedReader bufferedReader = new BufferedReader(reader)) {
                builder = new StringBuilder();

                String read;
                while ((read = bufferedReader.readLine()) != null) {
                    builder.append(read);
                    builder.append('\n');
                }
            }

            try {
                config.loadFromString(builder.toString());
            } catch (InvalidConfigurationException e) {
                throw new InstantiationException(e.getMessage());
            }

            bundle = new YMLResourceBundle(config, loadParent);
        }
    } else {
        bundle = super.newBundle(baseName, locale, format, loader, reload);
    }

    return bundle;
}