1 | public boolean isConnectionValid(Object connectionType, Object fromElement, | | 1 | public boolean isConnectionValid(Object connectionType, Object fromElement, |
2 | Object toElement, boolean checkWFR) { | | 2 | Object toElement, boolean checkWFR) { |
3 | // Get the list of valid model item pairs for the given connection type | | 3 | if (Model.getModelManagementHelper().isReadOnly(fromElement)) { |
4 | List validItems = (ArrayList) validConnectionMap.get(connectionType); | | 4 | // Don't allow connections to be created from a read only |
5 | if (validItems == null) { | | 5 | // model element to any other |
6 | return false; | | 6 | // TODO: This should be considered a workaround. It only works |
7 | } | | 7 | // because, by default, we place newly created relationships in |
8 | // See if there's a pair in this list that match the given | | 8 | // the namespace of the fromElement. The correct behavior in |
9 | // model elements | | 9 | // the presence of read-only elements really depends on the type of |
10 | Iterator it = validItems.iterator(); | | 10 | // connection as well as the writeability of both ends. |
11 | while (it.hasNext()) { | | 11 | return false; |
12 | Class[] modeElementPair = (Class[]) it.next(); | | 12 | } |
13 | if (modeElementPair[0].isInstance(fromElement) | | 13 | // Get the list of valid model item pairs for the given connection type |
14 | && modeElementPair[1].isInstance(toElement)) { | | 14 | List<Class<?>[]> validItems = validConnectionMap.get(connectionType); |
15 | if (checkWFR) { | | 15 | if (validItems == null) { |
16 | return isConnectionWellformed( | | 16 | return false; |
17 | (Class) connectionType, | | 17 | } |
18 | (Element) fromElement, | | 18 | // See if there's a pair in this list that match the given |
19 | (Element) toElement); | | 19 | // model elements |
20 | } else { | | 20 | for (Class<?>[] modeElementPair : validItems) { |
21 | return true; | | 21 | if (modeElementPair[0].isInstance(fromElement) |
22 | } | | 22 | && modeElementPair[1].isInstance(toElement)) { |
23 | } | | 23 | if (checkWFR) { |
24 | } | | 24 | return isConnectionWellformed( |
25 | return false; | | 25 | (Class<?>) connectionType, |
26 | } | | 26 | (ModelElement) fromElement, |
| | | 27 | (ModelElement) toElement); |
| | | 28 | } else { |
| | | 29 | return true; |
| | | 30 | } |
| | | 31 | } |
| | | 32 | } |
| | | 33 | return false; |
| | | 34 | } |