Example usage for java.lang InstantiationException getMessage

List of usage examples for java.lang InstantiationException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.fao.fenix.wds.web.rest.WDSRESTService.java

@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    try {/* www.  j av  a2 s. c o  m*/

        // timing
        long t0 = System.currentTimeMillis();

        // prepare output
        String output = parse(request.getParameterMap());
        String filename = filename(request.getParameterMap());

        // JSONP callback
        String jsonCallbackParam = request.getParameter("jsoncallback");
        if (jsonCallbackParam != null) {
            if (jsonCallbackParam.equals("?")) {
                output = "callback(" + output + ")";
            } else {
                output = jsonCallbackParam + "(" + output + ")";
            }
        }

        // set response
        switch (fwds.getOutput()) {
        case HTML:
            response.setContentType("text/html");
            break;
        case JSON:
            response.setContentType("application/json");
            break;
        case OLAPJSON:
            response.setContentType("application/json");
            if (request.getParameterMap().get("addFlags") != null) {
                boolean addFlags = Boolean.valueOf(request.getParameterMap().get("addFlags").toString());
                fwds.setAddFlags(addFlags);
            }
            break;
        case XML:
            response.setContentType("application/xml");
            break;
        case XML2:
            response.setContentType("application/xml");
            break;
        case CSV:
            response.setContentType("text/csv");
            response.setHeader("Content-disposition", "inline; filename=" + filename + ".csv");
            break;
        case EXCEL:
            response.setContentType("text/html");
            break;
        default:
            response.setContentType("text/html");
            break;
        }
        //         response.setContentLength(output.length());
        response.setCharacterEncoding("UTF-8");
        PrintWriter out = response.getWriter();
        out.println(output);

        // close stream
        out.close();
        out.flush();

        // timing
        long t1 = System.currentTimeMillis();
        //         System.out.println("[WDS] - SERVICE - REST - " + (t1 - t0) + " - " + FieldParser.parseDate(new Date(), "FENIXAPPS"));

    } catch (InstantiationException e) {
        handleException(response, e.getMessage());
    } catch (IllegalAccessException e) {
        handleException(response, e.getMessage());
    } catch (SQLException e) {
        handleException(response, e.getMessage());
    } catch (ClassNotFoundException e) {
        handleException(response, e.getMessage());
    } catch (WDSException e) {
        handleException(response, e.getMessage());
    }

}

From source file:com.petpet.c3po.controller.Controller.java

/**
 * Gets a new adaptor instance based on the type of adaptor. if the type is
 * unknown, then null is returned./*from ww w .  j  ava2s.  c  om*/
 *
 * @param type
 *          the type of the adaptor.
 * @return the instance of the adaptor.
 */
private AbstractAdaptor getAdaptor(String type) {
    AbstractAdaptor adaptor = null;
    Class<? extends AbstractAdaptor> clazz = this.knownAdaptors.get(type);
    if (clazz != null) {
        try {

            adaptor = clazz.newInstance();

        } catch (InstantiationException e) {
            LOG.error("An error occurred while instantiating the adaptor: ", e.getMessage());
        } catch (IllegalAccessException e) {
            LOG.error("An error occurred while instantiating the adaptor: ", e.getMessage());
        }
    }

    return adaptor;
}

From source file:org.apromore.test.heuristic.JavaBeanHeuristic.java

private Object newInstance(Class clazz) {
    try {/*from  ww  w  .  j av  a 2s  . c  om*/
        return tryToInstantiate(clazz);
    } catch (InstantiationException e) {
        throw new AssertionError("Class " + clazz.getName()
                + " could not be instantiated, does it have a non-private no-arg constructor?");
    } catch (IllegalAccessException e) {
        throw new AssertionError("Class " + clazz.getName()
                + " could not be instantiated, does it have a non-private no-arg constructor?");
    } catch (InvocationTargetException e) {
        throw new AssertionError("Exception thrown when constructing object of type " + clazz.getName() + " ["
                + e.getMessage() + "]");
    } catch (NoSuchMethodException e) {
        throw new AssertionError("Unable to find a default constructor for class " + clazz.getName());
    }
}

From source file:org.apache.oodt.cas.filemgr.tools.SolrIndexer.java

/**
 * This method adds a single product extracted from a metadata file to the
 * Solr index./*from   ww  w. j  a  v a2s  .  co  m*/
 * 
 * @param file
 *          The file containing product metadata.
 * @param delete
 *          Flag indicating whether the entry should be deleted from the
 *          index.
 * @throws SolrServerException
 *           When an error occurs communicating with the Solr server instance.
 */
public void indexMetFile(File file, boolean delete) throws SolrServerException {
    LOG.info("Attempting to index product from metadata file.");
    try {
        SerializableMetadata metadata = new SerializableMetadata("UTF-8", false);
        metadata.loadMetadataFromXmlStream(new FileInputStream(file));
        metadata.addMetadata("id", metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
        metadata.addMetadata(config.getProperty(ACCESS_KEY),
                config.getProperty(ACCESS_URL) + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
        if (delete) {
            server.deleteById(metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
        }
        server.add(this.getSolrDocument(metadata));
        LOG.info("Indexed product: " + metadata.getMetadata("CAS." + CoreMetKeys.PRODUCT_ID));
    } catch (InstantiationException e) {
        LOG.severe("Could not instantiate metadata object: " + e.getMessage());
    } catch (FileNotFoundException e) {
        LOG.severe("Could not find metadata file: " + e.getMessage());
    } catch (IOException e) {
        LOG.severe("Could not delete product from index: " + e.getMessage());
    }
}

From source file:org.apache.wiki.auth.AuthenticationManager.java

/**
 * Instantiates and executes a single JAAS
 * {@link javax.security.auth.spi.LoginModule}, and returns a Set of
 * Principals that results from a successful login. The LoginModule is instantiated,
 * then its {@link javax.security.auth.spi.LoginModule#initialize(Subject, CallbackHandler, Map, Map)}
 * method is called. The parameters passed to <code>initialize</code> is a 
 * dummy Subject, an empty shared-state Map, and an options Map the caller supplies.
 * //  w  ww  .ja  v a  2 s  .  c  o  m
 * @param clazz
 *            the LoginModule class to instantiate
 * @param handler
 *            the callback handler to supply to the LoginModule
 * @param options
 *            a Map of key/value strings for initializing the LoginModule
 * @return the set of Principals returned by the JAAS method {@link Subject#getPrincipals()}
 * @throws WikiSecurityException
 *             if the LoginModule could not be instantiated for any reason
 */
protected Set<Principal> doJAASLogin(Class<? extends LoginModule> clazz, CallbackHandler handler,
        Map<String, String> options) throws WikiSecurityException {
    // Instantiate the login module
    LoginModule loginModule = null;
    try {
        loginModule = clazz.newInstance();
    } catch (InstantiationException e) {
        throw new WikiSecurityException(e.getMessage(), e);
    } catch (IllegalAccessException e) {
        throw new WikiSecurityException(e.getMessage(), e);
    }

    // Initialize the LoginModule
    Subject subject = new Subject();
    loginModule.initialize(subject, handler, EMPTY_MAP, options);

    // Try to log in:
    boolean loginSucceeded = false;
    boolean commitSucceeded = false;
    try {
        loginSucceeded = loginModule.login();
        if (loginSucceeded) {
            commitSucceeded = loginModule.commit();
        }
    } catch (LoginException e) {
        // Login or commit failed! No principal for you!
    }

    // If we successfully logged in & committed, return all the principals
    if (loginSucceeded && commitSucceeded) {
        return subject.getPrincipals();
    }
    return NO_PRINCIPALS;
}

From source file:org.vulpe.controller.struts.VulpeStrutsController.java

/**
 * Method to add detail./*  w w w  .j  a va  2 s . c o  m*/
 *
 * @param collection
 * @since 1.0
 * @throws OgnlException
 */
protected void doAddDetail(final Collection collection) throws OgnlException {
    final Map context = ActionContext.getContext().getContextMap();
    final PropertyAccessor accessor = OgnlRuntime.getPropertyAccessor(collection.getClass());
    final Integer index = Integer.valueOf(collection.size());
    if (((vulpe.controller().type().equals(ControllerType.TABULAR)
            && vulpe.controller().config().getTabularConfig().isAddNewDetailsOnTop())
            || (vulpe.controller().type().equals(ControllerType.MAIN)
                    && vulpe.controller().detailConfig().isAddNewDetailsOnTop()))
            && VulpeValidationUtil.isNotEmpty(collection)) {
        final Object value = accessor.getProperty(context, collection, 0);
        try {
            final ENTITY detail = (ENTITY) value.getClass().newInstance();
            vulpe.updateAuditInfo(detail);
            ((ArrayList<ENTITY>) collection).add(0, prepareDetail(detail));
        } catch (InstantiationException e) {
            LOG.error(e.getMessage());
        } catch (IllegalAccessException e) {
            LOG.error(e.getMessage());
        }
    } else {
        final ENTITY detail = (ENTITY) accessor.getProperty(context, collection, index);
        vulpe.updateAuditInfo(detail);
        final ENTITY preparedDetail = prepareDetail(detail);
        if (!preparedDetail.equals(detail)) {
            accessor.setProperty(context, collection, index, preparedDetail);
        }
    }
}

From source file:org.ajax4jsf.templatecompiler.elements.A4JRendererElementsFactory.java

public TemplateElement getProcessor(final Node nodeElement, final CompilationContext componentBean)
        throws CompilationException {
    TemplateElement returnValue = null;/*ww w  .  j  a v  a2s . c o  m*/

    short nodeType = nodeElement.getNodeType();
    if (Node.CDATA_SECTION_NODE == nodeType) {
        returnValue = new CDATAElement(nodeElement, componentBean);
    } else if (Node.TEXT_NODE == nodeType) {
        returnValue = new TextElement(nodeElement, componentBean);
    } else if (Node.COMMENT_NODE == nodeType) {
        returnValue = new CommentElement(nodeElement, componentBean);
    } else if (Node.PROCESSING_INSTRUCTION_NODE == nodeType) {
        returnValue = new PIElement(nodeElement, componentBean);
    } else if (Node.ELEMENT_NODE == nodeType) {
        String className = (String) mapClasses.get(nodeElement.getNodeName());

        if (className == null) {
            className = DEFAULT_CLASS_ELEMENT_PROCESSOR;
        }

        if (!className.equals("")) {
            Class class1;
            try {
                log.debug("loading class: " + className);

                class1 = Class.forName(className);
                Object[] objects = new Object[2];
                objects[0] = nodeElement;
                objects[1] = componentBean;

                returnValue = (TemplateElement) class1.getConstructor(paramClasses).newInstance(objects);
            } catch (InstantiationException e) {
                throw new CompilationException("InstantiationException: " + e.getLocalizedMessage(), e);
            } catch (IllegalAccessException e) {
                throw new CompilationException("IllegalAccessException: " + e.getLocalizedMessage(), e);
            } catch (IllegalArgumentException e) {
                e.printStackTrace();
            } catch (SecurityException e) {
                e.printStackTrace();
            } catch (InvocationTargetException e) {
                e.printStackTrace();
                throw new CompilationException("InvocationTargetException: " + e.getMessage(), e);
            } catch (NoSuchMethodException e) {
                e.printStackTrace();
            } catch (ClassNotFoundException e) {
                throw new CompilationException(" error loading class: " + e.getLocalizedMessage());
            }
        }
    }
    return returnValue;
}

From source file:org.projectforge.excel.ExcelImport.java

/**
 * convert the contents of the table into an array.
 * //from   w  w  w  .  ja  v a 2 s.c  o  m
 * @param clazz the target class
 * @return an array with the object values.
 */
@SuppressWarnings("unchecked")
public T[] convertToRows(final Class<T> clazz) {
    if (clazzFactory == null) {
        setRowClass(clazz);
    }
    final HSSFSheet sheet = work.getSheetAt(activeSheet);
    final int numberOfRows = sheet.getLastRowNum();
    final List<T> list = new ArrayList<T>(numberOfRows);
    final HSSFRow columnNames = sheet.getRow(columnNameRow);
    for (int i = startAtRow; i <= numberOfRows; i++) {
        try {
            T line;
            line = convertToBean(sheet.getRow(i), columnNames, i + 1);
            if (line == null) {
                continue;
            }
            if (clazz.isInstance(line) == false) {
                throw new IllegalStateException("returned type " + line.getClass() + " is not assignable to "
                        + clazz + " in sheet='" + sheet.getSheetName() + "', row=" + i);
            }
            list.add(line);
        } catch (final InstantiationException ex) {
            throw new IllegalArgumentException("Can't create bean " + ex.toString() + " in sheet='"
                    + sheet.getSheetName() + "', row=" + i);
        } catch (final IllegalAccessException ex) {
            throw new IllegalArgumentException("Getter is not visible " + ex.toString() + " in sheet='"
                    + sheet.getSheetName() + "', row=" + i);
        } catch (final InvocationTargetException ex) {
            log.error(ex.getMessage(), ex);
            throw new IllegalArgumentException("Getter threw an exception " + ex.toString() + " in sheet='"
                    + sheet.getSheetName() + "', row=" + i);
        } catch (final NoSuchMethodException ex) {
            throw new IllegalArgumentException("Getter is not existant " + ex.toString() + " in sheet='"
                    + sheet.getSheetName() + "', row=" + i);
        }
    }
    return list.toArray((T[]) Array.newInstance(clazz, 0));
}

From source file:org.eclipse.skalli.core.project.ProjectComponent.java

@Override
public Project createProject(final String templateId, final String userId) {
    final Project project = (StringUtils.isNotBlank(templateId)) ? new Project(templateId) : new Project();
    project.setUuid(UUID.randomUUID());

    if (UserServices.getUser(userId) != null) {
        PeopleExtension peopleExt = new PeopleExtension();
        peopleExt.getLeads().add(new Member(userId));
        project.addExtension(peopleExt);
    }// w w w.  j a  v a2 s  .  c  o m

    final ProjectTemplate template = projectTemplateService.getProjectTemplateById(templateId);

    if (template != null) {
        for (Class<? extends ExtensionEntityBase> extensionClass : projectTemplateService
                .getSelectableExtensions(template, null)) {
            String extensionClassName = extensionClass.getName();
            if (template.isEnabled(extensionClassName)) {
                try {
                    if (project.getExtension(extensionClass) == null) {
                        project.addExtension(extensionClass.cast(extensionClass.newInstance()));
                    }
                } catch (InstantiationException e) {
                    LOG.warn(MessageFormat.format("Extension ''{0}'' could not be instantiated: {1}",
                            extensionClassName, e.getMessage()));
                } catch (IllegalAccessException e) {
                    LOG.warn(MessageFormat.format("Extension ''{0}'' could not be instantiated: {1}",
                            extensionClassName, e.getMessage()));
                }
            }
        }
    }

    return project;
}

From source file:de.iteratec.iteraplan.businesslogic.service.legacyExcel.ExcelAttributesImportServiceImpl.java

/**
 * Creates a new AttributeType instance with the type of the class.
 * @param userLog the processing log for saving import messages
 * @param atClass type for the attribute type
 * @return new AttributeType, or null/*from ww w  . ja  v  a2s . co  m*/
 */
private <T> T createNewAttributeTypeInstance(ProcessingLog userLog, Class<T> atClass) {
    T newAttributeType;
    try {
        newAttributeType = atClass.newInstance();
    } catch (InstantiationException e) {
        userLog.error(e.getMessage());
        return null;
    } catch (IllegalAccessException e) {
        userLog.error(e.getMessage());
        return null;
    }
    return newAttributeType;
}