1 17 package org.alfresco.service.cmr.repository; 18 19 import java.io.Serializable ; 20 21 import org.alfresco.error.AlfrescoRuntimeException; 22 23 28 public final class StoreRef implements EntityRef, Serializable 29 { 30 private static final long serialVersionUID = 3905808565129394486L; 31 32 public static final String PROTOCOL_WORKSPACE = "workspace"; 33 34 public static final String URI_FILLER = "://"; 35 36 private final String protocol; 37 private final String identifier; 38 39 46 public StoreRef(String protocol, String identifier) 47 { 48 if (protocol == null) 49 { 50 throw new IllegalArgumentException ("Store protocol may not be null"); 51 } 52 if (identifier == null) 53 { 54 throw new IllegalArgumentException ("Store identifier may not be null"); 55 } 56 57 this.protocol = protocol; 58 this.identifier = identifier; 59 } 60 61 public StoreRef(String string) 62 { 63 int dividerPatternPosition = string.indexOf(URI_FILLER); 64 if(dividerPatternPosition == -1) 65 { 66 throw new AlfrescoRuntimeException("Invalid store ref: Does not contain " + URI_FILLER + " " + string); 67 } 68 this.protocol = string.substring(0, dividerPatternPosition); 69 this.identifier = string.substring(dividerPatternPosition+3); 70 } 71 72 public String toString() 73 { 74 return protocol + URI_FILLER + identifier; 75 } 76 77 public boolean equals(Object obj) 78 { 79 if (this == obj) 80 { 81 return true; 82 } 83 if (obj instanceof StoreRef) 84 { 85 StoreRef that = (StoreRef) obj; 86 return (this.protocol.equals(that.protocol) 87 && this.identifier.equals(that.identifier)); 88 } else 89 { 90 return false; 91 } 92 } 93 94 97 public int hashCode() 98 { 99 return (protocol.hashCode() + identifier.hashCode()); 100 } 101 102 public String getProtocol() 103 { 104 return protocol; 105 } 106 107 public String getIdentifier() 108 { 109 return identifier; 110 } 111 } | Popular Tags |