Example usage for java.lang Class getClasses

List of usage examples for java.lang Class getClasses

Introduction

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

Prototype

@CallerSensitive
public Class<?>[] getClasses() 

Source Link

Document

Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object.

Usage

From source file:com.medigy.persist.util.HibernateConfiguration.java

public void registerReferenceEntitiesAndCaches() {
    final Iterator classMappings = getClassMappings();
    while (classMappings.hasNext()) {
        Class aClass = ((PersistentClass) classMappings.next()).getMappedClass(); //(Class) classMappings.next();
        if (ReferenceEntity.class.isAssignableFrom(aClass)) {
            boolean foundCache = false;
            for (final Class ic : aClass.getClasses()) {
                if (CachedReferenceEntity.class.isAssignableFrom(ic)) {
                    if (ic.isEnum()) {
                        referenceEntitiesAndCachesMap.put(aClass, ic);
                        foundCache = true;
                    } else
                        throw new HibernateException(ic + " must be an enum since " + aClass + " is a "
                                + ReferenceEntity.class.getName());

                    break;
                }/* w w w .  j a  va2s.c o m*/

            }

            if (!foundCache)
                log.warn(aClass
                        + " is marked as a ReferenceEntity but does not contain a ReferenceEntityCache enum.");

            // TODO: find out how to ensure the new mapping for reference type is immutable and read only
            // final PersistentClass pClass = getClassMapping(aClass.getLabel());
        } else if (CustomReferenceEntity.class.isAssignableFrom(aClass)) {
            for (final Class ic : aClass.getClasses()) {
                if (CachedCustomReferenceEntity.class.isAssignableFrom(ic)) {
                    if (ic.isEnum()) {
                        customReferenceEntitiesAndCachesMap.put(aClass, ic);
                    } else
                        throw new HibernateException(ic + " must be an enum since " + aClass + " is a "
                                + CachedCustomReferenceEntity.class.getName());

                    break;
                }
            }
            // if no cache is found, its ok since these are custom
        }
    }
}

From source file:adalid.core.EntityAtlas.java

void checkOperationClasses() {
    track("checkOperationClasses");
    Project project = TLC.getProject();/*from   www.  j  av  a  2s .c o  m*/
    assert project != null;
    String key;
    String pattern;
    String remarks;
    Class<?> operationClass;
    Class<?> dac = _declaringArtifact.getClass();
    Class<?>[] classArray = dac.getClasses();
    for (Class<?> clazz : classArray) {
        if (Operation.class.isAssignableFrom(clazz)) {
            key = clazz.getSimpleName();
            if (_operationClasses.containsKey(key)) {
                operationClass = _operationClasses.get(key);
                if (operationClass.equals(clazz)) {
                } else if (operationClass.isAssignableFrom(clazz)) {
                    _operationClasses.put(key, clazz);
                    ////                    pattern = "{0} is assignable from {1}";
                    ////                    remarks = MessageFormat.format(pattern, operationClass.getName(), clazz.getName());
                    //                      remarks = null;
                    //                      logOperationReferenceOverride(Project.getAlertLevel(), clazz, operationClass, dac, remarks);
                    //                      project.getParser().increaseWarningCount();
                } else if (clazz.isAssignableFrom(operationClass)) {
                    ////                    pattern = "{0} is assignable from {1}";
                    ////                    remarks = MessageFormat.format(pattern, clazz.getName(), operationClass.getName());
                    //                      remarks = null;
                    //                      logOperationReferenceOverride(Project.getAlertLevel(), operationClass, clazz, dac, remarks);
                    //                      project.getParser().increaseWarningCount();
                } else {
                    pattern = "{0} is not assignable from {1}";
                    remarks = MessageFormat.format(pattern, operationClass.getName(), clazz.getName());
                    logOperationReferenceOverride(Level.ERROR, clazz, operationClass, dac, remarks);
                    project.getParser().increaseErrorCount();
                }
            } else {
                _operationClasses.put(key, clazz);
                _operationFields.put(key, null);
            }
        }
    }
}

From source file:onl.netfishers.netshot.Database.java

/**
 * Initializes the database access, with Hibernate.
 *///from   w w  w  .j  a v a2 s . c  o  m
public static void init() {
    try {

        configuration = new Configuration();

        configuration
                .setProperty("hibernate.connection.driver_class",
                        Netshot.getConfig("netshot.db.driver_class", "com.mysql.jdbc.Driver"))
                .setProperty("hibernate.connection.url",
                        Netshot.getConfig("netshot.db.url", "jdbc:mysql://localhost/netshot01"))
                .setProperty("hibernate.connection.username",
                        Netshot.getConfig("netshot.db.username", "netshot"))
                .setProperty("hibernate.connection.password",
                        Netshot.getConfig("netshot.db.password", "netshot"))
                .setProperty("hibernate.c3p0.min_size", "5").setProperty("hibernate.c3p0.max_size", "30")
                .setProperty("hibernate.c3p0.timeout", "1800")
                .setProperty("hibernate.c3p0.max_statements", "50")
                .setProperty("hibernate.c3p0.unreturnedConnectionTimeout", "1800")
                .setProperty("hibernate.c3p0.debugUnreturnedConnectionStackTraces", "true");

        configuration.setProperty("factory_class", "org.hibernate.transaction.JDBCTransactionFactory")
                .setProperty("current_session_context_class", "thread")
                .setProperty("hibernate.hbm2ddl.auto", "update")
                //.setProperty("hibernate.show_sql", "true")
                .addAnnotatedClass(Device.class).addAnnotatedClass(DeviceGroup.class)
                .addAnnotatedClass(Config.class).addAnnotatedClass(DeviceAttribute.class)
                .addAnnotatedClass(DeviceNumericAttribute.class).addAnnotatedClass(DeviceTextAttribute.class)
                .addAnnotatedClass(DeviceLongTextAttribute.class).addAnnotatedClass(DeviceBinaryAttribute.class)
                .addAnnotatedClass(ConfigAttribute.class).addAnnotatedClass(ConfigNumericAttribute.class)
                .addAnnotatedClass(ConfigTextAttribute.class).addAnnotatedClass(ConfigLongTextAttribute.class)
                .addAnnotatedClass(ConfigBinaryAttribute.class).addAnnotatedClass(LongTextConfiguration.class)
                .addAnnotatedClass(StaticDeviceGroup.class).addAnnotatedClass(DynamicDeviceGroup.class)
                .addAnnotatedClass(Module.class).addAnnotatedClass(Domain.class)
                .addAnnotatedClass(PhysicalAddress.class).addAnnotatedClass(NetworkAddress.class)
                .addAnnotatedClass(Network4Address.class).addAnnotatedClass(Network6Address.class)
                .addAnnotatedClass(NetworkInterface.class).addAnnotatedClass(DeviceSnmpv1Community.class)
                .addAnnotatedClass(DeviceSnmpv2cCommunity.class).addAnnotatedClass(DeviceSshAccount.class)
                .addAnnotatedClass(DeviceSshKeyAccount.class).addAnnotatedClass(DeviceTelnetAccount.class)
                .addAnnotatedClass(Policy.class).addAnnotatedClass(Rule.class).addAnnotatedClass(Task.class)
                .addAnnotatedClass(Exemption.class).addAnnotatedClass(Exemption.Key.class)
                .addAnnotatedClass(CheckResult.class).addAnnotatedClass(CheckResult.Key.class)
                .addAnnotatedClass(SoftwareRule.class).addAnnotatedClass(HardwareRule.class)
                .addAnnotatedClass(DeviceJsScript.class).addAnnotatedClass(User.class);

        for (Class<?> clazz : Task.getTaskClasses()) {
            logger.info("Registering task class " + clazz.getName());
            configuration.addAnnotatedClass(clazz);
        }
        for (Class<?> clazz : Rule.getRuleClasses()) {
            configuration.addAnnotatedClass(clazz);
            for (Class<?> subClass : clazz.getClasses()) {
                if (subClass.getAnnotation(Entity.class) != null) {
                    configuration.addAnnotatedClass(subClass);
                }
            }
        }

        configuration.setNamingStrategy(new ImprovedNamingStrategy());

        configuration.setInterceptor(new DatabaseInterceptor());

        serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties())
                .build();
        sessionFactory = configuration.buildSessionFactory(serviceRegistry);

    } catch (HibernateException e) {
        logger.error(MarkerFactory.getMarker("FATAL"), "Unable to instantiate Hibernate", e);
        throw new RuntimeException("Unable to instantiate Hibernate, see logs for more details");
    }
}

From source file:org.apache.hadoop.yarn.webapp.hamlet.HamletGen.java

void initLut(Class<?> spec) {
    endTagOptional.clear();/* w w  w . java  2 s.c om*/
    inlineElements.clear();
    for (Class<?> cls : spec.getClasses()) {
        Annotation a = cls.getAnnotation(HamletSpec.Element.class);
        if (a != null && !((HamletSpec.Element) a).endTag()) {
            endTagOptional.add(cls.getSimpleName());
        }
        if (cls.getSimpleName().equals("Inline")) {
            for (Method method : cls.getMethods()) {
                String retName = method.getReturnType().getSimpleName();
                if (isElement(retName)) {
                    inlineElements.add(retName);
                }
            }
        }
    }
}

From source file:org.apache.hadoop.yarn.webapp.hamlet.HamletGen.java

void genImpl(Class<?> spec, String implClassName, int indent) {
    String specName = spec.getSimpleName();
    for (Class<?> cls : spec.getClasses()) {
        String className = cls.getSimpleName();
        if (cls.isInterface()) {
            genFactoryMethods(cls, indent);
        }//w w w. j a v  a 2s .com
        if (isElement(className)) {
            LOG.info("Generating class {}<T>", className);
            puts(indent, "\n", "public class ", className, "<T extends _>", " extends EImp<T> implements ",
                    specName, ".", className, " {\n", "  public ", className, "(String name, T parent,",
                    " EnumSet<EOpt> opts) {\n", "    super(name, parent, opts);\n", "  }");
            genMethods(className, cls, indent + 1);
            puts(indent, "}");
        } else if (className.equals("_Html")) {
            top = cls;
        }
    }
}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.protocol.TBSONUnstackedProtocol.java

public org.apache.thrift.TFieldIdEnum getFieldId(Class<? extends TBase> tbase, String fieldName)
        throws TException {

    try {// www .j ava 2  s .  c  o m
        Map<Class<?>, Map<String, org.apache.thrift.TFieldIdEnum>> thriftTFields = threadSafeTFieldsIdEnum
                .get();

        if (thriftTFields == null) {
            thriftTFields = new HashMap<>();
        }

        Map<String, org.apache.thrift.TFieldIdEnum> tfieldIdEnumByName = thriftTFields.get(tbase);

        // Load it in cache
        if (tfieldIdEnumByName == null) {

            Class<?>[] innerClasses = tbase.getClasses();

            for (Class<?> innerClass : innerClasses) {
                if ("_Fields".equals(innerClass.getSimpleName())) {
                    Field fieldsByName = innerClass.getDeclaredField("byName");
                    fieldsByName.setAccessible(true);

                    tfieldIdEnumByName = (Map<String, org.apache.thrift.TFieldIdEnum>) fieldsByName
                            .get(fieldsByName);

                    // store in the thread local
                    thriftTFields.put(tbase, tfieldIdEnumByName);
                    threadSafeTFieldsIdEnum.set(thriftTFields);
                }
            }
        }

        return tfieldIdEnumByName.get(fieldName);

    } catch (Exception e) {
        throw new TException(e);
    }
}

From source file:org.breizhbeans.thrift.tools.thriftmongobridge.secured.TBSONSecuredWrapper.java

public void secureThriftFields(Class<? extends TBase> tbase, boolean hash, TFieldIdEnum... fields)
        throws Exception {
    Map<Short, ThriftSecuredField> classSecuredFields = securedFields.get(tbase);
    if (classSecuredFields == null) {
        classSecuredFields = new ConcurrentHashMap<>();
    }/*w w w  .  ja v  a  2s .c o m*/

    // get the Field class
    Class<?> fieldClass = null;
    Class<?>[] innerClasses = tbase.getClasses();
    for (Class<?> innerClass : innerClasses) {
        if ("_Fields".equals(innerClass.getSimpleName())) {
            fieldClass = innerClass;
            break;
        }
    }

    // extract _Fields
    Class[] findByNameArgs = new Class[1];
    findByNameArgs[0] = String.class;
    Method findByNameMethod = fieldClass.getMethod("findByName", findByNameArgs);

    // extract metadataMap
    Field metafaField = tbase.getField("metaDataMap");
    Map<?, FieldMetaData> metaDataMap = (Map<?, org.apache.thrift.meta_data.FieldMetaData>) metafaField
            .get(tbase);

    for (TFieldIdEnum field : fields) {
        // get the _Field instance
        org.apache.thrift.TFieldIdEnum tfieldEnum = (TFieldIdEnum) findByNameMethod.invoke(null,
                field.getFieldName());

        // get the matadata
        FieldMetaData fieldMetaData = metaDataMap.get(tfieldEnum);

        // only string are supported
        switch (fieldMetaData.valueMetaData.type) {
        case TType.STRING:
            break;

        case TType.MAP:
            MapMetaData mapMetaData = (MapMetaData) fieldMetaData.valueMetaData;

            if (mapMetaData.valueMetaData.type != TType.STRING) {
                throw new UnsupportedTTypeException("Unsupported secured type - FIELD:" + field.getFieldName()
                        + " TYPE:" + mapMetaData.valueMetaData.type);
            }
            break;
        default:
            throw new UnsupportedTTypeException("Unsupported secured type - FIELD:" + field.getFieldName()
                    + " TYPE:" + fieldMetaData.valueMetaData.type);
        }

        classSecuredFields.put(field.getThriftFieldId(), new ThriftSecuredField(true, hash));
    }

    securedFields.put(tbase, classSecuredFields);
}

From source file:org.eclipse.wb.android.internal.model.util.AndroidListenerProperties.java

/**
 * @return the {@link List} of events which are supported by given widget.
 *//*from   w  w w.j a  v  a 2 s. c  o  m*/
private static List<ListenerInfo> getWidgetEvents(XmlObjectInfo widget) {
    Class<?> componentClass = widget.getDescription().getComponentClass();
    List<ListenerInfo> events = m_widgetEvents.get(componentClass);
    if (events == null) {
        GenericTypeResolver typeResolver = new GenericTypeResolver(null);
        events = Lists.newArrayList();
        m_widgetEvents.put(componentClass, events);
        {
            // events in Android has 'OnXXXListener' inner class as listener interface with
            // appropriate 'setOnXXXListener' method in main class
            Pattern pattern = Pattern.compile("On.*Listener");
            Class<?>[] classes = componentClass.getClasses();
            if (!ArrayUtils.isEmpty(classes)) {
                for (Class<?> innerClass : classes) {
                    String shortClassName = CodeUtils.getShortClass(innerClass.getName());
                    Matcher matcher = pattern.matcher(shortClassName);
                    if (matcher.matches()) {
                        // additionally check for method, it should be public (RefUtils returns with any visibility)
                        Method method = ReflectionUtils.getMethod(componentClass, "set" + shortClassName,
                                innerClass);
                        if (method != null && (method.getModifiers() & Modifier.PUBLIC) != 0) {
                            ListenerInfo listener = new ListenerInfo(method, componentClass, typeResolver);
                            events.add(listener);
                        }
                    }
                }
            }
        }
        // sort
        Collections.sort(events, new Comparator<ListenerInfo>() {
            public int compare(ListenerInfo o1, ListenerInfo o2) {
                return o1.getSimpleName().compareTo(o2.getSimpleName());
            }
        });
    }
    return events;
}

From source file:org.talend.metadata.managment.hive.EmbeddedHiveDataBaseMetadata.java

@Override
public ResultSet getTables(String catalog, String schema, String tableNamePattern, String[] types)
        throws SQLException {
    if (hiveObject == null) {
        throw new SQLException("Unable to instantiate org.apache.hadoop.hive.ql.metadata.Hive."); //$NON-NLS-1$
    }/*from ww  w  .  ja  v  a2 s  . c  om*/
    String hiveCat = catalog;
    if (StringUtils.isBlank(hiveCat)) {
        hiveCat = HIVE_SCHEMA_DEFAULT;
    }
    String[] hiveTypes = types;
    if (hiveTypes == null) {
        hiveTypes = new String[0];
    }

    // Added this for TDI-25456 by Marvin Wang on Apr. 11, 2013.
    ClassLoader currCL = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(classLoader);

    EmbeddedHiveResultSet tableResultSet = new EmbeddedHiveResultSet();
    tableResultSet.setMetadata(TABLE_META);
    List<String[]> list = new ArrayList<String[]>();
    tableResultSet.setData(list);

    try {
        Class hiveClass = hiveObject.getClass();
        Method method = hiveClass.getDeclaredMethod("getConf");//$NON-NLS-1$ 
        Object hiveConf = method.invoke(hiveObject);
        Class hiveConfClass = hiveConf.getClass();
        // find ConfVar enum in the HiveConf class.
        Class confVarClass = null;
        for (Class curClass : hiveConfClass.getClasses()) {
            if (curClass.getSimpleName().equals("ConfVars")) { //$NON-NLS-1$
                confVarClass = curClass;
                break;
            }
        }
        if (confVarClass != null) {
            Object confVar = null;
            // try to find enumeration: ConfVars.METASTORE_CLIENT_SOCKET_TIMEOUT
            for (Object curConfVar : confVarClass.getEnumConstants()) {
                if (curConfVar.toString().equals("hive.metastore.client.socket.timeout")) { //$NON-NLS-1$
                    confVar = curConfVar;
                    break;
                }
            }
            if (confVar != null) {
                Method setIntVarMethod = hiveConfClass.getDeclaredMethod("setIntVar", confVarClass, int.class); //$NON-NLS-1$
                int timeout = 15;
                if (GlobalServiceRegister.getDefault().isServiceRegistered(IDesignerCoreService.class)) {
                    IDesignerCoreService designerService = (IDesignerCoreService) GlobalServiceRegister
                            .getDefault().getService(IDesignerCoreService.class);
                    timeout = designerService.getDBConnectionTimeout();
                }
                setIntVarMethod.invoke(hiveConf, confVar, timeout);
            }
        }
        String tempTableNamepattern = tableNamePattern;
        if (StringUtils.isEmpty(tempTableNamepattern)
                || TableInfoParameters.DEFAULT_FILTER.equals(tempTableNamepattern)) {
            tempTableNamepattern = "*"; //$NON-NLS-1$
        }
        Object tables = ReflectionUtils.invokeMethod(hiveObject, "getTablesByPattern", //$NON-NLS-1$
                new Object[] { hiveCat, tempTableNamepattern });
        if (tables instanceof List) {
            List<String> tableList = (List<String>) tables;
            for (String tableName : tableList) {
                String tableType = getTableType(hiveCat, tableName);
                if (tableType != null && ArrayUtils.contains(hiveTypes, tableType)) {
                    String[] array = new String[] { "", hiveCat, tableName, tableType, "" }; //$NON-NLS-1$//$NON-NLS-2$
                    list.add(array);
                }
            }
        }
    } catch (Exception e) {
        throw new SQLException(e);
    } finally {
        Thread.currentThread().setContextClassLoader(currCL);
    }

    return tableResultSet;
}

From source file:org.xenei.classpathutils.ClassPathUtils.java

/**
 * Get all the interfaces that the class implements. Adds the interfaces to
 * the set of classes.//from ww w .  ja  va  2 s  .c  om
 *
 * This method calls recursively to find all parent interfaces.
 *
 * @param set
 *            The set off classes to add the interface classes to.
 * @param c
 *            The class to check.
 */
public static void getAllInterfaces(final Set<Class<?>> set, final Class<?> c) {
    if ((c == null) || (c == Object.class)) {
        return;
    }
    for (final Class<?> i : c.getClasses()) {
        if (i.isInterface()) {
            if (!set.contains(i)) {
                set.add(i);
                getAllInterfaces(set, i);
            }
        }
    }
    for (final Class<?> i : c.getInterfaces()) {
        if (!set.contains(i)) {
            set.add(i);
            getAllInterfaces(set, i);
        }
    }
    getAllInterfaces(set, c.getSuperclass());
}