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:org.apache.tiles.ComponentDefinition.java

/**
 * Create a controller from specified classname
 * @param classname Controller classname.
 * @return org.apache.tiles.Controller//from w w w.j a v  a2s.c om
 * @throws InstantiationException if an error occur while instanciating Controller :
 * (classname can't be instanciated, Illegal access with instanciated class,
 * Error while instanciating class, classname can't be instanciated.
 */
public static Controller createControllerFromClassname(String classname) throws InstantiationException {

    try {
        Class requestedClass = TilesUtil.applicationClass(classname);
        Object instance = requestedClass.newInstance();

        if (log.isDebugEnabled()) {
            log.debug("Controller created : " + instance);
        }
        return (Controller) instance;

    } catch (java.lang.ClassNotFoundException ex) {
        throw new InstantiationException("Error - Class not found :" + ex.getMessage());

    } catch (java.lang.IllegalAccessException ex) {
        throw new InstantiationException("Error - Illegal class access :" + ex.getMessage());

    } catch (java.lang.InstantiationException ex) {
        throw ex;

    } catch (java.lang.ClassCastException ex) {
        throw new InstantiationException(
                "Controller of class '" + classname + "' should implements 'Controller' or extends 'Action'");
    }
}

From source file:org.apache.struts.tiles.ComponentDefinition.java

/**
 * Create a controller from specified classname
 * @param classname Controller classname.
 * @return org.apache.struts.tiles.Controller
 * @throws InstantiationException if an error occur while instanciating Controller :
 * (classname can't be instanciated, Illegal access with instanciated class,
 * Error while instanciating class, classname can't be instanciated.
 *///w ww  .j av  a2  s.  c  om
public static Controller createControllerFromClassname(String classname) throws InstantiationException {

    try {
        Class requestedClass = RequestUtils.applicationClass(classname);
        Object instance = requestedClass.newInstance();

        if (log.isDebugEnabled()) {
            log.debug("Controller created : " + instance);
        }
        return (Controller) instance;

    } catch (java.lang.ClassNotFoundException ex) {
        throw new InstantiationException("Error - Class not found :" + ex.getMessage());

    } catch (java.lang.IllegalAccessException ex) {
        throw new InstantiationException("Error - Illegal class access :" + ex.getMessage());

    } catch (java.lang.InstantiationException ex) {
        throw ex;

    } catch (java.lang.ClassCastException ex) {
        throw new InstantiationException(
                "Controller of class '" + classname + "' should implements 'Controller' or extends 'Action'");
    }
}

From source file:org.xmlactions.action.config.ExecContext.java

public BaseAction getActionClass(String actionMapName, String actionKey)
        throws ClassNotFoundException, InstantiationException, IllegalAccessException {
    BaseAction action = null;//w w  w. j a  v a2s.  c  o  m
    String className = getAction(actionMapName, actionKey);
    if (StringUtils.isNotEmpty(className)) {
        Class<?> clas = ClassUtils.getClass(className);
        Object bean = clas.newInstance();
        if (!(bean instanceof BaseAction)) {
            throw new InstantiationException("class [" + bean.getClass().getName() + " must extend ["
                    + BaseAction.class.getName() + "]");
        }
        action = (BaseAction) bean;
    } else {
        log.info("no action class found for [" + actionMapName + "][" + actionKey + "]");
        // throw new IllegalArgumentException("no action class found for [" + actionMapName + "][" + actionKey + "]");
    }
    return action;
}

From source file:gda.device.scannable.ScannableMotionBase.java

/**
 * This method should be called at the end of an inheriting class's constructor.
 * <p>//  w w  w  .j av  a 2 s. c o m
 * It will do things such as validate that the class instantiated was valid, register the scannable with other
 * objects and generally complete the instantiation of the object.
 * 
 * @throws InstantiationException
 */
protected void completeInstantiation() throws InstantiationException {

    // check that size of arrays match
    if (inputNames.length + extraNames.length != outputFormat.length) {

        // if outputFormat too short then simply extend it, else throw an
        // error as one of the other arrays must be wrong

        if (outputFormat.length < inputNames.length + extraNames.length) {
            logger.warn("Error while instantiating " + getName()
                    + ". Extending outputFormat array to match sum of inputNames and outputNames.");
            // extend array
            String formatString = outputFormat[0];
            int length = inputNames.length + extraNames.length;
            outputFormat = new String[length];
            for (int i = 0; i < length; i++) {
                outputFormat[i] = formatString;
            }

        } else {
            // throw an error
            throw new InstantiationException("Error while instantiating " + getName()
                    + ". Sum of lengths of inputNames and outputNames should match with outFormat array length.");
        }
    }
}

From source file:axiom.framework.core.Application.java

/**
 * Get the application ready to run, initializing the evaluators and type manager.
 *
 * @param ignoreDirs comma separated list of directory names to ignore
 *///ww  w. ja  v a 2 s  . c om
public synchronized void init(String ignoreDirs)
        throws DatabaseException, IllegalAccessException, InstantiationException, ClassNotFoundException {

    running = true;

    // create and init type mananger
    typemgr = new TypeManager(this, ignoreDirs);
    // set the context classloader. Note that this must be done before
    // using the logging framework so that a new LogFactory gets created
    // for this app.
    Thread.currentThread().setContextClassLoader(typemgr.getClassLoader());
    try {
        typemgr.createPrototypes();
    } catch (Exception x) {
        logError("Error creating prototypes", x);
    }

    if (Server.getServer() != null) {
        Vector<AxiomExtension> extensions = Server.getServer().getExtensions();

        for (int i = 0; i < extensions.size(); i++) {
            AxiomExtension ext = (AxiomExtension) extensions.get(i);

            try {
                ext.applicationStarted(this);
            } catch (ConfigurationException e) {
                logEvent("couldn't init extension " + ext.getName() + ": " + e.toString());
            }
        }
    }

    // create and init evaluator/thread lists
    freeThreads = new Stack<RequestEvaluator>();
    allThreads = new Vector<RequestEvaluator>();

    // preallocate minThreads request evaluators
    int minThreads = 0;

    try {
        minThreads = Integer.parseInt(props.getProperty("minThreads"));
    } catch (Exception ignore) {
        try {
            minThreads = Integer.parseInt(props.getProperty("maxThreads"));
            minThreads /= 4;
        } catch (Exception ignoreagain) {
            minThreads = 0;
        }
    }

    if (minThreads > 0) {
        logEvent("Starting " + minThreads + " evaluator(s) for " + name);
    }

    for (int i = 0; i < minThreads; i++) {
        RequestEvaluator ev = new RequestEvaluator(this);

        ev.initScriptingEngine();

        freeThreads.push(ev);
        allThreads.addElement(ev);
    }

    activeRequests = new Hashtable<RequestTrans, RequestEvaluator>();
    activeCronJobs = new Hashtable<String, CronRunner>();
    customCronJobs = new Hashtable<String, CronJob>();

    // read in root id, root prototype, user prototype
    rootId = props.getProperty("rootid", "0");
    String rootPrototype = props.getProperty("rootprototype", "root");
    String userPrototype = props.getProperty("userprototype", "user");

    rootMapping = getDbMapping(rootPrototype);
    if (rootMapping == null)
        throw new RuntimeException("rootPrototype does not exist: " + rootPrototype);
    userMapping = getDbMapping(userPrototype);
    if (userMapping == null)
        throw new RuntimeException("userPrototype does not exist: " + userPrototype);

    // The whole user/userroot handling is basically old
    // ugly obsolete crap. Don't bother.
    ResourceProperties p = new ResourceProperties();
    String usernameField = (userMapping != null) ? userMapping.getNameField() : null;

    if (usernameField == null) {
        usernameField = "name";
    }

    p.put("_children", "");
    p.put("_children.type", "collection(" + userPrototype + ")");
    p.put("_children.accessname", usernameField);
    p.put("roles", "");
    p.put("roles.type", "String");
    p.put("roles.multivalue", "true");
    userRootMapping = new DbMapping(this, "__userroot__", p);
    userRootMapping.update();

    // add the session mappings for persisting sessions in the object database
    String sessionPrototype = props.getProperty("sessionprototype", "session");
    sessionMapping = getDbMapping(sessionPrototype);
    if (sessionMapping == null)
        throw new RuntimeException("sessionPrototype does not exist: " + sessionPrototype);
    p = new ResourceProperties();
    String nameField = (sessionMapping != null) ? sessionMapping.getNameField() : null;
    if (nameField == null) {
        nameField = "name";
    }
    p.put("_children", "");
    p.put("_children.type", "collection(" + sessionPrototype + ")");
    p.put("_children.accessname", nameField);
    sessionRootMapping = new DbMapping(this, "__sessionroot__", p);
    sessionRootMapping.update();

    // create/setup the path indexer for this application
    try {
        pathIndexer = new PathIndexer(this);
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new RuntimeException("Could not create the path indexer for the application " + this.name);
    }

    String cluster = this.getProperty("cluster", "false");
    if ("true".equalsIgnoreCase(cluster)) {
        try {
            this.clusterComm = new ClusterCommunicator(this);
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new InstantiationException("Could not initiate the jgroups cluster for " + this.name);
        }

        this.clusterHost = this.getProperty("cluster.host");
        if (this.clusterHost == null) {
            throw new InstantiationException("ERROR: cluster.host not specified in app.properties");
        }
    }

    // create the node manager
    nmgr = new NodeManager(this);
    nmgr.init(dbDir.getAbsoluteFile(), props);

    this.executionCache = new ExecutionCache(this, "rhino");

    this.talCache = new ExecutionCache(this, "tal");

    // create and init session manager
    String sessionMgrImpl = props.getProperty("sessionManagerImpl", "axiom.framework.core.SessionManager");
    sessionMgr = (SessionManager) Class.forName(sessionMgrImpl).newInstance();
    logEvent("Using session manager class " + sessionMgrImpl);
    sessionMgr.init(this);

    // read the sessions if wanted
    if ("true".equalsIgnoreCase(getProperty("persistentSessions"))) {
        RequestEvaluator ev = getEvaluator();
        try {
            ev.initScriptingEngine();
            sessionMgr.loadSessionData(null, ev.scriptingEngine);
        } finally {
            releaseEvaluator(ev);
        }
    }

    // reset the classloader to the parent/system/server classloader.
    Thread.currentThread().setContextClassLoader(typemgr.getClassLoader().getParent());

    try {
        this.qbean = new QueryBean(this, "query-filter-" + getName());
    } catch (Exception ex) {
        ex.printStackTrace();
        throw new InstantiationException("Could not instantiate the QueryBean for " + this.name);
    }

    Enumeration e = this.dbProps.keys();
    while (e.hasMoreElements()) {
        String key = (String) e.nextElement();
        if (key.indexOf(".type") != -1) {
            String value = this.dbProps.getProperty(key);
            if (!extDbTypes.contains(value) && !value.equalsIgnoreCase("relational")) {
                extDbTypes.add(value);
            }
        }
    }
    try {
        updateResources();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:org.jaffa.soa.dataaccess.DataTransformer.java

private static Object newGraphDataObject(Class clazz) throws InstantiationException {
    try {/*  w w  w  .  ja  v  a  2 s  .c o m*/
        Constructor c = clazz.getConstructor(new Class[] {});
        if (c == null)
            throw new InstantiationException("No zero argument construtor found");
        Object dao = c.newInstance((Object[]) null);
        if (log.isDebugEnabled())
            log.debug("Created Object : " + dao);
        return dao;
    } catch (InstantiationException e) {
        throw e;
    } catch (Exception e) {
        log.error("Can't create Graph Data Object - " + e.getMessage(), e);
        throw new InstantiationException(e.getMessage());
    }
}

From source file:com.redhat.rhn.manager.system.SystemManager.java

/**
 * Creates the client certificate (systemid) file for the given Server.
 * @param server Server whose client certificate is sought.
 * @return the client certificate (systemid) file for the given Server.
 * @throws InstantiationException thrown if error occurs creating the
 * client certificate.//from   w  ww .j  av a 2 s. co  m
 */
public static ClientCertificate createClientCertificate(Server server) throws InstantiationException {

    ClientCertificate cert = new ClientCertificate();
    // add members to this cert
    User user = UserManager.findResponsibleUser(server.getOrg(), RoleFactory.ORG_ADMIN);
    cert.addMember("username", user.getLogin());
    cert.addMember("os_release", server.getRelease());
    cert.addMember("operating_system", server.getOs());
    cert.addMember("architecture", server.getServerArch().getLabel());
    cert.addMember("system_id", "ID-" + server.getId().toString());
    cert.addMember("type", "REAL");
    String[] fields = { "system_id", "os_release", "operating_system", "architecture", "username", "type" };
    cert.addMember("fields", fields);

    try {
        //Could throw InvalidCertificateException in any fields are invalid
        cert.addMember("checksum", cert.genSignature(server.getSecret()));
    } catch (InvalidCertificateException e) {
        throw new InstantiationException("Couldn't generate signature");
    }

    return cert;
}