1 22 package org.jboss.metadata.plugins.repository.visitor; 23 24 import java.util.Collection ; 25 import java.util.Iterator ; 26 27 import org.jboss.metadata.spi.repository.MetaDataRepository; 28 import org.jboss.metadata.spi.repository.visitor.MetaDataRepositoryVisitor; 29 import org.jboss.metadata.spi.scope.Scope; 30 import org.jboss.metadata.spi.scope.ScopeKey; 31 import org.jboss.metadata.spi.scope.ScopeLevel; 32 33 39 public class FuzzyMetaDataRepositoryVisitor implements MetaDataRepositoryVisitor 40 { 41 42 private Scope[] matchScopes; 43 44 49 public FuzzyMetaDataRepositoryVisitor(ScopeKey matchKey) 50 { 51 if (matchKey != null) 52 { 53 Collection <Scope> testScopes = matchKey.getScopes(); 54 matchScopes = testScopes.toArray(new Scope[testScopes.size()]); 55 } 56 } 57 58 public boolean matchScope(MetaDataRepository repository, ScopeKey key) 59 { 60 if (matchScopes == null || matchScopes.length == 0) 61 return true; 62 63 boolean match = false; 64 int index = 0; 65 Iterator <Scope> i = key.getScopes().iterator(); 66 Scope repositoryScope = i.next(); 67 Scope matchScope = matchScopes[index]; 68 while (true) 69 { 70 ScopeLevel keyLevel = matchScope.getScopeLevel(); 71 ScopeLevel repositoryLevel = repositoryScope.getScopeLevel(); 72 73 if (keyLevel.compareTo(repositoryLevel) == 0) 75 { 76 if (matchScope.equals(repositoryScope)) 77 match = true; 78 else 79 { 80 match = false; 82 break; 83 } 84 } 85 86 if (keyLevel.compareTo(repositoryLevel) <= 0) 88 { 89 if (++index == matchScopes.length) 91 break; 92 matchScope = matchScopes[index]; 93 } 94 else 95 { 96 if (i.hasNext() == false) 98 break; 99 repositoryScope = i.next(); 100 } 101 } 102 return match; 103 } 104 } 105 | Popular Tags |