List of usage examples for java.lang Class getConstructors
@CallerSensitive public Constructor<?>[] getConstructors() throws SecurityException
From source file:edu.cornell.mannlib.vitro.webapp.utils.dataGetter.DataGetterUtils.java
/** * Returns a DataGetter using information in the * displayModel for the individual with the URI given by dataGetterURI * to configure it. //from w w w .j av a2 s . c o m * * May return null. * This should not throw an exception if the URI exists and has a type * that does not implement the DataGetter interface. */ public static DataGetter dataGetterForURI(VitroRequest vreq, Model displayModel, String dataGetterURI) throws InstantiationException, IllegalAccessException, ClassNotFoundException, IllegalArgumentException, InvocationTargetException, SecurityException { //get java class for dataGetterURI String dgClassName = getJClassForDataGetterURI(displayModel, dataGetterURI); //figure out if it implements interface DataGetter Class<?> clz = Class.forName(dgClassName); if (!DataGetter.class.isAssignableFrom(clz)) { log.debug("Class doesn't implement DataGetter: '" + dgClassName + "'"); return null; } // we want a constructor that will work for one of these argument lists (in this order) Object[][] argLists = new Object[][] { { vreq, displayModel, dataGetterURI }, { displayModel, dataGetterURI }, { vreq }, {} }; // look through the available constructors for the best fit for (Object[] argList : argLists) { for (Constructor<?> ct : clz.getConstructors()) { if (isConstructorSuitableForArguments(ct, argList)) { log.debug("Using this constructor: " + ct); return (DataGetter) ct.newInstance(argList); } } } log.debug("Didn't find a suitable constructor for '" + dgClassName + "'"); return null; }
From source file:org.killbill.billing.client.KillBillHttpClient.java
private static <T> T createEmptyResult(final Class<T> clazz) {// Return empty list for KillBillObjects instead of null for convenience if (Iterable.class.isAssignableFrom(clazz)) { for (final Constructor constructor : clazz.getConstructors()) { if (constructor.getParameterTypes().length == 0) { try { return clazz.cast(constructor.newInstance()); } catch (final InstantiationException e) { return null; } catch (final IllegalAccessException e) { return null; } catch (final InvocationTargetException e) { return null; }/*from w w w . j ava 2 s.c o m*/ } } return null; } else { return null; } }
From source file:com.opengamma.masterdb.security.SecurityTestCase.java
private static <T> Constructor<T> getBiggestConstructor(final Class<T> clazz) { final Constructor<T>[] constructors = (Constructor<T>[]) clazz.getConstructors(); int max = -1, bestIndex = -1; for (int i = 0; i < constructors.length; i++) { final Class<?>[] parameters = constructors[i].getParameterTypes(); if (parameters.length > max) { max = parameters.length;/*from ww w. j av a 2s . c o m*/ bestIndex = i; } } return constructors[bestIndex]; }
From source file:lucee.runtime.reflection.storage.WeakConstructorStorage.java
/** * stores the constructors for a Class// w ww.jav a 2 s . c o m * @param clazz * @return stored structure */ private Array store(Class clazz) { Constructor[] conArr = clazz.getConstructors(); Array args = new ArrayImpl(); for (int i = 0; i < conArr.length; i++) { storeArgs(conArr[i], args); } map.put(clazz, args); return args; }
From source file:it.unibas.spicy.persistence.object.operators.GenerateClassModelTree.java
private boolean isConstructorNoArgAvailable(Class currentClass) { Constructor[] constructors = currentClass.getConstructors(); for (Constructor constructor : constructors) { if (constructor.getParameterTypes().length == 0) { return true; }//from ww w . j a v a 2s.co m } return false; }
From source file:com.swtxml.swt.metadata.WidgetRegistry.java
@SuppressWarnings("unchecked") public Constructor getWidgetConstructor(Class<? extends Widget> widgetClass) { return CollectionUtils.find(Arrays.asList(widgetClass.getConstructors()), new IFilter<Constructor>() { public boolean match(Constructor constructor) { return (constructor.getParameterTypes().length == 2 && constructor.getParameterTypes()[1] == Integer.TYPE); }/*w ww. j ava 2 s . co m*/ }); }
From source file:org.openstreetmap.josm.plugins.conflation.config.parser.InstanceConstructor.java
/** * Return the class' public constructor with the largest number of arguments. *//*w w w . j av a2 s .com*/ private Constructor<?> getLargestPublicConstructor(Class<?> type) { Constructor<?> bestCnstr = null; for (Constructor<?> cnstr : type.getConstructors()) { if (Modifier.isPublic(cnstr.getModifiers()) && ((bestCnstr == null) || (cnstr.getParameterTypes().length > bestCnstr.getParameterTypes().length))) bestCnstr = cnstr; } return bestCnstr; }
From source file:org.xmlsh.util.JavaUtils.java
public static XValue newXValue(Class<?> cls, List<XValue> args) throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, CoreException { Constructor<?>[] constructors = cls.getConstructors(); return newXValue(cls, constructors, args); }
From source file:de.itsvs.cwtrpc.security.SimpleRpcAuthenticationFailureHandler.java
@SuppressWarnings("unchecked") protected <T extends Exception> Constructor<T> getMessageConstructor(Class<T> exception) { for (Constructor<?> constructor : exception.getConstructors()) { if ((constructor.getParameterTypes().length == 1) && String.class.equals(constructor.getParameterTypes()[0])) { return ((Constructor<T>) constructor); }//from w w w. ja v a2 s.c om } return null; }
From source file:org.fornax.cartridges.sculptor.framework.event.annotation.PublishAdvice.java
/** * Check if joda date time library is used, without introducing runtime * dependency.// www . ja va2 s.c om */ private boolean isJoda(Class<?> clazz) { for (Constructor<?> each : clazz.getConstructors()) { Class<?>[] parameterTypes = each.getParameterTypes(); if (parameterTypes.length > 0) { if (parameterTypes[0].getName().startsWith("org.joda.time.")) { return true; } } } return false; }