Package org.apache.avalon.framework.context

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


            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 {
                return getParameterAsInteger(paramName);
            } 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;
            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

                this.configurationFile = new DelayedRefreshSourceWrapper(urlSource,
                    1000L
                );

            } catch (IOException ioe) {
                throw new ContextException("Could not open configuration file.", ioe);
            } catch (Exception e) {
                throw new ContextException("contextualize(..) Exception", e);
            }
        }
    }
View Full Code Here

        // set up file
        m_persistentFile = new File(
                    ctx.getRealPath("/WEB-INF"),
                        DefaultEventRegistryImpl.PERSISTENT_FILE);
        if (m_persistentFile == null) {
            throw new ContextException("Could not obtain persistent file. " +
                "The cache event registry cannot be " +
                "used inside an unexpanded WAR file.");
        }
  }
View Full Code Here

    public void contextualize(Context context) throws ContextException {
        Request request = ContextHelper.getRequest(context);
        try {
            this.roles = PolicyUtil.getRoles(request);
        } catch (AccessControlException e) {
            throw new ContextException("Obtaining roles failed: ", e);
        }
        this.webappUrl = ServletHelper.getWebappURI(request);
    }
View Full Code Here

                urlSource.init((URL) context.get(Constants.CONTEXT_CONFIG_URL), null);
                this.configurationFile = new DelayedRefreshSourceWrapper(urlSource,
                                                                         1000L);

            } catch (IOException ioe) {
                throw new ContextException("Could not open configuration file.", ioe);
            } catch (Exception e) {
                throw new ContextException("contextualize(..) Exception", e);
            }
        }
    }
View Full Code Here

        // set up file
        m_persistentFile = new File(
                    ctx.getRealPath("/WEB-INF"),
                        DefaultEventRegistryImpl.PERSISTENT_FILE);
        if (m_persistentFile == null) {
            throw new ContextException("Could not obtain persistent file. " +
                "The cache event registry cannot be " +
                "used inside an unexpanded WAR file.");
        }
    }
View Full Code Here

        {
            return getName();
        }
        else
        {
            throw new ContextException( "Unknown key: " + key );
        }
    }
View Full Code Here

            try {
                File applicationHome =
                    (File)context.get(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

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.