Skip to content

io microsphere lang ClassDataRepository

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

ClassDataRepository

Type: Class | Module: microsphere-java-core | Package: io.microsphere.lang | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/lang/ClassDataRepository.java

Overview

A repository class that manages and provides access to classpath and class-related metadata.

This class offers methods for retrieving class names, package names, and their respective locations within the classpath. It maintains mappings such as:

- **Class path to class names:** Maps directories or JAR files to the set of fully qualified class names contained within.
- **Class name to class path:** Maps each fully qualified class name to its defining class path entry (e.g., a JAR file or directory).
- **Package name to class names:** Maps package names to the set of fully qualified class names belonging to them.

Example Usage

`// Get the singleton instance
ClassDataRepository repository = ClassDataRepository.INSTANCE;

// Get all package names discovered in the classpath
Set packages = repository.getAllPackageNamesInClassPaths();

// Get all class names under a specific package
Set classesInPackage = repository.getClassNamesInPackage("java.lang");

// Find the classpath where a specific class is located
String classPath = repository.findClassPath(String.class);

// Get all class names found in a specific classpath entry
Set classNames = repository.getClassNamesInClassPath("/usr/lib/jvm/rt.jar", false);

// Get code source location URL for a given class
URL location = repository.getCodeSourceLocation(ArrayList.class);
`

Declaration

public class ClassDataRepository

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Get the singleton instance
ClassDataRepository repository = ClassDataRepository.INSTANCE;

// Get all package names discovered in the classpath
Set<String> packages = repository.getAllPackageNamesInClassPaths();

// Get all class names under a specific package
Set<String> classesInPackage = repository.getClassNamesInPackage("java.lang");

// Find the classpath where a specific class is located
String classPath = repository.findClassPath(String.class);

// Get all class names found in a specific classpath entry
Set<String> classNames = repository.getClassNamesInClassPath("/usr/lib/jvm/rt.jar", false);

// Get code source location URL for a given class
URL location = repository.getCodeSourceLocation(ArrayList.class);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.lang.ClassDataRepository;

API Reference

Public Methods

Method Description
getAllPackageNamesInClassPaths Singleton instance of ClassDataRepository
findClassPath Find class path under specified class name
findClassPath Find class path under specified class name
getClassNamesInClassPath Gets class name Set under specified class path
getClassNamesInPackage Gets class name Set under specified package
getClassNamesInPackage Gets class name Set under specified package name
getAllClassNamesInClassPaths The map of all class names in ClassPathUtils#getClassPaths() class path , the class path for one {@link

Method Details

getAllPackageNamesInClassPaths

public Set<String> getAllPackageNamesInClassPaths()

Singleton instance of ClassDataRepository / public static final ClassDataRepository INSTANCE = new ClassDataRepository();

private final Map> classPathToClassNamesMap = initClassPathToClassNamesMap();

private final Map classNameToClassPathsMap = initClassNameToClassPathsMap();

private final Map> packageNameToClassNamesMap = initPackageNameToClassNamesMap();

/** Get all package names in ClassPathUtils#getClassPaths() class paths

getClassNamesInClassPath

public Set<String> getClassNamesInClassPath(String classPath, boolean recursive)

Gets class name Set under specified class path

getClassNamesInPackage

public Set<String> getClassNamesInPackage(Package onePackage)

Gets class name Set under specified package

getClassNamesInPackage

public Set<String> getClassNamesInPackage(String packageName)

Gets class name Set under specified package name

getAllClassNamesInClassPaths

public Set<String> getAllClassNamesInClassPaths()

The map of all class names in ClassPathUtils#getClassPaths() class path , the class path for one JarFile or classes directory as key , the class names set as value

See Also

  • ClassPathUtils

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally