From dd9db8647a05b2ba46fbd4df85f496f9de176741 Mon Sep 17 00:00:00 2001 From: Marc-André Lureau Date: Thu, 3 Jan 2013 00:27:10 +0100 Subject: Use base WixElement.load() method --- src/wixl.vala | 81 ++++++++++++++++++++++++++++------------------------------- 1 file changed, 39 insertions(+), 42 deletions(-) (limited to 'src') diff --git a/src/wixl.vala b/src/wixl.vala index c1b9521..891961a 100644 --- a/src/wixl.vala +++ b/src/wixl.vala @@ -405,7 +405,8 @@ namespace Wixl { public abstract void visit_property (WixProperty prop) throws GLib.Error; } - public class WixElement: Object { + public abstract class WixElement: Object { + public static string name; public string Id { get; set; } public List children; @@ -417,6 +418,16 @@ namespace Wixl { children.append (e); } + public virtual void load (Xml.Node *node) throws Wixl.Error { + if (node->name != name) + throw new Error.FAILED ("%s: invalid node %s".printf (name, node->name)); + + for (var prop = node->properties; prop != null; prop = prop->next) { + if (prop->type == Xml.ElementType.ATTRIBUTE_NODE) + set_property (prop->name, get_attribute_content (prop)); + } + } + public string to_string () { var type = get_type (); var klass = (ObjectClass)type.class_ref (); @@ -455,24 +466,22 @@ namespace Wixl { } public class WixProperty: WixElement { - public string Value { get; set; } - - public void load (Xml.Node *node) throws Wixl.Error { - if (node->name != "Property") - throw new Error.FAILED ("invalid node"); - - for (var prop = node->properties; prop != null; prop = prop->next) { - if (prop->type == Xml.ElementType.ATTRIBUTE_NODE) - set_property (prop->name, get_attribute_content (prop)); - } + static construct { + name = "Property"; } + public string Value { get; set; } + public override void accept (WixElementVisitor visitor) throws GLib.Error { visitor.visit_property (this); } } public class WixPackage: WixElement { + static construct { + name = "Package"; + } + public string Keywords { get; set; } public string InstallerDescription { get; set; } public string InstallerComments { get; set; } @@ -484,14 +493,8 @@ namespace Wixl { public string Comments { get; set; } public string Description { get; set; } - public void load (Xml.Node *node) throws Wixl.Error { - if (node->name != "Package") - throw new Error.FAILED ("invalid node"); - - for (var prop = node->properties; prop != null; prop = prop->next) { - if (prop->type == Xml.ElementType.ATTRIBUTE_NODE) - set_property (prop->name, get_attribute_content (prop)); - } + public override void load (Xml.Node *node) throws Wixl.Error { + base.load (node); for (var child = node->children; child != null; child = child->next) { switch (child->type) { @@ -514,24 +517,22 @@ namespace Wixl { } public class WixIcon: WixElement { - public string SourceFile { get; set; } - - public void load (Xml.Node *node) throws Wixl.Error { - if (node->name != "Icon") - throw new Error.FAILED ("invalid node"); - - for (var prop = node->properties; prop != null; prop = prop->next) { - if (prop->type == Xml.ElementType.ATTRIBUTE_NODE) - set_property (prop->name, get_attribute_content (prop)); - } + static construct { + name = "Icon"; } + public string SourceFile { get; set; } + public override void accept (WixElementVisitor visitor) throws GLib.Error { visitor.visit_icon (this); } } public class WixProduct: WixElement { + static construct { + name = "Product"; + } + public string Name { get; set; } public string UpgradeCode { get; set; } public string Language { get; set; } @@ -542,14 +543,8 @@ namespace Wixl { public WixProduct () { } - public void load (Xml.Node *node) throws Wixl.Error { - if (node->name != "Product") - throw new Error.FAILED ("invalid node"); - - for (var prop = node->properties; prop != null; prop = prop->next) { - if (prop->type == Xml.ElementType.ATTRIBUTE_NODE) - set_property (prop->name, get_attribute_content (prop)); - } + public override void load (Xml.Node *node) throws Wixl.Error { + base.load (node); for (var child = node->children; child != null; child = child->next) { switch (child->type) { @@ -587,16 +582,18 @@ namespace Wixl { } class WixRoot: WixElement { + static construct { + name = "Wix"; + } + public string xmlns { get; set; } public WixRoot () { } - public void load (Xml.Doc *doc) throws Wixl.Error { + public void load_xml (Xml.Doc *doc) throws Wixl.Error { var root = doc->children; - - if (root->name != "Wix") - throw new Error.FAILED ("invalid XML document"); + load (root); if (root->ns != null) xmlns = root->ns->href; @@ -674,7 +671,7 @@ namespace Wixl { FileUtils.get_contents (file.get_path (), out data); var doc = Xml.Parser.read_memory (data, data.length); var root = new WixRoot (); - root.load (doc); + root.load_xml (doc); var builder = new WixBuilder (root); var msi = builder.build (); msi.build ("foo.msi"); -- cgit