Пример #1
0
        public XElement AddXsElementIfNotPresent(XElement parentXsElement, XElement childXsElement)
        {
            XElement parentChoiceOrSequenceElement = XsMetaModel.ChoiceOrSequenceFor(XsMetaModel.ComplexTypeFor(parentXsElement));

            if (parentChoiceOrSequenceElement == null)
            {
                throw new ArgumentException(Log.LogAndReturn("Unable to locate complexType/sequence or complexType/choice under supplied parent XSD element"));
            }

            XAttribute childXsElementAttr = childXsElement.Attribute("name");
            string     localName          = childXsElementAttr.Value;

            XNamespace ns = "*";

            IEnumerable <XElement> existingElements = parentChoiceOrSequenceElement.Descendants(ns + childXsElement.Name.LocalName);

            foreach (XElement xsElement in existingElements)
            {
                XAttribute attr = xsElement.Attribute("name");
                if (attr != null && attr.Value.Equals(localName))
                {
                    return(xsElement);
                }
            }

            parentChoiceOrSequenceElement.Add(childXsElement);
            return(childXsElement);
        }
Пример #2
0
        //  Adds a previously created &lt;xs:element&gt; element (representing a field of an object)
        //  to the supplied element (presumed to be a <code>complexType/sequence</code>).

        public void AddFieldXsElement(XElement xsElement, XElement xsFieldElement)
        {
            if (xsFieldElement == null)
            {
                return;
            }
            XElement sequenceElement = XsMetaModel.SequenceForComplexTypeFor(xsElement);

            sequenceElement.Add(xsFieldElement);
        }
Пример #3
0
        //  Creates an &lt;xs:element&gt; element defining the presence of the named element
        //  representing a class

        public XElement CreateXsElementForNofClass(XDocument xsdDoc, XElement element, bool addCardinality)
        {
            // gather details from XML element
            string localName = element.Name.LocalName;

            //	<xs:element name="AO11ConfirmAnimalRegistration">
            //		<xs:complexType>
            //			<xs:sequence>
            //             <xs:element ref="nof:title"/>
            //             <!-- placeholder -->
            //			</xs:sequence>
            //			<xs:attribute ref="nof:feature"
            //			              default="class"/>
            //			<xs:attribute ref="nof:oid"/>
            //			<xs:attribute ref="nof:annotation"/>
            //			<xs:attribute ref="nof:fqn"/>
            //	    </xs:complexType>
            //	</xs:element>

            // xs:element/@name="class name"
            // add to XML schema as a global attribute
            XElement xsElementForNofClassElement = XsMetaModel.CreateXsElementElement(xsdDoc, localName, addCardinality);

            // xs:element/xs:complexType
            // xs:element/xs:complexType/xs:sequence
            XElement xsComplexTypeElement = XsMetaModel.ComplexTypeFor(xsElementForNofClassElement);
            XElement xsSequenceElement    = XsMetaModel.SequenceFor(xsComplexTypeElement);

            // xs:element/xs:complexType/xs:sequence/xs:element ref="nof:title"
            XElement xsTitleElement = XsMetaModel.CreateXsElement(Helper.DocFor(xsSequenceElement), "element");

            xsTitleElement.SetAttributeValue("ref", NofMetaModel.NofMetamodelNsPrefix + ":" + "title");
            xsSequenceElement.Add(xsTitleElement);
            XsMetaModel.SetXsCardinality(xsTitleElement, 0, 1);

            // xs:element/xs:complexType/xs:sequence/xs:element ref="extensions"
            //addXsElementForAppExtensions(xsSequenceElement, extensions);

            // xs:element/xs:complexType/xs:attribute ...
            XsMetaModel.AddXsNofFeatureAttributeElements(xsComplexTypeElement, "class");
            XsMetaModel.AddXsNofAttribute(xsComplexTypeElement, "oid");
            XsMetaModel.AddXsNofAttribute(xsComplexTypeElement, "fqn");
            XsMetaModel.AddXsNofAttribute(xsComplexTypeElement, "singular");
            XsMetaModel.AddXsNofAttribute(xsComplexTypeElement, "plural");
            XsMetaModel.AddXsNofAttribute(xsComplexTypeElement, "annotation");

            element.AddAnnotation(xsElementForNofClassElement);

            return(xsElementForNofClassElement);
        }
        // Start a snapshot at the root object, using supplied namespace manager.
        public XmlSnapshot(object obj, XmlSchema schema, INakedObjectManager nakedObjectManager, IMetamodelManager metamodelManager)
        {
            this.nakedObjectManager = nakedObjectManager;
            this.metamodelManager   = metamodelManager;

            INakedObjectAdapter rootObjectAdapter = nakedObjectManager.CreateAdapter(obj, null, null);

            Schema = schema;

            try {
                XmlDocument = new XDocument();
                XsdDocument = new XDocument();

                XsdElement = XsMetaModel.CreateXsSchemaElement(XsdDocument);

                rootPlace = AppendXml(rootObjectAdapter);
            }
            catch (ArgumentException e) {
                throw new NakedObjectSystemException(Log.LogAndReturn("Unable to build snapshot"), e);
            }
        }
Пример #5
0
        // Start a snapshot at the root object, using supplied namespace manager.
        public XmlSnapshot(object obj, XmlSchema schema, INakedObjectManager nakedObjectManager, IMetamodelManager metamodelManager)
        {
            this.nakedObjectManager = nakedObjectManager;
            this.metamodelManager   = metamodelManager;

            INakedObject rootObject = nakedObjectManager.CreateAdapter(obj, null, null);

            Log.Debug(".ctor(" + DoLog("rootObj", rootObject) + AndLog("schema", schema) + AndLog("addOids", "" + true) + ")");

            Schema = schema;

            try {
                XmlDocument = new XDocument();
                XsdDocument = new XDocument();

                XsdElement = XsMetaModel.CreateXsSchemaElement(XsdDocument);

                rootPlace = AppendXml(rootObject);
            }
            catch (ArgumentException e) {
                Log.Error("unable to build snapshot", e);
                throw new NakedObjectSystemException(e);
            }
        }
Пример #6
0
        ///**
        // * Creates an &lt;xs:element&gt; element defining the presence of the named element
        // * representing a collection in a class; appended to xs:sequence element
        // */
        public XElement CreateXsElementForNofCollection(XElement parentXsElementElement, XElement xmlCollectionElement, string referencedClassName)
        {
            // gather details from XML element
            string fieldName = xmlCollectionElement.Name.LocalName;

            // <xs:element name="%owning object%">
            //		<xs:complexType>
            //			<xs:sequence>
            //				<xs:element name="%%field object%%">
            //					<xs:complexType>
            //						<xs:sequence>
            //							<xs:element ref="nof:oids" minOccurs="0" maxOccurs="1"/>
            //						    <!-- nested element definitions go here -->
            //						</xs:sequence>
            //						<xs:attribute ref="nof:feature" fixed="collection"/>
            //						<xs:attribute ref="nof:type" fixed="%%appX%%:%%type%%"/>
            //						<xs:attribute ref="nof:size"/>
            //						<xs:attribute ref="nof:annotation"/>
            //					</xs:complexType>
            //				</xs:element>
            //			</xs:sequence>
            //		</xs:complexType>
            //	</xs:element>

            // xs:element/xs:complexType/xs:sequence
            XElement parentXsComplexTypeElement = XsMetaModel.ComplexTypeFor(parentXsElementElement);
            XElement parentXsSequenceElement    = XsMetaModel.SequenceFor(parentXsComplexTypeElement);

            // xs:element/xs:complexType/xs:sequence/xs:element name="%field object%%"
            XElement xsFieldElementElement = XsMetaModel.CreateXsElementElement(Helper.DocFor(parentXsSequenceElement), fieldName);

            parentXsSequenceElement.Add(xsFieldElementElement);

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType
            XElement xsFieldComplexTypeElement = XsMetaModel.ComplexTypeFor(xsFieldElementElement);
            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence
            XElement xsFieldSequenceElement = XsMetaModel.SequenceFor(xsFieldComplexTypeElement);

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence/xs:element ref="nof:oids"
            XElement xsFieldOidsElement = XsMetaModel.CreateXsElement(Helper.DocFor(xsFieldSequenceElement), "element");

            xsFieldOidsElement.SetAttributeValue("ref", NofMetaModel.NofMetamodelNsPrefix + ":" + "oids");
            xsFieldSequenceElement.Add(xsFieldOidsElement);
            XsMetaModel.SetXsCardinality(xsFieldOidsElement, 0, 1);

            // extensions
            // addXsElementForAppExtensions(xsFieldSequenceElement, extensions);

//		// xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence/xs:choice
//		XElement xsFieldChoiceElement = XsMetaModel.choiceFor(xsFieldComplexTypeElement); // placeholder
//		XsMetaModel.setXsCardinality(xsFieldChoiceElement, 0, Integer.MAX_VALUE);

//		XElement xsFieldTitleElement = addXsNofRefElementElement(xsFieldSequenceElement, "title");

//		XElement xsReferencedElementSequenceElement = sequenceFor(xsFieldSequenceElement);
//		setXsCardinality(xsReferencedElementSequenceElement, 0, 1);

            XsMetaModel.AddXsNofFeatureAttributeElements(xsFieldComplexTypeElement, "collection");
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "type", "app:" + referencedClassName, false);
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "size");
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "annotation");

            return(xsFieldElementElement);
        }
Пример #7
0
        //  Creates an &lt;xs:element&gt; element defining the presence of the named element
        //  representing a reference to a class; appended to xs:sequence element

        public XElement CreateXsElementForNofReference(XElement parentXsElementElement, XElement xmlReferenceElement, string referencedClassName)
        {
            // gather details from XML element
            string fieldName = xmlReferenceElement.Name.LocalName;

            // <xs:element name="%owning object%">
            //		<xs:complexType>
            //			<xs:sequence>
            //				<xs:element name="%%field object%%">
            //					<xs:complexType>
            //						<xs:sequence>
            //							<xs:element ref="nof:title" minOccurs="0"/>
            //				            <xs:element name="nof-extensions">
            //					            <xs:complexType>
            //						            <xs:sequence>
            //				                        <xs:element name="app:%extension class short name%" minOccurs="0" maxOccurs="1" default="%value%"/>
            //				                        <xs:element name="app:%extension class short name%" minOccurs="0" maxOccurs="1" default="%value%"/>
            //				                        ...
            //				                        <xs:element name="app:%extension class short name%" minOccurs="0" maxOccurs="1" default="%value%"/>
            //						            </xs:sequence>
            //					            </xs:complexType>
            //				            </xs:element>
            //							<xs:sequence minOccurs="0" maxOccurs="1"/>
            //						</xs:sequence>
            //						<xs:attribute ref="nof:feature" fixed="reference"/>
            //						<xs:attribute ref="nof:type" default="%%appX%%:%%type%%"/>
            //						<xs:attribute ref="nof:isEmpty"/>
            //						<xs:attribute ref="nof:annotation"/>
            //					</xs:complexType>
            //				</xs:element>
            //			</xs:sequence>
            //		</xs:complexType>
            //	</xs:element>

            // xs:element/xs:complexType/xs:sequence
            XElement parentXsComplexTypeElement = XsMetaModel.ComplexTypeFor(parentXsElementElement);
            XElement parentXsSequenceElement    = XsMetaModel.SequenceFor(parentXsComplexTypeElement);

            // xs:element/xs:complexType/xs:sequence/xs:element name="%%field object%"
            XElement xsFieldElementElement = XsMetaModel.CreateXsElementElement(Helper.DocFor(parentXsSequenceElement), fieldName);

            parentXsSequenceElement.Add(xsFieldElementElement);

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence
            XElement xsFieldComplexTypeElement = XsMetaModel.ComplexTypeFor(xsFieldElementElement);
            XElement xsFieldSequenceElement    = XsMetaModel.SequenceFor(xsFieldComplexTypeElement);

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence/xs:element ref="nof:title"
            XElement xsFieldTitleElement = XsMetaModel.CreateXsElement(Helper.DocFor(xsFieldSequenceElement), "element");

            xsFieldTitleElement.SetAttributeValue("ref", NofMetaModel.NofMetamodelNsPrefix + ":" + "title");
            xsFieldSequenceElement.Add(xsFieldTitleElement);
            XsMetaModel.SetXsCardinality(xsFieldTitleElement, 0, 1);

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence/xs:element name="nof-extensions"
            //addXsElementForAppExtensions(xsFieldSequenceElement, extensions);

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence/xs:sequence   // placeholder
            XElement xsReferencedElementSequenceElement = XsMetaModel.SequenceFor(xsFieldSequenceElement);

            XsMetaModel.SetXsCardinality(xsReferencedElementSequenceElement, 0, 1);

            XsMetaModel.AddXsNofFeatureAttributeElements(xsFieldComplexTypeElement, "reference");
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "type", "app:" + referencedClassName, false);
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "isEmpty");
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "annotation");
            return(xsFieldElementElement);
        }
Пример #8
0
        //  Creates an <code>xs:element</code> element to represent a value field in a class.
        //
        //  The returned element should be appended to <code>xs:sequence</code> element of the
        //  xs:element representing the type of the owning object.

        public XElement CreateXsElementForNofValue(XElement parentXsElementElement, XElement xmlValueElement)
        {
            // gather details from XML element

            XAttribute datatype  = xmlValueElement.Attribute(NofMetaModel.Nof + "datatype");
            string     fieldName = xmlValueElement.Name.LocalName;

            // <xs:element name="%owning object%">
            //		<xs:complexType>
            //			<xs:sequence>
            //				<xs:element name="%%field object%%">
            //					<xs:complexType>
            //						<xs:sequence>
            //				            <xs:element name="nof-extensions">
            //					            <xs:complexType>
            //						            <xs:sequence>
            //                                      <xs:element name="%extensionClassShortName%" default="%extensionObjString" minOccurs="0"/>
            //                                      <xs:element name="%extensionClassShortName%" default="%extensionObjString" minOccurs="0"/>
            //                                      ...
            //                                      <xs:element name="%extensionClassShortName%" default="%extensionObjString" minOccurs="0"/>
            //						            </xs:sequence>
            //					            </xs:complexType>
            //				            </xs:element>
            //						</xs:sequence>
            //						<xs:attribute ref="nof:feature" fixed="value"/>
            //						<xs:attribute ref="nof:datatype" fixed="nof:%datatype%"/>
            //						<xs:attribute ref="nof:isEmpty"/>
            //			            <xs:attribute ref="nof:annotation"/>
            //					</xs:complexType>
            //				</xs:element>
            //			</xs:sequence>
            //		</xs:complexType>
            //	</xs:element>

            // xs:element/xs:complexType/xs:sequence
            XElement parentXsComplexTypeElement = XsMetaModel.ComplexTypeFor(parentXsElementElement);
            XElement parentXsSequenceElement    = XsMetaModel.SequenceFor(parentXsComplexTypeElement);

            // xs:element/xs:complexType/xs:sequence/xs:element name="%%field object%"
            XElement xsFieldElementElement = XsMetaModel.CreateXsElementElement(Helper.DocFor(parentXsSequenceElement), fieldName);

            parentXsSequenceElement.Add(xsFieldElementElement);

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType
            XElement xsFieldComplexTypeElement = XsMetaModel.ComplexTypeFor(xsFieldElementElement);

            // NEW CODE TO SUPPORT EXTENSIONS;
            // uses a complexType/sequence

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence
            //XElement xsFieldSequenceElement = XsMetaModel.SequenceFor(xsFieldComplexTypeElement);

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence/xs:element name="nof-extensions"
            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:sequence
            //addXsElementForAppExtensions(xsFieldSequenceElement, extensions);

            XsMetaModel.AddXsNofFeatureAttributeElements(xsFieldComplexTypeElement, "value");
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "datatype", datatype == null ? "" : datatype.Value);
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "isEmpty");
            XsMetaModel.AddXsNofAttribute(xsFieldComplexTypeElement, "annotation");

            // ORIGINAL CODE THAT DIDN'T EXPORT EXTENSIONS
            // uses a simpleContent
            // (I've left this code in in case there is a need to regenerate schemas the "old way").

            // <xs:element name="%owning object%">
            //		<xs:complexType>
            //			<xs:sequence>
            //				<xs:element name="%%field object%%">
            //					<xs:complexType>
            //						<xs:simpleContent>
            //							<xs:extension base="xs:string">
            //								<xs:attribute ref="nof:feature" fixed="value"/>
            //								<xs:attribute ref="nof:datatype" fixed="nof:%datatype%"/>
            //								<xs:attribute ref="nof:isEmpty"/>
            //			                    <xs:attribute ref="nof:annotation"/>
            //							</xs:extension>
            //						</xs:simpleContent>
            //					</xs:complexType>
            //				</xs:element>
            //			</xs:sequence>
            //		</xs:complexType>
            //	</xs:element>

            // xs:element/xs:complexType/xs:sequence/xs:element/xs:complexType/xs:simpleContent/xs:extension
            //		XElement xsFieldSimpleContentElement = XsMetaModel.simpleContentFor(xsFieldComplexTypeElement);
            //		XElement xsFieldExtensionElement = XsMetaModel.extensionFor(xsFieldSimpleContentElement, "string");
            //		XsMetaModel.addXsNofFeatureAttributeElements(xsFieldExtensionElement, "value");
            //		XsMetaModel.addXsNofAttribute(xsFieldExtensionElement, "datatype", datatype);
            //		XsMetaModel.addXsNofAttribute(xsFieldExtensionElement, "isEmpty");
            //		XsMetaModel.addXsNofAttribute(xsFieldExtensionElement, "annotation");

            return(xsFieldElementElement);
        }