Beispiel #1
0
        public static XElement XslFunction(this XElement element, string name, string @as,
                                           params TemplateParameter[] parameters)
        {
            XElement templateElement = element.XslGenericElement("function");

            templateElement.AddAttributeWithValue("name", name);
            if (!string.IsNullOrEmpty(@as))
            {
                templateElement.AddAttributeWithValue("as", @as);
            }
            if (parameters != null)
            {
                foreach (TemplateParameter parameter in parameters)
                {
                    XElement param = templateElement.XslGenericElement("param");
                    param.AddAttributeWithValue("name", parameter.Name);
                    if (!string.IsNullOrEmpty(parameter.Type))
                    {
                        param.AddAttributeWithValue("as", parameter.Type);
                    }
                    if (!XPathExpr.IsNullOrEmpty(parameter.DefaultValue))
                    {
                        param.AddAttributeWithValue("select", parameter.DefaultValue);
                    }
                }
            }
            return(templateElement);
        }
        public static XElement XsdImport(this XElement parentElement, string schemaLocation, string @namespace)
        {
            XElement import = parentElement.XsdGenericElement("include");

            import.AddAttributeWithValue("schemaLocation", schemaLocation);
            import.AddAttributeWithValue("namespace", @namespace);
            return(import);
        }
Beispiel #3
0
        public static XElement SchematronLet(this XElement parentElement, string name, string value)
        {
            XElement param = parentElement.SchematronGenericElement("let");

            param.AddAttributeWithValue("name", name);
            param.AddAttributeWithValue("value", value);
            return(param);
        }
Beispiel #4
0
        public XDocument GetSchematronSchema([NotNull] TranslationSettings translationSettings)
        {
            XDocument doc       = new XDocument(new XDeclaration("1.0", "utf-8", null));
            XElement  schSchema = doc.SchematronSchema();
            XComment  comment   = new XComment(string.Format(" Generated by eXolutio on {0} {1} from {2}/{3}. ", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), PSMSchema.Project.Name, PSMSchema.Caption));

            schSchema.Add(comment);

            Dictionary <PSMClass, List <PatternInfo> > patterns = new Dictionary <PSMClass, List <PatternInfo> >();

            foreach (OCLScript oclScript in PSMSchema.OCLScripts)
            {
                // creates patterns, some patterns will be declared abstract
                TranslateScript(schSchema, oclScript, translationSettings, ref patterns);
            }

            #region create instance patterns
            foreach (PSMClass contextClass in PSMSchema.PSMClasses)
            {
                foreach (PSMClass ancestorClass in ModelIterator.GetGeneralizationsWithSelf(contextClass))
                {
                    if (patterns.ContainsKey(ancestorClass) && (ancestorClass != contextClass ||
                                                                ancestorClass.GeneralizationsAsGeneral.Count > 0))
                    {
                        foreach (PatternInfo pattern in patterns[ancestorClass])
                        {
                            if (ancestorClass != contextClass)
                            {
                                schSchema.Add(new XComment(string.Format("instance pattern for {0}'s ancestor {1}", contextClass, ancestorClass.Name)));
                            }
                            else
                            {
                                schSchema.Add(new XComment(string.Format("instance pattern for {0}", contextClass)));
                            }
                            XElement instancePattern   = schSchema.SchematronPattern();
                            string   instancePatternId = string.Format("{0}-as-{1}", contextClass.Name, pattern.PatternName);
                            instancePattern.AddAttributeWithValue("id", instancePatternId);
                            instancePattern.AddAttributeWithValue("is-a", pattern.PatternName);
                            instancePattern.SchematronParam(pattern.ContextVariableName, contextClass.GetXPathFull(false).ToString());
                        }
                    }
                }
            }

            #endregion

            PostprocessLogMessages();

            return(doc);
        }
Beispiel #5
0
        public static XElement XslVariable(this XElement element, string name, XPathExpr selectXPath = null, string type = null)
        {
            XElement variableElement = element.XslGenericElement("variable");

            variableElement.AddAttributeWithValue("name", name);
            if (selectXPath != null)
            {
                variableElement.AddAttributeWithValue("select", selectXPath);
            }
            if (!string.IsNullOrEmpty(type))
            {
                variableElement.AddAttributeWithValue("as", type);
            }
            return(variableElement);
        }
Beispiel #6
0
        public static XElement XslForEachGroup(this XElement element, XPathExpr selectXPath)
        {
            XElement copyOfElement = element.XslGenericElement("for-each-group");

            copyOfElement.AddAttributeWithValue("select", selectXPath);
            return(copyOfElement);
        }
Beispiel #7
0
        public static XElement XslForEach(this XElement element, XPathExpr selectXPath)
        {
            XElement forEachElement = element.XslGenericElement("for-each");

            forEachElement.AddAttributeWithValue("select", selectXPath);
            return(forEachElement);
        }
Beispiel #8
0
        public static XElement XslCopyOf(this XElement element, XPathExpr selectXPath)
        {
            XElement copyOfElement = element.XslGenericElement("copy-of");

            copyOfElement.AddAttributeWithValue("select", selectXPath);
            return(copyOfElement);
        }
Beispiel #9
0
        private static XElement XslApplyTemplates(this XElement element, XPathExpr selectXPath, IEnumerable <TemplateParameter> parameters)
        {
            XElement applyTemplatesElement = element.XslGenericElement("apply-templates");

            applyTemplatesElement.AddAttributeWithValue("select", selectXPath);
            if (parameters != null)
            {
                foreach (TemplateParameter keyValuePair in parameters)
                {
                    XElement param = applyTemplatesElement.XslGenericElement("with-param");
                    param.AddAttributeWithValue("name", keyValuePair.Name);
                    param.AddAttributeWithValue("select", keyValuePair.Value);
                }
            }
            return(applyTemplatesElement);
        }
Beispiel #10
0
        public static XElement XslCallTemplate(this XElement element, string templateName, IEnumerable <TemplateParameter> parameters)
        {
            XElement callTemplateElement = element.XslGenericElement("call-template");

            callTemplateElement.AddAttributeWithValue("name", templateName);
            if (parameters != null)
            {
                foreach (TemplateParameter keyValuePair in parameters)
                {
                    XElement param = callTemplateElement.XslGenericElement("with-param");
                    param.AddAttributeWithValue("name", keyValuePair.Name);
                    param.AddAttributeWithValue("select", keyValuePair.Value);
                }
            }
            return(callTemplateElement);
        }
Beispiel #11
0
        public static XElement XslSequence(this XElement element, XPathExpr selectXPath)
        {
            XElement valueOfElement = element.XslGenericElement("sequence");

            valueOfElement.AddAttributeWithValue("select", selectXPath);
            return(valueOfElement);
        }
Beispiel #12
0
        public static XElement XslWhen(this XElement element, XPathExpr test)
        {
            XElement option = element.XslGenericElement("when");

            option.AddAttributeWithValue("test", test);
            return(option);
        }
Beispiel #13
0
        public static XElement SchematronVariable(this XElement parentElement, string name, string value)
        {
            XElement let = parentElement.SchematronGenericElement("let");

            let.AddAttributeWithValue("name", value);
            return(let);
        }
        public static XElement XsdInclude(this XElement parentElement, string schemaLocation)
        {
            XElement include = parentElement.XsdGenericElement("include");

            include.AddAttributeWithValue("schemaLocation", schemaLocation);
            return(include);
        }
        /// <summary>
        /// Writes complexType element (with specified name)
        /// </summary>
        public static XElement XsdComplexType(this XElement parentElement, string name)
        {
            XElement complexType = parentElement.XsdGenericElement("complexType");

            complexType.AddAttributeWithValue("name", name);
            return(complexType);
        }
        /// <summary>
        /// Writes group element
        /// </summary>
        /// <param name="name">name of the group</param>
        public static XElement XsdGroup(this XElement parentElement, string name)
        {
            XElement group = parentElement.XsdGenericElement("group");

            group.AddAttributeWithValue("name", name);
            return(group);
        }
Beispiel #17
0
        public static XElement XslIf(this XElement element, XPathExpr test)
        {
            XElement valueOfElement = element.XslGenericElement("if");

            valueOfElement.AddAttributeWithValue("test", test);
            return(valueOfElement);
        }
Beispiel #18
0
        public static XElement SchematronValueOf(this XElement parentElement, string select)
        {
            XElement valueOf = parentElement.SchematronGenericElement("value-of");

            valueOf.AddAttributeWithValue("select", select);
            return(valueOf);
        }
        /// <summary>
        /// Writes extension element
        /// </summary>
        /// <param name="base"></param>
        public static XElement XsdExtension(this XElement parentElement, string @base)
        {
            XElement extension = parentElement.XsdGenericElement("extension");

            extension.AddAttributeWithValue("base", @base);
            return(extension);
        }
Beispiel #20
0
        public static XElement XslImport(this XElement parentElement, string href)
        {
            XElement importElement = parentElement.XslGenericElement("import");

            importElement.AddAttributeWithValue("href", href);
            return(importElement);
        }
        /// <summary>
        /// writes "element" element. with specified name
        /// </summary>
        /// <param name="name">name attribute of the element</param>
        public static XElement XsdElement(this XElement parentElement, string name)
        {
            XElement element = parentElement.XsdGenericElement("element");

            element.AddAttributeWithValue("name", name);
            return(element);
        }
Beispiel #22
0
        public static XElement SchematronRule(this XElement parentElement, string context)
        {
            XElement rule = parentElement.SchematronGenericElement("rule");

            rule.AddAttributeWithValue("context", context);
            return(rule);
        }
        /// <summary>
        /// Writes reference to a group
        /// </summary>
        /// <param name="ref">name of the referenced group</param>
        public static XElement XsdGroupRef(this XElement parentElement, string @ref)
        {
            XElement groupRef = parentElement.XsdGenericElement("group");

            groupRef.AddAttributeWithValue("ref", @ref);
            return(groupRef);
        }
        /// <summary>
        /// Writes <see cref="PSMAttribute"/> as an XML element (with name, value and multiplicity)
        /// </summary>
        /// <param name="name">name of the attribute</param>
        /// <param name="psmAttribute">written attribute</param>
        public static XElement XsdAttributeAsElement(this XElement parentElement, string name, PSMAttribute psmAttribute)
        {
            XElement attribute = parentElement.XsdGenericElement("element");

            attribute.AddAttributeWithValue("name", name);
            attribute.TypeAttribute(psmAttribute, true, false);
            return(attribute);
        }
 /// <summary>
 /// Writes minOccurs and maxOccurs attributes (if parameters are not equal to 1)
 /// </summary>
 /// <param name="lower">value for minOccurs attribute</param>
 /// <param name="upper">value for maxOccurs attribute</param>
 public static void CardinalityAttributes(this XElement parentElement, uint lower, UnlimitedInt upper)
 {
     if (lower != 1)
     {
         parentElement.AddAttributeWithValue("minOccurs", lower.ToString());
     }
     if (upper.Value != 1)
     {
         if (upper.IsInfinity)
         {
             parentElement.AddAttributeWithValue("maxOccurs", "unbounded");
         }
         else
         {
             parentElement.AddAttributeWithValue("maxOccurs", upper.ToString());
         }
     }
 }
Beispiel #26
0
        public static XElement XslStylesheet(this XDocument document, string version)
        {
            XElement styleSheetElement = new XElement(XSLT_NAMESPACE + "stylesheet");

            styleSheetElement.Add(new XAttribute(XNamespace.Xmlns + "xsl", XSLT_NAMESPACE.NamespaceName));
            styleSheetElement.AddAttributeWithValue("version", version);
            document.Add(styleSheetElement);
            return(styleSheetElement);
        }
Beispiel #27
0
        public static XElement SchematronPattern(this XElement parentElement, string id = null)
        {
            XElement pattern = parentElement.SchematronGenericElement("pattern");

            if (!string.IsNullOrEmpty(id))
            {
                pattern.AddAttributeWithValue("id", id);
            }
            return(pattern);
        }
Beispiel #28
0
        public static XElement SchematronReport(this XElement parentElement, string test, string message = null)
        {
            XElement report = parentElement.SchematronGenericElement("report");

            report.AddAttributeWithValue("test", test);
            if (!string.IsNullOrEmpty(message))
            {
                report.Add(new XText(message));
            }
            return(report);
        }
        /// <summary>
        /// Writes type attribute
        /// </summary>
        /// <param name="psmAttribute">psmAttribute whose <see cref="Model.TypedElement.Type"/> attribute is being written</param>
        /// <param name="simpleTypeWriter">writer where simple type definition is written if the type was not
        /// yet used</param>
        /// <param name="useOccurs">if set to true, minOccurs and maxOccurs attributes are also written if
        /// <paramref name="psmAttribute"/> multipicity is non-default</param>
        /// <param name="forceOptional">if set to <c>true</c> multiplicity of the attribute is ignored and
        /// use="optional" is written.</param>
        public static void TypeAttribute(this XElement parentElement, PSMAttribute psmAttribute, bool useOccurs, bool forceOptional)
        {
            if (psmAttribute.AttributeType == null)
            {
            }
            else
            {
                parentElement.AddAttributeWithValue("type", "xs:" + psmAttribute.AttributeType.Name);
            }

            if (!String.IsNullOrEmpty(psmAttribute.DefaultValue))
            {
                parentElement.AddAttributeWithValue("default", psmAttribute.DefaultValue);
            }

            if (forceOptional)
            {
                parentElement.AddAttributeWithValue("use", "optional");
            }
            else
            {
                if (!useOccurs)
                {
                    if (psmAttribute.Lower == 0)
                    {
                        parentElement.AddAttributeWithValue("use", "optional");
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(psmAttribute.DefaultValue))
                        {
                            parentElement.AddAttributeWithValue("use", "required");
                        }
                    }
                }
                else
                {
                    parentElement.CardinalityAttributes(psmAttribute.Lower, psmAttribute.Upper);
                }
            }
        }
        /// <summary>
        /// Writes <see cref="PSMAttribute"/> as an XML attribute (with name and value and default value)
        /// </summary>
        /// <param name="name">name of the attribute</param>
        /// <param name="psmAttribute">written attribute</param>
        /// <param name="forceOptional">if set to <c>true</c> multiplicity of the attribute is ignored and
        /// use="optional" is written.</param>
        public static XElement XsdAttribute(this XElement parentElement, string name, PSMAttribute psmAttribute, bool forceOptional)
        {
            if (psmAttribute.Lower == 0 && psmAttribute.Upper == 0)
            {
                return(null);
            }
            XElement attribute = parentElement.XsdGenericElement("attribute");

            attribute.AddAttributeWithValue("name", name);
            TypeAttribute(attribute, psmAttribute, false, forceOptional);
            return(attribute);
        }