Modified: james/server/trunk/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/domainlist/lib/AbstractDomainList.java Mon Apr 4 12:26:35 2011 @@ -17,8 +17,6 @@ * under the License. * ****************************************************************/ - - package org.apache.james.domainlist.lib; import java.net.InetAddress; @@ -40,81 +38,78 @@ import org.apache.james.lifecycle.api.Lo import org.slf4j.Logger; /** - * All implementations of the DomainList interface should extends this abstract class + * All implementations of the DomainList interface should extends this abstract + * class */ -public abstract class AbstractDomainList implements DomainList, LogEnabled, Configurable { +public abstract class AbstractDomainList implements DomainList, LogEnabled, Configurable { private DNSService dns; private boolean autoDetect = true; private boolean autoDetectIP = true; private Logger logger; private String defaultDomain; - - @Resource(name="dnsservice") + + @Resource(name = "dnsservice") public void setDNSService(DNSService dns) { this.dns = dns; } - - + public void setLog(Logger logger) { this.logger = logger; } - + protected Logger getLogger() { return logger; } - - public void configure(HierarchicalConfiguration config) throws ConfigurationException { - defaultDomain = config.getString("defaultDomain","localhost"); + defaultDomain = config.getString("defaultDomain", "localhost"); - setAutoDetect(config.getBoolean("autodetect", true)); - setAutoDetectIP(config.getBoolean("autodetectIP", true)); + setAutoDetect(config.getBoolean("autodetect", true)); + setAutoDetectIP(config.getBoolean("autodetectIP", true)); } - /* * (non-Javadoc) + * * @see org.apache.james.domainlist.api.DomainList#getDefaultDomain() */ - public String getDefaultDomain() throws DomainListException{ + public String getDefaultDomain() throws DomainListException { return defaultDomain; } - /* * (non-Javadoc) + * * @see org.apache.james.api.domainlist.DomainList#getDomains() */ - public String[] getDomains() throws DomainListException{ + public String[] getDomains() throws DomainListException { List<String> domains = getDomainListInternal(); if (domains != null) { - + String hostName = null; try { hostName = getDNSServer().getHostName(getDNSServer().getLocalHost()); - } catch (UnknownHostException ue) { + } catch (UnknownHostException ue) { hostName = "localhost"; } - + getLogger().info("Local host is: " + hostName); - + if (autoDetect == true && (!hostName.equals("localhost"))) { domains.add(hostName.toLowerCase(Locale.US)); } - if (autoDetectIP == true) { - domains.addAll(getDomainsIP(domains,dns,getLogger())); + domains.addAll(getDomainsIP(domains, dns, getLogger())); } - + if (getLogger().isInfoEnabled()) { - for (Iterator<String> i = domains.iterator(); i.hasNext(); ) { + for (Iterator<String> i = domains.iterator(); i.hasNext();) { getLogger().debug("Handling mail for: " + i.next()); } - } + } if (domains.isEmpty()) { - return null; + return null; } else { return domains.toArray(new String[domains.size()]); } @@ -122,38 +117,38 @@ public abstract class AbstractDomainList return null; } } - - + /** * Return a List which holds all ipAddress of the domains in the given List * - * @param domains List of domains + * @param domains + * List of domains * @return domainIP List of ipaddress for domains */ - private static List<String> getDomainsIP(List<String> domains,DNSService dns,Logger log) { + private static List<String> getDomainsIP(List<String> domains, DNSService dns, Logger log) { List<String> domainIP = new ArrayList<String>(); - if (domains.size() > 0 ) { + if (domains.size() > 0) { for (int i = 0; i < domains.size(); i++) { - List<String> domList = getDomainIP(domains.get(i).toString(),dns,log); - - for(int i2 = 0; i2 < domList.size();i2++) { - if(domainIP.contains(domList.get(i2)) == false) { + List<String> domList = getDomainIP(domains.get(i).toString(), dns, log); + + for (int i2 = 0; i2 < domList.size(); i2++) { + if (domainIP.contains(domList.get(i2)) == false) { domainIP.add(domList.get(i2)); } } } } - return domainIP; + return domainIP; } - + /** * @see #getDomainsIP(List, DNSService, Logger) */ private static List<String> getDomainIP(String domain, DNSService dns, Logger log) { List<String> domainIP = new ArrayList<String>(); try { - InetAddress[] addrs = dns.getAllByName(domain); - for (int j = 0; j < addrs.length ; j++) { + InetAddress[] addrs = dns.getAllByName(domain); + for (int j = 0; j < addrs.length; j++) { String ip = addrs[j].getHostAddress(); if (domainIP.contains(ip) == false) { domainIP.add(ip); @@ -164,33 +159,31 @@ public abstract class AbstractDomainList } return domainIP; } - /** - * Set to true to autodetect the hostname of the host on which - * james is running, and add this to the domain service - * Default is true + * Set to true to autodetect the hostname of the host on which james is + * running, and add this to the domain service Default is true * - * @param autodetect set to false for disable + * @param autodetect + * set to false for disable */ public synchronized void setAutoDetect(boolean autoDetect) { getLogger().info("Set autodetect to: " + autoDetect); this.autoDetect = autoDetect; } - - + /** - * Set to true to lookup the ipaddresses for each given domain - * and add these to the domain service - * Default is true + * Set to true to lookup the ipaddresses for each given domain and add these + * to the domain service Default is true * - * @param autodetectIP set to false for disable + * @param autodetectIP + * set to false for disable */ public synchronized void setAutoDetectIP(boolean autoDetectIP) { getLogger().info("Set autodetectIP to: " + autoDetectIP); this.autoDetectIP = autoDetectIP; } - + /** * Return dnsServer * @@ -199,7 +192,7 @@ public abstract class AbstractDomainList protected DNSService getDNSServer() { return dns; } - + /** * Return domainList *
Modified: james/server/trunk/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/mailrepository/lib/AbstractMailRepository.java Mon Apr 4 12:26:35 2011 @@ -17,8 +17,6 @@ * under the License. * ****************************************************************/ - - package org.apache.james.mailrepository.lib; import org.apache.commons.configuration.ConfigurationException; @@ -36,7 +34,8 @@ import java.util.Collection; import java.util.Iterator; /** - * This class represent an AbstractMailRepository. All MailRepositories should extend this class. + * This class represent an AbstractMailRepository. All MailRepositories should + * extend this class. */ public abstract class AbstractMailRepository implements MailRepository, LogEnabled, Configurable { @@ -44,31 +43,29 @@ public abstract class AbstractMailReposi * Whether 'deep debugging' is turned on. */ protected static final boolean DEEP_DEBUG = false; - + /** * A lock used to control access to repository elements, locking access - * based on the key + * based on the key */ private final Lock lock = new Lock();; - + private Logger logger; - public void setLog(Logger logger) { this.logger = logger; } - + protected Logger getLogger() { return logger; } - - public void configure(HierarchicalConfiguration configuration) throws ConfigurationException{ + + public void configure(HierarchicalConfiguration configuration) throws ConfigurationException { doConfigure(configuration); } - protected void doConfigure(HierarchicalConfiguration config) throws ConfigurationException { - + } /** @@ -77,14 +74,7 @@ public abstract class AbstractMailReposi public boolean unlock(String key) { if (lock.unlock(key)) { if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { - StringBuffer debugBuffer = - new StringBuffer(256) - .append("Unlocked ") - .append(key) - .append(" for ") - .append(Thread.currentThread().getName()) - .append(" @ ") - .append(new java.util.Date(System.currentTimeMillis())); + StringBuffer debugBuffer = new StringBuffer(256).append("Unlocked ").append(key).append(" for ").append(Thread.currentThread().getName()).append(" @ ").append(new java.util.Date(System.currentTimeMillis())); getLogger().debug(debugBuffer.toString()); } return true; @@ -99,14 +89,7 @@ public abstract class AbstractMailReposi public boolean lock(String key) { if (lock.lock(key)) { if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { - StringBuffer debugBuffer = - new StringBuffer(256) - .append("Locked ") - .append(key) - .append(" for ") - .append(Thread.currentThread().getName()) - .append(" @ ") - .append(new java.util.Date(System.currentTimeMillis())); + StringBuffer debugBuffer = new StringBuffer(256).append("Locked ").append(key).append(" for ").append(Thread.currentThread().getName()).append(" @ ").append(new java.util.Date(System.currentTimeMillis())); getLogger().debug(debugBuffer.toString()); } return true; @@ -115,7 +98,6 @@ public abstract class AbstractMailReposi } } - /** * @see org.apache.james.mailrepository.api.MailRepository#store(Mail) */ @@ -123,28 +105,24 @@ public abstract class AbstractMailReposi boolean wasLocked = true; String key = mc.getName(); try { - synchronized(this) { - wasLocked = lock.isLocked(key); - if (!wasLocked) { - //If it wasn't locked, we want a lock during the store - lock(key); - } + synchronized (this) { + wasLocked = lock.isLocked(key); + if (!wasLocked) { + // If it wasn't locked, we want a lock during the store + lock(key); + } } internalStore(mc); if ((DEEP_DEBUG) && (getLogger().isDebugEnabled())) { - StringBuffer logBuffer = - new StringBuffer(64) - .append("Mail ") - .append(key) - .append(" stored."); + StringBuffer logBuffer = new StringBuffer(64).append("Mail ").append(key).append(" stored."); getLogger().debug(logBuffer.toString()); } } catch (MessagingException e) { - getLogger().error("Exception caught while storing mail "+key,e); + getLogger().error("Exception caught while storing mail " + key, e); throw e; } catch (Exception e) { - getLogger().error("Exception caught while storing mail "+key,e); - throw new MessagingException("Exception caught while storing mail "+key,e); + getLogger().error("Exception caught while storing mail " + key, e); + throw new MessagingException("Exception caught while storing mail " + key, e); } finally { if (!wasLocked) { // If it wasn't locked, we need to unlock now @@ -156,13 +134,11 @@ public abstract class AbstractMailReposi } } - /** * @see #store(Mail) */ protected abstract void internalStore(Mail mc) throws MessagingException, IOException; - /** * @see org.apache.james.mailrepository.api.MailRepository#remove(Mail) */ @@ -170,12 +146,11 @@ public abstract class AbstractMailReposi remove(mail.getName()); } - /** * @see org.apache.james.mailrepository.api.MailRepository#remove(Collection) */ public void remove(Collection<Mail> mails) throws MessagingException { - Iterator<Mail>delList = mails.iterator(); + Iterator<Mail> delList = mails.iterator(); while (delList.hasNext()) { remove(delList.next()); } @@ -192,20 +167,14 @@ public abstract class AbstractMailReposi unlock(key); } } else { - StringBuffer exceptionBuffer = - new StringBuffer(64) - .append("Cannot lock ") - .append(key) - .append(" to remove it"); + StringBuffer exceptionBuffer = new StringBuffer(64).append("Cannot lock ").append(key).append(" to remove it"); throw new MessagingException(exceptionBuffer.toString()); } } - /** * @see #remove(String) */ protected abstract void internalRemove(String key) throws MessagingException; - } Modified: james/server/trunk/data-library/src/main/java/org/apache/james/mailrepository/lib/Lock.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/mailrepository/lib/Lock.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/mailrepository/lib/Lock.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/mailrepository/lib/Lock.java Mon Apr 4 12:26:35 2011 @@ -17,15 +17,12 @@ * under the License. * ****************************************************************/ - - package org.apache.james.mailrepository.lib; import java.util.Hashtable; /** * Provides Lock functionality - * */ public class Lock { /** @@ -35,8 +32,9 @@ public class Lock { /** * Check to see if the object is locked - * - * @param key the Object on which to check the lock + * + * @param key + * the Object on which to check the lock * @return true if the object is locked, false otherwise */ public boolean isLocked(final Object key) { @@ -45,12 +43,13 @@ public class Lock { /** * Check to see if we can lock on a given object. - * - * @param key the Object on which to lock + * + * @param key + * the Object on which to lock * @return true if the calling thread can lock, false otherwise */ public boolean canI(final Object key) { - Object o = locks.get( key ); + Object o = locks.get(key); if (null == o || o == this.getCallerId()) { return true; @@ -61,14 +60,15 @@ public class Lock { /** * Lock on a given object. - * - * @param key the Object on which to lock + * + * @param key + * the Object on which to lock * @return true if the locking was successful, false otherwise */ public boolean lock(final Object key) { Object theLock; - synchronized(this) { + synchronized (this) { theLock = locks.get(key); if (null == theLock) { @@ -84,8 +84,9 @@ public class Lock { /** * Release the lock on a given object. - * - * @param key the Object on which the lock is held + * + * @param key + * the Object on which the lock is held * @return true if the unlocking was successful, false otherwise */ public boolean unlock(final Object key) { @@ -106,7 +107,7 @@ public class Lock { /** * Private helper method to abstract away caller ID. - * + * * @return the id of the caller (i.e. the Thread reference) */ private Object getCallerId() { Modified: james/server/trunk/data-library/src/main/java/org/apache/james/repository/api/ObjectRepository.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/repository/api/ObjectRepository.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/repository/api/ObjectRepository.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/repository/api/ObjectRepository.java Mon Apr 4 12:26:35 2011 @@ -21,18 +21,17 @@ package org.apache.james.repository.api; import java.util.Iterator; -public interface ObjectRepository extends Repository{ +public interface ObjectRepository extends Repository { boolean containsKey(String key); - + Object get(String key); - + Object get(String key, ClassLoader loader); - Iterator<String> list(); - + void put(String key, Object value); - + void remove(String key); } Modified: james/server/trunk/data-library/src/main/java/org/apache/james/repository/api/StreamRepository.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/repository/api/StreamRepository.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/repository/api/StreamRepository.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/repository/api/StreamRepository.java Mon Apr 4 12:26:35 2011 @@ -23,13 +23,13 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Iterator; -public interface StreamRepository extends Repository{ +public interface StreamRepository extends Repository { InputStream get(String key); - + Iterator<String> list(); - + OutputStream put(String key); - + void remove(String key); } Modified: james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/AbstractFileRepository.java Mon Apr 4 12:26:35 2011 @@ -17,8 +17,6 @@ * under the License. * ****************************************************************/ - - package org.apache.james.repository.file; import org.apache.commons.configuration.ConfigurationException; @@ -46,25 +44,21 @@ import javax.annotation.Resource; /** * This an abstract class implementing functionality for creating a file-store. - * */ -public abstract class AbstractFileRepository - implements Repository, Configurable, LogEnabled { - +public abstract class AbstractFileRepository implements Repository, Configurable, LogEnabled { + protected static final boolean DEBUG = false; protected static final int BYTE_MASK = 0x0f; - - protected static final char[] HEX_DIGITS = new char[] { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' - }; + + protected static final char[] HEX_DIGITS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; protected String m_extension; - + protected String m_name; - + protected FilenameFilter m_filter; - + protected File m_baseDirectory; private FileSystem fileSystem; @@ -72,70 +66,63 @@ public abstract class AbstractFileReposi private Logger logger; private String destination; - - public void configure(HierarchicalConfiguration configuration) throws ConfigurationException{ - destination = configuration.getString( "[@destinationURL]" ); - } - - - @Resource(name="filesystem") + + public void configure(HierarchicalConfiguration configuration) throws ConfigurationException { + destination = configuration.getString("[@destinationURL]"); + } + + @Resource(name = "filesystem") public void setFileSystem(FileSystem fileSystem) { this.fileSystem = fileSystem; } - + public void setLog(Logger logger) { this.logger = logger; } - + protected Logger getLogger() { return logger; } - + protected abstract String getExtensionDecorator(); @PostConstruct - public void init() - throws Exception - { + public void init() throws Exception { - getLogger().info( "Init " + getClass().getName() + " Store" ); - setDestination( destination ); + getLogger().info("Init " + getClass().getName() + " Store"); + setDestination(destination); File directory; - try - { + try { directory = m_baseDirectory.getCanonicalFile(); + } catch (final IOException ioe) { + throw new ConfigurationException("Unable to form canonical representation of " + m_baseDirectory); } - catch( final IOException ioe ) - { - throw new ConfigurationException( "Unable to form canonical representation of " + - m_baseDirectory ); - } - - + m_name = "Repository"; String m_postfix = getExtensionDecorator(); m_extension = "." + m_name + m_postfix; m_filter = new ExtensionFileFilter(m_extension); - //m_filter = new NumberedRepositoryFileFilter(getExtensionDecorator()); + // m_filter = new NumberedRepositoryFileFilter(getExtensionDecorator()); directory.mkdirs(); - getLogger().info( getClass().getName() + " opened in " + m_baseDirectory ); + getLogger().info(getClass().getName() + " opened in " + m_baseDirectory); - //We will look for all numbered repository files in this - // directory and rename them to non-numbered repositories, - // logging all the way. + // We will look for all numbered repository files in this + // directory and rename them to non-numbered repositories, + // logging all the way. FilenameFilter num_filter = new NumberedRepositoryFileFilter(getExtensionDecorator()); - final String[] names = directory.list( num_filter ); + final String[] names = directory.list(num_filter); try { - for( int i = 0; i < names.length; i++ ) { + for (int i = 0; i < names.length; i++) { String origFilename = names[i]; - //This needs to handle (skip over) the possible repository numbers + // This needs to handle (skip over) the possible repository + // numbers int pos = origFilename.length() - m_postfix.length(); while (pos >= 1 && Character.isDigit(origFilename.charAt(pos - 1))) { pos--; @@ -162,15 +149,16 @@ public abstract class AbstractFileReposi /** * Set the destination for the repository * - * @param destination the destination under which the repository get stored - * @throws ConfigurationException - * @throws ConfigurationException get thrown on invalid destintion syntax - */ - protected void setDestination( final String destination ) - throws ConfigurationException { - - if( !destination.startsWith( FileSystem.FILE_PROTOCOL ) ){ - throw new ConfigurationException( "cannot handle destination " + destination); + * @param destination + * the destination under which the repository get stored + * @throws ConfigurationException + * @throws ConfigurationException + * get thrown on invalid destintion syntax + */ + protected void setDestination(final String destination) throws ConfigurationException { + + if (!destination.startsWith(FileSystem.FILE_PROTOCOL)) { + throw new ConfigurationException("cannot handle destination " + destination); } try { @@ -185,63 +173,47 @@ public abstract class AbstractFileReposi * Return a new instance of this class * * @return class a new instance of AbstractFileRepository - * @throws Exception get thrown if an error is detected while create the new instance + * @throws Exception + * get thrown if an error is detected while create the new + * instance */ - protected AbstractFileRepository createChildRepository() - throws Exception - { + protected AbstractFileRepository createChildRepository() throws Exception { return (AbstractFileRepository) getClass().newInstance(); } /* * (non-Javadoc) - * @see org.apache.james.repository.api.Repository#getChildRepository(java.lang.String) + * + * @see + * org.apache.james.repository.api.Repository#getChildRepository(java.lang + * .String) */ - public Repository getChildRepository( final String childName ) - { + public Repository getChildRepository(final String childName) { AbstractFileRepository child = null; - try - { + try { child = createChildRepository(); - } - catch( final Exception e ) - { - throw new RuntimeException( "Cannot create child repository " + - childName + " : " + e ); + } catch (final Exception e) { + throw new RuntimeException("Cannot create child repository " + childName + " : " + e); } child.setFileSystem(fileSystem); child.setLog(logger); - try - { - child.setDestination( m_baseDirectory.getAbsolutePath() + File.pathSeparatorChar + - childName + File.pathSeparator ); - } - catch( final ConfigurationException ce ) - { - throw new RuntimeException( "Cannot set destination for child child " + - "repository " + childName + - " : " + ce ); + try { + child.setDestination(m_baseDirectory.getAbsolutePath() + File.pathSeparatorChar + childName + File.pathSeparator); + } catch (final ConfigurationException ce) { + throw new RuntimeException("Cannot set destination for child child " + "repository " + childName + " : " + ce); } - try - { + try { child.init(); - } - catch( final Exception e ) - { - throw new RuntimeException( "Cannot initialize child " + - "repository " + childName + - " : " + e ); + } catch (final Exception e) { + throw new RuntimeException("Cannot initialize child " + "repository " + childName + " : " + e); } - if( DEBUG ) - { - getLogger().debug( "Child repository of " + m_name + " created in " + - m_baseDirectory + File.pathSeparatorChar + - childName + File.pathSeparator ); + if (DEBUG) { + getLogger().debug("Child repository of " + m_name + " created in " + m_baseDirectory + File.pathSeparatorChar + childName + File.pathSeparator); } return child; @@ -250,64 +222,61 @@ public abstract class AbstractFileReposi /** * Return the File Object which belongs to the given key * - * @param key the key for which the File get returned + * @param key + * the key for which the File get returned * @return file the File associted with the given Key - * @throws IOException get thrown on IO error + * @throws IOException + * get thrown on IO error */ - protected File getFile( final String key ) - throws IOException - { - return new File( encode( key ) ); + protected File getFile(final String key) throws IOException { + return new File(encode(key)); } /** * Return the InputStream which belongs to the given key * - * @param key the key for which the InputStream get returned + * @param key + * the key for which the InputStream get returned * @return in the InputStram associted with the given key - * @throws IOException get thrown on IO error + * @throws IOException + * get thrown on IO error */ - protected InputStream getInputStream( final String key ) - throws IOException - { - // This was changed to SharedFileInputStream but reverted to + protected InputStream getInputStream(final String key) throws IOException { + // This was changed to SharedFileInputStream but reverted to // fix JAMES-559. Usign SharedFileInputStream should be a good // performance improvement, but more checks have to be done // on the repository side to avoid concurrency in reading and // writing the same file. - return new FileInputStream( encode( key ) ); + return new FileInputStream(encode(key)); } /** * Return the OutputStream which belongs to the given key * - * @param key the key for which the OutputStream get returned + * @param key + * the key for which the OutputStream get returned * @return out the OutputStream - * @throws IOException get thrown on IO error + * @throws IOException + * get thrown on IO error */ - protected OutputStream getOutputStream( final String key ) - throws IOException - { - return new FileOutputStream( getFile( key ) ); + protected OutputStream getOutputStream(final String key) throws IOException { + return new FileOutputStream(getFile(key)); } - + /** * Remove the object associated to the given key. - * - * @param key the key to remove + * + * @param key + * the key to remove */ - public synchronized void remove( final String key ) - { - try - { - final File file = getFile( key ); + public synchronized void remove(final String key) { + try { + final File file = getFile(key); file.delete(); - if( DEBUG ) getLogger().debug( "removed key " + key ); - } - catch( final Exception e ) - { - throw new RuntimeException( "Exception caught while removing" + - " an object: " + e ); + if (DEBUG) + getLogger().debug("removed key " + key); + } catch (final Exception e) { + throw new RuntimeException("Exception caught while removing" + " an object: " + e); } } @@ -315,35 +284,30 @@ public abstract class AbstractFileReposi * * Indicates if the given key is associated to a contained object * - * @param key the key which checked for + * @param key + * the key which checked for * @return true if the repository contains the key */ - public synchronized boolean containsKey( final String key ) - { - try - { - final File file = getFile( key ); - if( DEBUG ) getLogger().debug( "checking key " + key ); + public synchronized boolean containsKey(final String key) { + try { + final File file = getFile(key); + if (DEBUG) + getLogger().debug("checking key " + key); return file.exists(); - } - catch( final Exception e ) - { - throw new RuntimeException( "Exception caught while searching " + - "an object: " + e ); + } catch (final Exception e) { + throw new RuntimeException("Exception caught while searching " + "an object: " + e); } } /** * Returns the list of used keys. */ - public Iterator<String> list() - { - final File storeDir = new File( m_baseDirectory.getAbsolutePath() ); - final String[] names = storeDir.list( m_filter ); + public Iterator<String> list() { + final File storeDir = new File(m_baseDirectory.getAbsolutePath()); + final String[] names = storeDir.list(m_filter); final List<String> list = new ArrayList<String>(); - for( int i = 0; i < names.length; i++ ) - { + for (int i = 0; i < names.length; i++) { String decoded = decode(names[i]); list.add(decoded); } @@ -351,60 +315,55 @@ public abstract class AbstractFileReposi return list.iterator(); } - /** - * Returns a String that uniquely identifies the object. - * <b>Note:</b> since this method uses the Object.toString() - * method, it's up to the caller to make sure that this method - * doesn't change between different JVM executions (like - * it may normally happen). For this reason, it's highly recommended - * (even if not mandated) that Strings be used as keys. - * - * @param key the key for which the Object should be searched - * @return result a unique String represent the Object which belongs to the key + * Returns a String that uniquely identifies the object. <b>Note:</b> since + * this method uses the Object.toString() method, it's up to the caller to + * make sure that this method doesn't change between different JVM + * executions (like it may normally happen). For this reason, it's highly + * recommended (even if not mandated) that Strings be used as keys. + * + * @param key + * the key for which the Object should be searched + * @return result a unique String represent the Object which belongs to the + * key */ - protected String encode( final String key ) - { + protected String encode(final String key) { final byte[] bytes = key.getBytes(); - final char[] buffer = new char[ bytes.length << 1 ]; + final char[] buffer = new char[bytes.length << 1]; - for( int i = 0, j = 0; i < bytes.length; i++ ) - { - final int k = bytes[ i ]; - buffer[ j++ ] = HEX_DIGITS[ ( k >>> 4 ) & BYTE_MASK ]; - buffer[ j++ ] = HEX_DIGITS[ k & BYTE_MASK ]; + for (int i = 0, j = 0; i < bytes.length; i++) { + final int k = bytes[i]; + buffer[j++] = HEX_DIGITS[(k >>> 4) & BYTE_MASK]; + buffer[j++] = HEX_DIGITS[k & BYTE_MASK]; } StringBuffer result = new StringBuffer(); - result.append( m_baseDirectory.getAbsolutePath() ); - result.append( File.separator ); - result.append( buffer ); - result.append( m_extension ); + result.append(m_baseDirectory.getAbsolutePath()); + result.append(File.separator); + result.append(buffer); + result.append(m_extension); return result.toString(); } - /** - * Inverse of encode exept it do not use path. - * So decode(encode(s) - m_path) = s. - * In other words it returns a String that can be used as key to retive - * the record contained in the 'filename' file. - * - * @param filename the filename for which the key should generated + * Inverse of encode exept it do not use path. So decode(encode(s) - m_path) + * = s. In other words it returns a String that can be used as key to + * retrieve the record contained in the 'filename' file. + * + * @param filename + * the filename for which the key should generated * @return key a String which can be used to retrieve the filename */ - protected String decode( String filename ) - { - filename = filename.substring( 0, filename.length() - m_extension.length() ); + protected String decode(String filename) { + filename = filename.substring(0, filename.length() - m_extension.length()); final int size = filename.length(); - final byte[] bytes = new byte[ size >>> 1 ]; + final byte[] bytes = new byte[size >>> 1]; - for( int i = 0, j = 0; i < size; j++ ) - { - bytes[ j ] = Byte.parseByte( filename.substring( i, i + 2 ), 16 ); - i +=2; + for (int i = 0, j = 0; i < size; j++) { + bytes[j] = Byte.parseByte(filename.substring(i, i + 2), 16); + i += 2; } - return new String( bytes ); + return new String(bytes); } } Modified: james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/ClassLoaderObjectInputStream.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/ClassLoaderObjectInputStream.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/ClassLoaderObjectInputStream.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/ClassLoaderObjectInputStream.java Mon Apr 4 12:26:35 2011 @@ -17,8 +17,6 @@ * under the License. * ****************************************************************/ - - package org.apache.james.repository.file; import java.io.IOException; @@ -28,38 +26,28 @@ import java.io.ObjectStreamClass; import java.io.StreamCorruptedException; /** - * A special ObjectInputStream to handle highly transient classes hosted - * by Avalon components that are juggling many classloaders. - * - * @version $Revision$ $Date$ + * A special ObjectInputStream to handle highly transient classes hosted by + * Avalon components that are juggling many classloaders. + * + * @version $Revision$ $Date: 2010-12-16 09:20:25 +0100 (Thu, 16 Dec + * 2010) $ */ -public class ClassLoaderObjectInputStream - extends ObjectInputStream -{ +public class ClassLoaderObjectInputStream extends ObjectInputStream { private ClassLoader m_classLoader; - public ClassLoaderObjectInputStream( final ClassLoader classLoader, - final InputStream inputStream ) - throws IOException, StreamCorruptedException - { - super( inputStream ); + public ClassLoaderObjectInputStream(final ClassLoader classLoader, final InputStream inputStream) throws IOException, StreamCorruptedException { + super(inputStream); m_classLoader = classLoader; } - protected Class resolveClass( final ObjectStreamClass objectStreamClass ) - throws IOException, ClassNotFoundException - { - final Class clazz = - Class.forName( objectStreamClass.getName(), false, m_classLoader ); + protected Class resolveClass(final ObjectStreamClass objectStreamClass) throws IOException, ClassNotFoundException { + final Class clazz = Class.forName(objectStreamClass.getName(), false, m_classLoader); - if( null != clazz ) - { + if (null != clazz) { return clazz; // the classloader knows of the class - } - else - { + } else { // classloader knows not of class, let the super classloader do it - return super.resolveClass( objectStreamClass ); + return super.resolveClass(objectStreamClass); } } } Modified: james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/ExtensionFileFilter.java Mon Apr 4 12:26:35 2011 @@ -17,57 +17,48 @@ * under the License. * ****************************************************************/ - - package org.apache.james.repository.file; import java.io.File; import java.io.FilenameFilter; /** - * This filters files based on the extension (what the filename - * ends with). This is used in retrieving all the files of a - * particular type. - * - * <p>Eg., to retrieve and print all <code>*.java</code> files in the current directory:</p> - * + * This filters files based on the extension (what the filename ends with). This + * is used in retrieving all the files of a particular type. + * + * <p> + * Eg., to retrieve and print all <code>*.java</code> files in the current + * directory: + * </p> + * * <pre> - * File dir = new File("."); - * String[] files = dir.list( new ExtensionFileFilter( new String[]{"java"} ) ); - * for (int i=0; i<files.length; i++) - * { + * File dir = new File("."); + * String[] files = dir.list(new ExtensionFileFilter(new String[] { "java" })); + * for (int i = 0; i < files.length; i++) { * System.out.println(files[i]); * } * </pre> - * - * @version CVS $Revision$ $Date$ + * + * @version CVS $Revision$ $Date: 2010-12-16 10:36:43 +0100 (Thu, 16 + * Dec 2010) $ */ -public class ExtensionFileFilter - implements FilenameFilter -{ +public class ExtensionFileFilter implements FilenameFilter { private String[] m_extensions; - public ExtensionFileFilter( final String[] extensions ) - { + public ExtensionFileFilter(final String[] extensions) { m_extensions = extensions; } - public ExtensionFileFilter( final String extension ) - { - m_extensions = new String[]{extension}; + public ExtensionFileFilter(final String extension) { + m_extensions = new String[] { extension }; } - public boolean accept( final File file, final String name ) - { - for( int i = 0; i < m_extensions.length; i++ ) - { - if( name.endsWith( m_extensions[ i ] ) ) - { + public boolean accept(final File file, final String name) { + for (int i = 0; i < m_extensions.length; i++) { + if (name.endsWith(m_extensions[i])) { return true; } } return false; } } - - Modified: james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java Mon Apr 4 12:26:35 2011 @@ -17,8 +17,6 @@ * under the License. * ****************************************************************/ - - package org.apache.james.repository.file; import java.io.InputStream; @@ -29,128 +27,108 @@ import java.io.OutputStream; import org.apache.james.repository.api.ObjectRepository; /** - * This is a simple implementation of persistent object store using - * object serialization on the file system. - * + * This is a simple implementation of persistent object store using object + * serialization on the file system. */ -public class FilePersistentObjectRepository - extends AbstractFileRepository - implements ObjectRepository -{ +public class FilePersistentObjectRepository extends AbstractFileRepository implements ObjectRepository { /* * (non-Javadoc) - * @see org.apache.james.repository.file.AbstractFileRepository#getExtensionDecorator() + * + * @see + * org.apache.james.repository.file.AbstractFileRepository#getExtensionDecorator + * () */ - protected String getExtensionDecorator() - { + protected String getExtensionDecorator() { return ".FileObjectStore"; } - /* * (non-Javadoc) - * @see org.apache.james.repository.api.ObjectRepository#get(java.lang.String) + * + * @see + * org.apache.james.repository.api.ObjectRepository#get(java.lang.String) */ - public synchronized Object get( final String key ) - { - try - { - final InputStream inputStream = getInputStream( key ); - - if( inputStream == null ) - throw new NullPointerException("Null input stream returned for key: " + key ); - try - { - final ObjectInputStream stream = new ObjectInputStream( inputStream ); + public synchronized Object get(final String key) { + try { + final InputStream inputStream = getInputStream(key); + + if (inputStream == null) + throw new NullPointerException("Null input stream returned for key: " + key); + try { + final ObjectInputStream stream = new ObjectInputStream(inputStream); - if( stream == null ) - throw new NullPointerException("Null stream returned for key: " + key ); + if (stream == null) + throw new NullPointerException("Null stream returned for key: " + key); final Object object = stream.readObject(); - if( DEBUG ) - { - getLogger().debug( "returning object " + object + " for key " + key ); + if (DEBUG) { + getLogger().debug("returning object " + object + " for key " + key); } return object; - } - finally - { + } finally { inputStream.close(); } - } - catch( final Throwable e ) - { - throw new RuntimeException( - "Exception caught while retrieving an object, cause: " + e.toString() ); + } catch (final Throwable e) { + throw new RuntimeException("Exception caught while retrieving an object, cause: " + e.toString()); } } - /* * (non-Javadoc) - * @see org.apache.james.repository.api.ObjectRepository#get(java.lang.String, java.lang.ClassLoader) + * + * @see + * org.apache.james.repository.api.ObjectRepository#get(java.lang.String, + * java.lang.ClassLoader) */ - public synchronized Object get( final String key, final ClassLoader classLoader ) - { - try - { - final InputStream inputStream = getInputStream( key ); - - if( inputStream == null ) - throw new NullPointerException("Null input stream returned for key: " + key ); - - try - { - final ObjectInputStream stream = new ClassLoaderObjectInputStream( classLoader, inputStream ); + public synchronized Object get(final String key, final ClassLoader classLoader) { + try { + final InputStream inputStream = getInputStream(key); - if( stream == null ) - throw new NullPointerException("Null stream returned for key: " + key ); + if (inputStream == null) + throw new NullPointerException("Null input stream returned for key: " + key); + + try { + final ObjectInputStream stream = new ClassLoaderObjectInputStream(classLoader, inputStream); + + if (stream == null) + throw new NullPointerException("Null stream returned for key: " + key); final Object object = stream.readObject(); - if( DEBUG ) - { - getLogger().debug( "returning object " + object + " for key " + key ); + if (DEBUG) { + getLogger().debug("returning object " + object + " for key " + key); } return object; - } - finally - { + } finally { inputStream.close(); } - } - catch( final Throwable e ) - { - throw new RuntimeException( "Exception caught while retrieving an object: " + e ); + } catch (final Throwable e) { + throw new RuntimeException("Exception caught while retrieving an object: " + e); } } - /* * (non-Javadoc) - * @see org.apache.james.repository.api.ObjectRepository#put(java.lang.String, java.lang.Object) + * + * @see + * org.apache.james.repository.api.ObjectRepository#put(java.lang.String, + * java.lang.Object) */ - public synchronized void put( final String key, final Object value ) - { - try - { - final OutputStream outputStream = getOutputStream( key ); - - try - { - final ObjectOutputStream stream = new ObjectOutputStream( outputStream ); - stream.writeObject( value ); - if( DEBUG ) getLogger().debug( "storing object " + value + " for key " + key ); - } - finally - { + public synchronized void put(final String key, final Object value) { + try { + final OutputStream outputStream = getOutputStream(key); + + try { + final ObjectOutputStream stream = new ObjectOutputStream(outputStream); + stream.writeObject(value); + if (DEBUG) + getLogger().debug("storing object " + value + " for key " + key); + } finally { outputStream.close(); } - } - catch( final Exception e ) - { - throw new RuntimeException( "Exception caught while storing an object: " + e ); + } catch (final Exception e) { + throw new RuntimeException("Exception caught while storing an object: " + e); } } Modified: james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/FilePersistentStreamRepository.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/FilePersistentStreamRepository.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/FilePersistentStreamRepository.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/FilePersistentStreamRepository.java Mon Apr 4 12:26:35 2011 @@ -29,7 +29,7 @@ import java.io.OutputStream; import org.apache.james.repository.api.StreamRepository; /** - * Implementation of a StreamRepository to a File. + * Implementation of a StreamRepository to a File.<br> * TODO: -retieve(String key) should return a FilterInputStream to allow * mark and reset methods. (working not like BufferedInputStream!!!) * Modified: james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/NumberedRepositoryFileFilter.java URL: http://svn.apache.org/viewvc/james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/NumberedRepositoryFileFilter.java?rev=1088591&r1=1088590&r2=1088591&view=diff ============================================================================== --- james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/NumberedRepositoryFileFilter.java (original) +++ james/server/trunk/data-library/src/main/java/org/apache/james/repository/file/NumberedRepositoryFileFilter.java Mon Apr 4 12:26:35 2011 @@ -17,8 +17,6 @@ * under the License. * ****************************************************************/ - - package org.apache.james.repository.file; import java.io.File; @@ -27,7 +25,6 @@ import java.io.FilenameFilter; /** * This filters files based on the extension and is tailored to provide * backwards compatibility of the numbered repositories that Avalon does. - * */ public class NumberedRepositoryFileFilter implements FilenameFilter { private String postfix; @@ -36,7 +33,8 @@ public class NumberedRepositoryFileFilte /** * Default Constructor * - * @param extension the extension for which checked + * @param extension + * the extension for which checked */ public NumberedRepositoryFileFilter(final String extension) { postfix = extension; @@ -47,26 +45,25 @@ public class NumberedRepositoryFileFilte * @see java.io.FilenameFilter#accept(File, String) */ public boolean accept(final File file, final String name) { - //System.out.println("check: " + name); - //System.out.println("post: " + postfix); + // System.out.println("check: " + name); + // System.out.println("post: " + postfix); if (!name.endsWith(postfix)) { return false; } - //Look for a couple of digits next + // Look for a couple of digits next int pos = name.length() - postfix.length(); - //We have to find at least one digit... if not then this isn't what we want + // We have to find at least one digit... if not then this isn't what we + // want if (!Character.isDigit(name.charAt(pos - 1))) { return false; } pos--; while (pos >= 1 && Character.isDigit(name.charAt(pos - 1))) { - //System.out.println("back one"); + // System.out.println("back one"); pos--; } - //System.out.println("sub: " + name.substring(0, pos)); - //Now want to check that we match the rest + // System.out.println("sub: " + name.substring(0, pos)); + // Now want to check that we match the rest return name.substring(0, pos).endsWith(prefix); } } - - --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
