1 4 package org.openedit.repository; 5 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 import java.util.Map ; 10 import java.util.Set ; 11 12 import com.openedit.util.PathUtilities; 13 14 20 public class CompoundRepository implements Repository 21 { 22 protected Map fieldRepositoryMap; 23 protected Repository fieldDefaultRepository; 24 25 public void addRepository( String inBasePath, Repository inRepository ) 26 { 27 getRepositoryMap().put( inBasePath, inRepository ); 28 } 29 30 public void removeRepository( String inBasePath ) 31 { 32 getRepositoryMap().remove( inBasePath ); 33 } 34 public Map getRepositoryMap() 35 { 36 if (fieldRepositoryMap == null) 37 { 38 fieldRepositoryMap = new HashMap (); 39 } 40 return fieldRepositoryMap; 41 } 42 43 51 public Repository resolveRepository(String inPath) 52 { 53 Set keys = getRepositoryMap().keySet(); for ( Iterator iter = keys.iterator(); iter.hasNext(); ) 55 { 56 String key = (String ) iter.next(); 57 if ( PathUtilities.match(inPath, key) ) 58 { 59 return (Repository) getRepositoryMap().get( key ); 60 } 61 } 62 return getDefaultRepository(); 63 } 64 65 public ContentItem get( String inPath ) throws RepositoryException 66 { 67 return resolveRepository( inPath ).get( inPath ); 68 } 69 public ContentItem getStub( String inPath ) throws RepositoryException 70 { 71 return resolveRepository( inPath ).getStub( inPath ); 72 } 73 74 public void put( ContentItem inContent ) throws RepositoryException 75 { 76 resolveRepository( inContent.getPath() ).put( inContent ); 77 } 78 79 public void copy( ContentItem inSource, ContentItem inDestination ) throws RepositoryException 80 { 81 Repository rep = resolveRepository( inDestination.getPath() ); 82 rep.copy( inSource, inDestination ); 83 } 84 85 public void move( ContentItem inSource, ContentItem inDestination ) throws RepositoryException 86 { 87 resolveRepository( inDestination.getPath() ).move( inSource, inDestination ); 88 89 } 90 91 public void remove( ContentItem inRevision ) throws RepositoryException 92 { 93 resolveRepository( inRevision.getPath() ).remove( inRevision ); 94 } 95 96 public List getVersions( String inPath ) throws RepositoryException 97 { 98 return resolveRepository( inPath ).getVersions( inPath ); 99 } 100 101 public Repository getDefaultRepository() 102 { 103 return fieldDefaultRepository; 104 } 105 public void setDefaultRepository( Repository defaultRepository ) 106 { 107 fieldDefaultRepository = defaultRepository; 108 } 109 public void setRepositoryMap( Map repositoryMap ) 110 { 111 fieldRepositoryMap = repositoryMap; 112 } 113 114 public boolean doesExist(String inPath) throws RepositoryException 115 { 116 return resolveRepository( inPath ).doesExist(inPath); 117 } 118 119 public ContentItem getLastVersion(String inPath) throws RepositoryException 120 { 121 return resolveRepository( inPath ).getLastVersion(inPath ); 122 } 123 124 public List getChildrenNames(String inParent) throws RepositoryException 125 { 126 return resolveRepository( inParent ).getChildrenNames(inParent ); 127 } 128 129 public void deleteOldVersions(String inPath) throws RepositoryException 130 { 131 resolveRepository( inPath ).deleteOldVersions(inPath); 132 } 133 } 134 | Popular Tags |