GetEntity() public abstract method

public abstract GetEntity ( Uri absoluteUri, string role, Type ofObjectToReturn ) : Object
absoluteUri Uri
role string
ofObjectToReturn Type
return Object
Beispiel #1
0
 // instance members
 public override object GetEntity(Uri absoluteUri, string role,
                                  Type ofObjectToReturn)
 {
     if (SecurityManager.SecurityEnabled)
     {
         // in case the security manager was switched after the constructor was called
         if (permissionSet == null)
         {
             throw new SecurityException(
                       S._("Security Manager wasn't active when instance was created."));
         }
         permissionSet.PermitOnly();
     }
     return(resolver.GetEntity(absoluteUri, role, ofObjectToReturn));
 }
		void ProcessExternal (ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaExternal ext, XmlSchemaSet col)
		{
			if (ext == null) {
				error (handler, String.Format ("Object of Type {0} is not valid in Includes Property of XmlSchema", ext.GetType().Name));
				return;
			}

			// The only case we want to handle where the SchemaLocation is null is if the external is an import.
			XmlSchemaImport import = ext as XmlSchemaImport;
			if (ext.SchemaLocation == null && import == null)
				return;
			
			XmlSchema includedSchema = null;
			if (ext.SchemaLocation != null)
			{
				Stream stream = null;
				string url = null;
				if (resolver != null) {
					url = GetResolvedUri (resolver, ext.SchemaLocation);
					if (handledUris.Contains (url))
						// This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
						return;
					handledUris.Add (url, url);
					try {
						stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream;
					} catch (Exception) {
					// LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
						warn (handler, "Could not resolve schema location URI: " + url);
						stream = null;
					}
				}
		
				// Process redefinition children in advance.
				XmlSchemaRedefine redefine = ext as XmlSchemaRedefine;
				if (redefine != null) {
					for (int j = 0; j < redefine.Items.Count; j++) {
						XmlSchemaObject redefinedObj = redefine.Items [j];
						redefinedObj.isRedefinedComponent = true;
						redefinedObj.isRedefineChild = true;
						if (redefinedObj is XmlSchemaType ||
							redefinedObj is XmlSchemaGroup ||
							redefinedObj is XmlSchemaAttributeGroup)
							compilationItems.Add (redefinedObj);
						else
							error (handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
					}
				}

				if (stream == null) {
					// It is missing schema components.
					missedSubComponents = true;
					return;
				} else {
					XmlTextReader xtr = null;
					try {
						xtr = new XmlTextReader (url, stream, nameTable);
						includedSchema = XmlSchema.Read (xtr, handler);
					} finally {
						if (xtr != null)
							xtr.Close ();
					}
					includedSchema.schemas = schemas;
				}
				includedSchema.SetParent ();
				ext.Schema = includedSchema;
			}

			// Set - actual - target namespace for the included schema * before compilation*.
			if (import != null) {
				if (ext.Schema == null && ext.SchemaLocation == null) {
					// if a schema location wasn't specified, check the other schemas we have to see if one of those
					// is a match.
					foreach(XmlSchema schema in col.Schemas())
					{
						if (schema.TargetNamespace == import.Namespace)
						{
							includedSchema = schema;
							includedSchema.schemas = schemas;
							includedSchema.SetParent ();
							ext.Schema = includedSchema;
							break;
						}
					}
					// handle case where target namespace doesn't exist in schema collection - i.e can't find it at all
					if (includedSchema == null)
						return;
				} else if (includedSchema != null) {
					if (TargetNamespace == includedSchema.TargetNamespace) {
						error (handler, "Target namespace must be different from that of included schema.");
						return;
					} else if (includedSchema.TargetNamespace != import.Namespace) {
						error (handler, "Attribute namespace and its importing schema's target namespace must be the same.");
						return;
					}
				}
			} else if (includedSchema != null) {
				if (TargetNamespace == null && 
					includedSchema.TargetNamespace != null) {
					error (handler, "Target namespace is required to include a schema which has its own target namespace");
					return;
				}
				else if (TargetNamespace != null && 
					includedSchema.TargetNamespace == null)
					includedSchema.TargetNamespace = TargetNamespace;
			}

			// Do not compile included schema here.
			if (includedSchema != null)
				AddExternalComponentsTo (includedSchema, compilationItems, handler, handledUris, resolver, col);
		}
 /// <include file='doc\XmlSecureResolver.uex' path='docs/doc[@for="XmlSecureResolver.GetEntity"]/*' />
 public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
 {
     permissionSet.PermitOnly();
     return(resolver.GetEntity(absoluteUri, role, ofObjectToReturn));
 }
Beispiel #4
0
        public long PrepareContent(XPathItemFactory itemFactory, XmlResolver resolver)
        {
            XPathItem item = this.Content;

             if (item != null) {

            XmlQualifiedName method = _Method ?? GetMethodFromMediaType(this.MediaType, this.Method);

            this.contentStream = new MemoryStream();
            Serialize(this.contentStream, itemFactory, method);
            this.contentStream.Position = 0;

             } else if (this.Src != null) {

            if (resolver == null) {
               throw new ArgumentNullException("resolver");
            }

            Stream source = resolver.GetEntity(this.Src, null, typeof(Stream)) as Stream;

            if (source != null) {

               if (source.CanSeek) {
                  this.contentStream = source;
               } else {
                  this.contentStream = new MemoryStream();

                  source.CopyTo(this.contentStream);
                  this.contentStream.Position = 0;

                  source.Dispose();
               }

            } else {
               throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, "Could not resolve {0}.", this.Src.AbsoluteUri));
            }
             }

             return (this.contentStream != null) ?
            this.contentStream.Length
            : 0;
        }
Beispiel #5
0
 public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn)
 {
     return(_resolver.GetEntity(absoluteUri, role, ofObjectToReturn));
 }
Beispiel #6
0
 public static XPathDocument LoadDoc(Uri uri, XmlResolver resolver){
     var s = resolver.GetEntity(uri, "", typeof (Stream)) as Stream;
     return GetDoc(s);
 }
Beispiel #7
0
 public static XPathDocument LoadDoc(string name, XmlResolver resolver){
     var uri = resolver.ResolveUri(null, name);
     var s = resolver.GetEntity(uri, "", typeof (Stream)) as Stream;
     return GetDoc(s);
 }