|
2 | 2 | * Initial version copyright 2008 Lockheed Martin Corporation, except |
3 | 3 | * as stated in the file entitled Licensing-Information. |
4 | 4 | * |
5 | | - * All modifications copyright 2009-2017 Data Access Technologies, Inc. |
| 5 | + * Modifications: |
| 6 | + * Copyright 2009-2012 Data Access Technologies, Inc. |
| 7 | + * Copyright 2020 Model Driven Solutions, Inc. |
6 | 8 | * |
7 | 9 | * Licensed under the Academic Free License version 3.0 |
8 | 10 | * (http://www.opensource.org/licenses/afl-3.0.php), except as stated |
|
25 | 27 | import fuml.semantics.activities.TokenList; |
26 | 28 | import fuml.semantics.simpleclassifiers.BooleanValue; |
27 | 29 | import fuml.semantics.simpleclassifiers.FeatureValueList; |
| 30 | +import fuml.semantics.simpleclassifiers.StructuredValue; |
| 31 | +import fuml.semantics.structuredclassifiers.ExtensionalValue; |
| 32 | +import fuml.semantics.structuredclassifiers.ExtensionalValueList; |
| 33 | +import fuml.semantics.structuredclassifiers.Link; |
| 34 | +import fuml.semantics.structuredclassifiers.LinkList; |
28 | 35 | import fuml.semantics.values.Value; |
29 | 36 | import fuml.semantics.values.ValueList; |
30 | 37 | import fuml.syntax.actions.Action; |
|
34 | 41 | import fuml.syntax.actions.OutputPinList; |
35 | 42 | import fuml.syntax.activities.ActivityNode; |
36 | 43 | import fuml.syntax.activities.ActivityNodeList; |
| 44 | +import fuml.syntax.classification.Property; |
| 45 | +import fuml.syntax.structuredclassifiers.Association; |
37 | 46 | import fuml.syntax.values.LiteralBoolean; |
38 | 47 |
|
39 | 48 | public abstract class ActionActivation extends |
@@ -418,6 +427,115 @@ public boolean valueParticipatesInLink( |
418 | 427 |
|
419 | 428 | return participates; |
420 | 429 | } // valueParticipatesInLink |
| 430 | + |
| 431 | + public fuml.syntax.structuredclassifiers.Association getAssociation( |
| 432 | + fuml.syntax.classification.StructuralFeature feature) { |
| 433 | + // If the given structural feature is an association end, then get |
| 434 | + // the associated association. |
| 435 | + |
| 436 | + Association association = null; |
| 437 | + if (feature instanceof Property) { |
| 438 | + association = ((Property) feature).association; |
| 439 | + } |
| 440 | + |
| 441 | + return association; |
| 442 | + } // getAssociation |
| 443 | + |
| 444 | + public fuml.semantics.values.ValueList getValues( |
| 445 | + fuml.semantics.values.Value sourceValue, |
| 446 | + fuml.syntax.classification.StructuralFeature feature) { |
| 447 | + // Get the values of the feature for the given source value. |
| 448 | + // If the feature is an association end, then get the values of |
| 449 | + // the feature end of the links with the source value as the |
| 450 | + // opposite end. |
| 451 | + // Otherwise, if the source value is a structured value, get |
| 452 | + // the values of the feature value for feature in the structured value. |
| 453 | + |
| 454 | + ValueList values = new ValueList(); |
| 455 | + |
| 456 | + Association association = this.getAssociation(feature); |
| 457 | + if (association != null) { |
| 458 | + LinkList links = this.getMatchingLinks(association, feature, sourceValue); |
| 459 | + for (int j = 0; j < links.size(); j++) { |
| 460 | + Link link = links.getValue(j); |
| 461 | + values.addValue(link.getFeatureValue(feature).values.getValue(0)); |
| 462 | + } |
| 463 | + } else { |
| 464 | + values = ((StructuredValue)sourceValue).getFeatureValue(feature).values; |
| 465 | + } |
| 466 | + |
| 467 | + return values; |
| 468 | + } |
| 469 | + |
| 470 | + public fuml.semantics.structuredclassifiers.LinkList getMatchingLinks( |
| 471 | + fuml.syntax.structuredclassifiers.Association association, |
| 472 | + fuml.syntax.classification.StructuralFeature end, |
| 473 | + fuml.semantics.values.Value oppositeValue) { |
| 474 | + // Get the links of the given binary association whose end opposite |
| 475 | + // to the given end has the given value |
| 476 | + |
| 477 | + return this.getMatchingLinksForEndValue(association, end, oppositeValue, null); |
| 478 | + } |
| 479 | + |
| 480 | + |
| 481 | + public fuml.semantics.structuredclassifiers.LinkList getMatchingLinksForEndValue( |
| 482 | + fuml.syntax.structuredclassifiers.Association association, |
| 483 | + fuml.syntax.classification.StructuralFeature end, |
| 484 | + fuml.semantics.values.Value oppositeValue, |
| 485 | + fuml.semantics.values.Value endValue) { |
| 486 | + // Get the links of the given binary association whose end opposite |
| 487 | + // to the given end has the given opposite value and, optionally, that |
| 488 | + // has a given end value for the given end. |
| 489 | + |
| 490 | + Property oppositeEnd = this.getOppositeEnd(association, end); |
| 491 | + |
| 492 | + ExtensionalValueList extent = this.getExecutionLocus().getExtent( |
| 493 | + association); |
| 494 | + |
| 495 | + LinkList links = new LinkList(); |
| 496 | + for (int i = 0; i < extent.size(); i++) { |
| 497 | + ExtensionalValue link = extent.getValue(i); |
| 498 | + if (link.getFeatureValue(oppositeEnd).values.getValue(0).equals(oppositeValue)) { |
| 499 | + boolean matches = true; |
| 500 | + if (endValue != null) { |
| 501 | + matches = link.getFeatureValue(end).values.getValue(0).equals(endValue); |
| 502 | + } |
| 503 | + if (matches) { |
| 504 | + if (!end.multiplicityElement.isOrdered | links.size() == 0) { |
| 505 | + links.addValue((Link) link); |
| 506 | + } else { |
| 507 | + int n = link.getFeatureValue(end).position; |
| 508 | + boolean continueSearching = true; |
| 509 | + int j = 0; |
| 510 | + while (continueSearching & j < links.size()) { |
| 511 | + j = j + 1; |
| 512 | + continueSearching = links.getValue(j - 1).getFeatureValue(end).position < n; |
| 513 | + } |
| 514 | + if (continueSearching) { |
| 515 | + links.addValue((Link) link); |
| 516 | + } else { |
| 517 | + links.addValue(j - 1, (Link) link); |
| 518 | + } |
| 519 | + } |
| 520 | + } |
| 521 | + } |
| 522 | + } |
| 523 | + |
| 524 | + return links; |
| 525 | + } // getMatchingLinksForEndValue |
| 526 | + |
| 527 | + public fuml.syntax.classification.Property getOppositeEnd( |
| 528 | + fuml.syntax.structuredclassifiers.Association association, |
| 529 | + fuml.syntax.classification.StructuralFeature end) { |
| 530 | + // Get the end of a binary association opposite to the given end. |
| 531 | + |
| 532 | + Property oppositeEnd = association.memberEnd.getValue(0); |
| 533 | + if (oppositeEnd == end) { |
| 534 | + oppositeEnd = association.memberEnd.getValue(1); |
| 535 | + } |
| 536 | + |
| 537 | + return oppositeEnd; |
| 538 | + } // getOppositeEnd |
421 | 539 |
|
422 | 540 | public fuml.semantics.simpleclassifiers.BooleanValue makeBooleanValue( |
423 | 541 | boolean value) { |
|
0 commit comments