'**************************************************
' FILE : BBCodeConfiguration.vb
' AUTHOR : Paulo Santos
' CREATION : 4/30/2009 10:57:20 PM
' COPYRIGHT : Copyright © 2009
' PJ on Development
' All Rights Reserved.
'
' Description:
' TODO: Add file description
'
' Change log:
' 0.1 4/30/2009 10:57:20 PM
' Paulo Santos
' Created.
'***************************************************
Imports System.Xml.Serialization
'''
''' Represents the configuration of the .
'''
_
_
Public NotInheritable Class BBCodeConfiguration
Implements IXmlSerializable
Private Shared ReadOnly __CurrentVersion As New System.Version(1, 0)
Private __Version As System.Version
Private __Dictionary As BBCodeElementDictionary
Private __ElementTypes As BBCodeElementTypeDictionary
''' Initializes an instance of the class.
''' This is the default constructor for this class.
Friend Sub New()
__Version = New Version(1, 0)
End Sub
'''
''' Gets the version of the configuration file.
'''
Public Property Version() As System.Version
Get
Return __Version
End Get
Private Set(ByVal value As System.Version)
If (value > __CurrentVersion) Then
Throw New ArgumentException("Unrecognized version.")
End If
__Version = value
End Set
End Property
'''
''' Gets the dictionary configuration.
'''
_
Public ReadOnly Property Dictionary() As BBCodeElementDictionary
Get
If (__Dictionary Is Nothing) Then
__Dictionary = New BBCodeElementDictionary()
End If
Return __Dictionary
End Get
End Property
'''
''' Gets the factory configuration.
'''
_
Public ReadOnly Property ElementTypes() As BBCodeElementTypeDictionary
Get
If (__ElementTypes Is Nothing) Then
__ElementTypes = New BBCodeElementTypeDictionary()
End If
Return __ElementTypes
End Get
End Property
''' This method is reserved and should not be used. When implementing the IXmlSerializable interface, you should return null (Nothing in Visual Basic) from this method, and instead, if specifying a custom schema is required, apply the to the class.
''' An that describes the XML representation of the object that is produced by the method and consumed by the method.
Public Function GetSchema() As System.Xml.Schema.XmlSchema Implements System.Xml.Serialization.IXmlSerializable.GetSchema
Return Nothing
End Function
''' Generates an object from its XML representation.
''' The stream from which the object is deserialized.
Public Sub ReadXml(ByVal reader As System.Xml.XmlReader) Implements System.Xml.Serialization.IXmlSerializable.ReadXml
'*
'* Check the name of the element
'*
If (reader.NamespaceURI <> STR_BBCodeSchemaNamespace) OrElse (reader.LocalName <> STR_BBCodeConfigurationXmlElement) Then
Exit Sub
End If
'*
'* Gets the version of the configuration
'*
Dim versionString = reader.GetAttribute("version")
If (Not String.IsNullOrEmpty(versionString)) Then
Me.Version = New System.Version(versionString)
End If
'*
'* Move to the first item
'*
reader.Read()
Dim dictionarySerializer = New XmlSerializer(GetType(BBCodeElementDictionary))
Dim typesSerializer = New XmlSerializer(GetType(BBCodeElementTypeDictionary))
__ElementTypes = Nothing
__Dictionary = Nothing
If (reader.LocalName = STR_BBCodeElementTypesXmlElement AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace) Then
__ElementTypes = typesSerializer.Deserialize(reader)
End If
If (reader.LocalName = STR_BBCodeDictionaryXmlElement AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace) Then
__Dictionary = dictionarySerializer.Deserialize(reader)
End If
If (__ElementTypes Is Nothing AndAlso reader.LocalName = STR_BBCodeElementTypesXmlElement AndAlso reader.NamespaceURI = STR_BBCodeSchemaNamespace) Then
__ElementTypes = typesSerializer.Deserialize(reader)
End If
End Sub
''' Converts an object into its XML representation.
''' The stream to which the object is serialized.
Public Sub WriteXml(ByVal writer As System.Xml.XmlWriter) Implements System.Xml.Serialization.IXmlSerializable.WriteXml
Dim dictionarySerializer = New XmlSerializer(GetType(BBCodeElementDictionary))
Dim typesSerializer = New XmlSerializer(GetType(BBCodeElementTypeDictionary))
If (ElementTypes.Count > 0) Then
typesSerializer.Serialize(writer, ElementTypes)
End If
If (Dictionary.Count > 0) Then
dictionarySerializer.Serialize(writer, Dictionary)
End If
End Sub
End Class