Search in sources :

Example 26 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-edr10 by opengeospatial.

the class CollectionsTime method dateTimeParameterDefinition.

/**
 * <pre>
 * Abstract Test 42: Validate that the dateTime query parameters are constructed correctly. (position)
 * Abstract Test 58: Validate that the dateTime query parameters are constructed correctly. (area)
 * Abstract Test 74: Validate that the dateTime query parameters are constructed correctly. (cube)
 * Abstract Test 139: Validate that the dateTime query parameters are constructed correctly. (instances)
 * </pre>
 *
 * @param testPoint the testPoint under test, never <code>null</code>
 * @param model api definition, never <code>null</code>
 */
public void dateTimeParameterDefinition(TestPoint testPoint, OpenApi3 model) {
    Parameter datetime = null;
    String paramName = "datetime";
    for (Path path : model.getPaths().values()) {
        if (path.getPathString().endsWith(testPoint.getPath())) {
            for (Operation op : path.getOperations().values()) {
                for (Parameter param : op.getParameters()) {
                    if (hasName(param)) {
                        if (param.getName().equals(paramName)) {
                            datetime = param;
                        }
                    }
                }
            }
        }
    }
    if (datetime != null) {
        String msg = "Expected property '%s' with value '%s' but was '%s'";
        assertEquals(datetime.getName(), paramName, String.format(msg, "name", paramName, datetime.getName()));
        assertEquals(datetime.getIn(), "query", String.format(msg, "in", "query", datetime.getIn()));
        assertFalse(isRequired(datetime), String.format(msg, "required", "false", datetime.getRequired()));
        assertEquals(datetime.getStyle(), "form", String.format(msg, "style", "form", datetime.getStyle()));
        assertFalse(isExplode(datetime), String.format(msg, "explode", "false", datetime.getExplode()));
    }
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) Operation(com.reprezen.kaizen.oasparser.model3.Operation)

Example 27 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-edr10 by opengeospatial.

the class CollectionsTime method corridorWidthParameterDefinition.

/**
 * <pre>
 * Abstract Test 118: Validate that the corridor-width query parameter is constructed correctly. (corridor)
 * </pre>
 * NOTE: Not referenced by ATS
 *
 * @param testPoint the testPoint under test, never <code>null</code>
 * @param model api definition, never <code>null</code>
 */
public void corridorWidthParameterDefinition(TestPoint testPoint, OpenApi3 model) {
    Parameter corridorWidth = null;
    String paramName = "corridor-width";
    for (Path path : model.getPaths().values()) {
        if (testPoint.getPath().equals(path.getPathString())) {
            for (Operation op : path.getOperations().values()) {
                for (Parameter param : op.getParameters()) {
                    if (hasName(param)) {
                        if (param.getName().equals(paramName)) {
                            corridorWidth = param;
                        }
                    }
                }
            }
        }
    }
    if (corridorWidth != null) {
        String msg = "Expected property '%s' with value '%s' but was '%s'";
        assertEquals(corridorWidth.getName(), paramName, String.format(msg, "name", paramName, corridorWidth.getName()));
        assertEquals(corridorWidth.getIn(), "query", String.format(msg, "in", "query", corridorWidth.getIn()));
        assertTrue(isRequired(corridorWidth), String.format(msg, "required", "true", corridorWidth.getRequired()));
        assertEquals(corridorWidth.getStyle(), "form", String.format(msg, "style", "form", corridorWidth.getStyle()));
        assertFalse(isExplode(corridorWidth), String.format(msg, "explode", "false", corridorWidth.getExplode()));
    }
}
Also used : Path(com.reprezen.kaizen.oasparser.model3.Path) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) Operation(com.reprezen.kaizen.oasparser.model3.Operation)

Example 28 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-edr10 by opengeospatial.

the class FeaturesAssertions method assertNumberMatched.

static void assertNumberMatched(OpenApi3 apiModel, URI iut, String collectionName, JsonPath jsonPath, boolean skipIfNoNumberMatched) throws URISyntaxException {
    if (!hasProperty("numberMatched", jsonPath))
        if (skipIfNoNumberMatched)
            throw new SkipException("Property numberMatched is not set in collection items '" + collectionName + "'");
        else
            return;
    int maximumLimit = -1;
    List<TestPoint> testPoints = retrieveTestPointsForCollection(apiModel, iut, collectionName);
    if (!testPoints.isEmpty()) {
        TestPoint testPoint = testPoints.get(0);
        Parameter limitParameter = OpenApiUtils.retrieveParameterByName(testPoint.getPath(), apiModel, "limit");
        if (limitParameter != null && limitParameter.getSchema() != null) {
            maximumLimit = limitParameter.getSchema().getMaximum().intValue();
        }
    }
    int numberMatched = jsonPath.getInt("numberMatched");
    int numberOfAllReturnedFeatures = collectNumberOfAllReturnedFeatures(jsonPath, maximumLimit);
    assertEquals(numberMatched, numberOfAllReturnedFeatures, "Value of numberReturned (" + numberMatched + ") does not match the number of features in all responses (" + numberOfAllReturnedFeatures + ")");
}
Also used : Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) SkipException(org.testng.SkipException) TestPoint(org.opengis.cite.ogcapiedr10.openapi3.TestPoint) TestPoint(org.opengis.cite.ogcapiedr10.openapi3.TestPoint)

Example 29 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project osate2 by osate.

the class AadlBaUtils method getFeatureType.

/**
 * Analyze the given AADL Osate element and return its enumeration type.
 *
 * It's an improved version of Osate2 org.osate.parser.AadlSemanticCheckSwitch#getFeatureType
 *
 * @param el the given AADL Osate element
 * @return the given AADL Osate element's type
 * @exception UnsupportedOperationException for the unsupported types
 */
/*
	 * <copyright>
	 * Copyright 2009 by Carnegie Mellon University, all rights reserved.
	 *
	 * Use of the Open Source AADL Tool Environment (OSATE) is subject to the terms of the license set forth
	 * at http://www.eclipse.org/legal/cpl-v10.html.
	 *
	 * NO WARRANTY
	 *
	 * ANY INFORMATION, MATERIALS, SERVICES, INTELLECTUAL PROPERTY OR OTHER PROPERTY OR RIGHTS GRANTED OR PROVIDED BY
	 * CARNEGIE MELLON UNIVERSITY PURSUANT TO THIS LICENSE (HEREINAFTER THE "DELIVERABLES") ARE ON AN "AS-IS" BASIS.
	 * CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED AS TO ANY MATTER INCLUDING,
	 * BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, INFORMATIONAL CONTENT,
	 * NONINFRINGEMENT, OR ERROR-FREE OPERATION. CARNEGIE MELLON UNIVERSITY SHALL NOT BE LIABLE FOR INDIRECT, SPECIAL OR
	 * CONSEQUENTIAL DAMAGES, SUCH AS LOSS OF PROFITS OR INABILITY TO USE SAID INTELLECTUAL PROPERTY, UNDER THIS LICENSE,
	 * REGARDLESS OF WHETHER SUCH PARTY WAS AWARE OF THE POSSIBILITY OF SUCH DAMAGES. LICENSEE AGREES THAT IT WILL NOT
	 * MAKE ANY WARRANTY ON BEHALF OF CARNEGIE MELLON UNIVERSITY, EXPRESS OR IMPLIED, TO ANY PERSON CONCERNING THE
	 * APPLICATION OF OR THE RESULTS TO BE OBTAINED WITH THE DELIVERABLES UNDER THIS LICENSE.
	 *
	 * Licensee hereby agrees to defend, indemnify, and hold harmless Carnegie Mellon University, its trustees, officers,
	 * employees, and agents from all claims or demands made against them (and any related losses, expenses, or
	 * attorney's fees) arising out of, or relating to Licensee's and/or its sub licensees' negligent use or willful
	 * misuse of or negligent conduct or willful misconduct regarding the Software, facilities, or other rights or
	 * assistance granted by Carnegie Mellon University under this License, including, but not limited to, any claims of
	 * product liability, personal injury, death, damage to property, or violation of any laws or regulations.
	 *
	 * Carnegie Mellon University Software Engineering Institute authored documents are sponsored by the U.S. Department
	 * of Defense under Contract F19628-00-C-0003. Carnegie Mellon University retains copyrights in all material produced
	 * under this contract. The U.S. Government retains a non-exclusive, royalty-free license to publish or reproduce these
	 * documents, or allow others to do so, for U.S. Government purposes only pursuant to the copyright license
	 * under the contract clause at 252.227.7013.
	 * </copyright>
	 */
public static org.osate.ba.aadlba.FeatureType getFeatureType(Element el) {
    if (el instanceof DataPort) {
        switch(((DataPort) el).getDirection()) {
            case IN:
                return FeatureType.IN_DATA_PORT;
            case OUT:
                return FeatureType.OUT_DATA_PORT;
            case IN_OUT:
                return FeatureType.IN_OUT_DATA_PORT;
        }
    } else if (el instanceof EventPort) {
        switch(((EventPort) el).getDirection()) {
            case IN:
                return FeatureType.IN_EVENT_PORT;
            case OUT:
                return FeatureType.OUT_EVENT_PORT;
            case IN_OUT:
                return FeatureType.IN_OUT_EVENT_PORT;
        }
    } else if (el instanceof EventDataPort) {
        switch(((EventDataPort) el).getDirection()) {
            case IN:
                return FeatureType.IN_EVENT_DATA_PORT;
            case OUT:
                return FeatureType.OUT_EVENT_DATA_PORT;
            case IN_OUT:
                return FeatureType.IN_OUT_EVENT_DATA_PORT;
        }
    } else if (el instanceof FeatureGroup) {
        return FeatureType.FEATURE_GROUP;
    } else if (el instanceof DataAccess) {
        switch(((DataAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_DATA_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_DATA_ACCESS;
        }
    } else if (el instanceof SubprogramAccess) {
        switch(((SubprogramAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_SUBPROGRAM_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_SUBPROGRAM_ACCESS;
        }
    } else if (el instanceof SubprogramGroupAccess) {
        switch(((SubprogramGroupAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_SUBPROGRAM_GROUP_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_SUBPROGRAM_GROUP_ACCESS;
        }
    } else if (el instanceof BusAccess) {
        switch(((BusAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_BUS_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_BUS_ACCESS;
        }
    } else if (el instanceof AbstractFeature) {
        return FeatureType.ABSTRACT_FEATURE;
    } else if (el instanceof Parameter) {
        switch(((Parameter) el).getDirection()) {
            case IN:
                return FeatureType.IN_PARAMETER;
            case OUT:
                return FeatureType.OUT_PARAMETER;
            case IN_OUT:
                return FeatureType.IN_OUT_PARAMETER;
        }
    } else if (el instanceof Prototype) {
        if (el instanceof ComponentPrototype) {
            switch(el.eClass().getClassifierID()) {
                case Aadl2Package.SUBPROGRAM_PROTOTYPE:
                    return FeatureType.SUBPROGRAM_PROTOTYPE;
                case Aadl2Package.SUBPROGRAM_GROUP_PROTOTYPE:
                    return FeatureType.SUBPROGRAM_GROUP_PROTOTYPE;
                case Aadl2Package.THREAD_PROTOTYPE:
                    return FeatureType.THREAD_PROTOTYPE;
                case Aadl2Package.THREAD_GROUP_PROTOTYPE:
                    return FeatureType.THREAD_GROUP_PROTOTYPE;
                default:
                    return FeatureType.COMPONENT_PROTOTYPE;
            }
        } else if (el instanceof FeaturePrototype) {
            return getFeaturePrototypeType((FeaturePrototype) el);
        } else if (el instanceof FeatureGroupPrototype) {
            return FeatureType.FEATURE_GROUP_PROTOTYPE;
        }
    } else if (el instanceof PrototypeBinding) {
        if (el instanceof ComponentPrototypeBinding) {
            return FeatureType.COMPONENT_PROTOTYPE_BINDING;
        } else if (el instanceof FeatureGroupPrototypeBinding) {
            return FeatureType.FEATURE_GROUP_PROTOTYPE_BINDING;
        } else // FeaturePrototypeBinding case.
        {
            return FeatureType.FEATURE_PROTOTYPE_BINDING;
        }
    } else if (el instanceof org.osate.aadl2.PropertyConstant) {
        return FeatureType.PROPERTY_CONSTANT;
    } else if (el instanceof org.osate.aadl2.Property) {
        return FeatureType.PROPERTY_VALUE;
    } else if (el instanceof ClassifierValue) {
        return FeatureType.CLASSIFIER_VALUE;
    } else if (el instanceof SubprogramGroup) {
        return FeatureType.SUBPROGRAM_GROUP;
    } else if (el instanceof SubprogramGroupAccess) {
        switch(((SubprogramGroupAccess) el).getKind()) {
            case PROVIDES:
                return FeatureType.PROVIDES_SUBPROGRAM_GROUP_ACCESS;
            case REQUIRES:
                return FeatureType.REQUIRES_SUBPROGRAM_GROUP_ACCESS;
        }
    } else if (el instanceof ThreadGroup) {
        return FeatureType.THREAD_GROUP;
    } else if (el instanceof SystemSubcomponent) {
        return FeatureType.SYSTEM_SUBCOMPONENT;
    } else if (el instanceof SubprogramSubcomponent) {
        return FeatureType.SUBPROGRAM_SUBCOMPONENT;
    } else if (el instanceof SubprogramClassifier) {
        return FeatureType.SUBPROGRAM_CLASSIFIER;
    } else if (el instanceof DataSubcomponent) {
        return FeatureType.DATA_SUBCOMPONENT;
    } else if (el instanceof DataClassifier) {
        return FeatureType.DATA_CLASSIFIER;
    } else if (el instanceof ProcessorClassifier) {
        return FeatureType.PROCESSOR_CLASSIFIER;
    } else if (el instanceof ProcessClassifier) {
        return FeatureType.PROCESS_CLASSIFIER;
    }
    String errorMsg = "getFeatureType : " + el.getClass().getSimpleName() + " is not supported yet at line " + Aadl2Utils.getLocationReference(el).getLine() + ".";
    System.err.println(errorMsg);
    throw new UnsupportedOperationException(errorMsg);
}
Also used : SubprogramGroup(org.osate.aadl2.SubprogramGroup) FeatureGroup(org.osate.aadl2.FeatureGroup) Prototype(org.osate.aadl2.Prototype) DataPrototype(org.osate.aadl2.DataPrototype) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) FeaturePrototype(org.osate.aadl2.FeaturePrototype) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ClassifierValue(org.osate.aadl2.ClassifierValue) DataClassifier(org.osate.aadl2.DataClassifier) AadlString(org.osate.aadl2.AadlString) SubprogramClassifier(org.osate.aadl2.SubprogramClassifier) DataAccess(org.osate.aadl2.DataAccess) ComponentPrototype(org.osate.aadl2.ComponentPrototype) ProcessorClassifier(org.osate.aadl2.ProcessorClassifier) DataPort(org.osate.aadl2.DataPort) EventDataPort(org.osate.aadl2.EventDataPort) FeatureGroupPrototype(org.osate.aadl2.FeatureGroupPrototype) EventPort(org.osate.aadl2.EventPort) SubprogramAccess(org.osate.aadl2.SubprogramAccess) ThreadGroup(org.osate.aadl2.ThreadGroup) EventDataPort(org.osate.aadl2.EventDataPort) PrototypeBinding(org.osate.aadl2.PrototypeBinding) FeaturePrototypeBinding(org.osate.aadl2.FeaturePrototypeBinding) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) BusAccess(org.osate.aadl2.BusAccess) FeatureGroupPrototypeBinding(org.osate.aadl2.FeatureGroupPrototypeBinding) ProcessClassifier(org.osate.aadl2.ProcessClassifier) AbstractFeature(org.osate.aadl2.AbstractFeature) ComponentPrototypeBinding(org.osate.aadl2.ComponentPrototypeBinding) SubprogramGroupAccess(org.osate.aadl2.SubprogramGroupAccess) BehaviorPropertyConstant(org.osate.ba.aadlba.BehaviorPropertyConstant) SystemSubcomponent(org.osate.aadl2.SystemSubcomponent) FeaturePrototype(org.osate.aadl2.FeaturePrototype) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Parameter(org.osate.aadl2.Parameter)

Example 30 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project osate2 by osate.

the class CreateConnectionsSwitch method appendSegment.

/**
 * appendSegment Append a segment to a connection instance.
 *
 * @param newSegment
 *            the declarative connection to be added to the connection
 *            instance
 * @param ci
 *            the component that contains the new segment
 * @param goOpposite
 *            the current declarative connection is bidirectional and we are
 *            following it toward its source
 * @param conni
 *            the connection instance representing the semantic connection
 */
// TODO-LW: set 'complete' in conn info
private void appendSegment(ConnectionInfo connInfo, final Connection newSegment, final ComponentInstance ci, final boolean goOpposite) {
    final boolean didModeTransitionConnection = doModeTransitionConnections(ci, connInfo, newSegment);
    final ConnectionEnd fromEnd = goOpposite ? newSegment.getAllDestination() : newSegment.getAllSource();
    final Context fromCtx = goOpposite ? newSegment.getAllDestinationContext() : newSegment.getAllSourceContext();
    ConnectionEnd toEnd = goOpposite ? newSegment.getAllSource() : newSegment.getAllDestination();
    final Context toCtx = goOpposite ? newSegment.getAllSourceContext() : newSegment.getAllDestinationContext();
    final ComponentInstance toCi = (toCtx instanceof Subcomponent) ? ci.findSubcomponentInstance((Subcomponent) toCtx) : null;
    final boolean finalComponent = isConnectionEndingComponent(toCtx);
    final boolean dstEmpty = toCtx instanceof Subcomponent && toCi.getComponentInstances().isEmpty();
    ConnectionInstanceEnd fromFi = null;
    ConnectionInstanceEnd toFi = null;
    FeatureInstance pushedFeature = null;
    FeatureInstance poppedFeature = null;
    FeatureInstance downedFeature = null;
    /*
		 * FIX JD If we have a data component directly connected to a subprogram
		 * parameter, we do not handle it because we do not deal with parameter
		 * connection within the instance model. See bug #220
		 */
    if ((toEnd instanceof ParameterImpl) && ((fromEnd instanceof DataSubcomponent) || (fromEnd instanceof DataAccess))) {
        return;
    }
    /*
		 * Fix JD bug #222.
		 * Tweaked again for Issue #2162: changed to check if the context is a subprogram call
		 * rather than just checking if the feature is contained in a subprogram.
		 */
    if ((toEnd instanceof DataAccess) && (toCtx instanceof SubprogramCall)) {
        return;
    }
    if (toCtx instanceof Subcomponent && toCi == null) {
        if (!(toCtx instanceof SubprogramSubcomponent)) {
            error(ci, "Instantiation error: no component instance for subcomponent " + toCtx.getName());
        }
        return;
    }
    if (!(fromEnd instanceof Subcomponent)) {
        // fromEnd is a feature
        final ComponentInstance fromCi = (fromCtx instanceof Subcomponent) ? ci.findSubcomponentInstance((Subcomponent) fromCtx) : null;
        if (fromCtx instanceof Subcomponent && fromCi == null) {
            if (!(fromCtx instanceof SubprogramSubcomponent)) {
                error(ci, "Instantiation error: no component instance for subcomponent " + fromCtx.getName());
            }
            return;
        }
        List<FeatureInstance> fiList = null;
        if (fromCtx instanceof FeatureGroup) {
            // TODO phf: find index and compare with stack
            FeatureInstance fgi = (FeatureInstance) AadlUtil.findNamedElementInList(ci.getFeatureInstances(), fromCtx.getName());
            if (fgi != null) {
                fiList = fgi.getFeatureInstances();
                fromFi = (FeatureInstance) AadlUtil.findNamedElementInList(fiList, fromEnd.getName());
            }
            if (fromFi != null) {
                if (!upFeature.empty()) {
                    FeatureInstance popfi = upFeature.peek();
                    // match against stack only if we don't reach deeper into feature group
                    if (connInfo.dstToMatch == null && !Aadl2InstanceUtil.isSame(popfi, (FeatureInstance) fromFi)) {
                        // did not match
                        return;
                    } else {
                        poppedFeature = upFeature.pop();
                    }
                } else {
                    downFeature.push((FeatureInstance) fromFi);
                    downedFeature = (FeatureInstance) fromFi;
                }
            }
        } else {
            fiList = (fromCi != null ? fromCi : ci).getFeatureInstances();
            fromFi = (FeatureInstance) AadlUtil.findNamedElementInList(fiList, fromEnd.getName());
        }
    } else {
        fromFi = ci.findSubcomponentInstance((Subcomponent) fromEnd);
    }
    if (!(toEnd instanceof Subcomponent)) {
        List<FeatureInstance> fiList = null;
        if (toCtx instanceof FeatureGroup) {
            FeatureInstance fgi = (FeatureInstance) AadlUtil.findNamedElementInList(ci.getFeatureInstances(), toCtx.getName());
            if (fgi != null) {
                fiList = fgi.getFeatureInstances();
                toFi = (FeatureInstance) AadlUtil.findNamedElementInList(fiList, toEnd.getName());
            }
            if (toFi != null) {
                upFeature.push((FeatureInstance) toFi);
                pushedFeature = (FeatureInstance) toFi;
            }
        } else {
            fiList = (toCi != null ? toCi : ci).getFeatureInstances();
            toFi = (FeatureInstance) AadlUtil.findNamedElementInList(fiList, toEnd.getName());
        }
    } else {
        toFi = ci.findSubcomponentInstance((Subcomponent) toEnd);
    }
    /*
		 * Issue 2032: We do not want connections that go from abstract subcomponent to the ports of
		 * their containing components if the containing component is final. We specifically are
		 * checking that the connection starts at a port feature and ends at a feature that is a feature
		 * of the containing component and the containing component is a connection ending component. We don't
		 * have to check that the end feature is a port because AADL semantics guarantee that it will be.
		 */
    if (fromFi instanceof FeatureInstance && ((FeatureInstance) fromFi).getFeature() instanceof Port && toFi.eContainer().equals(ci) && isConnectionEndingCategory(ci.getCategory())) {
        return;
    }
    try {
        boolean[] keep = { false };
        boolean valid = connInfo.addSegment(newSegment, fromFi, toFi, ci, goOpposite, keep);
        if (!keep[0]) {
            return;
        }
        if (!valid) {
            if (toFi == null) {
                error(ci, "Connection from " + connInfo.src.getInstanceObjectPath() + " via " + newSegment.getQualifiedName() + " has no valid direction. Connection instance not created.");
            } else {
                error(ci, "Connection from " + connInfo.src.getInstanceObjectPath() + " to " + toFi.getInstanceObjectPath() + " has no valid direction. Connection instance not created.");
            }
            return;
        }
        // first check if the connection must end with the new segment
        if (toEnd instanceof Subcomponent) {
            ComponentInstance toInstance = ci.findSubcomponentInstance((Subcomponent) toEnd);
            if (toInstance == null) {
                // happens if conn leaves system to aggregate data port
                warning(ci, "Connection to " + toEnd.getQualifiedName() + " could not be instantiated.");
            } else {
                // connection ends at a shared data, bus, or subprogram (group)
                connInfo.complete = true;
                finalizeConnectionInstance(ci.getSystemInstance(), connInfo, toInstance);
            }
        } else if (toEnd instanceof InternalFeature || toEnd instanceof ProcessorFeature) {
            // can't handle these
            // FIXME: What if a connection from outside goes to one of these?
            warning(ci, "Connection to " + toEnd.getQualifiedName() + " could not be instantiated.");
        } else {
            Feature toFeature = (Feature) toEnd;
            if (toEnd instanceof Parameter) {
                // connection ends at a parameter
                FeatureInstance dstFi = toCi.findFeatureInstance(toFeature);
                if (dstFi == null) {
                    error(toCi, "Destination feature " + toFeature.getName() + " not found. No connection created.");
                } else {
                    connInfo.complete = true;
                    finalizeConnectionInstance(ci, connInfo, dstFi);
                }
            } else if (dstEmpty) {
                // connection ends because the destination component does not
                // contain any subcomponents
                FeatureInstance dstFi = toCi.findFeatureInstance(toFeature);
                if (dstFi == null) {
                    error(toCi, "Destination feature " + toFeature.getName() + " not found. No connection created.");
                } else {
                    connInfo.complete = true;
                    finalizeConnectionInstance(ci, connInfo, dstFi);
                }
            } else if (!(toCtx instanceof Subcomponent)) {
                // implementation
                if (ci instanceof SystemInstance) {
                    if (toCtx instanceof FeatureGroup) {
                        // XXX: PHF: going up into an element of a feature group
                        // should we go to the FG or to the feature?
                        finalizeConnectionInstance(ci, connInfo, ci.findFeatureInstance((FeatureGroup) toCtx));
                    } else {
                        finalizeConnectionInstance(ci, connInfo, ci.findFeatureInstance(toFeature));
                    }
                } else {
                    if (toCtx instanceof FeatureGroup) {
                        toFeature = (FeatureGroup) toCtx;
                    // toFeature now points to the enclosing feature group
                    // this should be the starting feature for the next
                    // connection
                    }
                    ComponentInstance nextCi = ci.getContainingComponentInstance();
                    List<Connection> parentConns = InstanceUtil.getComponentImplementation(nextCi, 0, classifierCache).getAllConnections();
                    FeatureInstance dstFi = ci.findFeatureInstance(toFeature);
                    List<Connection> conns = filterOutgoingConnections(parentConns, dstFi.getFeature(), ci.getSubcomponent());
                    if (conns.isEmpty()) {
                        if (!didModeTransitionConnection) {
                            if (ci instanceof SystemInstance) {
                                finalizeConnectionInstance(ci, connInfo, ci.findFeatureInstance(toFeature));
                            } else {
                                warning(toFi, "Could not continue connection from " + connInfo.src.getInstanceObjectPath() + "  through " + toFi.getInstanceObjectPath() + ". No connection instance created.");
                            }
                        }
                    } else {
                        for (Connection nextConn : conns) {
                            // note: nextConn goes either up or across
                            final ConnectionInfo clone = connInfo.cloneInfo();
                            boolean opposite = false;
                            if (nextConn.isAllBidirectional()) {
                                /*
									 * The next connection is bidirectional, but we need to figure out if we are
									 * traveling from its src to dest or from its dest to src.
									 *
									 * Put another way, we traverse the next connection in the opposite direction
									 * only if the destination feature instance of the next connection is equal to
									 * the destination feature instance of the current connection (based on "toFeature" which
									 * already takes it's own opposite direction into account via "goOpposite" at
									 * the start of the method).
									 */
                                final ConnectionEnd nextConnDest = nextConn.getAllDestination();
                                if (nextConnDest instanceof Feature) {
                                    final Feature nextConnDstFeature = (Feature) nextConnDest;
                                    FeatureInstance nextConnDstFi = nextCi.findFeatureInstance(nextConnDstFeature);
                                    /*
										 * If we find the connection destination in the containing component instance, then
										 * the connection is a normal (not reversed) traversal of the connection. The
										 * value of `opposite` will stay `false`.
										 */
                                    if (nextConnDstFi == null) {
                                        /*
											 * Didn't find the next destination in the containing component, so the question
											 * still is, is the destination in a sibling subcomponent or is it a reversed
											 * traversal from the containing component, or even a reversed traversal from
											 * a sibling subcomponent?
											 */
                                        // next goes across, maybe?
                                        Context nextConnDstCtx = nextConn.getAllDestinationContext();
                                        if (nextConnDstCtx instanceof Subcomponent) {
                                            final ComponentInstance nextConnDstSubi = nextCi.findSubcomponentInstance((Subcomponent) nextConnDstCtx);
                                            nextConnDstFi = nextConnDstSubi.findFeatureInstance(nextConnDstFeature);
                                        }
                                        if (nextConnDstFi != null) {
                                            /*
												 * Opposite is true if the dest of the next connection the same feature instance as the
												 * dest of the current connection.
												 */
                                            opposite = ci.findFeatureInstance(toFeature) == nextConnDstFi;
                                        }
                                    }
                                }
                            } else {
                            /*
									 * not bidirectional, so the src of nextConn is a feature of 'ci', and the dest
									 * is a feature of either 'nextCi` or a sibling subcomponent. We are following
									 * the connection in its natural direction, so `opposite` is `false`.
									 */
                            }
                            appendSegment(clone, nextConn, nextCi, opposite);
                        }
                    }
                }
            } else {
                if (toCtx instanceof Subcomponent && toCi == null) {
                    if (!(toCtx instanceof SubprogramSubcomponent)) {
                        error(ci, "Instantiation error: no component instance for subcomponent " + toCtx.getName());
                    }
                    return;
                }
                toFi = toCi.findFeatureInstance(toFeature);
                if (toFi == null) {
                    error(ci, "Could not find instance object for feature " + toEnd.getName() + " of subcomponent " + ((Subcomponent) toCtx).getName() + ". No connection instance created.");
                    return;
                }
                ComponentImplementation toImpl = InstanceUtil.getComponentImplementation(toCi, 0, classifierCache);
                if (toImpl == null) {
                    connInfo.complete = true;
                    finalizeConnectionInstance(ci, connInfo, toFi);
                } else {
                    // there is a toImpl
                    /*
						 * Issue 2032: Get the connections internal to the destination component that connect
						 * to the feature. Two cases here. (1) If the component is final (thread/device/processor),
						 * we only follow access features inside, (2) otherwise we follow all the internal connections
						 * except for the parameter connections. We keep track of whether any internal connections were
						 * ignored so we know if we should create a connection instance that stops at the component itself.
						 */
                    final AtomicBoolean hasIgnoredConnection = new AtomicBoolean(false);
                    List<Connection> conns = AadlUtil.getIngoingConnections(toImpl, toFeature, c -> {
                        if (c instanceof AccessConnection) {
                            // never ignore access connections
                            return true;
                        } else if (c instanceof ParameterConnection) {
                            // always ignore parameter connections
                            hasIgnoredConnection.set(true);
                            return false;
                        } else {
                            // Ignore other connections only if the component is connection ending
                            if (finalComponent) {
                                hasIgnoredConnection.set(true);
                                return false;
                            } else {
                                return true;
                            }
                        }
                    });
                    if (conns.isEmpty()) {
                        // No internal connections, or they are all parameter connections, so we stop here
                        List<Subcomponent> subs = toImpl.getAllSubcomponents();
                        if (!subs.isEmpty()) {
                            if (!finalComponent) {
                                warning(ci, "No connection declaration from feature " + toEnd.getName() + " of component " + ((Subcomponent) toCtx).getName() + " to subcomponents. Connection instance ends at " + ((Subcomponent) toCtx).getName());
                            }
                            connInfo.complete = true;
                            finalizeConnectionInstance(ci, connInfo, toFi);
                        }
                    } else {
                        /*
							 * Issue 2032: If we get here then destination component has internal connections,
							 * not all of which are parameter connections. We definitely are going to proceed
							 * inside the component with the connection. However, if there are internal
							 * connections that were ignored, we also need to create a connection instance that
							 * ends at the component.
							 *
							 * NB. Not possible to have an ignored parameter connection from a feature and have a
							 * another not ignored connection from that feature because the only place a
							 * parameter connection can exist is in a subprogram or a thread, and it's
							 * not possible to have a regular port connections internal to
							 * either one of those (with the exception of abstract components, but those
							 * should probably be illegal anyway and we ignore those too).
							 */
                        if (hasIgnoredConnection.get()) {
                            final ConnectionInfo clone = connInfo.cloneInfo();
                            clone.complete = true;
                            finalizeConnectionInstance(ci, clone, toFi);
                        }
                        // as End or as Cxt
                        for (Connection nextConn : conns) {
                            final ConnectionInfo clone = connInfo.cloneInfo();
                            EList<Feature> toflist = toFeature.getAllFeatureRefinements();
                            Context dstCtx = nextConn.getAllDestinationContext();
                            // dstCtx is null if we're going down and in opposite direction
                            final boolean opposite = toflist.contains(nextConn.getAllDestination()) && (dstCtx == null || toCtx == dstCtx) || toflist.contains(dstCtx);
                            appendSegment(clone, nextConn, toCi, opposite);
                        }
                    }
                }
            }
        }
    } finally {
        if (pushedFeature != null) {
            if (!upFeature.empty()) {
                upFeature.pop();
            } else {
                warning(ci, "Popping from empty upindex");
            }
        }
        if (poppedFeature != null) {
            if (downFeature.empty()) {
                upFeature.push(poppedFeature);
            } else {
                // remove from downIndex
                warning(ci, "Trying to push back on while downIndex is not empty");
            }
        }
        if (downedFeature != null) {
            // remove from downIndex
            FeatureInstance popfeature = downFeature.pop();
            if (!Aadl2InstanceUtil.isSame(popfeature, downedFeature)) {
                // should be the same
                warning(ci, "Did not match popped downIndex");
            }
        }
    }
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) Aadl2InstanceUtil(org.osate.aadl2.util.Aadl2InstanceUtil) InstantiatedClassifier(org.osate.aadl2.instance.util.InstanceUtil.InstantiatedClassifier) VIRTUAL_BUS(org.osate.aadl2.ComponentCategory.VIRTUAL_BUS) Element(org.osate.aadl2.Element) ListIterator(java.util.ListIterator) InternalFeature(org.osate.aadl2.InternalFeature) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) Port(org.osate.aadl2.Port) DATA(org.osate.aadl2.ComponentCategory.DATA) BUS(org.osate.aadl2.ComponentCategory.BUS) ParameterConnection(org.osate.aadl2.ParameterConnection) ModeTransition(org.osate.aadl2.ModeTransition) SubprogramCall(org.osate.aadl2.SubprogramCall) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ParameterImpl(org.osate.aadl2.impl.ParameterImpl) AccessConnection(org.osate.aadl2.AccessConnection) ConnectionEnd(org.osate.aadl2.ConnectionEnd) ProcessorFeature(org.osate.aadl2.ProcessorFeature) FeatureCategory(org.osate.aadl2.instance.FeatureCategory) SystemInstance(org.osate.aadl2.instance.SystemInstance) VIRTUAL_PROCESSOR(org.osate.aadl2.ComponentCategory.VIRTUAL_PROCESSOR) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) TriggerPort(org.osate.aadl2.TriggerPort) ClassifierMatchingRule(org.osate.aadl2.contrib.modeling.ClassifierMatchingRule) Assert(org.eclipse.core.runtime.Assert) AadlProcessingSwitchWithProgress(org.osate.aadl2.modelsupport.modeltraversal.AadlProcessingSwitchWithProgress) EObject(org.eclipse.emf.ecore.EObject) Connection(org.osate.aadl2.Connection) Collectors(java.util.stream.Collectors) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Mode(org.osate.aadl2.Mode) SUBPROGRAM(org.osate.aadl2.ComponentCategory.SUBPROGRAM) List(java.util.List) SystemOperationMode(org.osate.aadl2.instance.SystemOperationMode) InstanceSwitch(org.osate.aadl2.instance.util.InstanceSwitch) InstanceObject(org.osate.aadl2.instance.InstanceObject) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) Feature(org.osate.aadl2.Feature) ComponentImplementation(org.osate.aadl2.ComponentImplementation) AnalysisErrorReporterManager(org.osate.aadl2.modelsupport.errorreporting.AnalysisErrorReporterManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) DataAccess(org.osate.aadl2.DataAccess) ModeTransitionTrigger(org.osate.aadl2.ModeTransitionTrigger) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) Stack(java.util.Stack) ArrayList(java.util.ArrayList) DataSubcomponent(org.osate.aadl2.DataSubcomponent) DEVICE(org.osate.aadl2.ComponentCategory.DEVICE) Subcomponent(org.osate.aadl2.Subcomponent) TreeIterator(org.eclipse.emf.common.util.TreeIterator) InstanceUtil(org.osate.aadl2.instance.util.InstanceUtil) Context(org.osate.aadl2.Context) FeatureGroup(org.osate.aadl2.FeatureGroup) AadlUtil(org.osate.aadl2.modelsupport.util.AadlUtil) Iterator(java.util.Iterator) SUBPROGRAM_GROUP(org.osate.aadl2.ComponentCategory.SUBPROGRAM_GROUP) PROCESSOR(org.osate.aadl2.ComponentCategory.PROCESSOR) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ModelingProperties(org.osate.aadl2.contrib.modeling.ModelingProperties) ConnectionInstance(org.osate.aadl2.instance.ConnectionInstance) ModeTransitionInstance(org.osate.aadl2.instance.ModeTransitionInstance) EList(org.eclipse.emf.common.util.EList) FeatureGroupType(org.osate.aadl2.FeatureGroupType) PortConnection(org.osate.aadl2.PortConnection) ConnectionReference(org.osate.aadl2.instance.ConnectionReference) ComponentCategory(org.osate.aadl2.ComponentCategory) ModeInstance(org.osate.aadl2.instance.ModeInstance) Parameter(org.osate.aadl2.Parameter) NamedElement(org.osate.aadl2.NamedElement) THREAD(org.osate.aadl2.ComponentCategory.THREAD) Collections(java.util.Collections) Access(org.osate.aadl2.Access) ConnectedElement(org.osate.aadl2.ConnectedElement) FeatureGroup(org.osate.aadl2.FeatureGroup) FeatureInstance(org.osate.aadl2.instance.FeatureInstance) ConnectionInstanceEnd(org.osate.aadl2.instance.ConnectionInstanceEnd) Port(org.osate.aadl2.Port) TriggerPort(org.osate.aadl2.TriggerPort) InternalFeature(org.osate.aadl2.InternalFeature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) Feature(org.osate.aadl2.Feature) DataAccess(org.osate.aadl2.DataAccess) SystemInstance(org.osate.aadl2.instance.SystemInstance) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) DataSubcomponent(org.osate.aadl2.DataSubcomponent) Subcomponent(org.osate.aadl2.Subcomponent) ComponentInstance(org.osate.aadl2.instance.ComponentInstance) InternalFeature(org.osate.aadl2.InternalFeature) ProcessorFeature(org.osate.aadl2.ProcessorFeature) List(java.util.List) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) SubprogramCall(org.osate.aadl2.SubprogramCall) Context(org.osate.aadl2.Context) SubprogramSubcomponent(org.osate.aadl2.SubprogramSubcomponent) ParameterConnection(org.osate.aadl2.ParameterConnection) AccessConnection(org.osate.aadl2.AccessConnection) FeatureGroupConnection(org.osate.aadl2.FeatureGroupConnection) Connection(org.osate.aadl2.Connection) PortConnection(org.osate.aadl2.PortConnection) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EList(org.eclipse.emf.common.util.EList) ParameterImpl(org.osate.aadl2.impl.ParameterImpl) DataSubcomponent(org.osate.aadl2.DataSubcomponent) ParameterConnection(org.osate.aadl2.ParameterConnection) Parameter(org.osate.aadl2.Parameter) ConnectionEnd(org.osate.aadl2.ConnectionEnd) AccessConnection(org.osate.aadl2.AccessConnection)

Aggregations

Parameter (com.reprezen.kaizen.oasparser.model3.Parameter)26 Path (com.reprezen.kaizen.oasparser.model3.Path)17 Operation (com.reprezen.kaizen.oasparser.model3.Operation)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)7 Parameter (org.osate.aadl2.Parameter)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 DataAccess (org.osate.aadl2.DataAccess)4 FeatureGroup (org.osate.aadl2.FeatureGroup)3 Test (org.testng.annotations.Test)3 Map (java.util.Map)2 Parameter (org.eclipse.jst.server.tomcat.core.internal.xml.server32.Parameter)2 TestPoint (org.opengis.cite.ogcapifeatures10.openapi3.TestPoint)2 AbstractFeature (org.osate.aadl2.AbstractFeature)2 ClassifierValue (org.osate.aadl2.ClassifierValue)2 DataSubcomponent (org.osate.aadl2.DataSubcomponent)2 Port (org.osate.aadl2.Port)2 SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)2 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)1 ParameterDef (com.devonfw.cobigen.openapiplugin.model.ParameterDef)1