Package org.apache.avalon.framework.context

Examples of org.apache.avalon.framework.context.ContextException


            try {
                Integer i = (Integer) ctx.get("param-integer:" + CONTEXT_ID_ENTRY);
                this.msgId = i.intValue();
            } catch (ContextException ce) {
                String message = "Missing mandatory context entry " + String.valueOf(CONTEXT_ID_ENTRY);
                throw new ContextException(message);
            }
        }
View Full Code Here


            this.aFolder = mctx.getTheFolder(CONTEXT_FOLDER_ENTRY);

            Integer i = (Integer) ctx.get("param-integer:" + CONTEXT_ID_ENTRY);
            if (i == null) {
                String message = "Missing mandatory context entry " + String.valueOf(CONTEXT_ID_ENTRY);
                throw new ContextException(message);
            }
            this.msgId = i.intValue();

            i = (Integer) ctx.get("param-integer:" + CONTEXT_PARTID_ENTRY);
            if (i == null) {
                String message = "Missing mandatory context entry " + String.valueOf(CONTEXT_PARTID_ENTRY);
                throw new ContextException(message);
            }
            this.partId = i.intValue();
        }
View Full Code Here

        if (keyString.startsWith(PARAM_PREFIX_ENTRY)) {
            String paramName = keyString.substring(PARAM_PREFIX_ENTRY.length());
            String paramValue = getParameter(paramName);
            if (paramValue == null) {
                String message = "No parameter " + String.valueOf(keyString) + " available.";
                throw new ContextException(message);
            }
            return paramValue;
        } else if (keyString.startsWith(PARAM_INTEGER_PREFIX_ENTRY)) {
            String paramName = keyString.substring(PARAM_INTEGER_PREFIX_ENTRY.length());
            try {
                Integer paramValue = getParameterAsInteger(paramName);
                return paramValue;
            } catch (NumberFormatException nfe) {
                String message = "Cannot create Integer for parameter " + String.valueOf(keyString);
                throw new ContextException(message, nfe);
            }
        } else if (keyString.startsWith(PARAM_FOLDER_PREFIX_ENTRY)) {
            String paramName = keyString.substring(PARAM_FOLDER_PREFIX_ENTRY.length());
            String folderName = getParameter(paramName);
            if (folderName == null) {
                // no folderName is available in the parameters bag
                // try to get the current working folder
                try {
                    folderName = (String) super.get(MAIL_CURRENT_WORKING_FOLDER_ENTRY);
                } catch (ContextException ce) {
                    // no current working folder entry available
                    String message = "No " + MAIL_CURRENT_WORKING_FOLDER_ENTRY + " entry available ";
                    getLogger().error(message);
                    throw new ContextException(message, ce);
                }
            }

            // get folder object, folderName is okay
            Folder folder = null;
            try {
                folder = (Folder) getFolder(folderName);
            } catch (ContextException ce) {
                // folder is not stored yet

                Store store = (Store) get(MAIL_STORE_ENTRY);
                // get folder, eventually connect the store
                try {
                    if (!store.isConnected()) {
                        store.connect();
                    }
                    final String DEFAULT_FOLDER_NAME = "~";

                    // empty folder name is specified by empty string, or "~"
                    if (folderName.equals(DEFAULT_FOLDER_NAME) || folderName.length() == 0) {
                        folder = store.getDefaultFolder();
                    } else {
                        folder = store.getFolder(folderName);
                    }

                    // save the Folder, for later access
                    putFolder(folder);
                } catch (MessagingException me) {
                    String message = "Cannot get folder " + String.valueOf(folderName);
                    throw new ContextException(message, ce);
                }
            }
            return folder;
        } else {
            return super.get(key);
View Full Code Here

        Folder f;
        try {
            f = (Folder) get("param-folder:" + entry);
        } catch (Exception e) {
            String message = "Cannot get Folder object for " + String.valueOf(entry);
            throw new ContextException(message, e);
        }
        return f;
    }
View Full Code Here

            try {
                File applicationHome =
                    (File)context.get(AvalonContextConstants.APPLICATION_HOME);
                baseDirectory = applicationHome.toString();
            } catch (ContextException ce) {
                throw new ContextException("Encountered exception when resolving application home in Avalon context.", ce);
            } catch (ClassCastException cce) {
                throw new ContextException("Application home object stored in Avalon context was not of type java.io.File.", cce);
            }
            StringBuffer fileNameBuffer =
                new StringBuffer(128)
                    .append(baseDirectory)
                    .append(File.separator)
                            .append(fileName);
            fileName = fileNameBuffer.toString();
        }
        try {
            File returnValue = (new File(fileName)).getCanonicalFile();
            return returnValue;
        } catch (IOException ioe) {
            throw new ContextException("Encountered an unexpected exception while retrieving file.", ioe);
        }
    }
View Full Code Here

            baseDirectory = ((File)context.get( "app.home") ).getCanonicalPath();
        }
        catch (Throwable e)
        {
            getLogger().error( "can't get base directory for mailet loader" );
            throw new ContextException("can't contextualise mailet loader " + e.getMessage(), e);
        }
    }
View Full Code Here

            try {
                File applicationHome =
                    (File)context.get(AvalonContextConstants.APPLICATION_HOME);
                baseDirectory = applicationHome.toString();
            } catch (ContextException ce) {
                throw new ContextException("Encountered exception when resolving application home in Avalon context.", ce);
            } catch (ClassCastException cce) {
                throw new ContextException("Application home object stored in Avalon context was not of type java.io.File.", cce);
            }
            StringBuffer fileNameBuffer =
                new StringBuffer(128)
                    .append(baseDirectory)
                    .append(File.separator)
                            .append(fileName);
            fileName = fileNameBuffer.toString();
        }
        try {
            File returnValue = (new File(fileName)).getCanonicalFile();
            return returnValue;
        } catch (IOException ioe) {
            throw new ContextException("Encountered an unexpected exception while retrieving file.", ioe);
        }
    }
View Full Code Here

            baseDirectory = ((File)context.get( "app.home") ).getCanonicalPath();
        }
        catch (Throwable e)
        {
            getLogger().error( "can't get base directory for mailet loader" );
            throw new ContextException("can't contextualise mailet loader " + e.getMessage(), e);
        }
    }
View Full Code Here

                (org.apache.cocoon.environment.Context) context.get(
                                    Constants.CONTEXT_ENVIRONMENT_CONTEXT);
        // set up file
        String path = ctx.getRealPath(PERSISTENT_FILE);
        if (path == null) {
            throw new ContextException("The cache event registry cannot be used inside an unexpanded WAR file. " +
                                       "Real path for <" + PERSISTENT_FILE + "> is null.");
        }

        m_persistentFile = new File(path);
    }
View Full Code Here

    public Object get( final Object key )
    throws ContextException {
        if ( ContextHelper.CONTEXT_OBJECT_MODEL.equals(key)) {
            final Environment env = CocoonComponentManager.getCurrentEnvironment();
            if ( env == null ) {
                throw new ContextException("Unable to locate " + key + " (No environment available)");
            }
            return env.getObjectModel();
        } else if ( ContextHelper.CONTEXT_SITEMAP_SERVICE_MANAGER.equals(key)) {
            final ComponentManager manager = CocoonComponentManager.getSitemapComponentManager();
            if ( manager == null ) {
                throw new ContextException("Unable to locate " + key + " (No environment available)");
            }
            return new ComponentManagerWrapper(manager);
        }
        if ( key instanceof String ) {
            String stringKey = (String)key;
            if ( stringKey.startsWith(OBJECT_MODEL_KEY_PREFIX) ) {
                final Environment env = CocoonComponentManager.getCurrentEnvironment();
                if ( env == null ) {
                    throw new ContextException("Unable to locate " + key + " (No environment available)");
                }
                final Map objectModel = env.getObjectModel();
                String objectKey = stringKey.substring(OBJECT_MODEL_KEY_PREFIX.length());
               
                Object o = objectModel.get( objectKey );
                if ( o == null ) {
                    final String message = "Unable to locate " + key;
                    throw new ContextException( message );
                }
                return o;
            }
        }
        return super.get( key );
View Full Code Here

TOP

Related Classes of org.apache.avalon.framework.context.ContextException

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.