1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.modeshape.repository.util;
25
26 import java.util.regex.Matcher;
27 import java.util.regex.Pattern;
28 import net.jcip.annotations.Immutable;
29 import org.modeshape.common.util.HashCode;
30 import org.modeshape.repository.RepositoryI18n;
31
32
33
34
35 @Immutable
36 public class RepositoryNodePath {
37
38 protected static final Pattern PATTERN = Pattern.compile("([^:/]):(/.*)");
39
40 public static RepositoryNodePath parse( String path,
41 String repositorySourceName,
42 String defaultRepositoryWorkspaceName ) {
43 Matcher matcher = PATTERN.matcher(path);
44 if (matcher.matches()) {
45 try {
46 return new RepositoryNodePath(repositorySourceName, matcher.group(1), matcher.group(2));
47 } catch (Throwable t) {
48 throw new IllegalArgumentException(RepositoryI18n.invalidRepositoryNodePath.text(path, t.getMessage()));
49 }
50 }
51 return new RepositoryNodePath(repositorySourceName, defaultRepositoryWorkspaceName, path);
52
53 }
54
55 private final String repositorySourceName;
56 private final String workspaceName;
57 private final String nodePath;
58 private final int hc;
59
60 public RepositoryNodePath( String repositorySourceName,
61 String workspaceName,
62 String nodePath ) {
63 this.repositorySourceName = repositorySourceName;
64 this.workspaceName = workspaceName;
65 this.nodePath = nodePath;
66 this.hc = HashCode.compute(this.repositorySourceName, this.workspaceName, this.nodePath);
67 }
68
69
70
71
72 public String getNodePath() {
73 return this.nodePath;
74 }
75
76
77
78
79 public String getRepositorySourceName() {
80 return this.repositorySourceName;
81 }
82
83
84
85
86 public String getWorkspaceName() {
87 return this.workspaceName;
88 }
89
90
91
92
93 @Override
94 public int hashCode() {
95 return this.hc;
96 }
97
98
99
100
101 @Override
102 public boolean equals( Object obj ) {
103 if (obj == this) return true;
104 if (obj instanceof RepositoryNodePath) {
105 RepositoryNodePath that = (RepositoryNodePath)obj;
106 if (!this.repositorySourceName.equals(that.repositorySourceName)) return false;
107 if (!this.workspaceName.equals(that.workspaceName)) return false;
108 if (!this.nodePath.equals(that.nodePath)) return false;
109 return true;
110 }
111 return false;
112 }
113
114
115
116
117 @Override
118 public String toString() {
119 return this.repositorySourceName + ":" + this.workspaceName + ":" + this.nodePath;
120 }
121 }