⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avalonmailstore.java

📁 java mail,java mailjava mailjava mailjava mail
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     *                            Configuration or retrieving the      *                            MailRepository     */    public synchronized Object select(Object hint) throws ServiceException {        Configuration repConf = null;        try {            repConf = (Configuration) hint;        } catch (ClassCastException cce) {            throw new ServiceException("",                "hint is of the wrong type. Must be a Configuration", cce);        }        String destination = null;        String protocol = null;        try {            destination = repConf.getAttribute("destinationURL");            int idx = destination.indexOf(':');            if ( idx == -1 )                throw new ServiceException("",                    "destination is malformed. Must be a valid URL: "                    + destination);            protocol = destination.substring(0,idx);        } catch (ConfigurationException ce) {            throw new ServiceException("",                "Malformed configuration has no destinationURL attribute", ce);        }        try        {            String type = repConf.getAttribute("type");            String repID = destination + type;            Object reply = repositories.get(repID);            StringBuffer logBuffer = null;            if (reply != null) {                if (getLogger().isDebugEnabled()) {                    logBuffer =                        new StringBuffer(128)                                .append("obtained repository: ")                                .append(repID)                                .append(",")                                .append(reply.getClass());                    getLogger().debug(logBuffer.toString());                }                return reply;            } else {                String key = protocol + type;                String repClass = (String) classes.get( key );                if (getLogger().isDebugEnabled()) {                    logBuffer =                        new StringBuffer(128)                                .append("obtained repository: ")                                .append(repClass)                                .append(" to handle: ")                                .append(protocol)                                .append(",")                                .append(type);                    getLogger().debug( logBuffer.toString() );                }                // If default values have been set, create a new repository                // configuration element using the default values                // and the values in the selector.                // If no default values, just use the selector.                Configuration config;                Configuration defConf = (Configuration)defaultConfigs.get(key);                if ( defConf == null) {                    config = repConf;                }                else {                    config = new DefaultConfiguration(repConf.getName(),                                                      repConf.getLocation());                    copyConfig(defConf, (DefaultConfiguration)config);                    copyConfig(repConf, (DefaultConfiguration)config);                }                try {                    reply = this.getClass().getClassLoader().loadClass(repClass).newInstance();                    if (reply instanceof LogEnabled) {                       setupLogger(reply);                    }                    ContainerUtil.contextualize(reply,context);                    ContainerUtil.service(reply,m_manager);                    if (reply instanceof Composable) {                        final String error = "no implementation in place to support Composable";                        getLogger().error( error );                        throw new IllegalArgumentException( error );                    }                                        ContainerUtil.configure(reply,config);                    ContainerUtil.initialize(reply);                    repositories.put(repID, reply);                    if (getLogger().isInfoEnabled()) {                        logBuffer =                            new StringBuffer(128)                                .append("added repository: ")                                .append(repID)                                .append("->")                                .append(repClass);                        getLogger().info(logBuffer.toString());                    }                    return reply;                } catch (Exception e) {                    if (getLogger().isWarnEnabled()) {                        getLogger().warn( "Exception while creating repository:" +                                          e.getMessage(), e );                    }                    throw new                        ServiceException("", "Cannot find or init repository",                                           e);                }            }        } catch( final ConfigurationException ce ) {            throw new ServiceException("", "Malformed configuration", ce );        }    }    /**     * <p>Returns a new name for a repository.</p>     *     * <p>Synchronized on the AvalonMailStore.class object to ensure     * against duplication of the repository name</p>     *     * @return a new repository name     */    public static final String getName() {        synchronized (AvalonMailStore.class) {            return REPOSITORY_NAME + id++;        }    }    /**     * Returns whether the mail store has a repository corresponding to     * the passed in hint.     *     * @param hint the Configuration object used to look up the repository     *     * @return whether the mail store has a repository corresponding to this hint     */    public boolean isSelectable( Object hint ) {        Object comp = null;        try {            comp = select(hint);        } catch(ServiceException ex) {            if (getLogger().isErrorEnabled()) {                getLogger().error("Exception AvalonMailStore.hasComponent-" + ex.toString());            }        }        return (comp != null);    }    /**     * Copies values from one config into another, overwriting duplicate attributes     * and merging children.     *     * @param fromConfig the Configuration to be copied     * @param toConfig the Configuration to which data is being copied     */    private void copyConfig(Configuration fromConfig, DefaultConfiguration toConfig)    {        // Copy attributes        String[] attrs = fromConfig.getAttributeNames();        for ( int i = 0; i < attrs.length; i++ ) {            String attrName = attrs[i];            String attrValue = fromConfig.getAttribute(attrName, null);            toConfig.setAttribute(attrName, attrValue);        }        // Copy children        Configuration[] children = fromConfig.getChildren();        for ( int i = 0; i < children.length; i++ ) {            Configuration child = children[i];            String childName = child.getName();            Configuration existingChild = toConfig.getChild(childName, false);            if ( existingChild == null ) {                toConfig.addChild(child);            }            else {                copyConfig(child, (DefaultConfiguration)existingChild);            }        }        // Copy value        String val = fromConfig.getValue(null);        if ( val != null ) {            toConfig.setValue(val);        }    }    /**     * Return the <code>Component</code> when you are finished with it.  In this     * implementation it does nothing     *     * @param component The Component we are releasing.     */    public void release(Object component) {}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -