Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataEntity / System / Data / EntityModel / SchemaObjectModel / RowTypePropertyElement.cs / 1305376 / RowTypePropertyElement.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using Som = System.Data.EntityModel.SchemaObjectModel; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Globalization; using System.Xml; using System.Xml.Schema; using System.Data; using System.IO; using System.Data.Metadata.Edm; using System.Data.Entity; using System.Text; namespace System.Data.EntityModel.SchemaObjectModel { class RowTypePropertyElement : ModelFunctionTypeElement { private ModelFunctionTypeElement _typeSubElement = null; private bool _isRefType = false; private CollectionKind _collectionKind = CollectionKind.None; internal RowTypePropertyElement(SchemaElement parentElement) : base(parentElement) { _typeUsageBuilder = new TypeUsageBuilder(this); } internal override void ResolveTopLevelNames() { if (_typeSubElement != null) { _typeSubElement.ResolveTopLevelNames(); } if(_unresolvedType != null) { base.ResolveTopLevelNames(); } } protected override bool HandleAttribute(XmlReader reader) { if (base.HandleAttribute(reader)) { return true; } else if (CanHandleAttribute(reader, XmlConstants.TypeElement)) { HandleTypeAttribute(reader); return true; } return false; } protected void HandleTypeAttribute(XmlReader reader) { Debug.Assert(reader != null); string type; if (!Utils.GetString(Schema, reader, out type)) return; TypeModifier typeModifier; Function.RemoveTypeModifier(ref type, out typeModifier, out _isRefType); switch (typeModifier) { case TypeModifier.Array: _collectionKind = CollectionKind.Bag; break; default: Debug.Assert(typeModifier == TypeModifier.None, string.Format(CultureInfo.CurrentCulture, "Type is not valid for property {0}: {1}. The modifier for the type cannot be used in this context.", FQName, reader.Value)); break; } if (!Utils.ValidateDottedName(Schema, reader, type)) return; _unresolvedType = type; } protected override bool HandleElement(XmlReader reader) { if (CanHandleElement(reader, XmlConstants.CollectionType)) { HandleCollectionTypeElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.ReferenceType)) { HandleReferenceTypeElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.TypeRef)) { HandleTypeRefElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.RowType)) { HandleRowTypeElement(reader); return true; } return false; } protected void HandleCollectionTypeElement(XmlReader reader) { Debug.Assert(reader != null); var subElement = new CollectionTypeElement(this); subElement.Parse(reader); _typeSubElement = subElement; } protected void HandleReferenceTypeElement(XmlReader reader) { Debug.Assert(reader != null); var subElement = new ReferenceTypeElement(this); subElement.Parse(reader); _typeSubElement = subElement; } protected void HandleTypeRefElement(XmlReader reader) { Debug.Assert(reader != null); var subElement = new TypeRefElement(this); subElement.Parse(reader); _typeSubElement = subElement; } protected void HandleRowTypeElement(XmlReader reader) { Debug.Assert(reader != null); var subElement = new RowTypeElement(this); subElement.Parse(reader); _typeSubElement = subElement; } internal override void WriteIdentity(StringBuilder builder) { builder.Append("Property("); if (UnresolvedType != null && !UnresolvedType.Trim().Equals(String.Empty)) { if (_collectionKind != CollectionKind.None) { builder.Append("Collection(" + UnresolvedType + ")"); } else if (_isRefType) { builder.Append("Ref(" + UnresolvedType + ")"); } else { builder.Append(UnresolvedType); } } else { _typeSubElement.WriteIdentity(builder); } builder.Append(")"); } internal override TypeUsage GetTypeUsage() { if (_typeUsage != null) { return _typeUsage; } Debug.Assert(_typeSubElement != null, "For attributes typeusage should have been resolved"); if (_typeSubElement != null) { _typeUsage = _typeSubElement.GetTypeUsage(); } return _typeUsage; } internal override bool ResolveNameAndSetTypeUsage(Converter.ConversionCache convertedItemCache, DictionarynewGlobalItems) { if (_typeUsage == null) { if (_typeSubElement != null) //Has sub-elements { return _typeSubElement.ResolveNameAndSetTypeUsage(convertedItemCache, newGlobalItems); } else //Does not have sub-elements; try to resolve { if (_type is ScalarType) //Create and store type usage for scalar type { _typeUsageBuilder.ValidateAndSetTypeUsage(_type as ScalarType, false); _typeUsage = _typeUsageBuilder.TypeUsage; } else //Try to resolve edm type. If not now, it will resolve in the second pass { EdmType edmType = (EdmType)Converter.LoadSchemaElement(_type, _type.Schema.ProviderManifest, convertedItemCache, newGlobalItems); if (edmType != null) { if (_isRefType) { EntityType entityType = edmType as EntityType; Debug.Assert(entityType != null); _typeUsage = TypeUsage.Create(new RefType(entityType)); } else { _typeUsageBuilder.ValidateAndSetTypeUsage(edmType, false); //use typeusagebuilder so dont lose facet information _typeUsage = _typeUsageBuilder.TypeUsage; } } } if (_collectionKind != CollectionKind.None) { _typeUsage = TypeUsage.Create(new CollectionType(_typeUsage)); } return _typeUsage != null; } } return true; } internal override void Validate() { base.Validate(); if (_type != null && _type is ScalarType == false && _typeUsageBuilder.HasUserDefinedFacets) { //Non-scalar return type should not have Facets AddError(ErrorCode.ModelFuncionFacetOnNonScalarType, EdmSchemaErrorSeverity.Error, Strings.FacetsOnNonScalarType(_type.FQName)); } if (_type == null && _typeUsageBuilder.HasUserDefinedFacets) { //Type attribute not specified but facets exist AddError(ErrorCode.ModelFunctionIncorrectlyPlacedFacet, EdmSchemaErrorSeverity.Error, Strings.FacetDeclarationRequiresTypeAttribute); } if (_type == null && _typeSubElement == null) { //Type not declared as either attribute or subelement AddError(ErrorCode.ModelFunctionTypeNotDeclared, EdmSchemaErrorSeverity.Error, Strings.TypeMustBeDeclared); } if (_type != null && _typeSubElement != null) { //Both attribute and sub-element declarations exist AddError(ErrorCode.TypeDeclaredAsAttributeAndElement, EdmSchemaErrorSeverity.Error, Strings.TypeDeclaredAsAttributeAndElement); } if (_type != null && _isRefType && !(_type is SchemaEntityType)) { //Ref type refers to non entity type AddError(ErrorCode.ReferenceToNonEntityType, EdmSchemaErrorSeverity.Error, Strings.ReferenceToNonEntityType(_type.FQName)); } if (_typeSubElement != null) { _typeSubElement.Validate(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- // // Copyright (c) Microsoft Corporation. All rights reserved. // // // @owner [....] // @backupOwner [....] //--------------------------------------------------------------------- using Som = System.Data.EntityModel.SchemaObjectModel; using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.Globalization; using System.Xml; using System.Xml.Schema; using System.Data; using System.IO; using System.Data.Metadata.Edm; using System.Data.Entity; using System.Text; namespace System.Data.EntityModel.SchemaObjectModel { class RowTypePropertyElement : ModelFunctionTypeElement { private ModelFunctionTypeElement _typeSubElement = null; private bool _isRefType = false; private CollectionKind _collectionKind = CollectionKind.None; internal RowTypePropertyElement(SchemaElement parentElement) : base(parentElement) { _typeUsageBuilder = new TypeUsageBuilder(this); } internal override void ResolveTopLevelNames() { if (_typeSubElement != null) { _typeSubElement.ResolveTopLevelNames(); } if(_unresolvedType != null) { base.ResolveTopLevelNames(); } } protected override bool HandleAttribute(XmlReader reader) { if (base.HandleAttribute(reader)) { return true; } else if (CanHandleAttribute(reader, XmlConstants.TypeElement)) { HandleTypeAttribute(reader); return true; } return false; } protected void HandleTypeAttribute(XmlReader reader) { Debug.Assert(reader != null); string type; if (!Utils.GetString(Schema, reader, out type)) return; TypeModifier typeModifier; Function.RemoveTypeModifier(ref type, out typeModifier, out _isRefType); switch (typeModifier) { case TypeModifier.Array: _collectionKind = CollectionKind.Bag; break; default: Debug.Assert(typeModifier == TypeModifier.None, string.Format(CultureInfo.CurrentCulture, "Type is not valid for property {0}: {1}. The modifier for the type cannot be used in this context.", FQName, reader.Value)); break; } if (!Utils.ValidateDottedName(Schema, reader, type)) return; _unresolvedType = type; } protected override bool HandleElement(XmlReader reader) { if (CanHandleElement(reader, XmlConstants.CollectionType)) { HandleCollectionTypeElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.ReferenceType)) { HandleReferenceTypeElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.TypeRef)) { HandleTypeRefElement(reader); return true; } else if (CanHandleElement(reader, XmlConstants.RowType)) { HandleRowTypeElement(reader); return true; } return false; } protected void HandleCollectionTypeElement(XmlReader reader) { Debug.Assert(reader != null); var subElement = new CollectionTypeElement(this); subElement.Parse(reader); _typeSubElement = subElement; } protected void HandleReferenceTypeElement(XmlReader reader) { Debug.Assert(reader != null); var subElement = new ReferenceTypeElement(this); subElement.Parse(reader); _typeSubElement = subElement; } protected void HandleTypeRefElement(XmlReader reader) { Debug.Assert(reader != null); var subElement = new TypeRefElement(this); subElement.Parse(reader); _typeSubElement = subElement; } protected void HandleRowTypeElement(XmlReader reader) { Debug.Assert(reader != null); var subElement = new RowTypeElement(this); subElement.Parse(reader); _typeSubElement = subElement; } internal override void WriteIdentity(StringBuilder builder) { builder.Append("Property("); if (UnresolvedType != null && !UnresolvedType.Trim().Equals(String.Empty)) { if (_collectionKind != CollectionKind.None) { builder.Append("Collection(" + UnresolvedType + ")"); } else if (_isRefType) { builder.Append("Ref(" + UnresolvedType + ")"); } else { builder.Append(UnresolvedType); } } else { _typeSubElement.WriteIdentity(builder); } builder.Append(")"); } internal override TypeUsage GetTypeUsage() { if (_typeUsage != null) { return _typeUsage; } Debug.Assert(_typeSubElement != null, "For attributes typeusage should have been resolved"); if (_typeSubElement != null) { _typeUsage = _typeSubElement.GetTypeUsage(); } return _typeUsage; } internal override bool ResolveNameAndSetTypeUsage(Converter.ConversionCache convertedItemCache, DictionarynewGlobalItems) { if (_typeUsage == null) { if (_typeSubElement != null) //Has sub-elements { return _typeSubElement.ResolveNameAndSetTypeUsage(convertedItemCache, newGlobalItems); } else //Does not have sub-elements; try to resolve { if (_type is ScalarType) //Create and store type usage for scalar type { _typeUsageBuilder.ValidateAndSetTypeUsage(_type as ScalarType, false); _typeUsage = _typeUsageBuilder.TypeUsage; } else //Try to resolve edm type. If not now, it will resolve in the second pass { EdmType edmType = (EdmType)Converter.LoadSchemaElement(_type, _type.Schema.ProviderManifest, convertedItemCache, newGlobalItems); if (edmType != null) { if (_isRefType) { EntityType entityType = edmType as EntityType; Debug.Assert(entityType != null); _typeUsage = TypeUsage.Create(new RefType(entityType)); } else { _typeUsageBuilder.ValidateAndSetTypeUsage(edmType, false); //use typeusagebuilder so dont lose facet information _typeUsage = _typeUsageBuilder.TypeUsage; } } } if (_collectionKind != CollectionKind.None) { _typeUsage = TypeUsage.Create(new CollectionType(_typeUsage)); } return _typeUsage != null; } } return true; } internal override void Validate() { base.Validate(); if (_type != null && _type is ScalarType == false && _typeUsageBuilder.HasUserDefinedFacets) { //Non-scalar return type should not have Facets AddError(ErrorCode.ModelFuncionFacetOnNonScalarType, EdmSchemaErrorSeverity.Error, Strings.FacetsOnNonScalarType(_type.FQName)); } if (_type == null && _typeUsageBuilder.HasUserDefinedFacets) { //Type attribute not specified but facets exist AddError(ErrorCode.ModelFunctionIncorrectlyPlacedFacet, EdmSchemaErrorSeverity.Error, Strings.FacetDeclarationRequiresTypeAttribute); } if (_type == null && _typeSubElement == null) { //Type not declared as either attribute or subelement AddError(ErrorCode.ModelFunctionTypeNotDeclared, EdmSchemaErrorSeverity.Error, Strings.TypeMustBeDeclared); } if (_type != null && _typeSubElement != null) { //Both attribute and sub-element declarations exist AddError(ErrorCode.TypeDeclaredAsAttributeAndElement, EdmSchemaErrorSeverity.Error, Strings.TypeDeclaredAsAttributeAndElement); } if (_type != null && _isRefType && !(_type is SchemaEntityType)) { //Ref type refers to non entity type AddError(ErrorCode.ReferenceToNonEntityType, EdmSchemaErrorSeverity.Error, Strings.ReferenceToNonEntityType(_type.FQName)); } if (_typeSubElement != null) { _typeSubElement.Validate(); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ContentFilePart.cs
- BindValidationContext.cs
- SortFieldComparer.cs
- DataControlFieldHeaderCell.cs
- ClientReliableChannelBinder.cs
- RequiredAttributeAttribute.cs
- SourceLineInfo.cs
- SimpleMailWebEventProvider.cs
- ThemeDirectoryCompiler.cs
- SafeThemeHandle.cs
- MsmqTransportSecurity.cs
- WebPartDisplayModeCancelEventArgs.cs
- ScanQueryOperator.cs
- TemplateBaseAction.cs
- SortableBindingList.cs
- metadatamappinghashervisitor.cs
- HttpCacheVaryByContentEncodings.cs
- MobileTextWriter.cs
- UIElementParaClient.cs
- CompilerParameters.cs
- Util.cs
- SecurityResources.cs
- BaseCodePageEncoding.cs
- WebScriptMetadataInstanceContextProvider.cs
- AssemblyCollection.cs
- Volatile.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- PipelineComponent.cs
- ChannelBinding.cs
- WindowsTreeView.cs
- AdPostCacheSubstitution.cs
- Point4DConverter.cs
- UTF32Encoding.cs
- ManagementException.cs
- DrawingContext.cs
- FloaterBaseParagraph.cs
- Profiler.cs
- Point4D.cs
- XmlSchemaIdentityConstraint.cs
- FontWeight.cs
- QueryableDataSourceHelper.cs
- CacheHelper.cs
- DBDataPermissionAttribute.cs
- ManagementException.cs
- RadioButtonPopupAdapter.cs
- MD5.cs
- Command.cs
- SectionInput.cs
- TimeIntervalCollection.cs
- QilReference.cs
- WhitespaceSignificantCollectionAttribute.cs
- SqlRowUpdatingEvent.cs
- SBCSCodePageEncoding.cs
- Debug.cs
- TypeUtil.cs
- Int64.cs
- Rotation3D.cs
- ObservableDictionary.cs
- AesManaged.cs
- SchemaElementDecl.cs
- ReliableSessionElement.cs
- TextHidden.cs
- FormsAuthenticationCredentials.cs
- Object.cs
- SpellCheck.cs
- AVElementHelper.cs
- SaveWorkflowAsyncResult.cs
- AmbientValueAttribute.cs
- InvocationExpression.cs
- VariableDesigner.xaml.cs
- SplineQuaternionKeyFrame.cs
- CollectionChangeEventArgs.cs
- TabControlEvent.cs
- HistoryEventArgs.cs
- AutomationPattern.cs
- CommandExpr.cs
- HandlerFactoryWrapper.cs
- SectionRecord.cs
- CompletionProxy.cs
- TextServicesManager.cs
- ellipse.cs
- OleDbRowUpdatedEvent.cs
- ConfigXmlAttribute.cs
- SequentialOutput.cs
- TextFormattingConverter.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- DataGridTable.cs
- ColorTransformHelper.cs
- XmlSchemaNotation.cs
- ToolStripContextMenu.cs
- DragStartedEventArgs.cs
- StaticExtensionConverter.cs
- ColumnMapVisitor.cs
- WebContentFormatHelper.cs
- StoreItemCollection.cs
- BaseDataListActionList.cs
- CodeStatementCollection.cs
- BaseResourcesBuildProvider.cs
- URLIdentityPermission.cs
- AnnotationObservableCollection.cs