class ClassGenerator implements IClassGenerator<String> {

    @Override
    public Class<?> generate(final String source)
            throws ClassGenerationException, InvalidArgumentException {

        if (null == source || source.isEmpty()) {
            throw new InvalidArgumentException("Source code should not be null or empty.");
        }
        String packageName = getFirstSubstringByPattern(source, Pattern.compile("package\\s+([\\w\\.]+)"));
        String className = getFirstSubstringByPattern(source, Pattern.compile("(?:class|interface)\\s+(\\w+)"));
        if (null == packageName || packageName.isEmpty()) {
            throw new InvalidArgumentException("Source code doesn't contain package name.");
        }
        if (null == className || className.isEmpty()) {
            throw new InvalidArgumentException("Source code doesn't contain class.");
        }
        try {
            String fullClassName = packageName + "." + className;
            Class<?> compiledClass = this.compiler.compile(fullClassName, source);
            return compiledClass;
        } catch (Throwable e) {
            throw new ClassGenerationException("Could not generate class.", e);
        }
    }

    public  ClassGenerator(final ClassLoader classLoader);

}