Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / SchemaElement.cs / 1305376 / SchemaElement.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Xml; using System.Data; using System.Data.Metadata.Edm; using System.Reflection; using System.Data.Entity; using System.Xml.Linq; using System.IO; using System.Linq; using System.Globalization; namespace System.Data.EntityModel.SchemaObjectModel { ////// Summary description for SchemaElement. /// [DebuggerDisplay("Name={Name}")] internal abstract class SchemaElement { // see http://www.w3.org/TR/2006/REC-xml-names-20060816/ internal const string XmlNamespaceNamespace = "http://www.w3.org/2000/xmlns/"; #region Instance Fields private SchemaElement _parentElement = null; private Schema _schema = null; private int _lineNumber = 0; private int _linePosition = 0; private string _name = null; private DocumentationElement _documentation = null; private List_otherContent; #endregion #region Static Fields /// protected const int MaxValueVersionComponent = short.MaxValue; #endregion #region Public Properties /// /// /// internal int LineNumber { get { return _lineNumber; } } ////// /// internal int LinePosition { get { return _linePosition; } } ////// /// public virtual string Name { get { return _name; } set { _name = value; } } ////// /// internal DocumentationElement Documentation { get { return _documentation; } set { _documentation = value; } } ////// /// internal SchemaElement ParentElement { get { return _parentElement; } private set { _parentElement = value; } } ////// /// internal Schema Schema { get { return _schema; } set { _schema = value; } } ////// /// public virtual string FQName { get { return Name; } } ////// /// public virtual string Identity { get { return Name; } } public ListOtherContent { get { if (_otherContent == null) { _otherContent = new List (); } return _otherContent; } } #endregion #region Internal Methods /// /// Validates this element and its children /// internal virtual void Validate() { } ////// /// /// /// /// /// /// internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, int lineNumber, int linePosition, object message ) { AddError(errorCode,severity,SchemaLocation,lineNumber,linePosition,message); } ////// /// /// /// /// /// internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, XmlReader reader, object message ) { int lineNumber; int linePosition; GetPositionInfo(reader, out lineNumber, out linePosition); AddError(errorCode,severity,SchemaLocation,lineNumber,linePosition,message); } ////// /// /// /// /// internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, object message ) { AddError(errorCode,severity,SchemaLocation,LineNumber,LinePosition,message); } ////// /// /// /// /// /// internal void AddError( ErrorCode errorCode, EdmSchemaErrorSeverity severity, SchemaElement element, object message ) { AddError(errorCode,severity,element.Schema.Location,element.LineNumber,element.LinePosition,message); } ////// /// /// ///internal void Parse(XmlReader reader) { GetPositionInfo(reader); bool hasEndElement = !reader.IsEmptyElement; Debug.Assert(reader.NodeType == XmlNodeType.Element); for ( bool more = reader.MoveToFirstAttribute(); more; more = reader.MoveToNextAttribute() ) { ParseAttribute(reader); } HandleAttributesComplete(); bool done = !hasEndElement; bool skipToNextElement = false; while ( !done ) { if ( skipToNextElement ) { skipToNextElement = false; reader.Skip(); if ( reader.EOF ) break; } else { if ( !reader.Read() ) break; } switch ( reader.NodeType ) { case XmlNodeType.Element: skipToNextElement = ParseElement(reader); break; case XmlNodeType.EndElement: { done = true; break; } case XmlNodeType.CDATA: case XmlNodeType.Text: case XmlNodeType.SignificantWhitespace: ParseText(reader); break; // we ignore these childless elements case XmlNodeType.Whitespace: case XmlNodeType.XmlDeclaration: case XmlNodeType.Comment: case XmlNodeType.Notation: case XmlNodeType.ProcessingInstruction: { break; } // we ignore these elements that can have children case XmlNodeType.DocumentType: case XmlNodeType.EntityReference: { skipToNextElement = true; break; } default: { AddError( ErrorCode.UnexpectedXmlNodeType, EdmSchemaErrorSeverity.Error, reader, System.Data.Entity.Strings.UnexpectedXmlNodeType(reader.NodeType)); skipToNextElement = true; break; } } } HandleChildElementsComplete(); if ( reader.EOF && reader.Depth > 0 ) { AddError( ErrorCode.MalformedXml, EdmSchemaErrorSeverity.Error, 0, 0, System.Data.Entity.Strings.MalformedXml(LineNumber,LinePosition)); } } /// /// Set the current line number and position for an XmlReader /// /// the reader whose position is desired internal void GetPositionInfo(XmlReader reader) { GetPositionInfo(reader,out _lineNumber,out _linePosition); } ////// Get the current line number and position for an XmlReader /// /// the reader whose position is desired /// the line number /// the line position internal static void GetPositionInfo(XmlReader reader, out int lineNumber, out int linePosition) { IXmlLineInfo xmlLineInfo = reader as IXmlLineInfo; if ( xmlLineInfo != null && xmlLineInfo.HasLineInfo() ) { lineNumber = xmlLineInfo.LineNumber; linePosition = xmlLineInfo.LinePosition; } else { lineNumber = 0; linePosition = 0; } } ////// /// internal virtual void ResolveTopLevelNames() { } internal virtual void ResolveSecondLevelNames() { } #endregion #region Protected Methods ////// /// /// internal SchemaElement(SchemaElement parentElement) { if ( parentElement != null ) { ParentElement = parentElement; for ( SchemaElement element = parentElement; element != null; element = element.ParentElement ) { Schema schema = element as Schema; if ( schema != null ) { Schema = schema; break; } } if (Schema == null) { throw EntityUtil.InvalidOperation(System.Data.Entity.Strings.AllElementsMustBeInSchema); } } } internal SchemaElement(SchemaElement parentElement, string name) : this(parentElement) { _name = name; } ////// /// protected virtual void HandleAttributesComplete() { } ////// /// protected virtual void HandleChildElementsComplete() { } ////// /// /// /// ///protected string HandleUndottedNameAttribute(XmlReader reader, string field) { string name = field; Debug.Assert(string.IsNullOrEmpty(field), string.Format(CultureInfo.CurrentCulture, "{0} is already defined", reader.Name)); bool success = Utils.GetUndottedName(Schema, reader, out name); if ( !success ) return name; return name; } /// /// /// /// /// /// ///protected ReturnValue HandleDottedNameAttribute(XmlReader reader, string field, Func
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Version.cs
- DataGridViewCellStyle.cs
- HtmlTableRow.cs
- ApplicationInterop.cs
- XmlComment.cs
- CookielessHelper.cs
- SqlConnectionPoolProviderInfo.cs
- SerializationInfo.cs
- TargetParameterCountException.cs
- Rijndael.cs
- BrowserCapabilitiesCompiler.cs
- StorageEndPropertyMapping.cs
- HtmlWindowCollection.cs
- AudioLevelUpdatedEventArgs.cs
- FormattedTextSymbols.cs
- GridViewColumnHeaderAutomationPeer.cs
- WMIGenerator.cs
- SymmetricAlgorithm.cs
- MSAANativeProvider.cs
- ImageListStreamer.cs
- CommonEndpointBehaviorElement.cs
- GradientStop.cs
- InvalidDataContractException.cs
- ToolStripItemTextRenderEventArgs.cs
- XmlSchemaIdentityConstraint.cs
- SmiMetaDataProperty.cs
- DisplayInformation.cs
- XmlLangPropertyAttribute.cs
- QuaternionConverter.cs
- TemplateBindingExpressionConverter.cs
- Identity.cs
- ListBindingConverter.cs
- DesignerActionItemCollection.cs
- RuntimeConfigurationRecord.cs
- EmptyQuery.cs
- ResolvedKeyFrameEntry.cs
- BCLDebug.cs
- GenericEnumConverter.cs
- SiteMapProvider.cs
- SqlCaseSimplifier.cs
- Label.cs
- RetriableClipboard.cs
- SqlServer2KCompatibilityCheck.cs
- DataServiceHost.cs
- InputMethodStateTypeInfo.cs
- StringComparer.cs
- XmlChildNodes.cs
- WaitHandleCannotBeOpenedException.cs
- cryptoapiTransform.cs
- altserialization.cs
- FontEmbeddingManager.cs
- PerfCounterSection.cs
- DateTimeValueSerializer.cs
- RotateTransform3D.cs
- CookieHandler.cs
- CustomErrorsSectionWrapper.cs
- TextProperties.cs
- NavigatorInvalidBodyAccessException.cs
- mda.cs
- HtmlControlPersistable.cs
- XamlDesignerSerializationManager.cs
- Serializer.cs
- AssociationTypeEmitter.cs
- CommonGetThemePartSize.cs
- DeviceContext.cs
- EntityDataSourceStatementEditor.cs
- WindowsListViewGroupSubsetLink.cs
- Point3DKeyFrameCollection.cs
- MetaDataInfo.cs
- Stopwatch.cs
- DoubleAnimationBase.cs
- EqualityComparer.cs
- ZoneLinkButton.cs
- CollectionTypeElement.cs
- EntityDataSourceViewSchema.cs
- QilInvoke.cs
- ConvertersCollection.cs
- FirstMatchCodeGroup.cs
- DbParameterHelper.cs
- TextPointer.cs
- ProgressBarRenderer.cs
- handlecollector.cs
- ViewBase.cs
- TextEvent.cs
- Int32Rect.cs
- SourceFileBuildProvider.cs
- ProtectedProviderSettings.cs
- BinaryUtilClasses.cs
- PrintDialog.cs
- _ScatterGatherBuffers.cs
- CatalogZoneBase.cs
- AsyncDataRequest.cs
- DockPattern.cs
- NetworkInformationException.cs
- CacheChildrenQuery.cs
- ColorKeyFrameCollection.cs
- TTSVoice.cs
- DoubleIndependentAnimationStorage.cs
- InheritablePropertyChangeInfo.cs
- PeerMessageDispatcher.cs