@@ -70,8 +70,13 @@ public Set<String> getRelationshipIdentifiers() {
7070 * @return an Element, or null if one doesn't exist
7171 */
7272 public Element getElement (String identifier ) {
73- identifier = identifier .toLowerCase ();
74- return elementsByIdentifier .get (identifier );
73+ for (String key : elementsByIdentifier .keySet ()) {
74+ if (key .equalsIgnoreCase (identifier )) {
75+ return elementsByIdentifier .get (key );
76+ }
77+ }
78+
79+ return null ;
7580 }
7681
7782 /**
@@ -89,8 +94,6 @@ public void register(String identifier, Element element) {
8994 identifier = UUID .randomUUID ().toString ();
9095 }
9196
92- identifier = identifier .toLowerCase ();
93-
9497 if (identifierScope == IdentifierScope .Hierarchical ) {
9598 identifier = calculateHierarchicalIdentifier (identifier , element );
9699 }
@@ -99,17 +102,17 @@ public void register(String identifier, Element element) {
99102 for (String id : elementsByIdentifier .keySet ()) {
100103 Element e = elementsByIdentifier .get (id );
101104
102- if (e .equals (element ) && !id .equals (identifier )) {
105+ if (e .equals (element ) && !id .equalsIgnoreCase (identifier )) {
103106 if (id .matches ("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}" )) {
104- throw new RuntimeException ("Please assign an identifier to \" " + element .getCanonicalName () + "\" before using it with !ref " );
107+ throw new RuntimeException ("Please assign an identifier to \" " + element .getCanonicalName () + "\" before using it" );
105108 } else {
106109 throw new RuntimeException ("The element is already registered with an identifier of \" " + id + "\" " );
107110 }
108111 }
109112 }
110113
111- Element e = elementsByIdentifier . get (identifier );
112- Relationship r = relationshipsByIdentifier . get (identifier );
114+ Element e = getElement (identifier );
115+ Relationship r = getRelationship (identifier );
113116
114117 if ((e == null && r == null ) || (e == element )) {
115118 elementsByIdentifier .put (identifier , element );
@@ -125,8 +128,13 @@ public void register(String identifier, Element element) {
125128 * @return a Relationship, or null if one doesn't exist
126129 */
127130 public Relationship getRelationship (String identifier ) {
128- identifier = identifier .toLowerCase ();
129- return relationshipsByIdentifier .get (identifier );
131+ for (String key : relationshipsByIdentifier .keySet ()) {
132+ if (key .equalsIgnoreCase (identifier )) {
133+ return relationshipsByIdentifier .get (key );
134+ }
135+ }
136+
137+ return null ;
130138 }
131139
132140 /**
@@ -144,10 +152,21 @@ public void register(String identifier, Relationship relationship) {
144152 identifier = UUID .randomUUID ().toString ();
145153 }
146154
147- identifier = identifier .toLowerCase ();
155+ // check whether this relationship has already been registered with another identifier
156+ for (String id : relationshipsByIdentifier .keySet ()) {
157+ Relationship r = relationshipsByIdentifier .get (id );
158+
159+ if (r .equals (relationship ) && !id .equalsIgnoreCase (identifier )) {
160+ if (id .matches ("[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}" )) {
161+ throw new RuntimeException ("Please assign an identifier to \" " + relationship .getCanonicalName () + "\" before using it" );
162+ } else {
163+ throw new RuntimeException ("The relationship is already registered with an identifier of \" " + id + "\" " );
164+ }
165+ }
166+ }
148167
149- Element e = elementsByIdentifier . get (identifier );
150- Relationship r = relationshipsByIdentifier . get (identifier );
168+ Element e = getElement (identifier );
169+ Relationship r = getRelationship (identifier );
151170
152171 if ((e == null && r == null ) || (r == relationship )) {
153172 relationshipsByIdentifier .put (identifier , relationship );
0 commit comments