Search in sources :

Example 1 with MadvocAction

use of jodd.madvoc.meta.MadvocAction in project jodd by oblac.

the class ActionMethodParser method readPackageActionPath.

// ---------------------------------------------------------------- readers
/**
	 * Reads action path for package. It can be used only if root package is set in
	 * {@link MadvocConfig madvoc configuration}.
	 * If annotation is not set on package-level, class package will be used for
	 * package action path part.
	 */
protected void readPackageActionPath(ActionNames actionNames, Class actionClass) {
    Package actionPackage = actionClass.getPackage();
    String actionPackageName = actionPackage.getName();
    final RootPackages rootPackages = madvocConfig.getRootPackages();
    String packagePath = rootPackages.getPackageActionPath(actionPackageName);
    if (packagePath == null) {
        packagePath = rootPackages.findPackagePathForActionPackage(actionPackageName);
        String rootPackage = null;
        if (packagePath != null) {
            rootPackage = rootPackages.findRootPackageForActionPath(packagePath);
        }
        // try locating marker class
        {
            String packageName = actionPackageName;
            String madvocRootPackageClassName = madvocConfig.getMadvocRootPackageClassName();
            if (madvocRootPackageClassName != null) {
                while (true) {
                    String className = packageName + '.' + madvocRootPackageClassName;
                    try {
                        Class<?> madvocRootPackageClass = ClassLoaderUtil.loadClass(className, actionClass.getClassLoader());
                        // class found, find the mapping
                        String mapping = StringPool.EMPTY;
                        MadvocAction madvocAction = madvocRootPackageClass.getAnnotation(MadvocAction.class);
                        if (madvocAction != null) {
                            mapping = madvocAction.value();
                        }
                        // register root package - so not to lookup twice
                        madvocConfig.getRootPackages().addRootPackage(packageName, mapping);
                        // repeat lookup
                        packagePath = rootPackages.findPackagePathForActionPackage(actionPackageName);
                        break;
                    } catch (ClassNotFoundException ignore) {
                        // continue
                        int dotNdx = packageName.lastIndexOf('.');
                        if (dotNdx == -1) {
                            break;
                        }
                        packageName = packageName.substring(0, dotNdx);
                        if (rootPackage != null) {
                            // don't go beyond found root package
                            if (packageName.equals(rootPackage)) {
                                break;
                            }
                        }
                    }
                }
            }
        }
        rootPackages.registerPackageActionPath(actionPackageName, packagePath);
    }
    // read package-level annotation
    MadvocAction madvocActionAnnotation = actionPackage.getAnnotation(MadvocAction.class);
    String packageActionPath = madvocActionAnnotation != null ? madvocActionAnnotation.value().trim() : null;
    if (StringUtil.isEmpty(packageActionPath)) {
        packageActionPath = null;
    }
    // if not set, resolve value
    if (packageActionPath == null) {
        // no package-level annotation
        if (packagePath == null) {
            // no root package path, just return
            return;
        }
        packageActionPath = packagePath;
    }
    actionNames.setPackageNames(StringUtil.stripChar(packagePath, '/'), StringUtil.surround(packageActionPath, StringPool.SLASH));
}
Also used : MadvocAction(jodd.madvoc.meta.MadvocAction) RootPackages(jodd.madvoc.RootPackages)

Example 2 with MadvocAction

use of jodd.madvoc.meta.MadvocAction in project jodd by oblac.

the class ActionMethodParser method readClassActionPath.

/**
	 * Reads action path from class. If the class is annotated with {@link MadvocAction} annotation,
	 * class action path will be read from annotation value. Otherwise, action class path will be built from the
	 * class name. This is done by removing the package name and the last contained word
	 * (if there is more then one) from the class name. Such name is finally uncapitalized.
	 * <p>
	 * If this method returns <code>null</code> class will be ignored.
	 */
protected void readClassActionPath(ActionNames actionNames, Class actionClass) {
    // read annotation
    MadvocAction madvocActionAnnotation = ((Class<?>) actionClass).getAnnotation(MadvocAction.class);
    String classActionPath = madvocActionAnnotation != null ? madvocActionAnnotation.value().trim() : null;
    if (StringUtil.isEmpty(classActionPath)) {
        classActionPath = null;
    }
    String name = actionClass.getSimpleName();
    name = StringUtil.uncapitalize(name);
    name = MadvocUtil.stripLastCamelWord(name);
    if (classActionPath == null) {
        classActionPath = name;
    }
    actionNames.setClassNames(name, classActionPath);
}
Also used : MadvocAction(jodd.madvoc.meta.MadvocAction)

Aggregations

MadvocAction (jodd.madvoc.meta.MadvocAction)2 RootPackages (jodd.madvoc.RootPackages)1