public SemanticOperationHandler(SemanticsGlobalScope semanticsScope, DocumentParser documentParser, Scope <Object> semanticOperationVariableMap) { this.semanticsScope = semanticsScope; this.documentParser = documentParser; // semanticOperationVariableMap.Add( // SemanticOperationKeyWords.PURLCONNECTION_MIME, // documentParser.purlConnection().mimeType()); this.semanticOperationVariableMap = semanticOperationVariableMap; }
public void HandleIf(IfSemanticOperation operation, DocumentParser parser, SemanticsGlobalScope infoCollector) { // conditions have been checked in handleSemanticAction() try { SetOperationState(operation, "state", SemanticOperation.INTER); List <SemanticOperation> nestedSemanticActions = operation.NestedSemanticActionList; foreach (SemanticOperation nestedSemanticAction in nestedSemanticActions) { HandleSemanticOperation(nestedSemanticAction, parser, infoCollector); } } catch (Exception e) { throw new IfOperationException(e, operation, semanticOperationVariableMap); } }
public SemanticOperationHandler(SemanticsGlobalScope semanticsScope, DocumentParser documentParser) : this(semanticsScope, documentParser, new Scope <Object>(BuiltInScope)) { }
public void HandleForLoop(ForEachSemanticOperation operation, DocumentParser parser, SemanticsGlobalScope infoCollector) { try { // get all the action which have to be performed in loop List <SemanticOperation> nestedSemanticActions = operation.NestedSemanticActionList; // get the collection object name on which we have to loop String collectionObjectName = operation.Collection; // if(checkPreConditionFlagsIfAny(action)) { Object collectionObject = semanticOperationVariableMap.Get(collectionObjectName); if (collectionObject == null) { Debug.WriteLine("Can't execute loop because collection is null: " + SimplTypesScope.Serialize(operation, StringFormat.Xml)); return; } // get the objects from the collection object /* List<Object> collection = new List<Object>(); * foreach (Object value in (IEnumerable)collectionObject) * { * collection.Add(value); * } */ int collectionSize = ((IList)collectionObject).Count; // set the size of collection in the for loop action. if (operation.Size != null) { // we have the size value. so we add it in parameters semanticOperationVariableMap.Put(operation.Size, collectionSize); } int start = 0; int end = collectionSize; if (operation.Start != null) { start = Int32.Parse(operation.Start); } if (operation.End != null) { end = Int32.Parse(operation.End); } if (GetOperationState(operation, "state", SemanticOperation.INIT) == SemanticOperation.INTER) { start = GetOperationState(operation, "current_index", 0); } SetOperationState(operation, "state", SemanticOperation.INTER); // start the loop over each object for (int i = start; i < end; i++) { SetOperationState(operation, "current_index", i); Object item = ((IList)collectionObject)[i]; // put it in semantic action return value map semanticOperationVariableMap.Put(operation.AsStr, item); // see if current index is needed if (operation.CurrentIndex != null) { // set the value of this variable in parameters semanticOperationVariableMap.Put(operation.CurrentIndex, i); } // now take all the actions nested inside for loop foreach (SemanticOperation nestedSemanticAction in nestedSemanticActions) { HandleSemanticOperation(nestedSemanticAction, parser, infoCollector); } if (requestWaiting) { break; } // at the end of each iteration clear flags so that we can do the next iteration operation.SetNestedOperationState("state", SemanticOperation.INIT); } } } catch (Exception e) { Debug.WriteLine(e.StackTrace); throw new ForLoopException(e, operation, semanticOperationVariableMap); } }
/** * main entry to handle semantic operations. FOR loops and IFs are handled directly (they have built- * in semantics and are not overridable). otherwise it will can the perform() method on the operation * object. * * @param action * @param parser * @param infoCollector */ public void HandleSemanticOperation(SemanticOperation operation, DocumentParser parser, SemanticsGlobalScope infoCollector) { int state = GetOperationState(operation, "state", SemanticOperation.INIT); if (state == SemanticOperation.FIN || requestWaiting) { return; } // debug("["+parser+"] semantic operation: " + action.getActionName() + ", SA class: " + action.getClassSimpleName() + "\n"); operation.SemanticOperationHandler = this; // here state must be INTER or INIT // if state == INIT, we check pre-conditions // if state == INTER, because this must have been started, we skip checking pre-conditions if (state == SemanticOperation.INIT) { if (!CheckConditionsIfAny(operation)) { if (!(operation is IfSemanticOperation)) { Debug.WriteLine("Semantic operation {0} not taken since (some) pre-requisite conditions are not met", operation); } return; } } else { Debug.WriteLine("re-entering operations with pre-conditions; checking pre-conditions skipped: " + operation.GetOperationName()); } operation.SessionScope = infoCollector; operation.SemanticOperationHandler = this; operation.DocumentParser = parser; String operationName = operation.GetOperationName(); try { if (SemanticOperationStandardMethods.ForEach.Equals(operationName)) { HandleForLoop((ForEachSemanticOperation)operation, parser, infoCollector); } else if (SemanticOperationStandardMethods.If.Equals(operationName)) { HandleIf((IfSemanticOperation)operation, parser, infoCollector); } else { HandleGeneralOperation(operation); } } catch (Exception e) { Debug.WriteLine("The action " + operationName + " could not be executed. Please see the stack trace for errors."); } finally { if (!requestWaiting) { SetOperationState(operation, "state", SemanticOperation.FIN); } } }