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:es.mityc.firmaJava.policy.Facturae30Manager.java

public Facturae30Manager() throws InstantiationException {
    if (config == null)
        throw new InstantiationException("No hay configuracin disponible");
}

From source file:ca.flop.jpublish.dwr.JPublishCreator.java

/**
 * obtain an instance of this Creator.//  w w w . j a  v  a 2 s  .co m
 *
 * @return the instance to use
 * @throws InstantiationException If for some reason the object can not be created
 */
public Object getInstance() throws InstantiationException {

    WebContext dwrContext = WebContextFactory.get();
    if (site == null) {
        site = (SiteContext) dwrContext.getServletContext().getAttribute(SiteContext.NAME);
        if (site == null) {
            throw new InstantiationException("Wrong JPublish version or invalid configuration.");
        }
    }
    return new DWRJPublishActionManager(site, actionName);
}

From source file:ORG.oclc.os.SRW.OpenSearchQueryResult.java

public OpenSearchQueryResult(String queryStr, SearchRetrieveRequestType request, SRWOpenSearchDatabase db)
        throws InstantiationException, SRWDiagnostic {
    int start;/* w  ww.  ja  v  a 2 s.  c  o  m*/
    PositiveInteger pi;
    String parameter;
    this.query = queryStr;
    // figure out what schema/template to use
    String schema = request.getRecordSchema();
    if (schema == null)
        schema = db.defaultSchemaID;
    if (schema == null)
        schema = db.defaultSchemaName;
    if (schema == null) {
        log.error("No schema provided");
        throw new InstantiationException("No schema provided");
    }

    CQLParser parser = new CQLParser(CQLParser.V1POINT1);
    CQLNode cqlQuery;
    try {
        cqlQuery = parser.parse(queryStr);
    } catch (CQLParseException | IOException e) {
        throw new SRWDiagnostic(SRWDiagnostic.QuerySyntaxError, queryStr);
    }
    if (!(cqlQuery instanceof CQLTermNode)) {
        throw new SRWDiagnostic(SRWDiagnostic.UnsupportedBooleanOperator, null);
    }
    CQLTermNode term = (CQLTermNode) cqlQuery;

    String template = db.templates.get(schema);
    log.debug("template=" + template);
    if (template == null)
        throw new SRWDiagnostic(SRWDiagnostic.RecordNotAvailableInThisSchema, schema);
    Pattern p = Pattern.compile("\\{([^\\}]+)\\}");
    Matcher m = p.matcher(template);
    while (m.find()) {
        parameter = m.group();
        log.debug("template parameter=" + parameter);
        switch (parameter) {
        case "{searchTerms}":
            template = template.replace(parameter, term.getTerm());
            break;
        case "{count}":
            NonNegativeInteger nni = request.getMaximumRecords();
            if (nni != null)
                count = nni.intValue();
            else {
                count = db.defaultNumRecs;
            }
            if (count <= 0)
                throw new InstantiationException(
                        "maximumRecords parameter not supplied and defaultNumRecs not specified in the database properties file");
            template = template.replace(parameter, Integer.toString(count));
            break;
        case "{startIndex}":
            pi = request.getStartRecord();
            if (pi != null)
                start = pi.intValue();
            else {
                start = 1;
            }
            template = template.replace(parameter, Integer.toString(start));
            break;
        case "{startPage}":
            pi = request.getStartRecord();
            if (pi != null) {
                start = pi.intValue();
                if (db.itemsPerPage == 0)
                    throw new InstantiationException(
                            "template expects startPage parameter but itemsPerPage not specified in the database properties file");
                start = start / db.itemsPerPage;
            } else {
                start = 1;
            }
            template = template.replace(parameter, Integer.toString(start));
            break;
        }
    }
    int i = template.indexOf('?');
    if (i > 0)
        template = template.substring(0, i + 1) + template.substring(i + 1).replaceAll(" ", "+");

    log.debug("url=" + template);
    URL url;
    try {
        url = new URL(template);
    } catch (MalformedURLException ex) {
        throw new SRWDiagnostic(SRWDiagnostic.GeneralSystemError, template);
    }
    try {
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.connect();
        log.debug("contentType=" + conn.getContentType());
        log.debug("responseCode=" + conn.getResponseCode());
        processResponse(request, conn, schema, conn.getContentType());
    } catch (IOException ex) {
        throw new SRWDiagnostic(SRWDiagnostic.GeneralSystemError, ex.getMessage());
    }
}

From source file:Main.java

public static <T> T newInstance(Class<T> type, Class<?>[] argsClass, Object[] argsValues)
        throws InstantiationException, IllegalAccessException {
    T instance = null;/*from  w w  w . j  a va  2 s .c  om*/
    try {
        Constructor<T> constructorDef = type.getConstructor(argsClass);
        instance = constructorDef.newInstance(argsValues);
    } catch (SecurityException e) {
        throw new InstantiationException(e.getMessage());
    } catch (NoSuchMethodException e) {
        throw new InstantiationException(e.getMessage());
    } catch (IllegalArgumentException e) {
        throw new InstantiationException(e.getMessage());
    } catch (InvocationTargetException e) {
        throw new InstantiationException(e.getMessage());
    }
    return instance;
}

From source file:com.zotoh.maedr.impl.UserDeviceFactory.java

/**
 * @param type//w  w  w.j  av a  2s .  c o  m
 * @param deviceClass
 * @throws Exception
 */
public void add(String type, String deviceClass) throws Exception {

    if (isEmpty(type) || isEmpty(deviceClass)) {
        return;
    }

    if (_devs.containsKey(type)) {
        errBadArg("Device type: " + type + " is already defined.");
    }

    Class<?> z = loadClass(deviceClass);
    Constructor<?> ctor;

    tstArgIsType("device", z, Device.class);
    try {
        ctor = z.getConstructor(DeviceManager.class);
    } catch (Throwable t) {
        throw new InstantiationException("Class: " + deviceClass + " is missing ctor(DeviceManager)");
    }

    _devs.put(type, ctor);
}

From source file:ORG.oclc.os.SRW.Lucene.BasicLuceneQueryTranslator.java

private Analyzer getAnalyzer(String name) throws InstantiationException {
    if (name.indexOf('.') == -1) // implicit package name
        if (name.startsWith("Standard"))
            name = "org.apache.lucene.analysis.standard." + name;
        else//www.  j  a  v a  2s  .  com
            name = "org.apache.lucene.analysis." + name;
    try {
        log.debug("creating instance of Analyzer class " + name);
        Class analyzerClass = Class.forName(name);
        return (Analyzer) analyzerClass.newInstance();
    } catch (Exception e) {
        log.error("Unable to create analyzer \"" + name + "\": " + e.getMessage());
        throw new InstantiationException("Unable to create analyzer \"" + name + "\": " + e.getMessage());
    }
}

From source file:com.pentaho.big.data.bundles.impl.shim.common.ShimBridgingClassloader.java

public static Object create(BundleContext bundleContext, String className, List<Object> arguments)
        throws KettlePluginException, ClassNotFoundException, IllegalAccessException, InstantiationException,
        InvocationTargetException {
    ShimBridgingClassloader shimBridgingClassloader = new ShimBridgingClassloader(pluginClassloaderGetter
            .getPluginClassloader(LifecyclePluginType.class.getCanonicalName(), HADOOP_SPOON_PLUGIN),
            bundleContext);// www.  j a v a 2s. co  m
    Class<?> clazz = Class.forName(className, true, shimBridgingClassloader);
    if (arguments == null || arguments.size() == 0) {
        return clazz.newInstance();
    }
    for (Constructor<?> constructor : clazz.getConstructors()) {
        Class<?>[] parameterTypes = constructor.getParameterTypes();
        if (parameterTypes.length == arguments.size()) {
            boolean match = true;
            for (int i = 0; i < parameterTypes.length; i++) {
                Object o = arguments.get(i);
                if (o != null && !parameterTypes[i].isInstance(o)) {
                    match = false;
                    break;
                }
            }
            if (match) {
                return constructor.newInstance(arguments.toArray());
            }
        }
    }
    throw new InstantiationException(
            "Unable to find constructor for class " + className + " with arguments " + arguments);
}

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 by java property {@code gda.hrpd.data.sample.info} in the data directory specified by another java
 * property {@code gda.data.scan.datawriter.datadir}. The default Excel spreadsheet file name is {@code Sample.xls}
 * /*www.j  a  va 2 s  . com*/
 * @throws InstantiationException
 */
public ExcelReader() throws InstantiationException {
    // check if the data directory has been defined
    dataDir = PathConstructor.createFromDefaultProperty();

    if (this.dataDir == null) {
        // this is compulsory - stop the scan
        String error = "java property gda.data.scan.datawriter.datadir not defined - cannot create a new data file";
        logger.error(error);
        throw new InstantiationException(error);
    }
    sampleInfoFile = LocalProperties.get("gda.hrpd.data.sample.info", "Sample.xls");
    // check if the sample information file is available
    filename = dataDir + File.separator + sampleInfoFile;
    try {
        fin = new FileInputStream(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.ejbca.core.model.ca.catoken.BaseCAToken.java

public BaseCAToken(String providerClass) throws InstantiationException {
    try {/* w w w . j a  v a 2s . c  o m*/
        Class.forName(providerClass);
    } catch (ClassNotFoundException e) {
        throw new InstantiationException("Class not found: " + providerClass);
    }
}

From source file:jp.furplag.util.commons.ObjectUtils.java

/**
 * substitute for {@link java.lang.Class#newInstance()}.
 *
 * @param type the Class object, return false if null.
 * @return empty instance of specified {@link java.lang.Class}.
 * @throws IllegalArgumentException//  w  w  w.  java2s .  c om
 * @throws InstantiationException
 * @throws IllegalAccessException
 * @throws InvocationTargetException
 * @throws ClassNotFoundException
 * @throws NegativeArraySizeException
 */
@SuppressWarnings("unchecked")
public static <T> T newInstance(final Class<T> type) throws InstantiationException {
    if (type == null)
        return null;
    if (type.isArray())
        return (T) Array.newInstance(type.getComponentType(), 0);
    if (Void.class.equals(ClassUtils.primitiveToWrapper(type))) {
        try {
            Constructor<Void> c = Void.class.getDeclaredConstructor();
            c.setAccessible(true);

            return (T) c.newInstance();
        } catch (SecurityException e) {
        } catch (NoSuchMethodException e) {
        } catch (InvocationTargetException e) {
        } catch (IllegalAccessException e) {
        }

        return null;
    }

    if (type.isInterface()) {
        if (!Collection.class.isAssignableFrom(type))
            throw new InstantiationException(
                    "could not create instance, the type \"" + type.getName() + "\" is an interface.");
        if (List.class.isAssignableFrom(type))
            return (T) Lists.newArrayList();
        if (Map.class.isAssignableFrom(type))
            return (T) Maps.newHashMap();
        if (Set.class.isAssignableFrom(type))
            return (T) Sets.newHashSet();
    }

    if (type.isPrimitive()) {
        if (boolean.class.equals(type))
            return (T) Boolean.FALSE;
        if (char.class.equals(type))
            return (T) Character.valueOf(Character.MIN_VALUE);

        return (T) NumberUtils.valueOf("0", (Class<? extends Number>) type);
    }
    if (ClassUtils.isPrimitiveOrWrapper(type))
        return null;
    if (Modifier.isAbstract(type.getModifiers()))
        throw new InstantiationException(
                "could not create instance, the type \"" + type.getName() + "\" is an abstract class.");

    try {
        Constructor<?> c = type.getDeclaredConstructor();
        c.setAccessible(true);

        return (T) c.newInstance();
    } catch (SecurityException e) {
    } catch (NoSuchMethodException e) {
    } catch (InvocationTargetException e) {
    } catch (IllegalAccessException e) {
    }

    throw new InstantiationException("could not create instance, the default constructor of \"" + type.getName()
            + "()\" is not accessible ( or undefined ).");
}