avalonmailstore.java
来自「邮件服务器系统 支持SMTP POP3 是著名的Apache写 有一定的参考」· Java 代码 · 共 424 行 · 第 1/2 页
JAVA
424 行
public synchronized Component select(Object hint) throws ComponentException { Configuration repConf = null; try { repConf = (Configuration) hint; } catch (ClassCastException cce) { throw new ComponentException( "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 ComponentException( "destination is malformed. Must be a valid URL: " + destination); protocol = destination.substring(0,idx); } catch (ConfigurationException ce) { throw new ComponentException( "Malformed configuration has no destinationURL attribute", ce); } try { String type = repConf.getAttribute("type"); String repID = destination + type; MailRepository reply = (MailRepository) 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 (Component)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 = (MailRepository) this.getClass().getClassLoader().loadClass(repClass).newInstance(); if (reply instanceof LogEnabled) { setupLogger(reply); } if (reply instanceof Contextualizable) { ((Contextualizable) reply).contextualize(context); } if (reply instanceof Composable) { ((Composable) reply).compose( componentManager ); } if (reply instanceof Configurable) { ((Configurable) reply).configure(config); } if (reply instanceof Initializable) { ((Initializable) reply).initialize(); } repositories.put(repID, reply); if (getLogger().isInfoEnabled()) { logBuffer = new StringBuffer(128) .append("added repository: ") .append(repID) .append("->") .append(repClass); getLogger().info(logBuffer.toString()); } return (Component)reply; } catch (Exception e) { if (getLogger().isWarnEnabled()) { getLogger().warn( "Exception while creating repository:" + e.getMessage(), e ); } throw new ComponentException("Cannot find or init repository", e); } } } catch( final ConfigurationException ce ) { throw new ComponentException( "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 the mail spool associated with this AvalonMailStore * * @return the mail spool * * @throws IllegalStateException if the inbound spool has not * yet been set */ public SpoolRepository getInboundSpool() { if (inboundSpool != null) { return inboundSpool; } else { throw new IllegalStateException("Inbound spool not defined"); } } /** * 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 hasComponent( Object hint ) { Component comp = null; try { comp = select(hint); } catch(ComponentException 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(Component component) {}}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?