List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:br.com.lucasisrael.regra.reflections.TratamentoReflections.java
/** * Perform the given callback operation on all matching methods of the given * class and superclasses (or given interface and super-interfaces). * <p>The same named method occurring on subclass and superclass will appear * twice, unless excluded by the specified {@link MethodFilter}. * @param clazz class to start looking at * @param mc the callback to invoke for each method * @param mf the filter that determines the methods to apply the callback to *//*from ww w. j ava 2 s.c o m*/ public static void doWithMethods(Class<?> clazz, MethodCallback mc, MethodFilter mf) throws IllegalArgumentException { // Keep backing up the inheritance hierarchy. Method[] methods = clazz.getDeclaredMethods(); for (Method method : methods) { if (mf != null && !mf.matches(method)) { continue; } try { mc.doWith(method); } catch (IllegalAccessException ex) { throw new IllegalStateException( "Shouldn't be illegal to access method '" + method.getName() + "': " + ex); } } if (clazz.getSuperclass() != null) { doWithMethods(clazz.getSuperclass(), mc, mf); } else if (clazz.isInterface()) { for (Class<?> superIfc : clazz.getInterfaces()) { doWithMethods(superIfc, mc, mf); } } }
From source file:org.eclipse.emf.teneo.hibernate.EPackageConstructor.java
/** * Build a list of EPackages from the passed EcoreModelClasses. *//*w ww .j a va2 s.c o m*/ private List<EPackage> buildFromModelClasses() { final ArrayList<EPackage> result = new ArrayList<EPackage>(); for (String ecoreModelPackageClassName : ecoreModelClasses) { try { final Class<?> cls = this.getClass().getClassLoader().loadClass(ecoreModelPackageClassName); final EPackage emp; // handle the case that this is an EPackage interface if (cls.isInterface()) { final Field f = cls.getField("eINSTANCE"); // purposely passing null because it must be static emp = (EPackage) f.get(null); } else { final Method m = cls.getMethod("init"); // purposely passing null because it must be static emp = (EPackage) m.invoke(null); } // initialise the emp, will also read the epackage result.add(emp); } catch (Exception e) { throw new IllegalStateException( "Excption while trying to retrieve EcoreModelPackage instance from class: " + ecoreModelPackageClassName, e); } } return result; }
From source file:org.jboss.ejb3.locator.client.Ejb3ServiceLocator.java
/** * Obtains the object associated with the specified business interface. * This may be obtained from the cache if possible when the "useCache" * flag is set, otherwise caching will be bypassed and a unique lookup * will take place on each subsequent request. * /* www . j av a2 s . co m*/ * @param <T> * @param clazz The business interface of the desired service * @param useCache Whether or not to retrieve the object from the cache, if possible. * @return * @throws Ejb3NotFoundException * If no services implementing the specified business interface * could be found on any of the configured local/remote hosts * @throws IllegalArgumentException * If the specified class is a business interface implemented by more than * one service across the configured local/remote hosts, or if the * specified class is no an interface */ protected <T> T getObject(Class<T> clazz, boolean useCache) throws Ejb3NotFoundException, IllegalArgumentException { // Ensure specified business interface is an interface if (!clazz.isInterface()) { throw new IllegalArgumentException("Specified class \"" + clazz.getName() + "\" is not an interface"); } // If caching is enabled and the object exists in the cache if (useCache && this.isObjectCached(clazz)) { // Obtain from cache T obj = this.getObjectFromCache(clazz); // Ensure implements specified interface if (!clazz.isAssignableFrom(obj.getClass())) { // Object was placed into cache under incorrect key; integrity of cache broken throw new ServiceLocatorException("Object in cache under key " + clazz.getName() + " does not implement this interface; cache integrity compromised."); } // Return from cache return obj; } // Obtain from the remote host T obj = this.getObject(clazz); // If caching is enabled if (useCache) { // Place into the cache this.addInterfaceAndSuperinterfacesToCache(clazz, obj); } // Return return obj; }
From source file:org.jabsorb.ng.serializer.impl.BeanSerializer.java
@Override public boolean canSerialize(final Class<?> clazz, final Class<?> jsonClazz) { return (!clazz.isArray() && !clazz.isPrimitive() && !clazz.isInterface() && (jsonClazz == null || jsonClazz == JSONObject.class)); }
From source file:org.jadira.scanner.classpath.types.JField.java
@Override public JType getType() throws ClasspathAccessException { final JType retVal; Class<?> clazz; try {//w w w.j a v a2 s.c om Field field = getActualField(); clazz = field.getType(); } catch (SecurityException e) { throw new ClasspathAccessException("Problem finding enclosing type: " + e.getMessage(), e); } if (clazz.isInterface()) { retVal = JInterface.getJInterface(clazz.getName(), getResolver()); } else if (clazz.isPrimitive()) { retVal = JPrimitiveClass.getJClass(clazz.getName(), getResolver()); } else if (clazz.isArray()) { retVal = JArrayClass.getJClass(clazz, getResolver()); } else { retVal = JClass.getJClass(clazz.getName(), getResolver()); } return retVal; }
From source file:org.ff4j.aop.FeatureAdvisor.java
/** {@inheritDoc} */ @Override//from w w w. j a v a 2 s. c om public Object postProcessBeforeInitialization(Object bean, String beanName) { // Before Initializing allow to check Annotations Class<?> target = bean.getClass(); // Scan interface only once. if (!target.isInterface() && target.getInterfaces() != null) { // Get Interface for (Class<?> currentInterface : target.getInterfaces()) { String currentInterfaceName = currentInterface.getCanonicalName(); if (!currentInterfaceName.startsWith("java.") && !targetInterfacesNames.contains(currentInterfaceName)) { targetInterfacesNames.add(currentInterfaceName); } } } return bean; }
From source file:br.gov.frameworkdemoiselle.behave.runner.webdriver.WebDriverRunner.java
public Element getElement(String currentPageName, String elementName) { if ((currentPageName == null) || (currentPageName.equals(""))) { throw new BehaveException(message.getString("exception-page-not-selected")); }// w w w . j ava 2s .co m Field f = ReflectionUtil.getElementMap(currentPageName, elementName); ElementMap map = f.getAnnotation(ElementMap.class); Class<?> clazz = f.getType(); Element element = null; // Comportamento padro usa o InjectionManager para resolver quem // implementa a interface if (clazz.isInterface()) { element = (Element) InjectionManager.getInstance().getInstanceDependecy(clazz); // Instancia a classe fornecida explicitamente como implementao da // interface Element } else if (Element.class.isAssignableFrom(clazz)) { try { element = (Element) clazz.newInstance(); } catch (Exception e) { element = null; } } else { throw new BehaveException(message.getString("exception-class-not-element", clazz.getName(), elementName, currentPageName)); } if (element == null) { throw new BehaveException( message.getString("exception-instance-element", elementName, currentPageName)); } element.setElementMap(map); return element; }
From source file:ca.uhn.fhir.rest.client.RestfulClientFactory.java
/** * Instantiates a new client instance/*from ww w. ja v a 2 s . co m*/ * * @param theClientType * The client type, which is an interface type to be instantiated * @param theServerBase * The URL of the base for the restful FHIR server to connect to * @return A newly created client * @throws ConfigurationException * If the interface type is not an interface */ @Override public synchronized <T extends IRestfulClient> T newClient(Class<T> theClientType, String theServerBase) { validateConfigured(); if (!theClientType.isInterface()) { throw new ConfigurationException(theClientType.getCanonicalName() + " is not an interface"); } ClientInvocationHandlerFactory invocationHandler = myInvocationHandlers.get(theClientType); if (invocationHandler == null) { IHttpClient httpClient = getHttpClient(theServerBase); invocationHandler = new ClientInvocationHandlerFactory(httpClient, myContext, theServerBase, theClientType); for (Method nextMethod : theClientType.getMethods()) { BaseMethodBinding<?> binding = BaseMethodBinding.bindMethod(nextMethod, myContext, null); invocationHandler.addBinding(nextMethod, binding); } myInvocationHandlers.put(theClientType, invocationHandler); } T proxy = instantiateProxy(theClientType, invocationHandler.newInvocationHandler(this)); return proxy; }
From source file:com.netflix.awsobjectmapper.AmazonObjectMapperTest.java
private boolean isModelClass(Class<?> c) { boolean skip = false; // Skip package and exception classes final String simpleName = c.getSimpleName(); skip = simpleName == "package-info" || simpleName.endsWith("Exception"); // Ignore transform classes skip = skip || c.getName().contains(".transform."); // Ignore interfaces skip = skip || c.isInterface(); // Must have an empty constructor skip = skip || !hasEmptyConstructor(c); return !skip; }
From source file:org.amplafi.flow.flowproperty.FixedFlowPropertyValueProvider.java
public FixedFlowPropertyValueProvider(Class<?> defaultClass) { ApplicationIllegalArgumentException.notNull(defaultClass, "Fixed defaultClass cannot be null."); ApplicationIllegalArgumentException.valid( !defaultClass.isAnnotation() && !defaultClass.isInterface() && !defaultClass.isPrimitive(), defaultClass, ": cannot be instantiated."); this.defaultObject = null; this.defaultClass = defaultClass; }