Package org.apache.avalon.framework.configuration

Examples of org.apache.avalon.framework.configuration.Configuration


            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
        }

        // read local settings
        try {
            Configuration conf = this.getConfiguration (
                    parameters.getParameter ("descriptor", (String) this.settings.get("descriptor")), resolver,
            parameters.getParameterAsBoolean("reloadable", reloadable));
            String valstr = parameters.getParameter ("validate", (String) settings.get("validate",""));
            String valsetstr = parameters.getParameter ("validate-set", (String) settings.get("validate-set",""));
            Configuration[] desc = conf.getChildren ("parameter");
            Configuration[] csets = conf.getChildren ("constraint-set");
            HashMap actionMap = new HashMap ();
            HashMap resultMap = new HashMap ();
            boolean allOK = true;

            /*
             * old obsoleted method
             */
            if (!"".equals (valstr.trim ())) {
                if (getLogger().isDebugEnabled())
                    getLogger().debug ("Validating parameters "
                                       + "as specified via 'validate' parameter");
                /* get list of params to be validated */
                String[] rparams = null;
                if (!"*".equals(valstr.trim())) {
                    rparams = Tokenizer.tokenize (valstr, ",", false);
                } else {
                    // validate _all_ parameters
                    rparams = new String[desc.length];
                    for (int i=0; i<desc.length; i++) {
                        rparams[i] = desc[i].getAttribute("name","");
                        if ("".equals(rparams[i])) {
                            if (getLogger().isDebugEnabled())
                                getLogger().debug ("Wrong syntax of the 'validate' parameter");
                            return null;
                        }
                    }
                }
                /* perform actual validation */
                ValidatorActionHelper result = null;
                String name = null;
                HashMap params = new HashMap (rparams.length);
                /* put required params into hash */
                for (int i = 0; i < rparams.length; i ++) {
                    name = rparams[i];
                    if (name == null || "".equals (name.trim ())) {
                        if (getLogger().isDebugEnabled())
                            getLogger().debug ("Wrong syntax of the 'validate' parameter");
                        return null;
                    }
                    name = name.trim ();
                    params.put (name, req.getParameter (name));
                }
                for (int i = 0; i < rparams.length; i ++) {
                    name = rparams[i].trim ();
                    result = validateParameter (name, null, desc,
                                                params, true);
                    if (!result.isOK()) {
                        if (getLogger().isDebugEnabled())
                            getLogger().debug ("Validation failed for parameter " + name);
                        allOK = false;
                    }
                    actionMap.put (name, result.getObject());
                    resultMap.put (name, result.getResult());
                }
            }
            /*
             * new set-based method
             */
            if (!"".equals (valsetstr.trim ())) {
                if (getLogger().isDebugEnabled())
                    getLogger().debug ("Validating parameters "
                                       + "from given constraint-set " + valsetstr);
                // go over all constraint sets
                // untill the requested set is found
                // set number will be in j
                Configuration cset = null;
                String setname = null;
                int j = 0;
                boolean found = false;
                for (j = 0; j < csets.length; j ++) {
                    setname = csets[j].getAttribute ("name", "");
                    if (valsetstr.trim().equals (setname.trim ())) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    if (getLogger().isDebugEnabled())
                        getLogger().debug ("Given set "
                                           + valsetstr
                                           + " does not exist in a description file");
                    return null;
                }
                cset = csets[j];
                /* get the list of params to be validated */
                Configuration[] set = cset.getChildren ("validate");

                /* perform actuall validation */
                ValidatorActionHelper result = null;
                String name = null;
                HashMap params = new HashMap (set.length);
View Full Code Here


        //      in this case the elements catalogue-name and catalogue-location specify
        //      the catalogue to be used
        //  (2) the new one supporting mulitple catalogues

        // obtain the base name of the message catalogue
        Configuration child = conf.getChild(I18N_CATALOGUE_NAME);
        catalogueName = child.getValue(null);

        // obtain the directory location of message catalogues
        child = conf.getChild(I18N_CATALOGUE_LOCATION);
        catalogueLocation = child.getValue(null);

        Configuration cataloguesConf = conf.getChild("catalogues", false);

        if ((catalogueName != null || catalogueLocation != null) && cataloguesConf != null) {
            // if old and new style configuration are used at the same time...
            throw new ConfigurationException("I18nTransformer: old and new configuration style are used at the same time. Use either the 'catalogue-name' and 'catalogue-location' elements or use the 'catalogues' element, but don't use both at the same time.");
        } else if (catalogueName != null || catalogueLocation != null) {
            if (!(catalogueName != null && catalogueLocation != null))
                throw new ConfigurationException("I18nTransformer: catalogue-name and catalogue-location must both be specified");
            if (getLogger().isDebugEnabled())
                getLogger().debug("using old-style configuration: name = " + catalogueName
                        + ", location = " + catalogueLocation);
        } else if (cataloguesConf == null) {
            // if both old and new style configuration are missing ...
            throw new ConfigurationException("Missing configuration for the I18nTransformer: a 'catalogues' element specifying the catalogues is required.");
        } else {
            // new configuration style
            Configuration[] catalogueConfs = cataloguesConf.getChildren("catalogue");
            for (int i = 0; i < catalogueConfs.length; i++) {
                String id = catalogueConfs[i].getAttribute("id");
                String name = catalogueConfs[i].getAttribute("name");
                String location = catalogueConfs[i].getAttribute("location");
                CatalogueInfo newCatalogueInfo;
                try {
                    newCatalogueInfo = new CatalogueInfo(name, location);
                } catch (PatternException e) {
                    throw new ConfigurationException("I18nTransformer: error in name or location attribute on catalogue element with id " + id, e);
                }
                catalogues.put(id, newCatalogueInfo);
            }

            defaultCatalogueId = cataloguesConf.getAttribute("default");
            if (!catalogues.containsKey(defaultCatalogueId))
                throw new ConfigurationException("I18nTransformer: default catalogue id '" + defaultCatalogueId + "' denotes a nonexisting catalogue");
        }

        // obtain default text to use for untranslated messages
View Full Code Here

        bytes = new byte[CONTINUATION_ID_LENGTH];
    }

    public void configure(Configuration config) {
        defaultTimeToLive = config.getAttributeAsInteger("time-to-live", (3600 * 1000));
        Configuration expireConf = config.getChild("expirations-check");

        try {
            ContinuationInterrupt interrupt = new ContinuationInterrupt(expireConf);
            m_commandSink.enqueue(interrupt);
        } catch (Exception ex) {
View Full Code Here

        if (this.documents == null)
            this.documents = Collections.synchronizedMap(new HashMap());

        if (!this.documents.containsKey(src)) {
            if (modeConf != null) {
                final Configuration fileConf = modeConf.getChild("file");
                reload = fileConf.getAttributeAsBoolean("reloadable",reload);
                cache = fileConf.getAttributeAsBoolean("cacheable",cache);
                if (fileConf.getAttribute("cachable", null) != null) {
                    throw new ConfigurationException(
                            "Bzzt! Wrong spelling at "+fileConf.getLocation()+": please use 'cacheable', not 'cachable'");
                }

            }
            this.documents.put(src, new DocumentHelper(reload, cache, src));
        }
View Full Code Here

            }

            InputStream is = this.servletContext.getResourceAsStream(logkitConfig);
            if (is == null) is = new FileInputStream(logkitConfig);
            final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
            final Configuration conf = builder.build(is);
            logKitManager.configure(conf);
        } catch (Exception e) {
            Hierarchy.getDefaultHierarchy().log("Could not set up Cocoon Logger, will use screen instead", e);
        }
View Full Code Here

            throw new ServletException("Please define the init-param 'instrumentation-config' in your web.xml");
        }

        final InputStream is = this.servletContext.getResourceAsStream(imConfig);
        final DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder();
        final Configuration conf = builder.build(is);

        // Get the logger for the instrument manager
        Logger imLogger =
            this.logKitManager.getLogger(conf.getAttribute( "logger", "core.instrument" ));

        // Set up the Instrument Manager
        DefaultInstrumentManager instrumentManager = new DefaultInstrumentManager();
        instrumentManager.enableLogging(new LogKitLogger(imLogger));
        instrumentManager.configure(conf);
View Full Code Here

            if (getLogger().isWarnEnabled())
                getLogger().warn("No input module given. FAILING");
            return null;
        }

        Configuration inputConfig = null;
        String inputName=null;
        Mapping mapping = this.mapping;
        String prefix = this.prefix;
        String suffix = this.suffix;
        String rmPrefix = this.rmPrefix;
View Full Code Here

            if (getLogger().isWarnEnabled())
                getLogger().warn("No input module given. FAILING");
            return null;
        }

        Configuration inputConfig = null;
        String inputName=null;
        Mapping mapping = this.mapping;
        String prefix = this.prefix;
        String suffix = this.suffix;
        String rmPrefix = this.rmPrefix;
View Full Code Here

            if (getLogger().isWarnEnabled())
                getLogger().warn("No input module given. FAILING");
            return null;
        }

        Configuration inputConfig = null;
        String inputName=null;
        Mapping mapping = this.mapping;
        String prefix = this.prefix;
        String suffix = this.suffix;
        String rmPrefix = this.rmPrefix;
View Full Code Here

     */
    protected ComponentManager createComponentManager(Configuration tree) throws Exception {

        // Get the map:component node
        // Don't check namespace here : this will be done by node builders
        Configuration config = tree.getChild("components", false);

        if (config == null) {
            if (this.getLogger().isDebugEnabled()) {
                getLogger().debug("Sitemap has no components definition at " + tree.getLocation());
            }
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.configuration.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.