Example usage for java.lang InstantiationException printStackTrace

List of usage examples for java.lang InstantiationException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:de.clusteval.run.statistics.RunDataStatisticCalculator.java

/**
 * This method parses a string and maps it to a subclass of
 * {@link RunDataStatistic} looking it up in the given repository.
 * /*from   w  w  w. j av a  2s . c  o m*/
 * @param repository
 *            The repository to look for the classes.
 * @param runDataStatistic
 *            The string representation of a run data statistic subclass.
 * @return A subclass of {@link RunDataStatistic}.
 * @throws UnknownRunDataStatisticException
 */
public static RunDataStatistic parseFromString(final Repository repository, String runDataStatistic)
        throws UnknownRunDataStatisticException {
    Class<? extends RunDataStatistic> c = repository.getRegisteredClass(RunDataStatistic.class,
            "de.clusteval.run.statistics." + runDataStatistic);

    try {
        RunDataStatistic statistic = c.getConstructor(Repository.class, boolean.class, long.class, File.class)
                .newInstance(repository, true, System.currentTimeMillis(), new File(runDataStatistic));
        return statistic;
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {

    } catch (IllegalArgumentException e1) {
        e1.printStackTrace();
    } catch (SecurityException e1) {
        e1.printStackTrace();
    } catch (InvocationTargetException e1) {
        e1.printStackTrace();
    } catch (NoSuchMethodException e1) {
        e1.printStackTrace();
    }
    throw new UnknownRunDataStatisticException(
            "\"" + runDataStatistic + "\" is not a known run data statistic.");
}

From source file:de.vandermeer.skb.datatool.commons.DataUtilities.java

/**
 * Takes the given entry map and tries to generate a special data object from it.
 * @param key the key pointing to the map entry
 * @param keyStart string used to start a key
 * @param map key/value mappings to load the key from
 * @param loadedTypes loaded types as lookup for links
 * @param cs core settings required for loading data
 * @return a new data object of specific type (as read from the map) on success, null on no success
 * @throws IllegalArgumentException if any of the required arguments or map entries are not set or empty
 * @throws URISyntaxException if creating a URI for an SKB link failed
 *///w w w .j a  va2s .com
public static Object loadData(EntryKey key, String keyStart, Map<?, ?> map, LoadedTypeMap loadedTypes,
        CoreSettings cs) throws URISyntaxException {
    if (!map.containsKey(key.getKey())) {
        return null;
    }

    Object data = map.get(key.getKey());
    if (key.getSkbUri() != null && data instanceof String) {
        return loadLink(data, loadedTypes);
    }

    if (key.getType().equals(String.class) && data instanceof String) {
        if (key.useTranslator() == true && cs.getTranslator() != null) {
            return cs.getTranslator().translate((String) data);
        }
        return data;
    }
    if (key.getType().equals(Integer.class) && data instanceof Integer) {
        return data;
    }

    if (ClassUtils.isAssignable(key.getType(), EntryObject.class)) {
        EntryObject eo;
        try {
            eo = (EntryObject) key.getType().newInstance();
            if (data instanceof Map) {
                eo.loadObject(keyStart, data, loadedTypes, cs);
            }
            return eo;
        } catch (InstantiationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    return null;
}

From source file:org.onesun.atomator.adaptors.AdaptorFactory.java

public static Adaptor newAdaptor(Channel channel, String feedURL, boolean fullText) {
    Adaptor adaptor = null;/*from w  w w  .  jav a2 s  .  c  o  m*/

    String type = channel.getEntry().getChannelType();
    if (adaptors.containsKey(type) == false) {
        type = GENERIC_ADAPTOR_NAME;
    }

    logger.info("Resolving class [asked]: " + channel + " [giving]: " + type);
    Class<?> clazz = adaptors.get(type);
    if (clazz != null) {
        try {
            adaptor = (Adaptor) clazz.newInstance();
            adaptor.setChannel(channel);

            if (feedURL != null) {
                adaptor.setFeedURL(feedURL);
            }

            adaptor.setFullText(fullText);
        } catch (InstantiationException e) {
            logger.error("Instantiation Exception while loading adaptors : " + e.getMessage());
            e.printStackTrace();

        } catch (IllegalAccessException e) {
            logger.error("Illegal Access Exception while loading adaptors : " + e.getMessage());
            e.printStackTrace();
        }
    }

    return adaptor;
}

From source file:com.projity.session.LocalSession.java

public static FileImporter getImporter(String name) {
    FileImporter importer = null;//from   w w w .  j  a  v  a  2 s.  c om
    try {
        importer = (FileImporter) ClassUtils.forName(name).newInstance();
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return importer;
}

From source file:com.ricemap.spateDB.core.SpatialSite.java

/**
 * Creates a stock shape according to the given configuration
 * @param job/*  w ww  .  ja  v  a2s .  co  m*/
 * @return
 */
public static Shape createStockShape(Configuration job) {
    Shape stockShape = null;
    try {
        Class<? extends Shape> shapeClass = getShapeClass(job);
        stockShape = shapeClass.newInstance();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return stockShape;
}

From source file:de.clusteval.data.dataset.generator.DataSetGenerator.java

/**
 * Parses a dataset generator from string.
 * //from w w  w  . j  av a  2  s . c  o m
 * @param repository
 *            the repository
 * @param dataSetGenerator
 *            The simple name of the dataset generator class.
 * @return the clustering quality measure
 * @throws UnknownDataSetGeneratorException
 */
public static DataSetGenerator parseFromString(final Repository repository, String dataSetGenerator)
        throws UnknownDataSetGeneratorException {

    Class<? extends DataSetGenerator> c = repository.getRegisteredClass(DataSetGenerator.class,
            "de.clusteval.data.dataset.generator." + dataSetGenerator);
    try {
        DataSetGenerator generator = c.getConstructor(Repository.class, boolean.class, long.class, File.class)
                .newInstance(repository, false, System.currentTimeMillis(), new File(dataSetGenerator));
        return generator;

    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (NullPointerException e) {

    } catch (IllegalArgumentException e1) {
        e1.printStackTrace();
    } catch (SecurityException e1) {
        e1.printStackTrace();
    } catch (InvocationTargetException e1) {
        e1.printStackTrace();
    } catch (NoSuchMethodException e1) {
        e1.printStackTrace();
    }
    throw new UnknownDataSetGeneratorException(
            "\"" + dataSetGenerator + "\" is not a known dataset generator.");
}

From source file:edu.uci.ics.jung.algorithms.matrix.GraphMatrixOperations.java

/**
 * Returns the graph that corresponds to the square of the (weighted)
 * adjacency matrix that the specified graph <code>g</code> encodes. The
 * implementation of MatrixElementOperations that is furnished to the
 * constructor specifies the implementation of the dot product, which is an
 * integral part of matrix multiplication.
 * /*from   w w  w.  j a v  a  2s.c o  m*/
 * @param g
 *            the graph to be squared
 * @return the result of squaring g
 */
@SuppressWarnings("unchecked")
public static <V, E> Graph<V, E> square(Graph<V, E> g, Factory<E> edgeFactory, MatrixElementOperations<E> meo) {
    // create new graph of same type
    Graph<V, E> squaredGraph = null;
    try {
        squaredGraph = g.getClass().newInstance();
    } catch (InstantiationException e3) {
        e3.printStackTrace();
    } catch (IllegalAccessException e3) {
        e3.printStackTrace();
    }

    Collection<V> vertices = g.getVertices();
    for (V v : vertices) {
        squaredGraph.addVertex(v);
    }
    for (V v : vertices) {
        for (V src : g.getPredecessors(v)) {
            // get the edge connecting src to v in G
            E e1 = g.findEdge(src, v);
            for (V dest : g.getSuccessors(v)) {
                // get edge connecting v to dest in G
                E e2 = g.findEdge(v, dest);
                // collect data on path composed of e1 and e2
                Number pathData = meo.computePathData(e1, e2);
                E e = squaredGraph.findEdge(src, dest);
                // if no edge from src to dest exists in G2, create one
                if (e == null) {
                    e = edgeFactory.create();
                    squaredGraph.addEdge(e, src, dest);
                }
                meo.mergePaths(e, pathData);
            }
        }
    }
    return squaredGraph;
}

From source file:com.mmj.app.lucene.solr.client.SolrClient.java

public static Object toBean(SolrDocument record, Class<?> clazz) {

    Object o = null;//from   www .  j  a v a 2 s  .c om
    try {
        o = clazz.newInstance();
    } catch (InstantiationException e1) {
        e1.printStackTrace();
    } catch (IllegalAccessException e1) {
        e1.printStackTrace();
    }
    Field[] fields = clazz.getDeclaredFields();
    for (Field field : fields) {
        Object value = record.get(field.getName());
        ConvertUtils.register(new DateConverter(null), java.util.Date.class);
        try {
            BeanUtils.setProperty(o, field.getName(), value);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
    return o;
}

From source file:edu.umass.cs.reconfiguration.reconfigurationpackets.ReconfigurationPacket.java

private static BasicReconfigurationPacket<?> getReconfigurationPacket(JSONObject json,
        Map<ReconfigurationPacket.PacketType, Class<?>> typeMap, Stringifiable<?> unstringer,
        boolean forcePrintException) throws JSONException {
    BasicReconfigurationPacket<?> rcPacket = null;
    ReconfigurationPacket.PacketType rcType = null;
    String canonicalClassName = null;
    try {//from   w  ww .  j ava 2s  .c o  m
        long t = System.nanoTime();
        if ((rcType = ReconfigurationPacket.PacketType.intToType.get(JSONPacket.getPacketType(json))) != null
                && (canonicalClassName = getPacketTypeCanonicalClassName(rcType)) != null) {
            rcPacket = (BasicReconfigurationPacket<?>) (Class.forName(canonicalClassName)
                    .getConstructor(JSONObject.class, Stringifiable.class).newInstance(json, unstringer));
        }
        DelayProfiler.updateDelayNano("rc_reflection", t);
    } catch (NoSuchMethodException nsme) {
        nsme.printStackTrace();
    } catch (InvocationTargetException ite) {
        ite.printStackTrace();
    } catch (IllegalAccessException iae) {
        iae.printStackTrace();
    } catch (ClassNotFoundException cnfe) {
        Reconfigurator.getLogger().info("Class " + canonicalClassName + " not found");
        cnfe.printStackTrace();
    } catch (InstantiationException ie) {
        ie.printStackTrace();
    } finally {
        if (forcePrintException
                && ReconfigurationPacket.PacketType.intToType.get(JSONPacket.getPacketType(json)) == null) {
            (new RuntimeException("No reconfiguration packet type found in: " + json)).printStackTrace();
        }
    }

    return rcPacket;
}

From source file:com.unovo.frame.utils.SharedPreferencesHelper.java

@SuppressWarnings("TryWithIdenticalCatches")
private static <T> Object buildTargetFromSource(Class<T> clx, T target, String preFix, Set<String> existKeys,
        SharedPreferences sp) {/*from   w  w  w.j av  a  2  s .c  o m*/
    // Each to Object
    if (clx == null || clx.equals(Object.class)) {
        return target;
    }

    // Create instance
    if (target == null) {
        try {
            target = clx.newInstance();
        } catch (InstantiationException e) {
            e.printStackTrace();
            return null;
        } catch (IllegalAccessException e) {
            e.printStackTrace();
            return null;
        }
    }

    // Get the class fields
    Field[] fields = clx.getDeclaredFields();
    if (fields == null || fields.length == 0)
        return target;

    // Foreach fields
    for (Field field : fields) {
        if (isContSupport(field))
            continue;

        final String fieldName = field.getName();
        Class<?> fieldType = field.getType();

        // Change the Field accessible status
        boolean isAccessible = field.isAccessible();
        if (!isAccessible)
            field.setAccessible(true);

        // Build the key
        String key = preFix + fieldName;
        // Get target value
        Object value = null;
        if (isBasicType(fieldType)) {
            if (existKeys.contains(key)) {
                // From the share map
                if (fieldType.equals(Byte.class) || fieldType.equals(byte.class)) {
                    value = (byte) sp.getInt(key, 0);
                } else if (fieldType.equals(Short.class) || fieldType.equals(short.class)) {
                    value = (short) sp.getInt(key, 0);
                } else if (fieldType.equals(Integer.class) || fieldType.equals(int.class)) {
                    value = sp.getInt(key, 0);
                } else if (fieldType.equals(Long.class) || fieldType.equals(long.class)) {
                    value = sp.getLong(key, 0);
                } else if (fieldType.equals(Float.class) || fieldType.equals(float.class)) {
                    value = sp.getFloat(key, 0);
                } else if (fieldType.equals(Double.class) || fieldType.equals(double.class)) {
                    value = Double.valueOf(sp.getString(key, "0.00"));
                } else if (fieldType.equals(Boolean.class) || fieldType.equals(boolean.class)) {
                    value = sp.getBoolean(key, false);
                } else if (fieldType.equals(Character.class) || fieldType.equals(char.class)) {
                    value = sp.getString(key, "").charAt(0);
                } else if (fieldType.equals(String.class)) {
                    value = sp.getString(key, "");
                }
            }
        } else {
            value = buildTargetFromSource(fieldType, null, preFix + fieldName + SEPARATOR, existKeys, sp);
        }

        // Set the field value
        if (value != null) {
            try {
                field.set(target, value);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
                Logger.e(TAG,
                        String.format("Set field error, Key:%s, type:%s, value:%s", key, fieldType, value));
            }
        } else {
            Logger.e(TAG, String.format("Get field value error, Key:%s, type:%s", key, fieldType));
        }
    }

    // Get super class fields
    return buildTargetFromSource(clx.getSuperclass(), target, preFix, existKeys, sp);
}