Example usage for java.lang ClassNotFoundException getMessage

List of usage examples for java.lang ClassNotFoundException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:edu.lternet.pasta.auditmanager.AuditManagerResource.java

/**
* <strong>Get Audit Record</strong> operation, retrieves a single audit record 
* based on the audit identifier value specified in the path.
 *
 * <h4>Responses:</h4>//ww w .java2  s.co m
 *
 * <p>
 * If the request is successful, the response will contain plain text.
 * </p>
 *
 * <table border="1" cellspacing="0" cellpadding="3">
 * <tr>
 * <td><b>Status</b></td>
 * <td><b>Reason</b></td>
 * <td><b>Entity</b></td>
 * <td><b>MIME type</b></td>
 * </tr>
 * <tr>
 * <td>200 OK</td>
 * <td>If the request was successful.</td>
 * <td>The specified subscription's attributes.</td>
 * <td><code>text/plain</code></td>
 * </tr>
 * <tr>
 * <td>400 Bad Request</td>
 * <td>If the specified identification number cannot be parsed as an
 * integer.</td>
 * <td>An error message.</td>
 * <td><code>text/plain</code></td>
 * </tr>
 * <tr>
 * <td>401 Unauthorized</td>
 * <td>If the requesting user is not authorized to read the specified
 * subscription.</td>
 * <td>An error message.</td>
 * <td><code>text/plain</code></td>
 * </tr>
 * <tr>
 * <td>404 Not Found</td>
 * <td>If the requested log entry does not exist.</td>
 * <td>An error message.</td>
 * <td><code>text/plain</code></td>
 * </tr>
 * </table>
 *
 * @param headers
 *             the HTTP request headers containing the authorization token.
 * @param oid
 *             the POST request's body, of XML representing a log entry.
 * @return an appropriate HTTP response.
 */
@GET
@Path("report/{oid}")
public Response getAuditRecord(@Context HttpHeaders headers, @PathParam(value = "oid") int oid) {
    try {
        Properties properties = ConfigurationListener.getProperties();
        assertAuthorizedToRead(headers, MethodNameUtility.methodName());
        AuditManager auditManager = new AuditManager(properties);
        Integer oidInteger = new Integer(oid);
        String oidString = oidInteger.toString();
        List<String> oidList = new ArrayList<String>();
        oidList.add(oidString);
        Map<String, List<String>> queryParams = new HashMap<String, List<String>>();
        queryParams.put("oid", oidList);
        String xmlString = auditManager.getAuditRecords(queryParams);
        if (xmlString.length() == (AuditManager.AUDIT_OPENING_TAG.length()
                + AuditManager.AUDIT_CLOSING_TAG.length())) {
            throw new ResourceNotFoundException(String.format("Oid %d does not exist.", oid));
        }
        return Response.ok(xmlString).build();
    } catch (ClassNotFoundException e) {
        return WebExceptionFactory.make(Status.INTERNAL_SERVER_ERROR, e, e.getMessage()).getResponse();
    } catch (SQLException e) {
        return WebExceptionFactory.make(Status.INTERNAL_SERVER_ERROR, e, e.getMessage()).getResponse();
    } catch (UnauthorizedException e) {
        return WebExceptionFactory.makeUnauthorized(e).getResponse();
    } catch (ResourceNotFoundException e) {
        return WebExceptionFactory.makeNotFound(e).getResponse();
    } catch (WebApplicationException e) {
        return e.getResponse();
    } catch (IllegalStateException e) {
        return WebExceptionFactory.makeBadRequest(e).getResponse();
    }
}

From source file:org.apache.dubbo.rpc.protocol.thrift.ThriftCodec.java

private void encodeResponse(Channel channel, ChannelBuffer buffer, Response response) throws IOException {

    RpcResult result = (RpcResult) response.getResult();

    RequestData rd = cachedRequest.get(response.getId());

    String resultClassName = ExtensionLoader
            .getExtensionLoader(ClassNameGenerator.class).getExtension(channel.getUrl()
                    .getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME))
            .generateResultClassName(rd.serviceName, rd.methodName);

    if (StringUtils.isEmpty(resultClassName)) {
        throw new RpcException(RpcException.SERIALIZATION_EXCEPTION,
                "Could not encode response, the specified interface may be incorrect.");
    }//from   www .j  a  v  a2s.co m

    Class clazz = cachedClass.get(resultClassName);

    if (clazz == null) {

        try {
            clazz = ClassHelper.forNameWithThreadContextClassLoader(resultClassName);
            cachedClass.putIfAbsent(resultClassName, clazz);
        } catch (ClassNotFoundException e) {
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
        }

    }

    TBase resultObj;

    try {
        resultObj = (TBase) clazz.newInstance();
    } catch (InstantiationException e) {
        throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
    }

    TApplicationException applicationException = null;
    TMessage message;

    if (result.hasException()) {
        Throwable throwable = result.getException();
        int index = 1;
        boolean found = false;
        while (true) {
            TFieldIdEnum fieldIdEnum = resultObj.fieldForId(index++);
            if (fieldIdEnum == null) {
                break;
            }
            String fieldName = fieldIdEnum.getFieldName();
            String getMethodName = ThriftUtils.generateGetMethodName(fieldName);
            String setMethodName = ThriftUtils.generateSetMethodName(fieldName);
            Method getMethod;
            Method setMethod;
            try {
                getMethod = clazz.getMethod(getMethodName);
                if (getMethod.getReturnType().equals(throwable.getClass())) {
                    found = true;
                    setMethod = clazz.getMethod(setMethodName, throwable.getClass());
                    setMethod.invoke(resultObj, throwable);
                }
            } catch (NoSuchMethodException e) {
                throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
            } catch (InvocationTargetException e) {
                throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
            } catch (IllegalAccessException e) {
                throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
            }
        }

        if (!found) {
            applicationException = new TApplicationException(throwable.getMessage());
        }

    } else {
        Object realResult = result.getResult();
        // result field id is 0
        String fieldName = resultObj.fieldForId(0).getFieldName();
        String setMethodName = ThriftUtils.generateSetMethodName(fieldName);
        String getMethodName = ThriftUtils.generateGetMethodName(fieldName);
        Method getMethod;
        Method setMethod;
        try {
            getMethod = clazz.getMethod(getMethodName);
            setMethod = clazz.getMethod(setMethodName, getMethod.getReturnType());
            setMethod.invoke(resultObj, realResult);
        } catch (NoSuchMethodException e) {
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
        } catch (InvocationTargetException e) {
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
        }

    }

    if (applicationException != null) {
        message = new TMessage(rd.methodName, TMessageType.EXCEPTION, rd.id);
    } else {
        message = new TMessage(rd.methodName, TMessageType.REPLY, rd.id);
    }

    RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(1024);

    TIOStreamTransport transport = new TIOStreamTransport(bos);

    TBinaryProtocol protocol = new TBinaryProtocol(transport);

    int messageLength;
    int headerLength;

    byte[] bytes = new byte[4];
    try {
        // magic
        protocol.writeI16(MAGIC);
        // message length
        protocol.writeI32(Integer.MAX_VALUE);
        // message header length
        protocol.writeI16(Short.MAX_VALUE);
        // version
        protocol.writeByte(VERSION);
        // service name
        protocol.writeString(rd.serviceName);
        // id
        protocol.writeI64(response.getId());
        protocol.getTransport().flush();
        headerLength = bos.size();

        // message
        protocol.writeMessageBegin(message);
        switch (message.type) {
        case TMessageType.EXCEPTION:
            applicationException.write(protocol);
            break;
        case TMessageType.REPLY:
            resultObj.write(protocol);
            break;
        }
        protocol.writeMessageEnd();
        protocol.getTransport().flush();
        int oldIndex = messageLength = bos.size();

        try {
            TFramedTransport.encodeFrameSize(messageLength, bytes);
            bos.setWriteIndex(MESSAGE_LENGTH_INDEX);
            protocol.writeI32(messageLength);
            bos.setWriteIndex(MESSAGE_HEADER_LENGTH_INDEX);
            protocol.writeI16((short) (0xffff & headerLength));
        } finally {
            bos.setWriteIndex(oldIndex);
        }

    } catch (TException e) {
        throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
    }

    buffer.writeBytes(bytes);
    buffer.writeBytes(bos.toByteArray());

}

From source file:com.alibaba.dubbo.rpc.protocol.thrift.ThriftCodec.java

private void encodeResponse(Channel channel, ChannelBuffer buffer, Response response) throws IOException {

    RpcResult result = (RpcResult) response.getResult();

    RequestData rd = cachedRequest.get(response.getId());

    String resultClassName = ExtensionLoader
            .getExtensionLoader(ClassNameGenerator.class).getExtension(channel.getUrl()
                    .getParameter(ThriftConstants.CLASS_NAME_GENERATOR_KEY, ThriftClassNameGenerator.NAME))
            .generateResultClassName(rd.serviceName, rd.methodName);

    if (StringUtils.isEmpty(resultClassName)) {
        throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, new StringBuilder(32)
                .append("Could not encode response, the specified interface may be incorrect.").toString());
    }/*  w ww . ja  v a  2  s .com*/

    Class clazz = cachedClass.get(resultClassName);

    if (clazz == null) {

        try {
            clazz = ClassHelper.forNameWithThreadContextClassLoader(resultClassName);
            cachedClass.putIfAbsent(resultClassName, clazz);
        } catch (ClassNotFoundException e) {
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
        }

    }

    TBase resultObj;

    try {
        resultObj = (TBase) clazz.newInstance();
    } catch (InstantiationException e) {
        throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
    }

    TApplicationException applicationException = null;
    TMessage message;

    if (result.hasException()) {
        Throwable throwable = result.getException();
        int index = 1;
        boolean found = false;
        while (true) {
            TFieldIdEnum fieldIdEnum = resultObj.fieldForId(index++);
            if (fieldIdEnum == null) {
                break;
            }
            String fieldName = fieldIdEnum.getFieldName();
            String getMethodName = ThriftUtils.generateGetMethodName(fieldName);
            String setMethodName = ThriftUtils.generateSetMethodName(fieldName);
            Method getMethod;
            Method setMethod;
            try {
                getMethod = clazz.getMethod(getMethodName);
                if (getMethod.getReturnType().equals(throwable.getClass())) {
                    found = true;
                    setMethod = clazz.getMethod(setMethodName, throwable.getClass());
                    setMethod.invoke(resultObj, throwable);
                }
            } catch (NoSuchMethodException e) {
                throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
            } catch (InvocationTargetException e) {
                throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
            } catch (IllegalAccessException e) {
                throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
            }
        }

        if (!found) {
            applicationException = new TApplicationException(throwable.getMessage());
        }

    } else {
        Object realResult = result.getResult();
        // result field id is 0
        String fieldName = resultObj.fieldForId(0).getFieldName();
        String setMethodName = ThriftUtils.generateSetMethodName(fieldName);
        String getMethodName = ThriftUtils.generateGetMethodName(fieldName);
        Method getMethod;
        Method setMethod;
        try {
            getMethod = clazz.getMethod(getMethodName);
            setMethod = clazz.getMethod(setMethodName, getMethod.getReturnType());
            setMethod.invoke(resultObj, realResult);
        } catch (NoSuchMethodException e) {
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
        } catch (InvocationTargetException e) {
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
        } catch (IllegalAccessException e) {
            throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
        }

    }

    if (applicationException != null) {
        message = new TMessage(rd.methodName, TMessageType.EXCEPTION, rd.id);
    } else {
        message = new TMessage(rd.methodName, TMessageType.REPLY, rd.id);
    }

    RandomAccessByteArrayOutputStream bos = new RandomAccessByteArrayOutputStream(1024);

    TIOStreamTransport transport = new TIOStreamTransport(bos);

    TBinaryProtocol protocol = new TBinaryProtocol(transport);

    int messageLength;
    int headerLength;

    byte[] bytes = new byte[4];
    try {
        // magic
        protocol.writeI16(MAGIC);
        // message length
        protocol.writeI32(Integer.MAX_VALUE);
        // message header length
        protocol.writeI16(Short.MAX_VALUE);
        // version
        protocol.writeByte(VERSION);
        // service name
        protocol.writeString(rd.serviceName);
        // id
        protocol.writeI64(response.getId());
        protocol.getTransport().flush();
        headerLength = bos.size();

        // message
        protocol.writeMessageBegin(message);
        switch (message.type) {
        case TMessageType.EXCEPTION:
            applicationException.write(protocol);
            break;
        case TMessageType.REPLY:
            resultObj.write(protocol);
            break;
        }
        protocol.writeMessageEnd();
        protocol.getTransport().flush();
        int oldIndex = messageLength = bos.size();

        try {
            TFramedTransport.encodeFrameSize(messageLength, bytes);
            bos.setWriteIndex(MESSAGE_LENGTH_INDEX);
            protocol.writeI32(messageLength);
            bos.setWriteIndex(MESSAGE_HEADER_LENGTH_INDEX);
            protocol.writeI16((short) (0xffff & headerLength));
        } finally {
            bos.setWriteIndex(oldIndex);
        }

    } catch (TException e) {
        throw new RpcException(RpcException.SERIALIZATION_EXCEPTION, e.getMessage(), e);
    }

    buffer.writeBytes(bytes);
    buffer.writeBytes(bos.toByteArray());

}

From source file:org.apache.jmeter.util.JMeterUtils.java

/**
 * Instatiate an object and guarantee its class.
 *
 * @param className//from w ww  .j ava2 s  .co  m
 *            The name of the class to instantiate.
 * @param impls
 *            The name of the class it must be an instance of
 * @return an instance of the class, or null if instantiation failed or the class did not implement/extend as required
 * @deprecated (3.0) not used out of this class
 */
// TODO probably not needed
@Deprecated
public static Object instantiate(String className, String impls) {
    if (className != null) {
        className = className.trim();
    }

    if (impls != null) {
        impls = impls.trim();
    }

    try {
        Class<?> c = Class.forName(impls);
        try {
            Class<?> o = Class.forName(className);
            Object res = o.newInstance();
            if (c.isInstance(res)) {
                return res;
            }
            throw new IllegalArgumentException(className + " is not an instance of " + impls);
        } catch (ClassNotFoundException e) {
            log.error("Error loading class " + className + ": class is not found");
        } catch (IllegalAccessException e) {
            log.error("Error loading class " + className + ": does not have access");
        } catch (InstantiationException e) {
            log.error("Error loading class " + className + ": could not instantiate");
        } catch (NoClassDefFoundError e) {
            log.error("Error loading class " + className + ": couldn't find class " + e.getMessage());
        }
    } catch (ClassNotFoundException e) {
        log.error("Error loading class " + impls + ": was not found.");
    }
    return null;
}

From source file:services.GoogleComputeEngineService.java

public void createCluster(String clusterName, Integer shards, Integer processes, Integer disksPerShard,
        String machineType, List<String> network, String sourceImage, String diskType, String diskRaid,
        String dataFileSystem, Integer dataDiskSizeGb, Integer rootDiskSizeGb)
        throws GoogleComputeEngineException, GoogleCloudStorageException {
    List<String> tags;
    SSHKey sshKey = SSHKeyFactory.generateKey();
    StringBuilder machinePrefix = new StringBuilder();
    machinePrefix.append("https://www.googleapis.com/compute/v1/projects/");
    machinePrefix.append(client.getProjectId());
    machinePrefix.append("/zones/");
    machinePrefix.append(client.getZone());
    machinePrefix.append("/machineTypes/");

    if (ConfigurationService.getClusterName() != null) {
        throw new GoogleComputeEngineException("cluster [" + ConfigurationService.getClusterName()
                + "] is already created, delete it first to create another");
    }//w w  w  .jav  a2 s.  c  o  m
    if (clusterName == null) {
        throw new GoogleComputeEngineException("cluster name not defined");
    }
    if (network == null || network.isEmpty()) {
        throw new GoogleComputeEngineException("network not defined");
    }

    File startupScript = ConfigurationService.getPuppetNodeStartupScriptFile(clusterName);
    /**
     * Verify the machine type to get the proper Link
     */
    for (MachineType t : client.getMachineTypes()) {
        if (machineType != null && machineType.equals(t.getName())) {
            machineType = t.getSelfLink();
            break;
        }
    }

    /**
     * Verify the disk type to get the proper Link
     */
    for (DiskType t : client.getDiskTypes()) {
        if (diskType != null && diskType.equals(t.getName())) {
            diskType = t.getSelfLink();
            break;
        }
    }

    /**
     * Verify the source image to get the proper Link
     */
    for (Image i : client.getImages()) {
        if (sourceImage != null && sourceImage.equals(i.getName())) {
            sourceImage = i.getSelfLink();
            break;
        }
    }

    /**
     * Verify the networks to get the proper Link
     */
    if (network != null) {
        for (Network n : client.getNetworks()) {
            for (int i = 0; i < network.size(); i++) {
                if (network.get(i) != null && network.get(i).equals(n.getName())) {
                    network.set(i, n.getSelfLink());
                }
            }
        }
    }

    /**
     * Overwrites the SSH key
     */
    try {
        SSHKeyStore store = new SSHKeyStore();
        store.addKey(ConfigurationService.CLUSTER_USER, sshKey);
    } catch (ClassNotFoundException e) {
        log.info("cannot store cluster ssh key on disk: " + e.getMessage());
        throw new GoogleComputeEngineException(e);
    } catch (IOException e) {
        log.info("cannot store cluster ssh key on disk: " + e.getMessage());
        throw new GoogleComputeEngineException(e);
    }

    /**
     * Create the puppetmaster node
     */
    String instanceName = ConfigurationService.getServerName(clusterName,
            ConfigurationService.NODE_NAME_PUPPET);
    tags = Arrays.asList(ConfigurationService.NODE_TAG_PUPPET, clusterName);
    if (!client.instanceExists(instanceName)) {
        String networkName = network.get(0);
        if (networkName.contains("/")) {
            networkName = networkName.substring(networkName.lastIndexOf("/") + 1);
        }
        try {
            client.createInstance(instanceName, machinePrefix.toString().concat("n1-standard-1"), network,
                    rootDiskSizeGb, sourceImage, null, tags,
                    Arrays.asList(sshKey.getSSHPublicKey(ConfigurationService.CLUSTER_USER)),
                    ConfigurationService.generatePuppetMasterStartupScript(clusterName, networkName, processes,
                            diskRaid, dataFileSystem),
                    true);
        } catch (IOException e) {
            throw new GoogleComputeEngineException(e);
        }
    } else {
        log.info("instance [" + instanceName + "] already exists, not created");
    }
    ConfigurationService.setClusterName(clusterName);
    ConfigurationService.setClusterNodeProcesses(processes);

    /**
     * Create the config nodes
     */
    instanceName = ConfigurationService.getServerName(clusterName, ConfigurationService.NODE_NAME_CONF);
    tags = Arrays.asList(ConfigurationService.NODE_TAG_CONF, clusterName);
    for (Integer i = 1; i <= 3; i++) {
        StringBuilder instance_name = new StringBuilder();
        instance_name.append(instanceName);
        instance_name.append("-node-");
        instance_name.append(i);

        if (client.instanceExists(instance_name.toString())) {
            log.info("instance [" + instance_name.toString() + "] already exists, not created");
            continue;
        }
        client.createInstance(instance_name.toString(), machinePrefix.toString().concat("n1-standard-1"),
                network, rootDiskSizeGb, sourceImage, null, tags,
                Arrays.asList(sshKey.getSSHPublicKey(ConfigurationService.CLUSTER_USER)),
                startupScript.getAbsolutePath(), false);
    }

    /**
     * Put the cluster node shard creation task in a background thread
     */
    final String t_instanceName = ConfigurationService.getServerName(clusterName,
            ConfigurationService.NODE_NAME_SHARD);
    final List<String> t_tags = Arrays.asList(ConfigurationService.NODE_TAG_SHARD, clusterName);
    final String t_machineType = machineType;
    final String t_sourceImage = sourceImage;
    final String t_diskType = diskType;

    Runnable shardNodesCreation = () -> {
        /**
         * Create the shard nodes data disks
         */
        String lastDiskCreated = null;
        Map<String, Map<String, String>> instancesDataDisks = new HashMap<>();

        for (Integer i = 1; i <= shards; i++) {
            Map<String, String> dataDisks = new HashMap<>();
            StringBuilder instance_name = new StringBuilder();
            instance_name.append(t_instanceName);
            instance_name.append("-node-");
            instance_name.append(i);
            try {
                for (Integer d = 1; d <= disksPerShard; d++) {
                    StringBuilder disk_name = new StringBuilder();
                    disk_name.append(instance_name.toString());
                    disk_name.append("-disk");
                    disk_name.append(d);
                    dataDisks.put(disk_name.toString(),
                            client.createDisk(disk_name.toString(), t_diskType, dataDiskSizeGb));
                    lastDiskCreated = disk_name.toString();
                }
                instancesDataDisks.put(instance_name.toString(), dataDisks);
            } catch (GoogleComputeEngineException e) {
                log.error("cannot create data disks for [" + instance_name.toString()
                        + "], instance not created: " + e.getMessage());
                continue;
            }
        }

        /**
         * Time to get all the disk resources ready to be attached
         */
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
        }

        /**
         * Create the shard nodes instances
         */
        try {
            try {
                for (Map.Entry<String, Map<String, String>> instance : instancesDataDisks.entrySet()) {
                    if (client.instanceExists(instance.getKey())) {
                        log.info("instance [" + instance.getKey() + "] already exists, not created");
                        continue;
                    }

                    client.createInstance(instance.getKey(), t_machineType, network, rootDiskSizeGb,
                            t_sourceImage, instance.getValue(), t_tags,
                            Arrays.asList(sshKey.getSSHPublicKey(ConfigurationService.CLUSTER_USER)),
                            startupScript.getAbsolutePath(), false);
                }
                log.info("Shard nodes creation finished");
            } catch (GoogleComputeEngineException e) {
                log.error("Shard nodes creation error: " + e.getMessage());
            }
        } finally {
            startupScript.delete();
        }
    };

    Thread thread = new Thread(shardNodesCreation);
    thread.start();
}

From source file:org.apache.jmeter.util.JMeterUtils.java

/**
 * Instantiate a vector of classes/*from  w  w w  . j a  v  a  2 s  .c  o  m*/
 *
 * @param v
 *            Description of Parameter
 * @param className
 *            Description of Parameter
 * @return Description of the Returned Value
 * @deprecated (3.0) not used out of this class
 */
@Deprecated
public static Vector<Object> instantiate(Vector<String> v, String className) {
    Vector<Object> i = new Vector<>();
    try {
        Class<?> c = Class.forName(className);
        Enumeration<String> elements = v.elements();
        while (elements.hasMoreElements()) {
            String name = elements.nextElement();
            try {
                Object o = Class.forName(name).newInstance();
                if (c.isInstance(o)) {
                    i.addElement(o);
                }
            } catch (ClassNotFoundException e) {
                log.error("Error loading class " + name + ": class is not found");
            } catch (IllegalAccessException e) {
                log.error("Error loading class " + name + ": does not have access");
            } catch (InstantiationException e) {
                log.error("Error loading class " + name + ": could not instantiate");
            } catch (NoClassDefFoundError e) {
                log.error("Error loading class " + name + ": couldn't find class " + e.getMessage());
            }
        }
    } catch (ClassNotFoundException e) {
        log.error("Error loading class " + className + ": class is not found");
    }
    return i;
}

From source file:com.appleframework.jmx.core.services.MBeanServiceImpl.java

private Class<?> getClass(String type, ClassLoader classLoader) {
    if (type.equals("boolean"))
        return Boolean.class;
    if (type.equals("byte"))
        return Byte.TYPE;
    if (type.equals("char"))
        return Character.class;
    if (type.equals("double"))
        return Double.class;
    if (type.equals("float"))
        return Float.class;
    if (type.equals("int"))
        return Integer.class;
    if (type.equals("long"))
        return Long.class;
    if (type.equals("short"))
        return Short.class;
    if (type.equals("void"))
        return Void.class;
    Class<?> clazz = null;/*from   w  w w  .j a v  a2  s  . c om*/
    try {
        clazz = Class.forName(type, true, classLoader);

    } catch (ClassNotFoundException e) {
        logger.info("Error finding class of type=" + type + ", error=" + e.getMessage());
    }
    return clazz;
}

From source file:be.fedict.eid.dss.webapp.AbstractProtocolServiceServlet.java

@SuppressWarnings("unchecked")
private void initializeDocumentServices(ServletContext servletContext) {

    if (!this.initDocumentServices) {
        return;//w  w  w.  j a v a2s . c  o  m
    }
    DSSDocumentContext dssDocumentContext = new ModelDSSDocumentContext(this.xmlSchemaManager,
            this.xmlStyleSheetManager, this.trustValidationService, this.configuration);
    this.documentServices = new HashMap<String, DSSDocumentService>();
    Map<String, String> documentServiceClassNames = StartupServletContextListener
            .getDocumentServiceClassNames(servletContext);
    for (Map.Entry<String, String> documentServiceEntry : documentServiceClassNames.entrySet()) {
        String contentType = documentServiceEntry.getKey();
        String documentServiceClassName = documentServiceEntry.getValue();
        Class<? extends DSSDocumentService> documentServiceClass;
        try {
            documentServiceClass = (Class<? extends DSSDocumentService>) Class
                    .forName(documentServiceClassName);
        } catch (ClassNotFoundException e) {
            LOG.error("document service class not found: " + documentServiceClassName);
            continue;
        }
        DSSDocumentService dssDocumentService;
        try {
            dssDocumentService = documentServiceClass.newInstance();
        } catch (Exception e) {
            LOG.error(
                    "could not create an instance of the document service class: " + documentServiceClassName);
            continue;
        }
        try {
            dssDocumentService.init(dssDocumentContext, contentType);
        } catch (Exception e) {
            LOG.error("error initializing document service: " + e.getMessage(), e);
        }
        this.documentServices.put(contentType, dssDocumentService);
    }
}

From source file:grails.core.DefaultGrailsApplication.java

/**
 * Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names
 *
 */// w  w w.jav a  2s  .co  m
public DefaultGrailsApplication(Resource[] resources) {
    this();
    for (Resource resource : resources) {

        Class<?> aClass;
        try {
            aClass = classLoader
                    .loadClass(GrailsResourceUtils.getClassName(resource.getFile().getAbsolutePath()));
        } catch (ClassNotFoundException e) {
            throw new GrailsConfigurationException(
                    "Class not found loading Grails application: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new GrailsConfigurationException(
                    "Class not found loading Grails application: " + e.getMessage(), e);
        }
        loadedClasses.add(aClass);
    }
}

From source file:grails.core.DefaultGrailsApplication.java

/**
 * Loads a GrailsApplication using the given ResourceLocator instance which will search for appropriate class names
 *
 *//*from w ww .ja  v  a2 s  .  co  m*/
public DefaultGrailsApplication(org.grails.io.support.Resource[] resources) {
    this();
    for (org.grails.io.support.Resource resource : resources) {

        Class<?> aClass;
        try {
            aClass = classLoader
                    .loadClass(GrailsResourceUtils.getClassName(resource.getFile().getAbsolutePath()));
        } catch (ClassNotFoundException e) {
            throw new GrailsConfigurationException(
                    "Class not found loading Grails application: " + e.getMessage(), e);
        } catch (IOException e) {
            throw new GrailsConfigurationException(
                    "Class not found loading Grails application: " + e.getMessage(), e);
        }
        loadedClasses.add(aClass);
    }
}