Search in sources :

Example 1 with ConfigurationException

use of com.opensymphony.xwork2.config.ConfigurationException in project qi4j-sdk by Qi4j.

the class Qi4jCodebehindPackageProvider method loadPackageConfig.

/**
 * Finds or creates the package configuration for an Action class.
 *
 * The namespace annotation is honored, if found,
 * and the namespace is checked for a parent configuration.
 *
 * @param actionNamespace The configuration namespace
 * @param actionPackage   The Java package containing our Action classes
 * @param actionClass     The Action class instance
 *
 * @return PackageConfig object for the Action class
 */
protected PackageConfig.Builder loadPackageConfig(String actionNamespace, String actionPackage, Class actionClass) {
    PackageConfig.Builder parent = null;
    // Check for the @Namespace annotation
    if (actionClass != null) {
        Namespace ns = (Namespace) actionClass.getAnnotation(Namespace.class);
        if (ns != null) {
            parent = loadPackageConfig(actionNamespace, actionPackage, null);
            actionNamespace = ns.value();
            actionPackage = actionClass.getName();
        // See if the namespace has been overridden by the @Action annotation
        } else {
            org.apache.struts2.config.Action actionAnn = (org.apache.struts2.config.Action) actionClass.getAnnotation(org.apache.struts2.config.Action.class);
            if (actionAnn != null && !actionAnn.DEFAULT_NAMESPACE.equals(actionAnn.namespace())) {
                // we pass null as the namespace in case the parent package hasn't been loaded yet
                parent = loadPackageConfig(null, actionPackage, null);
                actionPackage = actionClass.getName();
            }
        }
    }
    PackageConfig.Builder pkgConfig = packageLoader.getPackage(actionPackage);
    if (pkgConfig == null) {
        pkgConfig = new PackageConfig.Builder(actionPackage);
        pkgConfig.namespace(actionNamespace);
        if (parent == null) {
            PackageConfig cfg = configuration.getPackageConfig(defaultParentPackage);
            if (cfg != null) {
                pkgConfig.addParent(cfg);
            } else {
                throw new ConfigurationException("ClasspathPackageProvider: Unable to locate default parent package: " + defaultParentPackage);
            }
        }
        packageLoader.registerPackage(pkgConfig);
    // if the parent package was first created by a child, ensure the namespace is correct
    } else if (pkgConfig.getNamespace() == null) {
        pkgConfig.namespace(actionNamespace);
    }
    if (parent != null) {
        packageLoader.registerChildToParent(pkgConfig, parent);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("class:" + actionClass + " parent:" + parent + " current:" + (pkgConfig != null ? pkgConfig.getName() : ""));
    }
    return pkgConfig;
}
Also used : ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) org.apache.struts2.config(org.apache.struts2.config) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig)

Example 2 with ConfigurationException

use of com.opensymphony.xwork2.config.ConfigurationException in project Payara by payara.

the class HttpServiceStatsProviderBootstrap method postConstruct.

@Override
public void postConstruct() {
    if (config == null) {
        Object[] params = { VirtualServerInfoStatsProvider.class.getName(), HttpServiceStatsProvider.class.getName(), "http service", "virtual server" };
        logger.log(Level.SEVERE, LogFacade.UNABLE_TO_REGISTER_STATS_PROVIDERS, params);
        throw new ConfigurationException(rb.getString(LogFacade.NULL_CONFIG));
    }
    HttpService httpService = config.getHttpService();
    for (VirtualServer vs : httpService.getVirtualServer()) {
        String id = vs.getId();
        StatsProviderManager.register("http-service", PluginPoint.SERVER, "http-service/" + id, new VirtualServerInfoStatsProvider(vs));
        HttpServiceStatsProvider httpServiceStatsProvider = new HttpServiceStatsProvider(id, vs.getNetworkListeners(), config.getNetworkConfig());
        httpServiceStatsProviders.put(id, httpServiceStatsProvider);
        StatsProviderManager.register("http-service", PluginPoint.SERVER, "http-service/" + id + "/request", httpServiceStatsProvider);
    }
}
Also used : ConfigurationException(org.jvnet.hk2.config.ConfigurationException) HttpService(com.sun.enterprise.config.serverbeans.HttpService) VirtualServer(com.sun.enterprise.config.serverbeans.VirtualServer)

Example 3 with ConfigurationException

use of com.opensymphony.xwork2.config.ConfigurationException in project onebusaway-application-modules by camsys.

the class SpringContainer method register.

@Override
public void register(ContainerBuilder builder, LocatableProperties props) throws ConfigurationException {
    // Since we're about to override...
    builder.setAllowDuplicates(true);
    builder.factory(ObjectFactory.class, new Factory<ObjectFactory>() {

        public ObjectFactory create(Context xworkContext) throws Exception {
            SpringObjectFactory f = new SpringObjectFactory();
            xworkContext.getContainer().inject(f);
            f.setApplicationContext(_applicationContext);
            f.setAutowireStrategy(_autoWireStrategy);
            return f;
        }
    });
}
Also used : Context(com.opensymphony.xwork2.inject.Context) ApplicationContext(org.springframework.context.ApplicationContext) SpringObjectFactory(com.opensymphony.xwork2.spring.SpringObjectFactory) SpringObjectFactory(com.opensymphony.xwork2.spring.SpringObjectFactory) ObjectFactory(com.opensymphony.xwork2.ObjectFactory) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException)

Example 4 with ConfigurationException

use of com.opensymphony.xwork2.config.ConfigurationException in project qi4j-sdk by Qi4j.

the class Qi4jCodebehindPackageProvider method processActionClass.

/**
 * Create a default action mapping for a class instance.
 *
 * The namespace annotation is honored, if found, otherwise
 * the Java package is converted into the namespace
 * by changing the dots (".") to slashes ("/").
 *
 * @param cls  Action or POJO instance to process
 * @param pkgs List of packages that were scanned for Actions
 */
protected void processActionClass(Class<?> cls, String[] pkgs) {
    String name = cls.getName();
    String actionPackage = cls.getPackage().getName();
    String actionNamespace = null;
    String actionName = null;
    org.apache.struts2.config.Action actionAnn = (org.apache.struts2.config.Action) cls.getAnnotation(org.apache.struts2.config.Action.class);
    if (actionAnn != null) {
        actionName = actionAnn.name();
        if (actionAnn.namespace().equals(org.apache.struts2.config.Action.DEFAULT_NAMESPACE)) {
            actionNamespace = "";
        } else {
            actionNamespace = actionAnn.namespace();
        }
    } else {
        for (String pkg : pkgs) {
            if (name.startsWith(pkg)) {
                if (LOG.isDebugEnabled()) {
                    LOG.debug("ClasspathPackageProvider: Processing class " + name);
                }
                name = name.substring(pkg.length() + 1);
                actionNamespace = "";
                actionName = name;
                int pos = name.lastIndexOf('.');
                if (pos > -1) {
                    actionNamespace = "/" + name.substring(0, pos).replace('.', '/');
                    actionName = name.substring(pos + 1);
                }
                break;
            }
        }
        // Truncate Action suffix if found
        if (actionName.endsWith(getClassSuffix())) {
            actionName = actionName.substring(0, actionName.length() - getClassSuffix().length());
        }
        // Force initial letter of action to lowercase, if desired
        if ((forceLowerCase) && (actionName.length() > 1)) {
            int lowerPos = actionName.lastIndexOf('/') + 1;
            StringBuilder sb = new StringBuilder();
            sb.append(actionName.substring(0, lowerPos));
            sb.append(Character.toLowerCase(actionName.charAt(lowerPos)));
            sb.append(actionName.substring(lowerPos + 1));
            actionName = sb.toString();
        }
    }
    PackageConfig.Builder pkgConfig = loadPackageConfig(actionNamespace, actionPackage, cls);
    // In case the package changed due to namespace annotation processing
    if (!actionPackage.equals(pkgConfig.getName())) {
        actionPackage = pkgConfig.getName();
    }
    Annotation annotation = cls.getAnnotation(ParentPackage.class);
    if (annotation != null) {
        String parent = ((ParentPackage) annotation).value()[0];
        PackageConfig parentPkg = configuration.getPackageConfig(parent);
        if (parentPkg == null) {
            throw new ConfigurationException("ClasspathPackageProvider: Unable to locate parent package " + parent, annotation);
        }
        pkgConfig.addParent(parentPkg);
        if (!isNotEmpty(pkgConfig.getNamespace()) && isNotEmpty(parentPkg.getNamespace())) {
            pkgConfig.namespace(parentPkg.getNamespace());
        }
    }
    ResultTypeConfig defaultResultType = packageLoader.getDefaultResultType(pkgConfig);
    ActionConfig actionConfig = new ActionConfig.Builder(actionPackage, actionName, cls.getName()).addResultConfigs(new ResultMap<String, ResultConfig>(cls, actionName, defaultResultType)).build();
    pkgConfig.addActionConfig(actionName, actionConfig);
}
Also used : ActionConfig(com.opensymphony.xwork2.config.entities.ActionConfig) PackageConfig(com.opensymphony.xwork2.config.entities.PackageConfig) Annotation(java.lang.annotation.Annotation) ConfigurationException(com.opensymphony.xwork2.config.ConfigurationException) ResultTypeConfig(com.opensymphony.xwork2.config.entities.ResultTypeConfig) org.apache.struts2.config(org.apache.struts2.config)

Aggregations

ConfigurationException (com.opensymphony.xwork2.config.ConfigurationException)3 PackageConfig (com.opensymphony.xwork2.config.entities.PackageConfig)2 org.apache.struts2.config (org.apache.struts2.config)2 ObjectFactory (com.opensymphony.xwork2.ObjectFactory)1 ActionConfig (com.opensymphony.xwork2.config.entities.ActionConfig)1 ResultTypeConfig (com.opensymphony.xwork2.config.entities.ResultTypeConfig)1 Context (com.opensymphony.xwork2.inject.Context)1 SpringObjectFactory (com.opensymphony.xwork2.spring.SpringObjectFactory)1 HttpService (com.sun.enterprise.config.serverbeans.HttpService)1 VirtualServer (com.sun.enterprise.config.serverbeans.VirtualServer)1 Annotation (java.lang.annotation.Annotation)1 ConfigurationException (org.jvnet.hk2.config.ConfigurationException)1 ApplicationContext (org.springframework.context.ApplicationContext)1