List of usage examples for java.lang.reflect Constructor getParameterTypes
@Override
public Class<?>[] getParameterTypes()
From source file:it.tidalwave.northernwind.frontend.impl.ui.ViewBuilder.java
/******************************************************************************************************************* * * Computes the argument values for calling the given constructor. They are taken from the current * {@link BeanFactory}, with {@code instanceArgs} eventually overriding them. * * @param constructor the constructor * @param overridingArgs the overriding arguments * @return the arguments to pass to the constructor * ******************************************************************************************************************/ @Nonnull//from w w w. j a v a2 s .co m private Object[] computeConstructorArguments(final @Nonnull Constructor<?> constructor, final @Nonnull Object... overridingArgs) throws NotFoundException { final List<Object> result = new ArrayList<>(); x: for (final Class<?> argumentType : constructor.getParameterTypes()) { for (final Object overridingArg : overridingArgs) { if (argumentType.isAssignableFrom(overridingArg.getClass())) { result.add(overridingArg); continue x; } } if (Site.class.isAssignableFrom(argumentType)) { result.add(beanFactory.getBean(SiteProvider.class).getSite()); } else { result.add(beanFactory.getBean(argumentType)); } } return result.toArray(); }
From source file:ca.uhn.fhir.context.BaseRuntimeElementDefinition.java
@SuppressWarnings("unchecked") private Constructor<T> getConstructor(Object theArgument) { Class<? extends Object> argumentType; if (theArgument == null) { argumentType = VOID_CLASS;/* w w w.jav a2 s . co m*/ } else { argumentType = theArgument.getClass(); } Constructor<T> retVal = myConstructors.get(argumentType); if (retVal == null) { for (Constructor<?> next : getImplementingClass().getConstructors()) { if (argumentType == VOID_CLASS) { if (next.getParameterTypes().length == 0) { retVal = (Constructor<T>) next; break; } } else if (next.getParameterTypes().length == 1) { if (next.getParameterTypes()[0].isAssignableFrom(argumentType)) { retVal = (Constructor<T>) next; break; } } } if (retVal == null) { throw new ConfigurationException("Class " + getImplementingClass() + " has no constructor with a single argument of type " + argumentType); } myConstructors.put(argumentType, retVal); } return retVal; }
From source file:gobblin.runtime.cli.ConstructorAndPublicMethodsCliObjectFactory.java
private boolean canUseConstructor(Constructor<?> constructor) { if (!Modifier.isPublic(constructor.getModifiers())) { return false; }//from w w w .j a va 2 s .c o m if (!constructor.isAnnotationPresent(CliObjectSupport.class)) { return false; } for (Class<?> param : constructor.getParameterTypes()) { if (param != String.class) { return false; } } return constructor.getParameterTypes().length == constructor.getAnnotation(CliObjectSupport.class) .argumentNames().length; }
From source file:org.onecmdb.core.utils.ClassInjector.java
public Object toBeanObject(ICi ci) { Class cl = getClassForCi(ci); if (cl == null) { log.info("No class with alias " + ci.getAlias() + " found!"); return (null); /*/* ww w. j av a2 s.c o m*/ throw new IllegalArgumentException("No class found for alias <" + alias + ">"); */ } Object instance = null; Constructor constructors[] = cl.getConstructors(); // Check if it support constructor with ICi. for (Constructor con : constructors) { Class conPar[] = con.getParameterTypes(); if (conPar.length == 1) { // Check if we can create with ICi as constructor. if (conPar[0].isAssignableFrom(ICi.class)) { try { instance = con.newInstance(new Object[] { ci }); } catch (Throwable e) { log.error(cl.getSimpleName() + ".newInstance(ICi) error with alias '" + ci.getAlias() + "' class '" + cl.getName() + "' : " + e.toString()); } break; } } } // Default constructor. if (instance == null) { try { instance = cl.newInstance(); } catch (Throwable e) { log.error("Instacation exception with alias '" + ci.getAlias() + "' class '" + cl.getName() + "' : " + e.toString()); return (null); } } // Start to inject attributes injectAttributes(instance, ci); return (instance); }
From source file:org.echocat.jomon.process.daemon.ProcessDaemonRepository.java
@Nullable protected Object[] findRightParametersFor(@Nonnull Constructor<D> potentialConstructor, @Nonnull List<Object> potentialParameters) { final Class<?>[] types = potentialConstructor.getParameterTypes(); final Object[] parameters = new Object[types.length]; boolean allFound = true; for (int i = 0; i < types.length; i++) { final Class<?> expectedType = types[i]; parameters[i] = findRightParameterFor(expectedType, potentialParameters); if (parameters[i] == null) { allFound = false;/*www. j a va2 s. c o m*/ break; } } return allFound ? parameters : null; }
From source file:gobblin.runtime.cli.ConstructorAndPublicMethodsGobblinCliFactory.java
private boolean canUseConstructor(Constructor<?> constructor) { if (!Modifier.isPublic(constructor.getModifiers())) { return false; }//from w ww . j a v a 2s . c om if (!constructor.isAnnotationPresent(EmbeddedGobblinCliSupport.class)) { return false; } for (Class<?> param : constructor.getParameterTypes()) { if (param != String.class) { return false; } } return constructor.getParameterTypes().length == constructor.getAnnotation(EmbeddedGobblinCliSupport.class) .argumentNames().length; }
From source file:org.eclipse.emf.teneo.extension.DefaultExtensionManager.java
/** Return the constructor for a class and initialization arguments */ protected Constructor<?> getConstructor(Class<?> clz, Object[] initArgs) throws NoSuchMethodException { Constructor<?> result = null; final Class<?>[] initTypes = new Class<?>[initArgs.length]; int i = 0;//from ww w . jav a2 s . c o m final StringBuffer keyStr = new StringBuffer(); for (Object o : initArgs) { if (keyStr.length() > 0) { keyStr.append(","); } if (o == null) { initTypes[i++] = null; keyStr.append("null"); } else { initTypes[i++] = o.getClass(); keyStr.append(o.getClass().getName()); } } final String key = clz.getName() + keyStr; if ((result = constructorCache.get(key)) != null) { return result; } for (Constructor<?> constructor : clz.getConstructors()) { if (constructor.getParameterTypes().length != initTypes.length) { continue; } int j = 0; boolean found = true; for (Class<?> paramType : constructor.getParameterTypes()) { final Class<?> argumentType = initTypes[j++]; if (argumentType == null && !Object.class.isAssignableFrom(paramType)) { found = false; break; } else if (argumentType == null && Object.class.isAssignableFrom(paramType)) { // just continue } else if (!paramType.isAssignableFrom(argumentType)) { found = false; break; } } if (found) { result = constructor; constructorCache.put(key, result); break; } } if (result == null) { throw new TeneoExtensionException( "No constructor found for : " + clz.getName() + " and constructor argument types: " + keyStr); } return result; }
From source file:fitnesse.slim.StatementExecutor.java
private Object newInstance(Object[] args, Constructor<?> constructor) throws IllegalAccessException, InstantiationException, InvocationTargetException { Object[] initargs = ConverterSupport.convertArgs(args, constructor.getParameterTypes()); FixtureInteraction interaction = SlimService.getInteractionClass().newInstance(); return interaction.newInstance(constructor, initargs); }
From source file:gda.factory.corba.util.ImplFactory.java
protected void makeObjectsAvailable() throws FactoryException { POA poa = netService.getPOA(); //TODO All errors should lead to throwing a FactoryException - check error then lead to system exit org.omg.PortableServer.Servant servant; Runtime.getRuntime().addShutdownHook(uk.ac.gda.util.ThreadManager.getThread(new Runnable() { @Override//from w w w . j av a 2s . c o m public void run() { shutdown(); } }, getNamespace() + " ImplFactory shutdown")); List<Findable> findables = getFindablesToMakeAvailable(); for (Findable findable : findables) { String name = findable.getName(); if (findable instanceof Localizable && !((Localizable) findable).isLocal()) { if (excludedObjects != null && excludedObjects.contains(name)) { logger.info(String.format("Not exporting %s - it has been excluded", name)); continue; } Class<?> type = findable.getClass(); if (RbacUtils.objectIsCglibProxy(findable)) { // Object has been proxied. Get its original type type = type.getSuperclass(); } String implName = CorbaUtils.getImplementationClassName(type); String adapterClassName = CorbaUtils.getAdapterClassName(type); org.omg.CORBA.Object obj = null; try { Class<?> classDef = Class.forName(implName); Constructor<?>[] ctors = classDef.getDeclaredConstructors(); Constructor<?> ctor = ctors[0]; final Object[] args = new Object[] { findable, poa }; if (!ClassUtils.isAssignable(ClassUtils.toClass(args), ctor.getParameterTypes())) { logger.warn("Class " + implName + " is unsuitable for " + name + ", so it will be a local object"); } else { servant = (org.omg.PortableServer.Servant) ctor.newInstance(args); obj = poa.servant_to_reference(servant); } } catch (ClassNotFoundException ex) { logger.warn("Cannot find class " + implName + ": " + name + " will be a local object"); } catch (Exception e) { logger.error( "Could not instantiate class " + implName + ": " + name + " will be a local object", e); } String fullName = getNamespace() + NetService.OBJECT_DELIMITER + name; if (obj != null) { // bind throws a factory exception which is not caught // but passed back to the caller. store.put(fullName, new CorbaBoundObject(fullName, adapterClassName, obj)); netService.bind(fullName, adapterClassName, obj); logger.debug("ImplFactory created Corba object for " + fullName); } else { logger.warn("No CORBA object created for " + fullName); } } else { logger.debug( String.format("Not exporting %s - it is local (or does not implement Localizable)", name)); } } }
From source file:org.jboss.spring.aop.JBossAopProxy.java
/** * Match constructor.// w w w. j a v a2 s. c o m * * @param ctor the constructor * @return true if we have a match */ private boolean matchConstructor(Constructor<?> ctor) { TypeInfo[] params = constructorInfo.getParameterTypes(); Class<?>[] ctorParams = ctor.getParameterTypes(); if (params.length == ctorParams.length) { boolean match = true; for (int p = 0; p < params.length; p++) { if (!params[p].getName().equals(ctorParams[p].getName())) { match = false; break; } } if (match) { return true; } } return false; }