GDL 練習 4:定義建構的變體
鍛煉
定義兩個變體:*PFeature:PaperSize 和 *PFeature InputTray,以修改 練習 3 中的建構 *PFeature。
*PFeature: PaperSize 中包含的 POption 具有下列屬性: *Name、 *Command、 *Papersize。
*PFeature: InputTray 中包含的 POption 具有下列屬性: *Name、 *Command 和 *Capacity: #of sheets。
建立範本以抽象化這兩種 *POptions 類型的通用屬性。
方案
下列範本符合條件。
*Template: COMMAND_TYPE
{
*Type: DATATYPE
*DataType: FILTER_TYPE
*ElementType: XML_STRING
*FilterTypeName: "COMMAND_STRING"
}
*Template: ACOMMAND
{
*Name: "*Command"
*Type: ATTRIBUTE
*ValueType: COMMAND_TYPE
}
下列衍生選項範本會進一步定義虛擬範本 POPTION 的屬性。
*Template: GENERIC_OPTION
{
*Inherits: POPTION
*Members: (NAME, ACOMMAND)
*Instances: <ANY>
}
*Template: XML_INT4
{
*Type: DATATYPE
*DataType: XML_TYPE
*XMLDataType: "int"
}
*Template: INTEGER
{
*Type: DATATYPE
*DataType: FILTER_TYPE
*ElementType: XML_INT4
*FilterTypeName: "HEX_OR_INT"
}
*Template: XML_FLOAT
{
*Type: DATATYPE
*DataType: XML_TYPE
*XMLDataType: "float"
}
*Template: PAIR_OF_FLOAT
{
*Type: DATATYPE
*DataType: ARRAY
*ElementType: XML_FLOAT
*RequiredDelimiter: ","
*OptionalDelimiter: "<20 09>"
*ArrayLabel: "PAIR"
*ElementTags: (width, height)
*ArraySize: 2
}
*Template: LEN_UNITS
{
*Type: DATATYPE
*DataType: ENUMERATOR
*XMLDataType: "LengthUnits"
*EnumeratorList: (inches, mm, microns, pixels)
}
*Template: PAGE_DIM
{
*Type: DATATYPE
*DataType: COMPOSITE
*ElementType: (PAIR_OF_FLOAT, LEN_UNITS)
*RequiredDelimiter: ","
*OptionalDelimiter: "<20 09>"
*ElementTags: (dimensions, units)
}
*Template: PAPERDIMENSIONS
{
*Name: "*PaperSize"
*Type: ATTRIBUTE
*ValueType: PAGE_DIM
}
下列衍生選項範本會進一步特製化範本的屬性GENERIC_OPTION。
*Template: PAPERSIZE_OPTION
{
*Name: "*POption" *% Isolate branch from Base Templates
*Inherits: GENERIC_OPTION
*Members: (PAPERDIMENSIONS)
*Instances: <ANY>
}
*Template: PAPERSIZE_FEATURE
{
*Inherits: PFEATURE
*Members: (PAPERSIZE_OPTION)
*Instances: PaperSize
}
*Template: TRAY_CAPACITY
{
*Name: "*Capacity"
*Type: ATTRIBUTE
*ValueType: INTEGER
}
下列衍生選項範本會進一步特製化範本的屬性GENERIC_OPTION。
*Template: INPUTTRAY_OPTION
{
*Name: "*POption" *% Isolate branch from Base Templates
*Inherits: GENERIC_OPTION
*Members: (TRAY_CAPACITY)
*Instances: <ANY>
}
*Template: INPUTTRAY_FEATURE
{
*Inherits: PFEATURE
*Members: (INPUTTRAY_OPTION)
*Instances: InputTray
}