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.infoglue.cms.util.sorters.CompoundComparable.java

/**
 * Returns a list of sorted <code>ContentVO</code> objects.
 * @param sorts the list using the comparatorClass specified. The comparator must implement the interface org.infoglue.cms.util.sorters.TemplateControllerAwareComparator
 * @return the sorted list./*w w  w .jav a2s  . co  m*/
 */
public List getContentResult(String comparatorClass) {
    TemplateControllerAwareComparator comp = null;
    if (comparatorClass != null && !comparatorClass.equals("")) {
        try {
            Class clazz = Class.forName(comparatorClass);
            if (clazz != null) {
                try {
                    comp = (TemplateControllerAwareComparator) clazz.newInstance();
                    comp.setController(this.controller);
                } catch (InstantiationException e) {
                    throw new IllegalArgumentException(
                            "Couldnt instantiate comparator class " + comparatorClass + " " + e.getMessage());
                } catch (IllegalAccessException e) {
                    throw new IllegalArgumentException(
                            "Couldnt access comparator class " + comparatorClass + " " + e.getMessage());
                }
            }
        } catch (ClassNotFoundException e) {
            throw new IllegalArgumentException(
                    "Couldnt find comparator class " + comparatorClass + " " + e.getMessage());
        }
    } else {
        throw new IllegalArgumentException("Must specify a comparator classname");
    }

    Collections.sort(elements, comp);

    final List result = new ArrayList();
    for (final Iterator i = elements.iterator(); i.hasNext();) {
        final SortElement struct = (SortElement) i.next();
        result.add(struct.getContentVO());
    }

    return result;
}

From source file:com.concursive.connect.indexer.LuceneIndexer.java

private Object getObjectIndexer(String className) {
    Object classRef = null;/*from  w  w  w .  ja v a2 s . com*/
    if (classes.containsKey(className)) {
        classRef = classes.get(className);
    } else {
        try {
            classRef = Class.forName(className).newInstance();
            classes.put(className, classRef);
        } catch (ClassNotFoundException cnfe) {
            LOG.warn("Class Not Found Exception. MESSAGE = " + cnfe.getMessage(), cnfe);
        } catch (InstantiationException ie) {
            LOG.error("Instantiation Exception. MESSAGE = " + ie.getMessage(), ie);
        } catch (IllegalAccessException iae) {
            LOG.error("Illegal Argument Exception. MESSAGE = " + iae.getMessage(), iae);
        }
    }
    return classRef;
}

From source file:org.josescalia.common.dao.impl.CommonDaoImpl.java

/**
 * Method to get all entity data from database
 *
 * @return ArrayList of entity/*w  w  w.ja v  a  2  s  .  c om*/
 */
@Override
public List<T> getAll() {
    T t = null;
    try {
        t = clazz.newInstance();
    } catch (InstantiationException e) {
        logger.error(e.getMessage());
    } catch (IllegalAccessException e) {
        logger.error(e.getMessage());
    }
    if (t instanceof ReferenceBase) {
        Criteria criteria = getCurrentSession().createCriteria(t.getClass());
        criteria.add(Restrictions.eq("deleted", 0));
        return criteria.list();
    } else if (t instanceof AuditableBase) {
        Criteria criteria = getCurrentSession().createCriteria(t.getClass());
        return criteria.list();
    } else {
        return (List<T>) getCurrentSession().createQuery("from " + clazz.getName()).list();
    }
}

From source file:org.methodize.nntprss.feed.ChannelManager.java

/**
 * RSS Manager configuration/*from   w  ww  .  ja  va  2  s  .  c  o m*/
 * 
 * - Monitored RSS feeds
 *   feed url, and matching newsgroup name
 * 
 * Once feeds are loaded, load existing persistent 
 * store information about feeds
 * 
 */

public void configure(Document config) {

    channelDAO.loadConfiguration(this);

    updateProxyConfig();

    // Get poller Configuration
    Element rootElm = config.getDocumentElement();
    NodeList cfgElms = rootElm.getElementsByTagName("poller");
    if (cfgElms != null && cfgElms.getLength() > 0) {
        Element pollerElm = (Element) cfgElms.item(0);
        String threadsStr = pollerElm.getAttribute("threads");
        if (threadsStr != null) {
            pollerThreads = Integer.parseInt(threadsStr);
        }
    }

    NodeList processorsElms = rootElm.getElementsByTagName("itemProcessors");
    if (processorsElms != null && processorsElms.getLength() > 0) {
        NodeList processorElms = ((Element) processorsElms.item(0)).getElementsByTagName("processor");
        if (processorElms != null && processorElms.getLength() > 0) {
            List processors = new ArrayList();
            for (int i = 0; i < processorElms.getLength(); i++) {
                Element processorElm = (Element) processorElms.item(i);

                String itemProcessorClassName = processorElm.getAttribute("class");
                if (itemProcessorClassName != null) {
                    try {
                        Object itemProcessorObject = Class.forName(itemProcessorClassName).newInstance();
                        if (!(itemProcessorObject instanceof ItemProcessor)) {
                            log.warn(itemProcessorClassName
                                    + " not instance of org.methodize.nntprss.plugin.ItemProcessor, skipping");
                        } else {
                            try {
                                ItemProcessor itemProcessor = (ItemProcessor) itemProcessorObject;
                                itemProcessor.initialize(processorElm);
                                processors.add(itemProcessor);
                            } catch (PluginException pe) {
                                log.warn("Error initializing ItemProcessor plug-in: " + pe.getMessage()
                                        + ", skipping.", pe);
                            }
                        }
                    } catch (ClassNotFoundException cnfe) {
                        log.warn("Cannot find ItemProcessor class " + itemProcessorClassName, cnfe);
                    } catch (IllegalAccessException iae) {
                        log.warn("Error instantiating ItemProcessor class: " + iae.getMessage(), iae);
                    } catch (InstantiationException ie) {
                        log.warn("Error instantiating ItemProcessor class: " + ie.getMessage(), ie);
                    }
                }

            }
            if (processors.size() > 0) {
                itemProcessors = (ItemProcessor[]) processors.toArray(new ItemProcessor[0]);
            }
        }
    }

    // Load feeds...
    categories = channelDAO.loadCategories();
    channels = channelDAO.loadChannels(this);
}

From source file:nz.co.gregs.properties.adapt.AdaptableTypeSyncer.java

/**
 *
 * @param propertyName used in error messages
 * @param internalQdtType internalQdtType
 * @param internalQdtLiteralType internalQdtLiteralType
 * @param externalSimpleType externalSimpleType
 * @param typeAdaptor typeAdaptor typeAdaptor
 *//*  w w  w .j  a v a 2s  .  c  o  m*/
public AdaptableTypeSyncer(String propertyName, Class<? extends AdaptableType> internalQdtType,
        Class<?> internalQdtLiteralType, Class<?> externalSimpleType, TypeAdaptor<Object, Object> typeAdaptor) {
    if (typeAdaptor == null) {
        throw new PropertyException("Null typeAdaptor was passed, this is an internal bug");
    }
    this.propertyName = propertyName;
    this.typeAdaptor = typeAdaptor;
    this.internalQdtType = internalQdtType;
    this.toExternalSimpleTypeAdaptor = new SafeOneWaySimpleTypeAdaptor(propertyName, typeAdaptor,
            Direction.TO_EXTERNAL, internalQdtLiteralType, externalSimpleType);

    this.toInternalSimpleTypeAdaptor = new SafeOneWaySimpleTypeAdaptor(propertyName, typeAdaptor,
            Direction.TO_INTERNAL, externalSimpleType, internalQdtLiteralType);

    try {
        this.internalQdt = internalQdtType.newInstance();
    } catch (InstantiationException e) {
        // TODO produce a better error message that is consistent with how this is handled elsewhere
        throw new PropertyException("Instantiation error creating internal " + internalQdtType.getSimpleName()
                + " QDT: " + e.getMessage(), e);
    } catch (IllegalAccessException e) {
        // TODO produce a better error message that is consistent with how this is handled elsewhere
        throw new PropertyException(
                "Access error creating internal " + internalQdtType.getSimpleName() + " QDT: " + e.getMessage(),
                e);
    }
}

From source file:org.josescalia.common.dao.impl.CommonDaoImpl.java

/**
 * This method is used to find list of object in the database using paired
 * field and value//from  w w w . j  a  v  a2 s  .com
 *
 * @param paramFieldValue a paired field and value to search
 * @return List of object
 *
 */
@Override
public List<T> findExact(Map<String, Object> paramFieldValue) throws Exception {
    T t = null;
    try {
        t = clazz.newInstance();
    } catch (InstantiationException e) {
        throw new Exception(e.getMessage());
    } catch (IllegalAccessException e) {
        throw new Exception(e.getMessage());
    }
    List<T> rList = new ArrayList<T>();
    String field = "";
    Object value = null;
    for (Object key : paramFieldValue.keySet()) {
        field = (String) key.toString();
        value = paramFieldValue.get(field);
    }
    String query = "from " + clazz.getName() + " where ";
    Criteria criteria = getCurrentSession().createCriteria(t.getClass());
    if (value instanceof String) {
        criteria.add(Restrictions.eq(field, String.valueOf(value)));
    } else {
        criteria.add(Restrictions.eq(field, value));
    }

    try {
        rList = criteria.list();
    } catch (Exception e) {
        throw new Exception(e.getMessage());
    }
    return rList;
}

From source file:net.mojodna.sprout.SproutAutoLoaderPlugIn.java

@SuppressWarnings("unchecked")
private void loadAction(final Class bean) {
    final Annotation[] annotations = bean.getAnnotations();

    for (int i = 0; i < annotations.length; i++) {
        final Annotation a = annotations[i];
        final Class type = a.annotationType();

        if (type.equals(SproutAction.class)) {
            final SproutAction form = (SproutAction) a;
            final String path = form.path();
            final Class<ActionConfig> mappingClass = form.mappingClass();
            final String scope = form.scope();
            final String name = form.name();
            final boolean validate = form.validate();
            final String input = form.input();
            final SproutProperty[] properties = form.properties();
            final SproutForward[] forwards = form.forwards();
            ActionConfig actionConfig = null;

            try {
                Constructor<ActionConfig> constructor = mappingClass.getDeclaredConstructor(new Class[] {});

                actionConfig = constructor.newInstance(new Object[] {});
            } catch (NoSuchMethodException nsme) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + nsme.getMessage());
            } catch (InstantiationException ie) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + ie.getMessage());
            } catch (IllegalAccessException iae) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + iae.getMessage());
            } catch (InvocationTargetException ite) {
                log.error("Failed to create a new instance of " + mappingClass.toString() + ", "
                        + ite.getMessage());
            }/*from www . j  a v a2s  .c  o  m*/

            if (actionConfig != null) {
                actionConfig.setPath(path);
                actionConfig.setType(bean.getName());
                actionConfig.setScope(scope);
                actionConfig.setValidate(validate);

                if (name.length() > 0) {
                    actionConfig.setName(name);
                }
                if (input.length() > 0) {
                    actionConfig.setInput(input);
                }

                if (properties != null && properties.length > 0) {
                    Map actionConfigBeanMap = new BeanMap(actionConfig);

                    for (int j = 0; j < properties.length; j++) {
                        actionConfigBeanMap.put(properties[j].property(), properties[j].value());
                    }
                }

                if (forwards != null && forwards.length > 0) {
                    for (int j = 0; j < forwards.length; j++) {
                        String fcModule = forwards[j].module();

                        actionConfig.addForwardConfig(makeForward(forwards[j].name(), forwards[j].path(),
                                forwards[j].redirect(), fcModule.length() == 0 ? null : fcModule));
                    }
                }
            }

            if (log.isDebugEnabled()) {
                log.debug("Action " + path + " -> " + bean.getName());
            }

            getModuleConfig().addActionConfig(actionConfig);
        }
    }
}

From source file:org.apache.jmeter.junit.JMeterTest.java

public static Collection<Object> getObjects(Class<?> extendsClass) throws Exception {
    String exName = extendsClass.getName();
    Object myThis = "";
    Iterator<String> classes = ClassFinder
            .findClassesThatExtend(JMeterUtils.getSearchPaths(), new Class[] { extendsClass }).iterator();
    List<Object> objects = new LinkedList<>();
    String n = "";
    boolean caughtError = true;
    Throwable caught = null;/*from w  w w  .j a va 2  s  . co  m*/
    try {
        while (classes.hasNext()) {
            n = classes.next();
            // TODO - improve this check
            if (n.endsWith("RemoteJMeterEngineImpl")) {
                continue; // Don't try to instantiate remote server
            }
            Class<?> c = null;
            try {
                c = Class.forName(n);
                try {
                    // Try with a parameter-less constructor first
                    objects.add(c.newInstance());
                } catch (InstantiationException e) {
                    caught = e;
                    try {
                        // Events often have this constructor
                        objects.add(c.getConstructor(new Class[] { Object.class })
                                .newInstance(new Object[] { myThis }));
                    } catch (NoSuchMethodException f) {
                        // no luck. Ignore this class
                        System.out.println(
                                "o.a.j.junit.JMeterTest WARN: " + exName + ": NoSuchMethodException  " + n
                                        + ", missing empty Constructor or Constructor with Object parameter");
                    }
                }
            } catch (NoClassDefFoundError e) {
                // no luck. Ignore this class
                System.out.println("o.a.j.junit.JMeterTest WARN: " + exName + ": NoClassDefFoundError " + n
                        + ":" + e.getMessage());
                e.printStackTrace(System.out);
            } catch (IllegalAccessException e) {
                caught = e;
                System.out.println("o.a.j.junit.JMeterTest WARN: " + exName + ": IllegalAccessException " + n
                        + ":" + e.getMessage());
                e.printStackTrace(System.out);
                // We won't test restricted-access classes.
            } catch (HeadlessException | ExceptionInInitializerError e) {// EIIE can be caused by Headless
                caught = e;
                System.out.println("o.a.j.junit.JMeterTest Error creating " + n + " " + e.toString());
            } catch (Exception e) {
                caught = e;
                if (e instanceof RemoteException) { // not thrown, so need to check here
                    System.out.println(
                            "o.a.j.junit.JMeterTest WARN: " + "Error creating " + n + " " + e.toString());
                } else {
                    throw new Exception("Error creating " + n, e);
                }
            }
        }
        caughtError = false;
    } finally {
        if (caughtError) {
            System.out.println("Last class=" + n);
            System.out.println("objects.size=" + objects.size());
            System.out.println("Last error=" + caught);
        }
    }

    if (objects.isEmpty()) {
        System.out.println("No classes found that extend " + exName + ". Check the following:");
        System.out.println("Search paths are:");
        String ss[] = JMeterUtils.getSearchPaths();
        for (String s : ss) {
            System.out.println(s);
        }
        if (!classPathShown) {// Only dump it once
            System.out.println("Class path is:");
            String cp = System.getProperty("java.class.path");
            String classPathElements[] = JOrphanUtils.split(cp, java.io.File.pathSeparator);
            for (String classPathElement : classPathElements) {
                System.out.println(classPathElement);
            }
            classPathShown = true;
        }
    }
    return objects;
}

From source file:org.rasea.core.configuration.ConfigurationLoader.java

private Object initFieldValue(final Field field) {
    Object fieldValue = null;/*from   w ww.j a  v  a  2s.  c o  m*/

    try {
        fieldValue = field.getType().newInstance();

    } catch (final InstantiationException cause) {
        final String message = "Failed to instante property: " + field.getType().getName()
                + " has no default constructor";
        this.log(message, field.getType().isLocalClass());

    } catch (final IllegalAccessException cause) {
        logger.warn(cause.getMessage());
    }

    return fieldValue;
}

From source file:com.gdcn.modules.db.jdbc.processor.CamelBeanProcessor.java

/**
 * Factory method that returns a new instance of the given Class.  This
 * is called at the start of the bean creation process and may be
 * overridden to provide custom behavior like returning a cached bean
 * instance.//from   ww w  .  j a va  2  s. c o  m
 * @param <T> The type of object to create
 * @param c The Class to create an object from.
 * @return A newly created object of the Class.
 * @throws SQLException if creation failed.
 */
protected <T> T newInstance(Class<T> c) throws SQLException {
    try {
        return c.newInstance();

    } catch (InstantiationException e) {
        throw new SQLException("Cannot create " + c.getName() + ": " + e.getMessage());

    } catch (IllegalAccessException e) {
        throw new SQLException("Cannot create " + c.getName() + ": " + e.getMessage());
    }
}