コード例 #1
0
        public bool isCollection(
            string schemaName_in,

            out string ntype_out,
            out string name_out
            )
        {
            ntype_out = string.Empty;
            name_out  = string.Empty;

            ExtendedMetadata_complexTypeKeys _complextypekeys
                = root_ref.ExtendedMetadata.ComplexTypeKeys[Type];

            if (_complextypekeys != null)
            {
                XS_Schema _schema = root_ref_.SchemaCollection[schemaName_in];

                for (int c = 0; c < _schema.ComplexType.Count; c++)
                {
                    for (int a = 0; a < _schema.ComplexType[c].Attribute.Count; a++)
                    {
                        if (_schema.ComplexType[c].Attribute[a].Name == _complextypekeys.Keys)
                        {
                            ntype_out = _schema.ComplexType[c].Attribute[a].NType;
                            name_out  = _schema.ComplexType[c].Attribute[a].Name;
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
コード例 #2
0
        public bool mustImplementCollection(
            string schemaName_in,
            out ComplexTypeItem[] complexTypeCollection_out
            )
        {
            complexTypeCollection_out = null;

            XS_Schema _schema = root_ref_.SchemaCollection[schemaName_in];

            for (int c = 0; c < _schema.ComplexType.Count; c++)
            {
                for (int e = 0; e < _schema.ComplexType[c].Sequence.Element.Count; e++)
                {
                    if (
                        // if there's an Element pointing this ComplexType
                        (_schema.ComplexType[c].Sequence.Element[e].Type == Name)
                        &&
                        // and if this Element occurance is unbounded
                        (_schema.ComplexType[c].Sequence.Element[e].MaxOccurs
                         == XS_Element.MaxOccursEnum.unbounded)
                        )
                    {
                        // then this ComplexType must implement a Collection

                        ExtendedMetadata_complexType _complextype
                            = root_ref_.ExtendedMetadata.ComplexType[
                                  Name
                              ];

                        if (_complextype != null)
                        {
                            complexTypeCollection_out = new ComplexTypeItem[_complextype.ComplexTypeKey.Count];
                            for (int k = 0; k < _complextype.ComplexTypeKey.Count; k++)
                            {
                                for (int a = 0; a < Attribute.Count; a++)
                                {
                                    if (
                                        Attribute[a].Name
                                        ==
                                        _complextype.ComplexTypeKey[k].Name
                                        )
                                    {
                                        complexTypeCollection_out[k] = new ComplexTypeItem(
                                            Attribute[a].Name,
                                            Attribute[a].NType,
                                            _complextype.ComplexTypeKey[k].caseSensitive
                                            );
                                        break;
                                    }
                                }
                            }
                        }

                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #3
0
        public bool mustImplementCollection(
            string schemaName_in,

            out string keys_ntype_out,
            out string keys_name_out
            )
        {
            keys_ntype_out = string.Empty;
            keys_name_out  = string.Empty;

            XS_Schema _schema = root_ref_.SchemaCollection[schemaName_in];

            for (int c = 0; c < _schema.ComplexType.Count; c++)
            {
                for (int e = 0; e < _schema.ComplexType[c].Sequence.Element.Count; e++)
                {
                    if (
                        // if there's an Element pointing this ComplexType
                        (_schema.ComplexType[c].Sequence.Element[e].Type == Name)
                        &&
                        // and if this Element occurance is unbounded
                        (_schema.ComplexType[c].Sequence.Element[e].MaxOccurs
                         == XS_Element.MaxOccursEnum.unbounded)
                        )
                    {
                        // then this ComplexType must implement a Collection

                        ExtendedMetadata_complexTypeKeys _complextypekeys
                            = root_ref_.ExtendedMetadata.ComplexTypeKeys[
                                  Name
                              ];

                        if (_complextypekeys != null)
                        {
                            for (int a = 0; a < Attribute.Count; a++)
                            {
                                if (Attribute[a].Name == _complextypekeys.Keys)
                                {
                                    keys_name_out  = Attribute[a].Name;
                                    keys_ntype_out = Attribute[a].NType;
                                }
                            }
                        }

                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #4
0
        public bool isCollection(
            string schemaName_in,
            out ComplexTypeItem[] complexTypeCollection_out
            )
        {
            complexTypeCollection_out = null;

            ExtendedMetadata_complexType _complextype
                = root_ref.ExtendedMetadata.ComplexType[
                      Type
                  ];

            if (_complextype != null)
            {
                XS_Schema _schema = root_ref_.SchemaCollection[schemaName_in];

                for (int c = 0; c < _schema.ComplexType.Count; c++)
                {
                    if (
                        _schema.ComplexType[c].Name
                        ==
                        _complextype.Name
                        )
                    {
                        complexTypeCollection_out = new ComplexTypeItem[_complextype.ComplexTypeKey.Count];
                        for (int k = 0; k < _complextype.ComplexTypeKey.Count; k++)
                        {
                            for (int a = 0; a < _schema.ComplexType[c].Attribute.Count; a++)
                            {
                                if (
                                    _schema.ComplexType[c].Attribute[a].Name
                                    ==
                                    _complextype.ComplexTypeKey[k].Name
                                    )
                                {
                                    complexTypeCollection_out[k] = new ComplexTypeItem(
                                        _schema.ComplexType[c].Attribute[a].Name,
                                        _schema.ComplexType[c].Attribute[a].NType,
                                        _complextype.ComplexTypeKey[k].caseSensitive
                                        );
                                    break;
                                }
                            }
                        }
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #5
0
        public static XS_Schema[] Load_fromFile(
            RootMetadata root_ref_in,
            params string[] filePath_in
            )
        {
            FileStream _stream;

            XS_Schema[] _output = new XS_Schema[filePath_in.Length];

            for (int i = 0; i < filePath_in.Length; i++)
            {
                _stream = new FileStream(
                    filePath_in[i],
                    FileMode.Open,
                    FileAccess.Read,
                    FileShare.Read
                    );

                try {
                    _output[i] = (XS_Schema) new XmlSerializer(typeof(XS_Schema)).Deserialize(
                        _stream
                        );
                    _output[i].root_schema_ = ROOT + "." + SCHEMA + "[" + i + "]";
                } catch (Exception _ex) {
                    throw new Exception(string.Format(
                                            "\n---\n{0}.{1}.Load_fromFile(): - ERROR READING XML:\n{2}\n---\n{3}",
                                            typeof(XS_Schema).Namespace,
                                            typeof(XS_Schema).Name,
                                            filePath_in[i],
                                            _ex.Message
                                            ));
                }

                _output[i].parent_ref = root_ref_in;                 // ToDos: now!
                if (root_ref_in != null)
                {
                    _output[i].root_ref = root_ref_in;
                }
            }

            return(_output);
        }
コード例 #6
0
ファイル: XS_SchemaCollection.cs プロジェクト: katshann/ogen
		public XS_SchemaCollection(
			XS_Schema[] schemas_in
		) {
			schemas_ = schemas_in;
		}
コード例 #7
0
        public RootMetadata(
            string metadataFilepath_in
            )
        {
            string _metadataPath = System.IO.Path.GetDirectoryName(metadataFilepath_in);

            metadatafiles_ = Metadatas.Load_fromFile(metadataFilepath_in);

            #region string[] _schemaFilepath = new string[(int _total_schema = ...)];
            #region int _total_schema = ...;
            int _total_schema = 0;
            for (int f = 0; f < metadatafiles_.MetadataFiles.Count; f++)
            {
                switch (metadatafiles_.MetadataFiles[f].XMLFileType)
                {
                case XS_Schema.SCHEMA:
                    _total_schema++;
                    break;
                }
            }
            #endregion
            string[] _schemaFilepath = new string[
                _total_schema
                                       ];
            #endregion
            _total_schema     = 0;
            extendedmetadata_ = null;
            for (int f = 0; f < metadatafiles_.MetadataFiles.Count; f++)
            {
                switch (metadatafiles_.MetadataFiles[f].XMLFileType)
                {
                case XS_Schema.SCHEMA:
                    _schemaFilepath[_total_schema] = System.IO.Path.Combine(
                        _metadataPath,
                        metadatafiles_.MetadataFiles[f].XMLFilename
                        );
                    _total_schema++;
                    break;

                case ExtendedMetadata.METADATA:
                    if (extendedmetadata_ != null)
                    {
                        throw new Exception("expected only one ExtendedMetadata");
                    }
                    extendedmetadata_ = ExtendedMetadata.Load_fromFile(
                        System.IO.Path.Combine(
                            _metadataPath,
                            metadatafiles_.MetadataFiles[f].XMLFilename
                            ),
                        this
                        );
                    break;
                }
            }
            if (extendedmetadata_ == null)
            {
                throw new Exception("expected one ExtendedMetadata");
            }

            schemacollection_ = new XS_SchemaCollection(
                XS_Schema.Load_fromFile(
                    this,
                    _schemaFilepath
                    )
                );
        }
コード例 #8
0
ファイル: Program.cs プロジェクト: katshann/ogen
		public static void Main(string[] args) {
			RootMetadata _root = new RootMetadata(
				System.IO.Path.Combine(
					#if !NET_1_1
					System.Configuration.ConfigurationManager.AppSettings
					#else
					System.Configuration.ConfigurationSettings.AppSettings
					#endif
						["ogenPath"],

					@"..\..\OGen-NTier\NTier_metadata\OGenXSD-metadatas\MD_NTier_metadata.OGenXSD-metadata.xml"
				)
			);
			string ntype = string.Empty;
			string name = string.Empty;
			bool must = false;
			for (int c = 0; c < _root.SchemaCollection[0].ComplexType.Count; c++) {
				must = _root.SchemaCollection[0].ComplexType[c].mustImplementCollection(
					"metadata",
					out ntype,
					out name
				);
				Console.WriteLine(
					"{0}:{1}:{2}", 
					must, 
					ntype, 
					name
				);
			}
			PressAnyKey();
			return;

			#region //XmlSchema...
//			string _filepath = @"c:\test.xml";
//
//			FileStream _file = new FileStream(
//				_filepath,
//				FileMode.Create,
//				FileAccess.Write,
//				FileShare.ReadWrite
//			);
//
//			//ValidationEventHandler _eventHandler 
//			//	= new ValidationEventHandler(Program.ShowCompileErrors);
//
//			XmlSerializerNamespaces _xmlserializernamespaces 
//				= new XmlSerializerNamespaces();
//			_xmlserializernamespaces.Add("PREFIX1", "NAMESPACE111");
//			//_xmlserializernamespaces.Add("PREFIX2", "NAMESPACE222");
//
//			XmlSchema _xmlschema = new XmlSchema();
//			//XmlSchema.Read(
//			//	_file2, 
//			//	_eventHandler
//			//);
//			_xmlschema.ElementFormDefault = XmlSchemaForm.Qualified;
//			_xmlschema.Namespaces = _xmlserializernamespaces;
//			//_xmlschema.Elements;
//
//			_xmlschema.Write(_file);
//			_file.Flush();
//			_file.Close();
			#endregion


			XS_Schema _schema = new XS_Schema();
//			_schema.xmlNS_xs = "http://www.w3.org/2001/XMLSchema";
			_schema.TargetNamespace = "http://ogen.berlios.de";
			_schema.xmlNS = "http://ogen.berlios.de";
			_schema.ElementFormDefault = "qualified";
			
			XS_SimpleType _simpletype = new XS_SimpleType();
			_simpletype.Name = "someEnum";
			_simpletype.Restriction.Base = "xs:string";
			_simpletype.Restriction.Enumeration.Add(
				new XS_Enumeration("someenum1"), 
				new XS_Enumeration("someenum2"), 
				new XS_Enumeration("someenum3")
			);
			_schema.SimpleType.Add(
				_simpletype
			);

			XS_Attribute _attrib1 = new XS_Attribute();
			_attrib1.Name = "someAttrib1";
			_attrib1.Type = "xs:string";
			XS_ComplexType _someType1 = new XS_ComplexType();
			_someType1.Name = "someType1";
			_someType1.Attribute.Add(
				_attrib1
			);

			XS_Attribute _attrib2 = new XS_Attribute();
			_attrib2.Name = "someAttrib2";
			_attrib2.Type = "xs:string";
			XS_Attribute _attrib3 = new XS_Attribute();
			_attrib3.Name = "someAttrib3";
			_attrib3.Type = "xs:string";
			XS_ComplexType _someType2 = new XS_ComplexType();
			_someType2.Name = "someType2";
			_someType2.Attribute.Add(
				_attrib2, 
				_attrib3
			);

			XS_Element _element1 = new XS_Element();
			_element1.Name = "someCollection";
			_element1.Type = "someType1";
			_element1.MaxOccurs 
				//= MaxOccursEnum.unbounded;
				= XS_Element.MaxOccursEnum.unbounded;
			XS_Element _element2 = new XS_Element();
			_element2.Name = "someItem";
			_element2.Type = "someType1";
			_someType2.Sequence.Element.Add(
				_element1, 
				_element2
			);

			_schema.ComplexType.Add(
				_someType1, 
				_someType2
			);
			
			//XS_Element _someElement = new XS_Element();
			//_someElement.Name = "someElement";
			//_someElement.Type = "someType2";
			//_schema.Element = _someElement;
			_schema.Element.Name = "someElement";
			_schema.Element.Type = "someType2";

Console.WriteLine(
	"'{0}' == '{1}'", 
	_schema.SimpleType[0].Restriction.Enumeration[2].Value, 
	_schema.Read_fromRoot("ROOT.simpleType[0].restriction.enumeration[2].value")
);
PressAnyKey();
//Console.WriteLine(
//	"'{0}' == '{1}'", 
//	_schema.SimpleType[0].Restriction.Enumeration[2].XXX, 
//	_schema.Read_fromRoot("ROOT.simpleType[0].restriction.enumeration[2].XXX")
//);
//Console.Write("Press any key to continue . . . ");
//Console.ReadKey(true); Console.WriteLine();
//_schema.IterateThrough_fromRoot(
//	"ROOT.simpleType[n].restriction.enumeration[n]", 
//	notifyme//cClaSSe.dIteration_found
//);
//PressAnyKey();

			string _filepath = @"c:\test.xml";
			_schema.SaveState_toFile(_filepath);
			Output(_schema);
			PressAnyKey();
			_schema = XS_Schema.Load_fromFile(_filepath)[0];
			Output(_schema);
			PressAnyKey();
		}
コード例 #9
0
ファイル: Program.cs プロジェクト: katshann/ogen
		public static void Output(XS_Schema schema_in) {
			Console.WriteLine(
				"<xs:schema targetNamespace=\"{0}\" elementFormDefault=\"{1}\">", 
				schema_in.TargetNamespace, 
				schema_in.ElementFormDefault
			);
			for (int i = 0; i < schema_in.SimpleType.Count; i++) {
				Console.WriteLine(
					"\t<xs:simpleType name=\"{0}\" />", 
					schema_in.SimpleType[i].Name
				);
			}
			for (int i = 0; i < schema_in.ComplexType.Count; i++) {
				Console.WriteLine(
					"\t<xs:complexType name=\"{0}\" />", 
					schema_in.ComplexType[i].Name
				);
			}
			Console.WriteLine(
				"\t<xs:element name=\"{0}\" type=\"{1}\" />", 
				schema_in.Element.Name, 
				schema_in.Element.Type
			);
			Console.WriteLine("</xs:schema>");
		}
コード例 #10
0
ファイル: XS_Schema.cs プロジェクト: katshann/ogen
		public static XS_Schema[] Load_fromFile(
			RootMetadata root_ref_in, 
			params string[] filePath_in
		) {
			FileStream _stream;
			XS_Schema[] _output = new XS_Schema[filePath_in.Length];

			for (int i = 0; i < filePath_in.Length; i++) {
				_stream = new FileStream(
					filePath_in[i],
					FileMode.Open,
					FileAccess.Read,
					FileShare.Read
				);

				try {
					_output[i] = (XS_Schema)new XmlSerializer(typeof(XS_Schema)).Deserialize(
						_stream
					);
					_output[i].root_schema_ = ROOT + "." + SCHEMA + "[" + i + "]";
				} catch (Exception _ex) {
					throw new Exception(string.Format(
						"\n---\n{0}.{1}.Load_fromFile(): - ERROR READING XML:\n{2}\n---\n{3}",
						typeof(XS_Schema).Namespace, 
						typeof(XS_Schema).Name, 
						filePath_in[i],
						_ex.Message
					));
				}

				_output[i].parent_ref = root_ref_in; // ToDos: now!
				if (root_ref_in != null) _output[i].root_ref = root_ref_in;
			}

			return _output;
		}