Search in sources :

Example 1 with PetiteBean

use of jodd.petite.meta.PetiteBean in project jodd by oblac.

the class AutomagicPetiteConfigurator method onEntry.

/**
	 * Scans all classes and registers only those annotated with {@link jodd.petite.meta.PetiteBean}.
	 * Because of performance purposes, classes are not dynamically loaded; instead, their
	 * file content is examined. 
	 */
@Override
protected void onEntry(EntryData entryData) {
    String entryName = entryData.getName();
    InputStream inputStream = entryData.openInputStream();
    if (!isTypeSignatureInUse(inputStream, petiteBeanAnnotationBytes)) {
        return;
    }
    Class<?> beanClass;
    try {
        beanClass = loadClass(entryName);
    } catch (ClassNotFoundException cnfex) {
        throw new PetiteException("Unable to load class: " + cnfex, cnfex);
    }
    if (beanClass == null) {
        return;
    }
    PetiteBean petiteBean = beanClass.getAnnotation(PetiteBean.class);
    if (petiteBean == null) {
        return;
    }
    container.registerPetiteBean(beanClass, null, null, null, false);
}
Also used : PetiteBean(jodd.petite.meta.PetiteBean) InputStream(java.io.InputStream) PetiteException(jodd.petite.PetiteException)

Example 2 with PetiteBean

use of jodd.petite.meta.PetiteBean in project jodd by oblac.

the class PetiteUtil method resolveBeanName.

/**
	 * Resolves bean's name from bean annotation or type name. May be used for resolving bean name
	 * of base type during registration of bean subclass.
	 */
public static String resolveBeanName(Class type, boolean useLongTypeName) {
    PetiteBean petiteBean = ((Class<?>) type).getAnnotation(PetiteBean.class);
    String name = null;
    if (petiteBean != null) {
        name = petiteBean.value().trim();
    }
    if ((name == null) || (name.length() == 0)) {
        if (useLongTypeName) {
            name = type.getName();
        } else {
            name = StringUtil.uncapitalize(type.getSimpleName());
        }
    }
    return name;
}
Also used : PetiteBean(jodd.petite.meta.PetiteBean)

Example 3 with PetiteBean

use of jodd.petite.meta.PetiteBean in project jodd by oblac.

the class PetiteUtil method beanHasAnnotationName.

/**
	 * Returns <code>true</code> if bean has name defined by Petite annotation.
	 */
public static boolean beanHasAnnotationName(Class type) {
    PetiteBean petiteBean = ((Class<?>) type).getAnnotation(PetiteBean.class);
    if (petiteBean == null) {
        return false;
    }
    String name = petiteBean.value().trim();
    return !name.isEmpty();
}
Also used : PetiteBean(jodd.petite.meta.PetiteBean)

Aggregations

PetiteBean (jodd.petite.meta.PetiteBean)3 InputStream (java.io.InputStream)1 PetiteException (jodd.petite.PetiteException)1