Imports System
Imports System.Text
Namespace DesignPatterns.Core.Composite
Public Class StoriesWriter
……中略……
' Elementのインスタンスによるじか書きされた親要素の置き換え
Private Sub WriteTasksTo(ByVal xml As StringBuilder, ByVal myStory As Story)
For Each myTask As Task In myStory
xml.Append("<task")
xml.Append(" no=""")
xml.Append(myTask.No.ToString())
xml.Append("""")
xml.Append(" storyNo=""")
xml.Append(myTask.StoryNo.ToString())
xml.Append(""">")
Dim taskElement As Element = New Element("task")
taskElement.AddAttribute("no", myTask.No.ToString())
taskElement.AddAttribute("storyNo", myTask.StoryNo.ToString())
' StringBuilderの代わりにElementを引き渡す
WriteTaskActualPointTo(xml, myTask)<
WriteTaskActualPointTo(taskElement, myTask)
WriteTaskEstimatedPointTo(xml, myTask)<
WriteTaskEstimatedPointTo(taskElement, myTask)
WriteTaskContentTo(xml, myTask)<
WriteTaskContentTo(taskElement, myTask)
' StringBuilderにはElementの文字列表現を格納する
xml.Append("</task>")<
xml.Append(taskElement.ToString())
Next
End Sub
' 引き渡された親Elementに子Elementを追加する
Private Sub WriteTaskActualPointTo(ByVal xml As StringBuilder, _
ByVal myTask As Task)
Private Sub WriteTaskActualPointTo(ByVal taskElement As Element, _
ByVal myTask As Task)
Dim actualPointElement As Element = New Element("actualPoint")
actualPointElement.AddAttribute("isOver", myTask.IsOverPoint().ToString())
actualPointElement.Content = myTask.ActualPoint.ToString("##.0")
xml.Append(actualPointElement.ToString())
taskElement.Add(actualPointElement)
End Sub
' 引き渡された親Elementに子Elementを追加する
Private Sub WriteTaskEstimatedPointTo(ByVal xml As StringBuilder, _
ByVal myTask As Task)
Private Sub WriteTaskEstimatedPointTo(ByVal taskElement As Element, _
ByVal myTask As Task)
Dim estimatedPointElement As Element = New Element("estimatedPoint")
estimatedPointElement.Content = myTask.EstimatedPoint.ToString("##.0")
xml.Append(estimatedPointElement.ToString())
taskElement.Add(estimatedPointElement)
End Sub
' 引き渡された親Elementに子Elementを追加する
Private Sub WriteTaskContentTo(ByVal xml As StringBuilder, _
ByVal myTask As Task)
Private Sub WriteTaskContentTo(ByVal taskElement As Element, _
ByVal myTask As Task)
Dim contentElement As Element = New Element("content")
contentElement.Content = myTask.Content
xml.Append(contentElement.ToString())
taskElement.Add(contentElement)
End Sub
End Class
End Namespace
|
|