summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@gmail.com>2013-01-05 13:43:33 +0100
committerMarc-André Lureau <marcandre.lureau@gmail.com>2013-01-06 16:38:26 +0100
commit05676e2ab509122490fbfeb6c0d8d581f4cf9cf6 (patch)
tree8df4d9ebe71a1a902d43ed0e2f92e643f2ca8045
parent8789300d31e3c9b4310254c2416473bfdfa4739a (diff)
downloadmsitools-05676e2ab509122490fbfeb6c0d8d581f4cf9cf6.tar.gz
msitools-05676e2ab509122490fbfeb6c0d8d581f4cf9cf6.tar.xz
msitools-05676e2ab509122490fbfeb6c0d8d581f4cf9cf6.zip
Move child loading code to WixElement
-rw-r--r--src/wix.vala203
1 files changed, 56 insertions, 147 deletions
diff --git a/src/wix.vala b/src/wix.vala
index f4dfeb2..33291fd 100644
--- a/src/wix.vala
+++ b/src/wix.vala
@@ -13,10 +13,12 @@ namespace Wixl {
public abstract void visit_remove_folder (WixRemoveFolder rm) throws GLib.Error;
public abstract void visit_registry_value (WixRegistryValue reg) throws GLib.Error;
public abstract void visit_file (WixFile reg) throws GLib.Error;
+ public abstract void visit_shortcut (WixShortcut shortcut) throws GLib.Error;
}
public abstract class WixElement: Object {
public class string name;
+
public string Id { get; set; }
public WixElement parent;
public List<WixElement> children;
@@ -25,6 +27,18 @@ namespace Wixl {
Value.register_transform_func (typeof (WixElement), typeof (string), (ValueTransform)WixElement.value_to_string);
}
+ protected class HashTable<string, Type> child_types = null; // FIXME: would be nice if vala always initialize class member to null
+ class construct {
+ child_types = new HashTable<string, Type> (int_hash, int_equal);
+ }
+
+ public class void add_child_types (HashTable<string, Type> table, Type[] child_types) {
+ foreach (var t in child_types) {
+ var name = ((WixElement) Object.new (t)).name;
+ table.insert (name, t);
+ }
+ }
+
public void add_child (WixElement e) {
e.parent = this;
children.append (e);
@@ -38,6 +52,24 @@ namespace Wixl {
if (prop->type == Xml.ElementType.ATTRIBUTE_NODE)
set_property (prop->name, get_attribute_content (prop));
}
+
+ for (var child = node->children; child != null; child = child->next) {
+ switch (child->type) {
+ case Xml.ElementType.COMMENT_NODE:
+ case Xml.ElementType.TEXT_NODE:
+ continue;
+ case Xml.ElementType.ELEMENT_NODE:
+ var t = child_types.lookup (child->name);
+ if (t != 0) {
+ var elem = Object.new (t) as WixElement;
+ elem.load (child);
+ add_child (elem);
+ continue;
+ }
+ break;
+ }
+ debug ("unhandled child %s node %s", name, child->name);
+ }
}
public string to_string () {
@@ -183,32 +215,12 @@ namespace Wixl {
public class WixFeature: WixElement {
static construct {
name = "Feature";
+
+ add_child_types (child_types, { typeof (WixComponentRef) });
}
public string Level { get; set; }
- 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) {
- case Xml.ElementType.COMMENT_NODE:
- case Xml.ElementType.TEXT_NODE:
- continue;
- case Xml.ElementType.ELEMENT_NODE:
- switch (child->name) {
- case "ComponentRef":
- var ref = new WixComponentRef ();
- ref.load (child);
- add_child (@ref);
- continue;
- }
- break;
- }
- debug ("unhandled node %s", child->name);
- }
- }
-
public override void accept (WixElementVisitor visitor) throws GLib.Error {
base.accept (visitor);
visitor.visit_feature (this);
@@ -228,6 +240,15 @@ namespace Wixl {
public class WixProduct: WixElement {
static construct {
name = "Product";
+
+ add_child_types (child_types, {
+ typeof (WixPackage),
+ typeof (WixIcon),
+ typeof (WixProperty),
+ typeof (WixMedia),
+ typeof (WixDirectory),
+ typeof (WixFeature)
+ });
}
public string Name { get; set; }
@@ -240,53 +261,6 @@ namespace Wixl {
public WixProduct () {
}
- 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) {
- case Xml.ElementType.COMMENT_NODE:
- case Xml.ElementType.TEXT_NODE:
- continue;
- case Xml.ElementType.ELEMENT_NODE:
- switch (child->name) {
- case "Package":
- var package = new WixPackage ();
- package.load (child);
- add_child (package);
- continue;
- case "Icon":
- var icon = new WixIcon ();
- icon.load (child);
- add_child (icon);
- continue;
- case "Property":
- var prop = new WixProperty ();
- prop.load (child);
- add_child (prop);
- continue;
- case "Media":
- var media = new WixMedia ();
- media.load (child);
- add_child (media);
- continue;
- case "Directory":
- var directory = new WixDirectory ();
- directory.load (child);
- add_child (directory);
- continue;
- case "Feature":
- var feature = new WixFeature ();
- feature.load (child);
- add_child (feature);
- continue;
- }
- break;
- }
- debug ("unhandled node %s", child->name);
- }
- }
-
public override void accept (WixElementVisitor visitor) throws GLib.Error {
base.accept (visitor);
visitor.visit_product (this);
@@ -312,43 +286,17 @@ namespace Wixl {
public class WixComponent: WixElement {
static construct {
name = "Component";
+
+ add_child_types (child_types, {
+ typeof (WixRemoveFolder),
+ typeof (WixRegistryValue),
+ typeof (WixFile)
+ });
}
public string Guid { get; set; }
public WixKeyElement? key;
- 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) {
- case Xml.ElementType.COMMENT_NODE:
- case Xml.ElementType.TEXT_NODE:
- continue;
- case Xml.ElementType.ELEMENT_NODE:
- switch (child->name) {
- case "RemoveFolder":
- var rm = new WixRemoveFolder ();
- rm.load (child);
- add_child (rm);
- continue;
- case "RegistryValue":
- var reg = new WixRegistryValue ();
- reg.load (child);
- add_child (reg);
- continue;
- case "File":
- var file = new WixFile ();
- file.load (child);
- add_child (file);
- continue;
- }
- break;
- }
- debug ("unhandled node %s", child->name);
- }
- }
-
public override void accept (WixElementVisitor visitor) throws GLib.Error {
base.accept (visitor);
visitor.visit_component (this);
@@ -358,37 +306,15 @@ namespace Wixl {
public class WixDirectory: WixElement {
static construct {
name = "Directory";
+
+ add_child_types (child_types, {
+ typeof (WixDirectory),
+ typeof (WixComponent),
+ });
}
public string Name { get; set; }
- 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) {
- case Xml.ElementType.COMMENT_NODE:
- case Xml.ElementType.TEXT_NODE:
- continue;
- case Xml.ElementType.ELEMENT_NODE:
- switch (child->name) {
- case "Directory":
- var directory = new WixDirectory ();
- directory.load (child);
- add_child (directory);
- continue;
- case "Component":
- var component = new WixComponent ();
- component.load (child);
- add_child (component);
- continue;
- }
- break;
- }
- debug ("unhandled node %s", child->name);
- }
- }
-
public override void accept (WixElementVisitor visitor) throws GLib.Error {
base.accept (visitor);
visitor.visit_directory (this);
@@ -398,6 +324,8 @@ namespace Wixl {
class WixRoot: WixElement {
static construct {
name = "Wix";
+
+ add_child_types (child_types, { typeof (WixProduct) });
}
public string xmlns { get; set; }
@@ -411,25 +339,6 @@ namespace Wixl {
if (root->ns != null)
xmlns = root->ns->href;
-
- for (var child = root->children; child != null; child = child->next) {
- switch (child->type) {
- case Xml.ElementType.COMMENT_NODE:
- case Xml.ElementType.TEXT_NODE:
- continue;
- case Xml.ElementType.ELEMENT_NODE:
- switch (child->name) {
- case "Product":
- var product = new WixProduct ();
- product.load (child);
- add_child (product);
- continue;
- }
- break;
- }
-
- debug ("unhandled node %s", child->name);
- }
}
}