Example usage for java.lang Class isInterface

List of usage examples for java.lang Class isInterface

Introduction

In this page you can find the example usage for java.lang Class isInterface.

Prototype

@HotSpotIntrinsicCandidate
public native boolean isInterface();

Source Link

Document

Determines if the specified Class object represents an interface type.

Usage

From source file:de.itsvs.cwtrpc.controller.PreparedRemoteServiceConfig.java

public PreparedRemoteServiceConfig(String serviceName, Class<?> serviceInterface,
        boolean responseCompressionEnabled, RpcTokenValidator rpcTokenValidator) {
    Assert.hasText(serviceName, "'serviceName' must not be empty");
    Assert.notNull(serviceInterface, "'serviceInterface' must not be null");

    if (!serviceInterface.isInterface()) {
        throw new IllegalArgumentException("'serviceInterface' must be an interface");
    }//www.j a  va2  s  .co m

    this.serviceName = serviceName;
    this.serviceInterface = serviceInterface;
    this.responseCompressionEnabled = responseCompressionEnabled;
    this.rpcTokenValidator = rpcTokenValidator;
}

From source file:com.jaliansystems.activeMQLite.impl.ObjectRepository.java

/**
 * Publish an object.//from w ww .j  a  v  a 2s  .c o  m
 * 
 * @param o
 *            the object
 * @param iface
 *            the interface implemented by the object.
 * @return the object handle
 */
public ObjectHandle publish(Object o, Class<?> iface) {
    if (!iface.isInterface())
        throw new IllegalAccessError("Only objects that implement interfaces can be exported");
    if (!iface.isInstance(o))
        throw new IllegalArgumentException("The object should implement the interface");
    publishedInterfaces.put(iface, o);
    exportedInterfaces.add(iface);
    return createHandle(o, iface);
}

From source file:javadz.beanutils.MethodUtils.java

/**
 * Gets the number of steps required needed to turn the source class into the 
 * destination class. This represents the number of steps in the object hierarchy 
 * graph./* w ww  .j a v a2  s .c  o  m*/
 * @param srcClass The source class
 * @param destClass The destination class
 * @return The cost of transforming an object
 */
private static float getObjectTransformationCost(Class srcClass, Class destClass) {
    float cost = 0.0f;
    while (destClass != null && !destClass.equals(srcClass)) {
        if (destClass.isInterface() && isAssignmentCompatible(destClass, srcClass)) {
            // slight penalty for interface match. 
            // we still want an exact match to override an interface match, but  
            // an interface match should override anything where we have to get a 
            // superclass.
            cost += 0.25f;
            break;
        }
        cost++;
        destClass = destClass.getSuperclass();
    }

    /*
     * If the destination class is null, we've travelled all the way up to 
     * an Object match. We'll penalize this by adding 1.5 to the cost.
     */
    if (destClass == null) {
        cost += 1.5f;
    }

    return cost;
}

From source file:net.ymate.platform.core.beans.impl.DefaultBeanFactory.java

public void registerExcludedClass(Class<?> excludedClass) {
    if (excludedClass.isInterface()) {
        this.__excludedClassSet.add(excludedClass);
    }/*from   w w w . j  a v  a  2 s . co  m*/
}

From source file:org.jgentleframework.integration.remoting.rmi.context.RmiBindingInstantiationInterceptor.java

@Override
public Object instantiate(ObjectInstantiation oi) throws Throwable {

    Object result = null;//w w  w  .j a va 2 s  .co  m
    Class<?> target = oi.getTargetClass();
    Definition definition = this.definitionManager.getDefinition(target);
    if (definition.isAnnotationPresent(Remote.class)) {
        if (!target.isInterface()) {
            if (log.isFatalEnabled()) {
                log.fatal("Could not binding to RMI service", new RmiBindingException());
            }
        }
        Remote remote = definition.getAnnotation(Remote.class);
        if (remote.type() == RemoteType.RMI && definition.isAnnotationPresent(RmiBinding.class)) {
            RmiBinding rmiBinding = definition.getAnnotation(RmiBinding.class);
            result = instantiate(definition, target, rmiBinding, oi);
        } else {
            if (log.isWarnEnabled()) {
                log.warn("The remote type is not [" + RemoteType.RMI.name()
                        + "] or current target interface is not annotated with [" + RmiBinding.class
                        + " annotation]");
            }
        }
    } else {
        if (log.isWarnEnabled()) {
            log.warn("The target interface is not annotated with [" + Remote.class + "]");
        }
    }
    return result;
}

From source file:org.apache.openjpa.enhance.PCSubclassValidator.java

public void assertCanSubclass() {
    Class superclass = meta.getDescribedType();
    String name = superclass.getName();
    if (superclass.isInterface())
        addError(loc.get("subclasser-no-ifaces", name), meta);
    if (Modifier.isFinal(superclass.getModifiers()))
        addError(loc.get("subclasser-no-final-classes", name), meta);
    if (Modifier.isPrivate(superclass.getModifiers()))
        addError(loc.get("subclasser-no-private-classes", name), meta);
    if (PersistenceCapable.class.isAssignableFrom(superclass))
        addError(loc.get("subclasser-super-already-pc", name), meta);

    try {/*from   www . ja va 2 s .  co  m*/
        Constructor c = superclass.getDeclaredConstructor(new Class[0]);
        if (!(Modifier.isProtected(c.getModifiers()) || Modifier.isPublic(c.getModifiers())))
            addError(loc.get("subclasser-private-ctor", name), meta);
    } catch (NoSuchMethodException e) {
        addError(loc.get("subclasser-no-void-ctor", name), meta);
    }

    // if the BCClass we loaded is already pc and the superclass is not,
    // then we should never get here, so let's make sure that the
    // calling context is caching correctly by throwing an exception.
    if (pc.isInstanceOf(PersistenceCapable.class) && !PersistenceCapable.class.isAssignableFrom(superclass))
        throw new InternalException(loc.get("subclasser-class-already-pc", name));

    if (AccessCode.isProperty(meta.getAccessType()))
        checkPropertiesAreInterceptable();

    if (errors != null && !errors.isEmpty())
        throw new UserException(errors.toString());
    else if (contractViolations != null && !contractViolations.isEmpty() && log.isWarnEnabled())
        log.warn(contractViolations.toString());
}

From source file:org.gradle.model.internal.manage.schema.extraction.ModelSchemaExtractor.java

public <T> void validateType(Class<T> type) {
    if (!isManaged(type)) {
        throw invalid(type, String.format("must be annotated with %s", Managed.class.getName()));
    }//from   w  w w .  j  av a 2 s  .  c o  m

    if (!type.isInterface()) {
        throw invalid(type, "must be defined as an interface");
    }

    if (type.getInterfaces().length != 0) {
        throw invalid(type, "cannot extend other types");
    }

    if (type.getTypeParameters().length != 0) {
        throw invalid(type, "cannot be a parameterized type");
    }
}

From source file:com.futureplatforms.kirin.internal.attic.ProxyGenerator.java

private Object handleGetter(final JSONObject obj, Class<?> returnType, String propertyName) throws Exception {
    Object retValue = obj.opt(propertyName);

    if (retValue instanceof JSONObject) {
        if (returnType.isInterface()) {
            return javascriptProxyForResponse((JSONObject) retValue, returnType);
        } else if (!JSONObject.class.equals(returnType)) {
            throw new Exception("Trying to cast a JSONObject to a " + returnType.getName());
        }/*from   w  w w  .  ja  v  a2  s . com*/
    }
    return retValue;
}

From source file:com.threewks.thundr.injection.InjectionContextImpl.java

@Override
public <T> InjectorBuilder<T> inject(Class<T> type) {

    if (!TypeIntrospector.isABasicType(type)
            && (type.isInterface() || Modifier.isAbstract(type.getModifiers()))) {
        throw new InjectionException(
                "Unable to inject the type '%s' - you cannot inject interfaces or abstract classes",
                type.getName());/* w  w  w. j a v  a  2 s.  c  o  m*/
    }

    return new InjectorBuilder<T>(this, type);
}

From source file:org.springframework.data.web.ProjectingJackson2HttpMessageConverter.java

@Override
public boolean canRead(Type type, Class<?> contextClass, MediaType mediaType) {

    if (!canRead(mediaType)) {
        return false;
    }/*from w ww  .j ava  2  s .  c  o  m*/

    ResolvableType owner = contextClass == null ? null : ResolvableType.forClass(contextClass);
    Class<?> rawType = ResolvableType.forType(type, owner).resolve(Object.class);
    Boolean result = supportedTypesCache.get(rawType);

    if (result != null) {
        return result;
    }

    result = rawType.isInterface() && AnnotationUtils.findAnnotation(rawType, ProjectedPayload.class) != null;
    supportedTypesCache.put(rawType, result);

    return result;
}