List of usage examples for java.lang Class isInterface
@HotSpotIntrinsicCandidate public native boolean isInterface();
From source file:com.vityuk.ginger.DefaultLocalization.java
@SuppressWarnings("unchecked") @Override//from w w w .j av a 2s . c o m public <T extends Localizable> T getLocalizable(Class<T> localizable) { checkNotNull(localizable); checkArgument(localizable.isInterface(), "Parameter 'localizable' must be an interface"); checkArgument(Localizable.class.isAssignableFrom(localizable), "%s must extend %s", localizable.getName(), Localizable.class.getName()); try { T localizableInstance = (T) localizableCache.getUnchecked((Class<Localizable>) localizable); return localizableInstance; } catch (UncheckedExecutionException e) { throw Throwables.propagate(e.getCause()); } }
From source file:org.apache.bval.cdi.BValExtension.java
public <A> void processAnnotatedType(final @Observes ProcessAnnotatedType<A> pat) { if (!isExecutableValidationEnabled) { return;/*from w w w. ja va2 s . c o m*/ } final AnnotatedType<A> annotatedType = pat.getAnnotatedType(); if (!annotatedTypeFilter.accept(annotatedType)) { return; } final Class<A> javaClass = annotatedType.getJavaClass(); final int modifiers = javaClass.getModifiers(); if (!javaClass.isInterface() && !Modifier.isFinal(modifiers) && !Modifier.isAbstract(modifiers)) { try { ensureFactoryValidator(); try { final BeanDescriptor classConstraints = validator.getConstraintsForClass(javaClass); if (annotatedType.isAnnotationPresent(ValidateOnExecution.class) || hasValidationAnnotation(annotatedType.getMethods()) || hasValidationAnnotation(annotatedType.getConstructors()) || classConstraints != null && (validBean && classConstraints.isBeanConstrained() || validConstructors && !classConstraints.getConstrainedConstructors().isEmpty() || validBusinessMethods && !classConstraints .getConstrainedMethods(MethodType.NON_GETTER).isEmpty() || validGetterMethods && !classConstraints .getConstrainedMethods(MethodType.GETTER).isEmpty())) { final BValAnnotatedType<A> bValAnnotatedType = new BValAnnotatedType<A>(annotatedType); pat.setAnnotatedType(bValAnnotatedType); } } catch (final NoClassDefFoundError ncdfe) { // skip } } catch (final ValidationException ve) { LOGGER.log(Level.FINEST, ve.getMessage(), ve); } catch (final Exception e) { // just info LOGGER.log(Level.INFO, e.getMessage()); } } }
From source file:org.eclipse.emf.teneo.hibernate.tuplizer.EMFTuplizer.java
@Override protected ProxyFactory buildProxyFactory(PersistentClass persistentClass, Getter idGetter, Setter idSetter) { if (persistentClass.getProxyInterface() == null) { // an entity, no // proxy//w w w .ja va 2 s . c o m return null; } final HbDataStore ds = HbHelper.INSTANCE.getDataStore(persistentClass); final EClass eclass = ds.getEntityNameStrategy().toEClass(persistentClass.getEntityName()); if (eclass == null && !persistentClass.getEntityName().equals(Constants.EAV_EOBJECT_ENTITY_NAME)) { throw new HbMapperException("No eclass found for entityname: " + persistentClass.getEntityName()); } // get all the interfaces from the main class, add the real interface // first final Set<Class<?>> proxyInterfaces = new LinkedHashSet<Class<?>>(); final Class<?> pInterface = persistentClass.getProxyInterface(); if (pInterface != null && pInterface.isInterface()) { proxyInterfaces.add(pInterface); } Class<?> mappedClass = persistentClass.getMappedClass(); if (mappedClass == null) { mappedClass = DynamicEObjectImpl.class; } if (mappedClass.isInterface()) { proxyInterfaces.add(mappedClass); } proxyInterfaces.add(HibernateProxy.class); proxyInterfaces.add(TeneoInternalEObject.class); for (Class<?> interfaces : mappedClass.getInterfaces()) { proxyInterfaces.add(interfaces); } // iterate over all subclasses and add them also final Iterator<?> iter = persistentClass.getSubclassIterator(); while (iter.hasNext()) { final Subclass subclass = (Subclass) iter.next(); final Class<?> subclassProxy = subclass.getProxyInterface(); final Class<?> subclassClass = subclass.getMappedClass(); if (subclassProxy != null && subclassClass != null && !subclassClass.equals(subclassProxy)) { proxyInterfaces.add(subclassProxy); } } // get the idgettters/setters final Method theIdGetterMethod = idGetter == null ? null : idGetter.getMethod(); final Method theIdSetterMethod = idSetter == null ? null : idSetter.getMethod(); final Method proxyGetIdentifierMethod = theIdGetterMethod == null || pInterface == null ? null : ReflectHelper.getMethod(pInterface, theIdGetterMethod); final Method proxySetIdentifierMethod = theIdSetterMethod == null || pInterface == null ? null : ReflectHelper.getMethod(pInterface, theIdSetterMethod); ProxyFactory pf = Environment.getBytecodeProvider().getProxyFactoryFactory().buildProxyFactory(); try { pf.postInstantiate(getEntityName(), mappedClass, proxyInterfaces, proxyGetIdentifierMethod, proxySetIdentifierMethod, persistentClass.hasEmbeddedIdentifier() ? (CompositeType) persistentClass.getIdentifier().getType() : null); } catch (HbStoreException e) { log.warn("could not create proxy factory for:" + getEntityName(), e); pf = null; } return pf; }
From source file:org.resthub.rpc.AMQPHessianProxyFactory.java
/** * Creates a new proxy from the specified interface. * @param api the interface// w w w . j ava 2s.c om * @return the proxy to the object with the specified interface */ @SuppressWarnings("unchecked") public <T> T create(Class<T> api) { if (null == api || !api.isInterface()) { throw new IllegalArgumentException("Parameter 'api' is required"); } this.serviceInterface = api; this.afterPropertiesSet(); AMQPHessianProxy handler = new AMQPHessianProxy(this); return (T) Proxy.newProxyInstance(api.getClassLoader(), new Class[] { api }, handler); }
From source file:fr.mby.utils.spring.beans.factory.support.BasicProxywiredFactory.java
@Override @SuppressWarnings("unchecked") public IManageableProxywired proxy(final DependencyDescriptor descriptor, final IProxywiredIdentifier identifier, final Object target) { Assert.notNull(descriptor, "No DependencyDescriptor provided !"); Assert.notNull(descriptor, "No IProxywiredIdentifier provided !"); Assert.notNull(descriptor, "No Target to proxy provided !"); final IManageableProxywired result; final Class<?> dependencyType = descriptor.getDependencyType(); if (Map.class.isAssignableFrom(dependencyType) && dependencyType.isInterface()) { result = this.proxyDependencyMap(identifier, (Map<String, Object>) target); } else if (List.class.isAssignableFrom(dependencyType) && dependencyType.isInterface()) { result = this.proxyDependencyList(identifier, (List<Object>) target); } else if (Collection.class.isAssignableFrom(dependencyType) && dependencyType.isInterface()) { result = this.proxyDependencyCollection(identifier, (Collection<Object>) target, dependencyType); } else if (dependencyType.isArray()) { // We can't do anything throw new IllegalStateException("You cannot use Proxywired annotation on an Array !"); } else if (dependencyType.isInterface()) { result = this.proxySingleDependency(identifier, target, dependencyType); } else {/* w ww . ja v a2 s . c om*/ throw new IllegalStateException("Dependency type not supported by this factory !"); } return result; }
From source file:com.infinities.skyport.timeout.ServiceProviderTimeLimiter.java
public <T> T newProxy(final T target, Class<T> interfaceType, final Object configuration) throws InitializationException { if (target == null) { return target; }//from w ww . j ava 2s . c o m checkNotNull(interfaceType); checkNotNull(configuration); checkArgument(interfaceType.isInterface(), "interfaceType must be an interface type"); checkMethodOwnFunctionConfiguration(interfaceType, configuration); final Set<Method> interruptibleMethods = findInterruptibleMethods(interfaceType); InvocationHandler handler = new InvocationHandler() { @Override public Object invoke(Object obj, final Method method, final Object[] args) throws Throwable { String methodName = method.getName(); long timeoutDuration = 0; TimeUnit timeUnit = TimeUnit.SECONDS; try { FunctionConfiguration functionConfiguration = (FunctionConfiguration) PropertyUtils .getProperty(configuration, methodName); Time timeout = functionConfiguration.getTimeout(); if (timeout != null) { timeoutDuration = timeout.getNumber(); timeUnit = timeout.getUnit(); } } catch (NoSuchMethodException | IllegalArgumentException e) { if (IGNORED_SET.contains(method.getName()) || method.getAnnotation(Deprecated.class) != null) { return method.invoke(target, args); } throwCause(e, false); throw new AssertionError("can't get here"); } catch (InvocationTargetException e) { throwCause(e, false); throw new AssertionError("can't get here"); } Callable<Object> callable = new Callable<Object>() { @Override public Object call() throws Exception { try { return method.invoke(target, args); } catch (InvocationTargetException e) { throwCause(e, false); throw new AssertionError("can't get here"); } } }; if (timeoutDuration > 0) { return limiter.callWithTimeout(callable, timeoutDuration, timeUnit, interruptibleMethods.contains(method)); } else { // no timeout return method.invoke(target, args); } } }; return newProxy(interfaceType, handler); }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
private void validateType(ModelType<?> type, ModelSchemaExtractionContext<?> extractionContext) { Class<?> typeClass = type.getConcreteClass(); if (!typeClass.isInterface() && !Modifier.isAbstract(typeClass.getModifiers())) { throw new InvalidManagedModelElementTypeException(extractionContext, "must be defined as an interface or an abstract class."); }// w w w. j a va2 s .c o m if (typeClass.getTypeParameters().length > 0) { throw new InvalidManagedModelElementTypeException(extractionContext, "cannot be a parameterized type."); } Constructor<?> customConstructor = findCustomConstructor(typeClass); if (customConstructor != null) { throw invalidMethod(extractionContext, "custom constructors are not allowed", customConstructor); } ensureNoInstanceScopedFields(extractionContext, typeClass); ensureNoProtectedOrPrivateMethods(extractionContext, typeClass); }
From source file:org.broadleafcommerce.openadmin.server.dao.provider.metadata.AbstractFieldMetadataProvider.java
protected Map<String, FieldMetadataOverride> getTargetedOverride(DynamicEntityDao dynamicEntityDao, String configurationKey, String ceilingEntityFullyQualifiedClassname) { if (metadataOverrides != null && (configurationKey != null || ceilingEntityFullyQualifiedClassname != null)) { if (metadataOverrides.containsKey(configurationKey)) { return metadataOverrides.get(configurationKey); }/*from w w w .j a v a 2 s .c om*/ if (metadataOverrides.containsKey(ceilingEntityFullyQualifiedClassname)) { return metadataOverrides.get(ceilingEntityFullyQualifiedClassname); } Class<?> test; try { test = Class.forName(ceilingEntityFullyQualifiedClassname); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } if (test.isInterface()) { //if it's an interface, get the least derive polymorphic concrete implementation Class<?>[] types = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(test); return metadataOverrides.get(types[types.length - 1].getName()); } else { //if it's a concrete implementation, try the interfaces Class<?>[] types = test.getInterfaces(); for (Class<?> type : types) { if (metadataOverrides.containsKey(type.getName())) { return metadataOverrides.get(type.getName()); } } } } return null; }
From source file:com.mockey.ui.ServiceSetupServlet.java
/** * // w w w .j av a2 s. co m * * @param req * basic request * @param resp * basic resp * @throws ServletException * basic * @throws IOException * basic */ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String[] realSrvUrl = req.getParameterValues("realServiceUrl[]"); Service service = new Service(); Long serviceId = null; try { serviceId = new Long(req.getParameter("serviceId")); service = store.getServiceById(serviceId); } catch (Exception e) { // Do nothing } if (service == null) { service = new Service(); } // NEW REAL URL LIST // 1. Overwrite list of predefined URLs // 2. Ensure non-empty trim String for new Url objects. if (realSrvUrl != null) { List<Url> newUrlList = new ArrayList<Url>(); for (int i = 0; i < realSrvUrl.length; i++) { String url = realSrvUrl[i]; if (url.trim().length() > 0) { newUrlList.add(new Url(realSrvUrl[i].trim())); } } for (Url urlItem : newUrlList) { service.saveOrUpdateRealServiceUrl(urlItem); } } // UPDATE HANGTIME - optional try { service.setHangTime(Integer.parseInt(req.getParameter("hangTime"))); } catch (Exception e) { // DO NOTHING } // NAME - optional if (req.getParameter("serviceName") != null) { service.setServiceName(req.getParameter("serviceName")); } // TAG - optional if (req.getParameter("tag") != null) { service.setTag(req.getParameter("tag")); } // Last visist if (req.getParameter("lastVisit") != null) { try { String lastvisit = req.getParameter("lastVisit"); if (lastvisit.trim().length() > 0 && !"mm/dd/yyyy".equals(lastvisit.trim().toLowerCase())) { Date f = formatter.parse(lastvisit); service.setLastVisit(f.getTime()); } else { service.setLastVisit(null); } } catch (Exception e) { } } String classNameForRequestInspector = req.getParameter("requestInspectorName"); if (classNameForRequestInspector != null && classNameForRequestInspector.trim().length() > 0) { /** * OPTIONAL See if we can create an instance of a request inspector. * If yes, then set the service to the name. */ try { Class<?> clazz = Class.forName(classNameForRequestInspector); if (!clazz.isInterface() && IRequestInspector.class.isAssignableFrom(clazz)) { service.setRequestInspectorName(classNameForRequestInspector); } else { service.setRequestInspectorName(""); } } catch (ClassNotFoundException t) { logger.error("Service setup: unable to find class '" + classNameForRequestInspector + "'", t); } } // DESCRIPTION - optional if (req.getParameter("description") != null) { service.setDescription(req.getParameter("description")); } // MOCK URL - optional if (req.getParameter("url") != null) { service.setUrl(req.getParameter("url")); } Map<String, String> errorMap = ServiceValidator.validate(service); if ((errorMap != null) && (errorMap.size() == 0)) { // no errors, so create service. Util.saveSuccessMessage("Service updated.", req); Service updatedService = store.saveOrUpdateService(service); String redirectUrl = Url.getContextAwarePath("/setup?serviceId=" + updatedService.getId(), req.getContextPath()); resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); String resultingJSON = "{ \"result\": { \"redirect\": \"" + redirectUrl + "\"}}"; out.println(resultingJSON); out.flush(); out.close(); return; } else { resp.setContentType("application/json"); PrintWriter out = resp.getWriter(); String resultingJSON = Util.getJSON(errorMap); out.println(resultingJSON); out.flush(); out.close(); } return; // AJAX thing. Return nothing at this time. }
From source file:net.ymate.platform.core.beans.impl.DefaultBeanFactory.java
@SuppressWarnings("unchecked") public <T> T getBean(Class<T> clazz) { T _obj = null;/*from w ww.ja va2s . com*/ if (clazz != null && !clazz.isAnnotation()) { BeanMeta _beanMeta = null; if (clazz.isInterface()) { Class<?> _targetClass = this.__beanInterfacesMap.get(clazz); _beanMeta = this.__beanInstancesMap.get(_targetClass); } else { _beanMeta = this.__beanInstancesMap.get(clazz); } if (_beanMeta != null) { if (!_beanMeta.isSingleton()) { try { _obj = (T) _beanMeta.getBeanClass().newInstance(); if (__proxyFactory != null) { _obj = (T) __wrapProxy(__proxyFactory, _obj); } __initBeanIoC(_beanMeta.getBeanClass(), _obj); } catch (Exception e) { _LOG.warn("", e); } } else { _obj = (T) _beanMeta.getBeanObject(); } } if (_obj == null && this.__parentFactory != null) { _obj = this.__parentFactory.getBean(clazz); } } return _obj; }