1 17 18 package org.apache.geronimo.gbean; 19 20 import java.io.Serializable ; 21 import java.util.Collections ; 22 import java.util.Iterator ; 23 import java.util.LinkedHashSet ; 24 import java.util.Set ; 25 26 29 public class ReferencePatterns implements Serializable { 30 private static final long serialVersionUID = 1888371271299507818L; 31 32 private final Set patterns; 33 private final AbstractName abstractName; 34 35 public ReferencePatterns(Set patterns) { 36 this.patterns = new LinkedHashSet (); 37 for (Iterator iterator = patterns.iterator(); iterator.hasNext();) { 38 Object pattern = iterator.next(); 39 if (pattern instanceof AbstractName) { 40 AbstractName name = (AbstractName) pattern; 41 this.patterns.add(new AbstractNameQuery(name)); 42 } else if (pattern instanceof AbstractNameQuery) { 43 AbstractNameQuery nameQuery = (AbstractNameQuery) pattern; 44 this.patterns.add(nameQuery); 45 } else { 46 throw new IllegalArgumentException ("Unknown pattern type: " + pattern); 47 } 48 } 49 this.abstractName = null; 50 } 51 52 public ReferencePatterns(AbstractNameQuery abstractNameQuery) { 53 this.patterns = Collections.singleton(abstractNameQuery); 54 this.abstractName = null; 55 } 56 57 public ReferencePatterns(AbstractName abstractName) { 58 if (abstractName == null) { 59 throw new IllegalArgumentException ("parameter abstractName is null"); 60 } 61 this.abstractName = abstractName; 62 this.patterns = null; 63 } 64 65 public Set getPatterns() { 66 if (patterns == null) { 67 throw new IllegalStateException ("This is resolved to: " + abstractName); 68 } 69 return patterns; 70 } 71 72 public AbstractName getAbstractName() { 73 if (abstractName == null) { 74 throw new IllegalStateException ("This is not resolved with patterns: " + patterns); 75 } 76 return abstractName; 77 } 78 79 public boolean isResolved() { 80 return abstractName != null; 81 } 82 83 public String toString() { 84 if (abstractName != null) { 85 return abstractName.toString(); 86 } else { 87 return patterns.toString(); 88 } 89 } 90 91 public boolean equals(Object other) { 92 if (other instanceof ReferencePatterns) { 93 ReferencePatterns otherRefPat = (ReferencePatterns) other; 94 if (abstractName != null) { 95 return abstractName.equals(otherRefPat.abstractName); 96 } 97 return patterns.equals(otherRefPat.patterns); 98 } 99 return false; 100 } 101 102 public int hashCode() { 103 if (abstractName != null) { 104 return abstractName.hashCode(); 105 } 106 return patterns.hashCode(); 107 } 108 } 109 | Popular Tags |