示例#1
0
        private static Pair <string, XPathResultType> MakeProperty(
            SchemaElementComplex parent,
            Property property,
            XPathNamespaceContext ctx,
            bool isLast,
            bool isDynamic,
            string defaultNamespacePrefix)
        {
            var text = property.PropertyNameAtomic;
            var obj  = SchemaUtil.FindPropertyMapping(parent, text);

            if (obj is SchemaElementSimple || obj is SchemaElementComplex)
            {
                return(MakeElementProperty(
                           (SchemaElement)obj,
                           property,
                           ctx,
                           isLast,
                           isDynamic,
                           defaultNamespacePrefix));
            }

            if (obj != null)
            {
                return(MakeAttributeProperty((SchemaItemAttribute)obj, property, ctx));
            }

            if (isDynamic)
            {
                return(MakeElementProperty(null, property, ctx, isLast, isDynamic, defaultNamespacePrefix));
            }

            return(null);
        }
示例#2
0
        /// <summary>
        ///     Processes the model group.
        /// </summary>
        /// <param name="xsModel">The schema model.</param>
        /// <param name="xsObject">The schema that represents the model group.</param>
        /// <param name="simpleElements">The simple elements.</param>
        /// <param name="complexElements">The complex elements.</param>
        /// <param name="node">The node.</param>
        /// <param name="complexActualElement">The complex actual element.</param>
        /// <param name="complexElement">The complex element.</param>
        /// <returns></returns>
        private SchemaElementComplex ProcessModelGroup(
            XmlSchema xsModel,
            XmlSchemaObject xsObject,
            IList <SchemaElementSimple> simpleElements,
            IList <SchemaElementComplex> complexElements,
            ElementPathNode node,
            XmlSchemaComplexType complexActualElement,
            SchemaElementComplex complexElement)
        {
            var xsGroup = xsObject as XmlSchemaGroupBase;

            if (xsGroup != null)
            {
                return(ProcessModelGroup(
                           xsModel,
                           xsGroup.Items.Cast <XmlSchemaObject>(),
                           simpleElements,
                           complexElements,
                           node,
                           complexActualElement,
                           complexElement));
            }

            return(complexElement);
        }
示例#3
0
        /// <summary>
        ///     Finds an apropiate definition for the given property, starting at the * given
        ///     definition. First look if the property es an attribute. If not, look at simple and
        ///     then child element definitions.
        /// </summary>
        /// <param name="def">the definition to start looking</param>
        /// <param name="property">the property to look for</param>
        /// <returns>
        ///     schema element or null if not found
        /// </returns>
        public static SchemaItem FindPropertyMapping(
            SchemaElementComplex def,
            string property)
        {
            foreach (var attribute in def.Attributes)
            {
                if (attribute.Name == property)
                {
                    return(attribute);
                }
            }

            foreach (var simple in def.SimpleElements)
            {
                if (simple.Name == property)
                {
                    return(simple);
                }
            }

            foreach (var complex in def.ComplexElements)
            {
                if (complex.Name == property)
                {
                    return(complex);
                }
            }

            //property not found in schema
            return(null);
        }
示例#4
0
 /// <summary>
 ///     Ctor.
 /// </summary>
 /// <param name="component">top level component</param>
 /// <param name="namespaces">list of namespaces</param>
 public SchemaModel(
     SchemaElementComplex component,
     IList <string> namespaces)
 {
     Components = new List <SchemaElementComplex>(1);
     Components.Add(component);
     Namespaces = namespaces;
 }
示例#5
0
        private SchemaElementComplex Process(
            XmlSchema xsModel,
            XmlQualifiedName complexElementName,
            XmlSchemaComplexType complexActualElement,
            bool isArray,
            ElementPathNode node)
        {
            if (Log.IsDebugEnabled)
            {
                Log.Debug(
                    "Processing complex {0} {1} stack {2}",
                    complexElementName.Namespace,
                    complexElementName.Name,
                    node);
            }

            var attributes      = new List <SchemaItemAttribute>();
            var simpleElements  = new List <SchemaElementSimple>();
            var complexElements = new List <SchemaElementComplex>();

            XmlSchemaSimpleType optionalSimpleType     = null;
            XmlQualifiedName    optionalSimpleTypeName = null;

            DetermineOptionalSimpleType(
                xsModel,
                complexActualElement,
                out optionalSimpleType,
                out optionalSimpleTypeName
                );

            var complexElement = new SchemaElementComplex(
                complexElementName.Name,
                complexElementName.Namespace,
                attributes,
                complexElements,
                simpleElements,
                isArray,
                optionalSimpleType,
                optionalSimpleTypeName);

            // add attributes
            attributes.AddRange(GetAttributes(xsModel, complexActualElement));

            var complexParticles = GetContentModelParticles(
                xsModel,
                complexActualElement);

            complexElement = ProcessModelGroup(
                xsModel,
                complexParticles,
                simpleElements,
                complexElements,
                node,
                complexActualElement,
                complexElement);

            return(complexElement);
        }
示例#6
0
        private static SchemaElementComplex RecursiveDeepMatch(
            SchemaElementComplex parent,
            string @namespace,
            string elementName)
        {
            if (!string.IsNullOrEmpty(@namespace))
            {
                foreach (var complexElement in parent.ComplexElements)
                {
                    if (complexElement.Namespace.Equals(@namespace) && complexElement.Name.Equals(elementName))
                    {
                        return(complexElement);
                    }
                }
            }
            else
            {
                foreach (var complexElement in parent.ComplexElements)
                {
                    if (complexElement.Name.Equals(elementName))
                    {
                        return(complexElement);
                    }
                }
            }

            foreach (var complexElement in parent.ComplexElements)
            {
                var found = RecursiveDeepMatch(complexElement, @namespace, elementName);
                if (found != null)
                {
                    return(found);
                }
            }

            return(null);
        }
示例#7
0
        /// <summary>
        ///     Processes the model group.
        /// </summary>
        /// <param name="xsModel">The schema model.</param>
        /// <param name="childParticles">The schema objects in this model group.</param>
        /// <param name="simpleElements">The simple elements.</param>
        /// <param name="complexElements">The complex elements.</param>
        /// <param name="node">The node.</param>
        /// <param name="complexActualElement">The complex actual element.</param>
        /// <param name="complexElement">The complex element.</param>
        /// <returns></returns>
        private SchemaElementComplex ProcessModelGroup(
            XmlSchema xsModel,
            IEnumerable <XmlSchemaObject> childParticles,
            IList <SchemaElementSimple> simpleElements,
            IList <SchemaElementComplex> complexElements,
            ElementPathNode node,
            XmlSchemaComplexType complexActualElement,
            SchemaElementComplex complexElement)
        {
            foreach (var childParticle in childParticles)
            {
                if (childParticle is XmlSchemaElement)
                {
                    var schemaElement = (XmlSchemaElement)childParticle;
                    var isArrayFlag   = IsArray(schemaElement);

                    // the name for this element
                    XmlQualifiedName elementName;
                    // the type for this element ... this may take different paths
                    // depending upon how the type is provided to us.
                    XmlSchemaType    schemaType;
                    XmlQualifiedName schemaTypeName;

                    if (schemaElement.RefName.IsEmpty)
                    {
                        elementName = schemaElement.QualifiedName;
                        if (Equals(elementName, XmlQualifiedName.Empty))
                        {
                            elementName = new XmlQualifiedName(
                                schemaElement.Name,
                                xsModel.TargetNamespace);
                        }

                        schemaType     = schemaElement.SchemaType;
                        schemaTypeName = schemaElement.SchemaTypeName;
                        if (schemaType == null && !schemaTypeName.IsEmpty)
                        {
                            schemaType = ResolveSchemaType(xsModel, schemaTypeName);
                        }
                    }
                    else
                    {
                        // this element contains a reference to another element... the element will
                        // share the name of the reference and the type of the reference.  the reference
                        // type should be a complex type.
                        var referenceElement     = ResolveElement(schemaElement.RefName);
                        var referenceElementType = referenceElement.SchemaType;

                        var elementNamespace = string.IsNullOrEmpty(schemaElement.RefName.Namespace)
                            ? xsModel.TargetNamespace
                            : schemaElement.RefName.Namespace;
                        elementName = new XmlQualifiedName(
                            schemaElement.RefName.Name,
                            elementNamespace);

                        schemaType     = referenceElementType;
                        schemaTypeName = referenceElement.SchemaTypeName;
                        // TODO
                    }

                    var simpleType = schemaType as XmlSchemaSimpleType;
                    if (simpleType != null)
                    {
                        var fractionDigits = GetFractionRestriction(simpleType);
                        var simpleElement  = new SchemaElementSimple(
                            elementName.Name,
                            elementName.Namespace,
                            simpleType,
                            schemaTypeName.Name,
                            isArrayFlag,
                            fractionDigits);
                        simpleElements.Add(simpleElement);
                    }
                    else
                    {
                        var complexType = schemaType as XmlSchemaComplexType;
                        var newChild    = node.AddChild(elementName);
                        if (newChild.DoesNameAlreadyExistInHierarchy())
                        {
                            continue;
                        }

                        complexActualElement = complexType;

                        var innerComplex = Process(
                            xsModel,
                            elementName,
                            complexActualElement,
                            isArrayFlag,
                            newChild
                            );

                        if (Log.IsDebugEnabled)
                        {
                            Log.Debug("Adding complex {0}", complexElement);
                        }

                        complexElements.Add(innerComplex);
                    }
                }

                ProcessModelGroup(
                    xsModel,
                    childParticle,
                    simpleElements,
                    complexElements,
                    node,
                    complexActualElement,
                    complexElement);
            }

            return(complexElement);
        }
示例#8
0
        public EventType GetCreateXMLDOMType(
            string rootTypeName,
            string derivedEventTypeName,
            string moduleName,
            SchemaElementComplex complex,
            string representsFragmentOfProperty)
        {
            if (rootTypes == null) {
                rootTypes = new Dictionary<string, SchemaXMLEventType>();
            }

            if (derivedTypes == null) {
                derivedTypes = new Dictionary<string, SchemaXMLEventType>();
            }

            var type = rootTypes.Get(rootTypeName);
            if (type == null) {
                throw new IllegalStateException("Failed to find XML root event type '" + rootTypeName + "'");
            }

            var config = type.ConfigurationEventTypeXMLDOM;

            // add a new type
            var xmlDom = new ConfigurationCommonEventTypeXMLDOM();
            xmlDom.RootElementName = "//" + complex.Name; // such the reload of the type can resolve it
            xmlDom.RootElementNamespace = complex.Namespace;
            xmlDom.IsAutoFragment = config.IsAutoFragment;
            xmlDom.IsEventSenderValidatesRoot = config.IsEventSenderValidatesRoot;
            xmlDom.IsXPathPropertyExpr = config.IsXPathPropertyExpr;
            xmlDom.IsXPathResolvePropertiesAbsolute = config.IsXPathResolvePropertiesAbsolute;
            xmlDom.SchemaResource = config.SchemaResource;
            xmlDom.SchemaText = config.SchemaText;
            xmlDom.XPathFunctionResolver = config.XPathFunctionResolver;
            xmlDom.XPathVariableResolver = config.XPathVariableResolver;
            xmlDom.DefaultNamespace = config.DefaultNamespace;
            xmlDom.AddNamespacePrefixes(config.NamespacePrefixes);

            var metadata = new EventTypeMetadata(
                derivedEventTypeName,
                moduleName,
                EventTypeTypeClass.STREAM,
                EventTypeApplicationType.XML,
                NameAccessModifier.PRECONFIGURED,
                EventTypeBusModifier.BUS,
                false,
                new EventTypeIdPair(CRC32Util.ComputeCRC32(derivedEventTypeName), -1));
            var eventType = (SchemaXMLEventType) eventTypeFactory.EventTypeFactory.CreateXMLType(
                metadata,
                xmlDom,
                type.SchemaModel,
                representsFragmentOfProperty,
                rootTypeName,
                eventTypeFactory,
                this,
                eventTypeNameResolver);
            derivedTypes.Put(derivedEventTypeName, eventType);

            optionalCompileTimeRegistry?.NewType(eventType);

            return eventType;
        }
示例#9
0
        public SchemaXMLEventType(
            EventTypeMetadata eventTypeMetadata,
            ConfigurationCommonEventTypeXMLDOM config,
            SchemaModel schemaModel,
            string representsFragmentOfProperty,
            string representsOriginalTypeName,
            EventBeanTypedEventFactory eventBeanTypedEventFactory,
            EventTypeNameResolver eventTypeResolver,
            XMLFragmentEventTypeFactory xmlEventTypeFactory)
            : base(
                eventTypeMetadata,
                config,
                eventBeanTypedEventFactory,
                eventTypeResolver,
                xmlEventTypeFactory)
        {
            propertyGetterCache = new Dictionary<string, EventPropertyGetterSPI>();
            SchemaModel = schemaModel;
            rootElementNamespace = config.RootElementNamespace;
            schemaModelRoot = SchemaUtil.FindRootElement(schemaModel, rootElementNamespace, RootElementName);
            isPropertyExpressionXPath = config.IsXPathPropertyExpr;
            RepresentsFragmentOfProperty = representsFragmentOfProperty;
            RepresentsOriginalTypeName = representsOriginalTypeName;

            // Set of namespace context for XPath expressions
            var ctx = new XPathNamespaceContext();
            if (config.DefaultNamespace != null) {
                ctx.SetDefaultNamespace(config.DefaultNamespace);
            }

            foreach (var entry in config.NamespacePrefixes) {
                ctx.AddNamespace(entry.Key, entry.Value);
            }

            NamespaceContext = ctx;

            // add properties for the root element
            IList<ExplicitPropertyDescriptor> additionalSchemaProps = new List<ExplicitPropertyDescriptor>();

            // Add a property for each complex child element
            foreach (SchemaElementComplex complex in schemaModelRoot.ComplexElements) {
                var propertyName = complex.Name;
                var returnType = typeof(XmlNode);
                Type propertyComponentType = null;

                if (complex.OptionalSimpleType != null) {
                    returnType = SchemaUtil.ToReturnType(complex);
                    if (returnType == typeof(string)) {
                        propertyComponentType = typeof(char);
                    }
                }

                if (complex.IsArray) {
                    returnType = typeof(XmlNode[]); // We use Node[] for arrays and NodeList for XPath-Expressions returning Nodeset
                    propertyComponentType = typeof(XmlNode);
                }

                var isFragment = false;
                if (ConfigurationEventTypeXMLDOM.IsAutoFragment && !ConfigurationEventTypeXMLDOM.IsXPathPropertyExpr) {
                    isFragment = CanFragment(complex);
                }

                var getter = DoResolvePropertyGetter(propertyName, true);
                var desc = new EventPropertyDescriptor(
                    propertyName,
                    returnType,
                    propertyComponentType,
                    false,
                    false,
                    complex.IsArray,
                    false,
                    isFragment);
                var @explicit = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Add a property for each simple child element
            foreach (var simple in schemaModelRoot.SimpleElements) {
                var propertyName = simple.Name;
                var returnType = SchemaUtil.ToReturnType(simple);
                var componentType = GenericExtensions.GetComponentType(returnType);
                var isIndexed = simple.IsArray || componentType != null;
                var getter = DoResolvePropertyGetter(propertyName, true);
                var desc = new EventPropertyDescriptor(
                    propertyName,
                    returnType,
                    componentType,
                    false,
                    false,
                    isIndexed,
                    false,
                    false);
                var @explicit = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Add a property for each attribute
            foreach (var attribute in schemaModelRoot.Attributes) {
                var propertyName = attribute.Name;
                var returnType = SchemaUtil.ToReturnType(attribute);
                var componentType = GenericExtensions.GetComponentType(returnType);
                var isIndexed = componentType != null;
                var getter = DoResolvePropertyGetter(propertyName, true);
                var desc = new EventPropertyDescriptor(
                    propertyName,
                    returnType,
                    componentType,
                    false,
                    false,
                    isIndexed,
                    false,
                    false);
                var @explicit = new ExplicitPropertyDescriptor(desc, getter, false, null);
                additionalSchemaProps.Add(@explicit);
            }

            // Finally add XPath properties as that may depend on the rootElementNamespace
            Initialize(config.XPathProperties.Values, additionalSchemaProps);
        }
示例#10
0
 private static void VerifySizes(SchemaElementComplex element, int expectedNumberOfAttributes, int expectedNumberOfSimpleElements, int expectedNumberOfChildren)
 {
     Assert.That(element.Attributes.Count, Is.EqualTo(expectedNumberOfAttributes));
     Assert.That(element.SimpleElements.Count, Is.EqualTo(expectedNumberOfSimpleElements));
     Assert.That(element.ComplexElements.Count, Is.EqualTo(expectedNumberOfChildren));
 }
示例#11
0
 private static void VerifyComplexElement(SchemaElementComplex element, string name, bool isArray)
 {
     Assert.That(element.OptionalSimpleType, Is.Null);
     Assert.That(element.IsArray, Is.EqualTo(isArray));
     VerifyElement(element, name);
 }
示例#12
0
        public void TestMap()
        {
            Uri    uri       = _container.ResourceManager().ResolveResourceURL("regression/simpleSchema.xsd");
            String schemaUri = uri.ToString();

            SchemaModel model = XSDSchemaMapper.LoadAndMap(schemaUri, null);

            Assert.AreEqual(1, model.Components.Count);

            SchemaElementComplex component = model.Components[0];

            Assert.AreEqual("simpleEvent", component.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", component.Namespace);
            Assert.AreEqual(0, component.Attributes.Count);
            Assert.AreEqual(0, component.SimpleElements.Count);
            Assert.AreEqual(3, component.ComplexElements.Count);
            Assert.IsFalse(component.IsArray);
            Assert.IsNull(component.OptionalSimpleType);

            SchemaElementComplex nested1Element = component.ComplexElements[0];

            Assert.AreEqual("nested1", nested1Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", nested1Element.Namespace);
            Assert.AreEqual(1, nested1Element.Attributes.Count);
            Assert.AreEqual(2, nested1Element.SimpleElements.Count);
            Assert.AreEqual(1, nested1Element.ComplexElements.Count);
            Assert.IsFalse(nested1Element.IsArray);
            Assert.IsNull(nested1Element.OptionalSimpleType);

            var schemaTypeString  = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.String);
            var schemaTypeBoolean = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Boolean);
            var schemaTypeInteger = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Int);
            var schemaTypeId      = XmlSchemaType.GetBuiltInSimpleType(XmlTypeCode.Id);

            Assert.AreEqual("attr1", nested1Element.Attributes[0].Name);
            Assert.AreEqual(String.Empty, nested1Element.Attributes[0].Namespace);
            Assert.AreEqual(schemaTypeString, nested1Element.Attributes[0].SimpleType);
            Assert.AreEqual("prop1", nested1Element.SimpleElements[0].Name);
            Assert.AreEqual(schemaTypeString, nested1Element.SimpleElements[0].SimpleType);
            Assert.AreEqual("prop2", nested1Element.SimpleElements[1].Name);
            Assert.AreEqual(schemaTypeBoolean, nested1Element.SimpleElements[1].SimpleType);

            SchemaElementComplex nested2Element = nested1Element.ComplexElements[0];

            Assert.AreEqual("nested2", nested2Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", nested2Element.Namespace);
            Assert.AreEqual(0, nested2Element.Attributes.Count);
            Assert.AreEqual(1, nested2Element.SimpleElements.Count);
            Assert.AreEqual(0, nested2Element.ComplexElements.Count);
            Assert.IsFalse(nested2Element.IsArray);
            Assert.IsNull(nested2Element.OptionalSimpleType);

            SchemaElementSimple simpleProp3 = nested2Element.SimpleElements[0];

            Assert.AreEqual("prop3", simpleProp3.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", simpleProp3.Namespace);
            Assert.AreEqual(schemaTypeInteger, simpleProp3.SimpleType);
            Assert.IsTrue(simpleProp3.IsArray);

            SchemaElementComplex prop4Element = component.ComplexElements[1];

            Assert.AreEqual("prop4", prop4Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", prop4Element.Namespace);
            Assert.AreEqual(1, prop4Element.Attributes.Count);
            Assert.AreEqual(0, prop4Element.SimpleElements.Count);
            Assert.AreEqual(0, prop4Element.ComplexElements.Count);
            Assert.AreEqual("attr2", prop4Element.Attributes[0].Name);
            Assert.AreEqual(schemaTypeBoolean, prop4Element.Attributes[0].SimpleType);
            Assert.IsFalse(prop4Element.IsArray);
            Assert.AreEqual(schemaTypeString, prop4Element.OptionalSimpleType);

            SchemaElementComplex nested3Element = component.ComplexElements[2];

            Assert.AreEqual("nested3", nested3Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", nested3Element.Namespace);
            Assert.AreEqual(0, nested3Element.Attributes.Count);
            Assert.AreEqual(0, nested3Element.SimpleElements.Count);
            Assert.AreEqual(1, nested3Element.ComplexElements.Count);
            Assert.IsFalse(nested3Element.IsArray);
            Assert.IsNull(nested3Element.OptionalSimpleType);

            SchemaElementComplex nested4Element = nested3Element.ComplexElements[0];

            Assert.AreEqual("nested4", nested4Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", nested4Element.Namespace);
            Assert.AreEqual(1, nested4Element.Attributes.Count);
            Assert.AreEqual(1, nested4Element.SimpleElements.Count);
            Assert.AreEqual(0, nested4Element.ComplexElements.Count);
            Assert.AreEqual("id", nested4Element.Attributes[0].Name);
            Assert.AreEqual(schemaTypeId, nested4Element.Attributes[0].SimpleType);
            Assert.IsTrue(nested4Element.IsArray);
            Assert.IsNull(nested4Element.OptionalSimpleType);

            SchemaElementSimple prop5Element = nested4Element.SimpleElements[0];

            Assert.AreEqual("prop5", prop5Element.Name);
            Assert.AreEqual("samples:schemas:simpleSchema", prop5Element.Namespace);
            Assert.AreEqual(schemaTypeString, prop5Element.SimpleType);
            Assert.IsTrue(prop5Element.IsArray);
        }