Example usage for java.lang Class getInterfaces

List of usage examples for java.lang Class getInterfaces

Introduction

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

Prototype

public Class<?>[] getInterfaces() 

Source Link

Document

Returns the interfaces directly implemented by the class or interface represented by this object.

Usage

From source file:com.dc.tes.License.java

private static String Lisence(Core core, String license) {
    // ??/*from   ww w.jav  a 2 s  . c  om*/
    boolean[] adapterFlag = new boolean[C_ADAPTER_LIST_SIZE];
    // ?
    Date[] adapterDate = new Date[C_ADAPTER_LIST_SIZE];
    // 
    Date tesDate;
    // ??
    int adapterNum;

    try {
        // ?License
        //String license = RuntimeUtils.ReadResource("license.dat", RuntimeUtils.utf8);
        byte[] _enData = new BASE64Decoder().decodeBuffer(license);

        byte[] _buffer = new byte[_enData.length - 8];
        System.arraycopy(_enData, 0, _buffer, 0, _enData.length - 8);

        license = new String(decrypt(_buffer, "nuclearg".getBytes()));

        String[] segments = StringUtils.split(license, "\r");
        for (int i = 0; i < C_ADAPTER_LIST_SIZE; i++)
            adapterFlag[i] = segments[0].charAt(i) == '1';

        String[] _adapterDate = segments[1].split("\\|");
        for (int i = 0; i < C_ADAPTER_LIST_SIZE; i++)
            if (adapterFlag[i])
                adapterDate[i] = _adapterDate[i + 1].equals("00000000") ? null
                        : new SimpleDateFormat("yyyyMMdd").parse(_adapterDate[i + 1]);

        tesDate = segments[2].equals("00000000") ? null : new SimpleDateFormat("yyyyMMdd").parse(segments[2]);

        adapterNum = Integer.parseInt(segments[3]);
    } catch (Exception ex) {
        throw new LicenseException("?License", ex);
    }

    if (tesDate != null && new Date().after(tesDate))
        throw new LicenseException("");

    int count = 0;
    StringBuffer buffer = new StringBuffer();

    List<String> disabledChannelNames = new ArrayList<String>();
    for (String name : core.channels.getChannelNames())
        if (core.channels.getChannel(name) instanceof IAdapterChannel) {
            count++;
            Class<? extends IChannel> cls = core.channels.getChannel(name).getClass();

            String pName = core.channels.getChannel(name).getClass().getPackage().getName();
            pName = pName.substring(pName.lastIndexOf('.') + 1);
            int id = pName.hashCode() & 0x7fffffff % 64;
            if (ArrayUtils.contains(cls.getInterfaces(), IListenerChannel.class))
                id += 64;

            if (!adapterFlag[id] || (adapterDate[id] != null && new Date().after(adapterDate[id])))
                disabledChannelNames.add(name);
        }

    if (adapterNum > 0 && count > adapterNum)
        throw new LicenseException("??license?");

    for (String disabledChannel : disabledChannelNames) {
        buffer.append("License?" + disabledChannel + "??")
                .append(SystemUtils.LINE_SEPARATOR);
        core.channels.getChannelNames().remove(disabledChannel);
    }

    return buffer.toString();
}

From source file:org.apache.hadoop.hive.metastore.RetryingMetaStoreClient.java

/**
 * This constructor is meant for Hive internal use only.
 * Please use getProxy(HiveConf hiveConf, HiveMetaHookLoader hookLoader) for external purpose.
 *///  w  w  w .  j  av  a 2s .c  o m
public static IMetaStoreClient getProxy(HiveConf hiveConf, Class<?>[] constructorArgTypes,
        Object[] constructorArgs, Map<String, Long> metaCallTimeMap, String mscClassName) throws MetaException {

    Class<? extends IMetaStoreClient> baseClass = (Class<? extends IMetaStoreClient>) MetaStoreUtils
            .getClass(mscClassName);

    RetryingMetaStoreClient handler = new RetryingMetaStoreClient(hiveConf, constructorArgTypes,
            constructorArgs, metaCallTimeMap, baseClass);
    return (IMetaStoreClient) Proxy.newProxyInstance(RetryingMetaStoreClient.class.getClassLoader(),
            baseClass.getInterfaces(), handler);
}

From source file:ReflectUtil.java

/**
 * Returns a set of all interfaces implemented by class supplied. This includes all
 * interfaces directly implemented by this class as well as those implemented by
 * superclasses or interface superclasses.
 * //  ww w  . j  av  a  2s .  c o m
 * @param clazz
 * @return all interfaces implemented by this class
 */
public static Set<Class<?>> getImplementedInterfaces(Class<?> clazz) {
    Set<Class<?>> interfaces = new HashSet<Class<?>>();

    if (clazz.isInterface())
        interfaces.add(clazz);

    while (clazz != null) {
        for (Class<?> iface : clazz.getInterfaces())
            interfaces.addAll(getImplementedInterfaces(iface));
        clazz = clazz.getSuperclass();
    }

    return interfaces;
}

From source file:de.hasait.clap.impl.CLAPClassNode.java

private static <A extends Annotation> A findAnnotation(final Class<?> pClass, final Class<A> pAnnotationClass) {
    final LinkedList<Class<?>> queue = new LinkedList<Class<?>>();
    queue.add(pClass);//  ww w .j  a v  a2  s .  c  o  m
    while (!queue.isEmpty()) {
        final Class<?> clazz = queue.removeFirst();
        if (clazz != null) {
            final A result = clazz.getAnnotation(pAnnotationClass);
            if (result != null) {
                return result;
            }
            queue.add(clazz.getSuperclass());
            for (final Class<?> interfaze : clazz.getInterfaces()) {
                queue.add(interfaze);
            }
        }
    }
    return null;
}

From source file:org.apache.ibatis.plugin.Plugin.java

private static Class<?>[] getAllInterfaces(Class<?> type, Map<Class<?>, Set<Method>> signatureMap) {
    Set<Class<?>> interfaces = new HashSet<Class<?>>();
    while (type != null) {
        for (Class<?> c : type.getInterfaces()) {
            if (signatureMap.containsKey(c)) {
                interfaces.add(c);//  w  w  w.j a  v a 2  s .co  m
            }
        }
        type = type.getSuperclass();
    }
    return interfaces.toArray(new Class<?>[interfaces.size()]);
}

From source file:net.ymate.platform.commons.util.ClassUtils.java

/**
 * @param clazz //from  ww w  .  j  a  v a2s .  c om
 * @return ????
 */
public static String[] getInterfaceNames(Class<?> clazz) {
    Class<?>[] interfaces = clazz.getInterfaces();
    List<String> names = new ArrayList<String>();
    for (Class<?> i : interfaces) {
        names.add(i.getName());
    }
    return names.toArray(new String[names.size()]);
}

From source file:cc.kave.commons.utils.json.JsonUtils.java

private static Set<Class<?>> getAllTypesFromHierarchyExceptObject(Class<?> elem, boolean includeElem) {
    Set<Class<?>> hierarchy = Sets.newHashSet();
    if (elem == null || elem.equals(Object.class)) {
        return hierarchy;
    }/* w  w  w.  j av a  2 s.c om*/

    if (includeElem) {
        hierarchy.add(elem);
    }

    for (Class<?> i : elem.getInterfaces()) {
        hierarchy.addAll(getAllTypesFromHierarchyExceptObject(i, true));
    }
    hierarchy.addAll(getAllTypesFromHierarchyExceptObject(elem.getSuperclass(), true));

    return hierarchy;
}

From source file:com.hbs.common.josn.JSONUtil.java

/**
 * Recursive method to visit all the interfaces of a class (and its superclasses and super-interfaces) if they
 * haven't already been visited.//  w  w  w.  j a  v  a  2  s .  c o m
 *
 * Always visits itself if it hasn't already been visited
 *
 * @param thisClass         the current class to visit (if not already done so)
 * @param classesVisited    classes already visited
 * @param visitor           this vistor is called for each class/interface encountered
 * @return true if recursion can continue, false if it should be aborted
 */
@SuppressWarnings("unchecked")
private static boolean visitUniqueInterfaces(Class thisClass, ClassVisitor visitor,
        List<Class> classesVisited) {
    boolean okayToContinue = true;

    if (!classesVisited.contains(thisClass)) {
        classesVisited.add(thisClass);
        okayToContinue = visitor.visit(thisClass);

        if (okayToContinue) {
            Class[] interfaces = thisClass.getInterfaces();
            int index = 0;
            while ((index < interfaces.length) && (okayToContinue)) {
                okayToContinue = visitUniqueInterfaces(interfaces[index++], visitor, classesVisited);
            }

            if (okayToContinue) {
                Class superClass = thisClass.getSuperclass();
                if ((superClass != null) && (!Object.class.equals(superClass))) {
                    okayToContinue = visitUniqueInterfaces(superClass, visitor, classesVisited);
                }
            }
        }
    }
    return okayToContinue;
}

From source file:com.github.valdr.thirdparty.spring.AnnotationUtils.java

/**
 * Find a single {@link java.lang.annotation.Annotation} of {@code annotationType} from the supplied {@link Class},
 * traversing its interfaces and superclasses if no annotation can be found on the given class itself.
 * <p>This method explicitly handles class-level annotations which are not declared as
 * {@link java.lang.annotation.Inherited inherited} <i>as well as annotations on interfaces</i>.
 * <p>The algorithm operates as follows: Searches for an annotation on the given class and returns
 * it if found. Else searches all interfaces that the given class declares, returning the annotation
 * from the first matching candidate, if any. Else proceeds with introspection of the superclass
 * of the given class, checking the superclass itself; if no annotation found there, proceeds
 * with the interfaces that the superclass declares. Recursing up through the entire superclass
 * hierarchy if no match is found.//from   w w w .j ava  2s  .  c om
 * @param clazz the class to look for annotations on
 * @param annotationType the annotation class to look for
 * @return the annotation found, or {@code null} if none found
 */
public static <A extends Annotation> A findAnnotation(Class<?> clazz, Class<A> annotationType) {
    A annotation = clazz.getAnnotation(annotationType);
    if (annotation != null) {
        return annotation;
    }
    for (Class<?> ifc : clazz.getInterfaces()) {
        annotation = findAnnotation(ifc, annotationType);
        if (annotation != null) {
            return annotation;
        }
    }
    if (!Annotation.class.isAssignableFrom(clazz)) {
        for (Annotation ann : clazz.getAnnotations()) {
            annotation = findAnnotation(ann.annotationType(), annotationType);
            if (annotation != null) {
                return annotation;
            }
        }
    }
    Class<?> superClass = clazz.getSuperclass();
    if (superClass == null || superClass.equals(Object.class)) {
        return null;
    }
    return findAnnotation(superClass, annotationType);
}

From source file:org.jdbcluster.JDBClusterUtil.java

/**
 * @param superClass//from www.  j a  v a 2s.  c  o  m
 *            Class or Interface to look for
 * @param clazz
 *            the class instance
 * @return -1 for not found. Counter for supercasses above parameter
 *         superClass
 */
static private int countSuper(Class<?> superClass, Class<?> clazz) {
    if (superClass.isInterface())
        return countSuperInterface(0, superClass, clazz.getInterfaces());
    else
        return countSuperClass(0, superClass, clazz);
}