use of jodd.petite.PetiteException 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);
}
use of jodd.petite.PetiteException in project jodd by oblac.
the class AutomagicPetiteConfigurator method configure.
/**
* Configures {@link jodd.petite.PetiteContainer} with specified class path.
* @see AutomagicPetiteConfigurator#configure(jodd.petite.PetiteContainer)
*/
public void configure(PetiteContainer petiteContainer, File[] classpath) {
this.container = petiteContainer;
rulesEntries.smartMode();
elapsed = System.currentTimeMillis();
try {
scanPaths(classpath);
} catch (Exception ex) {
throw new PetiteException("Scan classpath error", ex);
}
elapsed = System.currentTimeMillis() - elapsed;
log.info("Petite configured in " + elapsed + " ms. Total beans: " + petiteContainer.getTotalBeans());
}
use of jodd.petite.PetiteException in project jodd by oblac.
the class CtorResolver method resolve.
/**
* Resolves constructor injection point from type. Looks for single annotated constructor.
* If no annotated constructors found, the total number of constructors will be checked.
* If there is only one constructor, that one will be used as injection point. If more
* constructors exist, the default one will be used as injection point. Otherwise, exception
* is thrown.
*/
public CtorInjectionPoint resolve(Class type, boolean useAnnotation) {
ClassDescriptor cd = ClassIntrospector.lookup(type);
CtorDescriptor[] allCtors = cd.getAllCtorDescriptors();
Constructor foundedCtor = null;
Constructor defaultCtor = null;
String refValues = null;
for (CtorDescriptor ctorDescriptor : allCtors) {
Constructor<?> ctor = ctorDescriptor.getConstructor();
Class<?>[] paramTypes = ctor.getParameterTypes();
if (paramTypes.length == 0) {
// detects default ctors
defaultCtor = ctor;
}
if (!useAnnotation) {
continue;
}
PetiteInject ref = ctor.getAnnotation(PetiteInject.class);
if (ref == null) {
continue;
}
if (foundedCtor != null) {
throw new PetiteException("Two or more constructors are annotated as injection points in bean: " + type.getName());
}
foundedCtor = ctor;
refValues = ref.value().trim();
}
if (foundedCtor == null) {
if (allCtors.length == 1) {
foundedCtor = allCtors[0].getConstructor();
} else {
foundedCtor = defaultCtor;
}
}
if (foundedCtor == null) {
throw new PetiteException("No constructor (annotated, single or default) founded as injection point for: " + type.getName());
}
String[][] references = PetiteUtil.convertAnnValueToReferences(refValues);
return injectionPointFactory.createCtorInjectionPoint(foundedCtor, references);
}
use of jodd.petite.PetiteException in project jodd by oblac.
the class DestroyMethodResolver method resolve.
public DestroyMethodPoint[] resolve(Object bean) {
Class<?> type = bean.getClass();
// lookup methods
List<DestroyMethodPoint> list = new ArrayList<>();
ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null);
MethodDescriptor[] allMethods = cd.getAllMethodDescriptors();
for (MethodDescriptor methodDescriptor : allMethods) {
Method method = methodDescriptor.getMethod();
PetiteDestroyMethod petiteDestroyMethod = method.getAnnotation(PetiteDestroyMethod.class);
if (petiteDestroyMethod == null) {
continue;
}
if (method.getParameterTypes().length > 0) {
throw new PetiteException("Arguments are not allowed for Petite destroy method: " + type.getName() + '#' + method.getName());
}
list.add(new DestroyMethodPoint(method));
}
DestroyMethodPoint[] methods;
if (list.isEmpty()) {
methods = DestroyMethodPoint.EMPTY;
} else {
methods = list.toArray(new DestroyMethodPoint[list.size()]);
}
return methods;
}
use of jodd.petite.PetiteException in project jodd by oblac.
the class InitMethodResolver method resolve.
public InitMethodPoint[] resolve(Object bean) {
Class<?> type = bean.getClass();
// lookup methods
List<InitMethodPoint> list = new ArrayList<>();
ClassDescriptor cd = new ClassDescriptor(type, false, false, false, null);
MethodDescriptor[] allMethods = cd.getAllMethodDescriptors();
for (MethodDescriptor methodDescriptor : allMethods) {
Method method = methodDescriptor.getMethod();
PetiteInitMethod petiteInitMethod = method.getAnnotation(PetiteInitMethod.class);
if (petiteInitMethod == null) {
continue;
}
if (method.getParameterTypes().length > 0) {
throw new PetiteException("Arguments are not allowed for Petite init method: " + type.getName() + '#' + method.getName());
}
int order = petiteInitMethod.order();
list.add(new InitMethodPoint(method, order, petiteInitMethod.invoke()));
}
InitMethodPoint[] methods;
if (list.isEmpty()) {
methods = InitMethodPoint.EMPTY;
} else {
Collections.sort(list);
methods = list.toArray(new InitMethodPoint[list.size()]);
}
return methods;
}
Aggregations