internal void AcceptValidationError(ArchetypeConstraint constraint, string message) { if (AcceptError != null && !IsSuppressingAcceptErrors) { AcceptError(constraint, new ValidationEventArgs(constraint, message)); } }
internal ValidationEventArgs(ArchetypeConstraint constraint, string message) { Check.Require(constraint != null, "constraint must not be null."); Check.Require(!string.IsNullOrEmpty(message), "message must not be null or empty."); this.message = message; this.constraint = constraint; this.path = new Lazy <string>(FullPath); }
internal ValidationEventArgs(ArchetypeConstraint constraint, string message) { Check.Require(constraint != null, "constraint must not be null."); Check.Require(!string.IsNullOrEmpty(message), "message must not be null or empty."); this.message = message; this.constraint = constraint; this.path = new Lazy<string>(FullPath); }
public override bool IsSubsetOf(ArchetypeConstraint other) { Check.Require(other != null, string.Format(CommonStrings.XMustNotBeNull, "other")); CPrimitiveObject otherPrimitive = other as CPrimitiveObject; if (otherPrimitive == null) return false; if (this.Item.GetType() != otherPrimitive.Item.GetType()) return false; return this.Item.IsSubsetOf(otherPrimitive.Item); }
protected virtual string FullPath() { string result = ""; ArchetypeConstraint parent = constraint; do { CArchetypeRoot cArchetypeRoot = parent as CArchetypeRoot; if (cArchetypeRoot != null) { string rootPath = cArchetypeRoot.Parent != null ? cArchetypeRoot.Path : ""; if (result.StartsWith(rootPath)) { result = result.Substring(rootPath.Length); } result = rootPath + CArchetypeRootPredicate(cArchetypeRoot) + result; parent = cArchetypeRoot.Parent; } else { if (string.IsNullOrEmpty(result)) { result = parent.Path; } CObject cObject = parent as CObject; if (cObject != null) { parent = cObject.Parent; } else { CAttribute cAttribute = parent as CAttribute; if (cAttribute != null) { parent = cAttribute.parent; } } } } while (parent != null); Check.Ensure(result != null); return(result); }
public void testParseIncludesExcludes() { string adl = System.IO.File.ReadAllText(@"..\..\..\..\java-libs\adl-parser\src\test\resources\adl-test-entry.archetype_slot.test.adl"); se.acode.openehr.parser.ADLParser parser = new se.acode.openehr.parser.ADLParser(adl); org.openehr.am.archetype.Archetype archetype = parser.parse(); Assert.IsNotNull(archetype); ArchetypeConstraint node = archetype.node("/content[at0001]"); // Type e = typeof(node); ArchetypeSlot slot = (ArchetypeSlot)node; Assert.AreEqual("at0001", slot.getNodeId(), "nodeId wrong"); Assert.AreEqual("SECTION", slot.getRmTypeName(), "rmTypeName wrong"); Interval a = new Interval(0, 1); // Assert.AreEqual( a, slot.getOccurrences());//错误??? Assert.AreEqual("/content[at0001]", slot.path(), "path wrong"); Assert.AreEqual(1, slot.getIncludes().size(), "includes total wrong"); Assert.AreEqual(2, slot.getExcludes().size(), "Excludes total wrong"); object b = slot.getIncludes().iterator().next(); Assertion assertion = (Assertion)b; ExpressionItem item = assertion.getExpression(); Assert.IsInstanceOfType(item, typeof(ExpressionBinaryOperator)); //assertTrue("expressionItem type wrong", // item instanceof ExpressionBinaryOperator); ExpressionBinaryOperator bo = (ExpressionBinaryOperator)item; ExpressionItem leftOp = bo.getLeftOperand(); ExpressionItem rightOp = bo.getRightOperand(); Assert.IsInstanceOfType(leftOp, typeof(ExpressionLeaf)); //assertTrue("left operator type wrong", // leftOp instanceof ExpressionLeaf); ExpressionLeaf left = (ExpressionLeaf)leftOp; Assert.AreEqual("domain_concept", left.getItem(), "left value wrong"); Assert.IsInstanceOfType(rightOp, typeof(ExpressionLeaf)); // assertTrue("right operator type wrong", rightOp instanceof ExpressionLeaf); ExpressionLeaf right = (ExpressionLeaf)rightOp; Assert.IsInstanceOfType(right.getItem(), typeof(CString)); // assertTrue("right item type wrong", right.getItem() instanceof CString); CString cstring = (CString)right.getItem(); Assert.AreEqual("blood_pressure.v1", cstring.getPattern(), "right value wrong"); }
public void testParseSingleInclude() { string adl = System.IO.File.ReadAllText(@"..\..\..\..\java-libs\adl-parser\src\test\resources\adl-test-entry.archetype_slot.test2.adl"); se.acode.openehr.parser.ADLParser parser = new se.acode.openehr.parser.ADLParser(adl); org.openehr.am.archetype.Archetype archetype = parser.parse(); Assert.IsNotNull(archetype); ArchetypeConstraint node = archetype.node("/content[at0001]"); ArchetypeSlot slot = (ArchetypeSlot)node; Assert.AreEqual("at0001", slot.getNodeId(), "nodeId wrong"); Assert.AreEqual("SECTION", slot.getRmTypeName(), "rmTypeName wrong"); // Assert.AreEqual("occurrences wrong", new Interval<Integer>(0, 1),slot.getOccurrences()); Assert.AreEqual("/content[at0001]", slot.path(), "path wrong"); Assert.AreEqual(1, slot.getIncludes().size(), "includes total wrong"); Assertion assertion = (Assertion)slot.getIncludes().iterator().next(); ExpressionItem item = assertion.getExpression(); //assertTrue("expressionItem type wrong", // item instanceof ExpressionBinaryOperator); ExpressionBinaryOperator bo = (ExpressionBinaryOperator)item; ExpressionItem leftOp = bo.getLeftOperand(); ExpressionItem rightOp = bo.getRightOperand(); //assertTrue("left operator type wrong", // leftOp instanceof ExpressionLeaf); ExpressionLeaf left = (ExpressionLeaf)leftOp; Assert.AreEqual("archetype_id/value", left.getItem(), "left value wrong"); //assertTrue("right operator type wrong", // rightOp instanceof ExpressionLeaf); ExpressionLeaf right = (ExpressionLeaf)rightOp; //assertTrue("right item type wrong", right.getItem() instanceof CString); string cstring = Convert.ToString(right.getItem()); //Assert.AreEqual("right value wrong", "openEHR-EHR-CLUSTER\\.device\\.v1", // cstring.getPattern()); Assert.IsNotNull("stringExpression missing", assertion.getStringExpression()); String expectedStringExpression = "archetype_id/value matches {/openEHR-EHR-CLUSTER\\.device\\.v1/}"; Assert.AreEqual(expectedStringExpression, assertion.getStringExpression(), "stringExpression wrong, got: " + assertion.getStringExpression()); }
public void testParseInternalRefWithGenerics() { string adl = System.IO.File.ReadAllText(@"..\..\..\..\java-libs\adl-parser\src\test\resources\adl-test-SOME_TYPE.generic_type_use_node.draft.adl"); se.acode.openehr.parser.ADLParser parser = new se.acode.openehr.parser.ADLParser(adl); org.openehr.am.archetype.Archetype archetype = parser.parse(); Assert.IsNotNull(archetype); ArchetypeConstraint node = archetype.node("/interval_attr2"); //assertTrue("ArchetypeInternalRef expected, actual: " + node.getClass(), // node instanceof ArchetypeInternalRef); Assert.IsInstanceOfType(node, typeof(ArchetypeInternalRef)); ArchetypeInternalRef refe = (ArchetypeInternalRef)node; Assert.AreEqual("INTERVAL<QUANTITY>", refe.getRmTypeName()); Assert.AreEqual("/interval_attr[at0001]", refe.getTargetPath()); }
public void testParseInternalRefWithOverwrittingOccurrences() { string adl = System.IO.File.ReadAllText(@"..\..\..\..\java-libs\adl-parser\src\test\resources\adl-test-entry.archetype_internal_ref.test.adl"); se.acode.openehr.parser.ADLParser parser = new se.acode.openehr.parser.ADLParser(adl); org.openehr.am.archetype.Archetype archetype = parser.parse(); Assert.IsNotNull(archetype); ArchetypeConstraint node = archetype.node("/attribute2"); Assert.IsInstanceOfType(node, typeof(ArchetypeInternalRef)); ArchetypeInternalRef refff = (ArchetypeInternalRef)node; Assert.AreEqual("SECTION", refff.getRmTypeName(), "rmType wrong"); Assert.AreEqual("/attribute1", refff.getTargetPath(), "path wrong"); Interval occurrences = new Interval(1, 2); //Assert.AreEqual( occurrences, refff.getOccurrences());//错误??? }
public override bool IsSubsetOf(ArchetypeConstraint other) { throw new NotImplementedException(); }
internal void AcceptValidationError(ArchetypeConstraint constraint, string message) { if (AcceptError != null && !IsSuppressingAcceptErrors) AcceptError(constraint, new ValidationEventArgs(constraint, message)); }
private void WriteXml(ArchetypeConstraint archetypeConstraint) { if (archetypeConstraint == null) throw new ArgumentNullException(string.Format(CommonStrings.XIsNull, "archetypeConstraint")); const string methodName = "WriteXml"; try { System.Reflection.MethodInfo method = this.GetType().GetMethod(methodName, System.Reflection.BindingFlags.ExactBinding | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, Type.DefaultBinder, new Type[] { archetypeConstraint.GetType() }, new System.Reflection.ParameterModifier[0]); if (method != null) { // Avoid StackOverflow exceptions by executing only if the method and visitable // are different from the last parameters used. if (method != lastMethodWriteXmlArchetypeConstraint || archetypeConstraint != lastArchetypeConstraintWrite) { lastMethodWriteXmlArchetypeConstraint = method; lastArchetypeConstraintWrite = archetypeConstraint; method.Invoke(this, new Object[] { archetypeConstraint }); } else { string message = string.Format(CommonStrings.LoopingMethodTerminated, methodName, archetypeConstraint.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } else { string message = string.Format(CommonStrings.MethodXNotImplementedForParamTypeY, methodName, archetypeConstraint.GetType().ToString()); System.Diagnostics.Debug.WriteLine(message); throw new ApplicationException(message); } } catch (System.Reflection.TargetInvocationException ex) { if (ex.InnerException != null) throw new ApplicationException(ex.InnerException.Message, ex.InnerException); else throw new ApplicationException(ex.Message, ex); } }
internal CArchetypeRoot FetchOperationalObject(ArchetypeConstraint constraint, ObjectId id) { return FetchObject != null ? FetchObject(constraint, new FetchOperationalObjectEventArgs(id)) : null; }
protected void Validate(ArchetypeConstraint archetypeConstraint) { Invariant(!string.IsNullOrEmpty(archetypeConstraint.Path), string.Format( CommonStrings.XMustNotBeNullOrEmpty, "ArchetypeConstraint.Path")); }
public override bool IsSubsetOf(ArchetypeConstraint other) { throw new NotImplementedException( string.Format(AmValidationStrings.IsSubsetNotImplementedInX, "ArchetypeInternalRef")); }
internal CArchetypeRoot FetchOperationalObject(ArchetypeConstraint constraint, ObjectId id) { return(FetchObject != null?FetchObject(constraint, new FetchOperationalObjectEventArgs(id)) : null); }