コード例 #1
0
        static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                Console.WriteLine("usage:\r\nCodeDomGen schemaFile outputFile codeNamespace");
                return;
            }

            string inputFile     = args[0];
            string outputFile    = args[1];
            string codeNamespace = args[2];

            var typeLoader = new XmlSchemaTypeLoader();

            typeLoader.Load(inputFile);
            UTF8Encoding encoding = new UTF8Encoding();
            FileStream   strm     = File.Open(outputFile, FileMode.Create);

            // TODO: NativeCodeGen will use NativeSchemaInfo to generate code.
            NativeSchemaInfo schemaInfo = new NativeSchemaInfo(typeLoader);
            NativeCodeGen    codeGen    = new NativeCodeGen();

            //string s = SchemaGen.Generate(typeLoader, codeNamespace, inputFile);
            string s = codeGen.Generate(schemaInfo, codeNamespace, inputFile);

            byte[] bytes = encoding.GetBytes(s);
            strm.Write(bytes, 0, bytes.Length);
        }
コード例 #2
0
        /// <summary>
        /// Constructor</summary>
        /// <param name="loader">Type loader to translate element names to DOM node types</param>
        public CircuitReader(XmlSchemaTypeLoader loader)
            : base(loader)
        {
            var typeloader = loader as SchemaLoader;

            m_version = typeloader.Version; // tool's current schema version
        }
コード例 #3
0
        private XmlSchemaTypeLoader GetSchemaLoader()
        {
            XmlSchemaTypeLoader loader = new XmlSchemaTypeLoader();

            loader.SchemaResolver = new ResourceStreamResolver(Assembly.GetExecutingAssembly(),
                                                               "UnitTests.Atf/Resources");
            loader.Load(Assembly.GetExecutingAssembly(), "testSubstitutionGroups.xsd");

            return(loader);
        }
コード例 #4
0
ファイル: NativeInfo.cs プロジェクト: jethac/LevelEditor
        public NativeSchemaInfo(XmlSchemaTypeLoader typeLoader)
        {
            m_nativeClasses = new List <NativeClassInfo>();

            // parse schema & add our Annotations
            foreach (DomNodeType domType in typeLoader.GetNodeTypes())
            {
                IEnumerable <XmlNode> annotations = domType.GetTagLocal <IEnumerable <XmlNode> >();
                if (annotations == null)
                {
                    continue;
                }

                NativeClassInfo classInfo = null;
                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == SchemaStrings.LegeNativeType)
                    {
                        classInfo = new NativeClassInfo(elm, domType.IsAbstract);
                        m_nativeClasses.Add(classInfo);
                        break;
                    }
                }

                if (classInfo == null)
                {
                    continue;
                }

                foreach (XmlNode annot in annotations)
                {
                    XmlElement elm = annot as XmlElement;
                    if (elm.LocalName == SchemaStrings.LeGeNativeProperty)
                    {
                        NativePropertyInfo info = new NativePropertyInfo(elm);
                        classInfo.Properties.Add(info);
                    }
                    else if (elm.LocalName == SchemaStrings.LeGeNativeElement)
                    {
                        NativeListInfo info = new NativeListInfo(elm);
                        classInfo.Lists.Add(info);
                    }
                }
            }
        }
コード例 #5
0
        private static XmlSchemaTypeCollection GetTypeCollection(XmlSchemaTypeLoader typeLoader, string schemaNamespace)
        {
            XmlSchemaTypeCollection typeCollection;

            if (schemaNamespace != "")
            {
                typeCollection = typeLoader.GetTypeCollection(schemaNamespace);
            }
            else
            {
                IEnumerable <XmlSchemaTypeCollection> collections = typeLoader.GetTypeCollections();
                typeCollection = collections.First();
            }
            if (typeCollection == null)
            {
                throw new InvalidOperationException(string.Format("schema namespace '{0}' is missing or has no types", schemaNamespace));
            }
            return(typeCollection);
        }
コード例 #6
0
 public CustomDomXmlReader(Uri documentRoot, XmlSchemaTypeLoader typeLoader) : base(typeLoader)
 {
     _documentRoot = documentRoot;
 }
コード例 #7
0
ファイル: TestSchemas.cs プロジェクト: zparr/ATF
        public void Test()
        {
            XmlSchemaTypeLoader loader = new XmlSchemaTypeLoader();

            loader.SchemaResolver = new ResourceStreamResolver(
                Assembly.GetExecutingAssembly(),
                "UnitTests.Atf/Resources");
            loader.Load("testComplexTypes.xsd");

            DomNodeType abstractType = loader.GetNodeType("test:abstractType");

            Assert.IsTrue(abstractType != null);
            Assert.IsTrue(abstractType.IsAbstract);

            DomNodeType complexType1 = loader.GetNodeType("test:complexType1");

            Assert.IsTrue(complexType1 != null);
            Assert.IsTrue(!complexType1.IsAbstract);
            Assert.IsTrue(complexType1.BaseType == abstractType);
            //Assert.IsTrue(complexType1.FindAnnotation("annotation") != null);
            //Assert.IsTrue(complexType1.FindAnnotation("annotation", "attr1") != null);

            DomNodeType complexType2 = loader.GetNodeType("test:complexType2");

            Assert.IsTrue(complexType2 != null);
            Assert.IsTrue(!complexType2.IsAbstract);
            AttributeInfo attr1 = complexType2.GetAttributeInfo("attr1");

            Assert.IsTrue(attr1 != null);
            Assert.IsTrue(attr1.DefaultValue.Equals(1));
            //Assert.IsTrue(attr1.FindAnnotation("annotation") != null);
            AttributeInfo attr2 = complexType2.GetAttributeInfo("attr2");

            Assert.IsTrue(attr2 != null);
            Assert.IsTrue(attr2.DefaultValue.Equals(2));

            DomNodeType complexType3 = loader.GetNodeType("test:complexType3");

            Assert.IsTrue(complexType3 != null);
            Assert.IsTrue(!complexType3.IsAbstract);
            Assert.IsTrue(complexType3.BaseType == complexType2);
            AttributeInfo attr3 = complexType3.GetAttributeInfo("attr3");

            Assert.IsTrue(attr3 != null);
            ChildInfo elem1 = complexType3.GetChildInfo("elem1");

            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == complexType1);
            //Assert.IsTrue(elem1.FindAnnotation("annotation") != null);
            ChildInfo elem2 = complexType3.GetChildInfo("elem2");

            Assert.IsTrue(elem2 != null);
            Assert.IsTrue(elem2.Type == complexType1);
            Assert.IsTrue(MinMaxCheck(elem2, 1, 3));
            ChildInfo elem3 = complexType3.GetChildInfo("elem3");

            Assert.IsTrue(elem3 != null); //because a sequence of simple types becomes a sequence of child DomNodes
            attr3 = complexType3.GetAttributeInfo("elem3");
            Assert.IsTrue(attr3 == null); //because a sequence of simple types becomes a sequence of child DomNodes
            DomNode       node3                   = new DomNode(complexType3);
            DomNode       elem3Child1             = new DomNode(elem3.Type);
            AttributeInfo elem3ValueAttributeInfo = elem3.Type.GetAttributeInfo(string.Empty);

            elem3Child1.SetAttribute(elem3ValueAttributeInfo, 1);
            DomNode elem3Child2 = new DomNode(elem3.Type);

            elem3Child2.SetAttribute(elem3ValueAttributeInfo, 1);
            DomNode elem3Child3 = new DomNode(elem3.Type);

            elem3Child3.SetAttribute(elem3ValueAttributeInfo, 1);
            node3.GetChildList(elem3).Add(elem3Child1);
            node3.GetChildList(elem3).Add(elem3Child2);
            node3.GetChildList(elem3).Add(elem3Child3);

            IList <DomNode> node3Children = node3.GetChildList(elem3);

            Assert.IsTrue((int)node3Children[0].GetAttribute(elem3ValueAttributeInfo) == 1);
            Assert.IsTrue((int)node3Children[1].GetAttribute(elem3ValueAttributeInfo) == 1);
            Assert.IsTrue((int)node3Children[2].GetAttribute(elem3ValueAttributeInfo) == 1);

            // Update on 8/16/2011. DomXmlReader would not be able to handle a sequence of elements
            //  of a simple type like this. When reading, each subsequent element's value would be
            //  used to set the attribute on the DomNode, overwriting the previous one. So, since
            //  this behavior of converting more than one element of a simple type into an attribute
            //  array was broken, I want to change this unit test that I wrote and make sequences of
            //  elements of simple types into a sequence of DomNode children with a value attribute.
            //  (A value attribute means an attribute whose name is "".) --Ron
            //ChildInfo elem3 = complexType3.GetChildInfo("elem3");
            //Assert.IsTrue(elem3 == null); //because a sequence of simple types becomes an attribute
            //attr3 = complexType3.GetAttributeInfo("elem3");
            //Assert.IsTrue(attr3 != null); //because a sequence of simple types becomes an attribute
            //DomNode node3 = new DomNode(complexType3);
            //object attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int &&
            //    (int)attr3Obj == 0); //the default integer
            //node3.SetAttribute(attr3, 1);
            //attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int &&
            //    (int)attr3Obj == 1);
            //node3.SetAttribute(attr3, new int[] { 1, 2, 3 });
            //attr3Obj = node3.GetAttribute(attr3);
            //Assert.IsTrue(
            //    attr3Obj is int[] &&
            //    ((int[])attr3Obj)[2]==3);

            DomNodeType complexType4 = loader.GetNodeType("test:complexType4");

            Assert.IsTrue(complexType4 != null);
            Assert.IsTrue(!complexType4.IsAbstract);
            attr1 = complexType4.GetAttributeInfo("attr1");
            Assert.IsTrue(attr1 != null);
            elem1 = complexType4.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == complexType3);
            Assert.IsTrue(MinMaxCheck(elem1, 1, 1));

            DomNodeType complexType5 = loader.GetNodeType("test:complexType5");

            Assert.IsTrue(complexType5 != null);
            Assert.IsTrue(!complexType5.IsAbstract);
            elem1 = complexType5.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == abstractType);
            Assert.IsTrue(MinMaxCheck(elem1, 1, Int32.MaxValue));

            DomNode node5 = new DomNode(complexType5);

            elem2 = complexType5.GetChildInfo("elem2");
            DomNode node2 = new DomNode(complexType2);

            node5.SetChild(elem2, node2);
            node5.SetChild(elem2, null);
            node3 = new DomNode(complexType3);
            elem3 = complexType5.GetChildInfo("elem3");
            node5.SetChild(elem3, node3);
            //The following should violate xs:choice, but we don't fully support this checking yet.
            //ExceptionTester.CheckThrow<InvalidOperationException>(delegate { node5.AddChild(elem2, node2); });

            DomNodeType complexType6 = loader.GetNodeType("test:complexType6");

            Assert.IsTrue(complexType6 != null);
            Assert.IsTrue(!complexType6.IsAbstract);
            elem1 = complexType6.GetChildInfo("elem1");
            Assert.IsTrue(elem1 != null);
            Assert.IsTrue(elem1.Type == abstractType);
            Assert.IsTrue(MinMaxCheck(elem1, 1, Int32.MaxValue));
            elem2 = complexType6.GetChildInfo("elem2");
            Assert.IsTrue(elem2 != null);
            Assert.IsTrue(elem2.Type == complexType2);
            Assert.IsTrue(MinMaxCheck(elem2, 1, Int32.MaxValue));

            //DomNodeType complexType7 = loader.GetNodeType("test:complexType7");
            //Assert.IsTrue(complexType7 != null);
            //Assert.IsTrue(!complexType7.IsAbstract);
            //AttributeInfo attrSimpleSequence = complexType7.GetAttributeInfo("elemSimpleSequence");
            //Assert.IsTrue(attrSimpleSequence == null); //because a sequence of simple types becomes a sequence of child DomNodes
            //ChildInfo elemSimpleSequence = complexType7.GetChildInfo("elemSimpleSequence");
            //Assert.IsTrue(elemSimpleSequence != null); //because a sequence of simple types becomes a sequence of child DomNodes
            //DomNode node7 = new DomNode(complexType7);
            //object attrObj7 = node7.GetAttribute(attrSimpleSequence);
            //Assert.IsTrue(
            //    attrObj7 is float[] &&
            //    ((float[])attrObj7)[0] == 0 &&
            //    ((float[])attrObj7)[1] == 0 &&
            //    ((float[])attrObj7)[2] == 0); //the default vector
            //float[][] newSequence =
            //{
            //    new float[] {1, 2, 3},
            //    new float[] {4, 5, 6},
            //    new float[] {7, 8, 9}
            //};
            //node7.SetAttribute(attrSimpleSequence, newSequence);
            //attrObj7 = node7.GetAttribute(attrSimpleSequence);
            //Assert.IsTrue(ArraysEqual(attrObj7, newSequence));
        }
コード例 #8
0
ファイル: AtgiXmlPersister.cs プロジェクト: zoombapup/ATF
 /// <summary>
 /// Constructor</summary>
 /// <param name="loader">Type loader to translate element names to DOM node types</param>
 public AtgiXmlPersister(XmlSchemaTypeLoader loader)
     : base(loader)
 {
 }
コード例 #9
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="typeLoader">Schema loader</param>
 public SledSpfReader(XmlSchemaTypeLoader typeLoader)
 {
     m_typeLoader = typeLoader;
 }
コード例 #10
0
 public CustomDomXmlReader(Uri resourceRoot, XmlSchemaTypeLoader typeLoader)
     : base(typeLoader)
 {
     m_resourceRoot = resourceRoot;
 }
コード例 #11
0
ファイル: CircuitReader.cs プロジェクト: zparr/ATF
 /// <summary>
 /// Constructor</summary>
 /// <param name="loader">Type loader to translate element names to DOM node types</param>
 public CircuitReader(XmlSchemaTypeLoader loader)
     : base(loader)
 {
 }
コード例 #12
0
ファイル: ColladaXmlPersister.cs プロジェクト: zparr/ATF
 /// <summary>
 /// Constructor</summary>
 /// <param name="loader">Type loader to translate element names to DOM node types</param>
 public ColladaXmlPersister(XmlSchemaTypeLoader loader)
     : base(loader)
 {
 }