KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > service > cmr > repository > StoreRef


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.service.cmr.repository;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.alfresco.error.AlfrescoRuntimeException;
22
23 /**
24  * Reference to a node store
25  *
26  * @author Derek Hulley
27  */

28 public final class StoreRef implements EntityRef, Serializable JavaDoc
29 {
30     private static final long serialVersionUID = 3905808565129394486L;
31
32     public static final String JavaDoc PROTOCOL_WORKSPACE = "workspace";
33     
34     public static final String JavaDoc URI_FILLER = "://";
35
36     private final String JavaDoc protocol;
37     private final String JavaDoc identifier;
38
39     /**
40      * @param protocol
41      * well-known protocol for the store, e.g. <b>workspace</b> or
42      * <b>versionstore</b>
43      * @param identifier
44      * the identifier, which may be specific to the protocol
45      */

46     public StoreRef(String JavaDoc protocol, String JavaDoc identifier)
47     {
48         if (protocol == null)
49         {
50             throw new IllegalArgumentException JavaDoc("Store protocol may not be null");
51         }
52         if (identifier == null)
53         {
54             throw new IllegalArgumentException JavaDoc("Store identifier may not be null");
55         }
56
57         this.protocol = protocol;
58         this.identifier = identifier;
59     }
60
61     public StoreRef(String JavaDoc 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 JavaDoc toString()
73     {
74         return protocol + URI_FILLER + identifier;
75     }
76
77     public boolean equals(Object JavaDoc 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     /**
95      * Creates a hashcode from both the {@link #getProtocol()} and {@link #getIdentifier()}
96      */

97     public int hashCode()
98     {
99         return (protocol.hashCode() + identifier.hashCode());
100     }
101
102     public String JavaDoc getProtocol()
103     {
104         return protocol;
105     }
106
107     public String JavaDoc getIdentifier()
108     {
109         return identifier;
110     }
111 }
Popular Tags