VirtualBox

source: vbox/trunk/src/VBox/Main/VirtualBoxImplExtra.cpp@ 12400

Last change on this file since 12400 was 8155, checked in by vboxsync, 17 years ago

The Big Sun Rebranding Header Change

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 6.2 KB
Line 
1/** @file
2 *
3 * VirtualBox COM class implementation extra definitions
4 *
5 * This file pulls in generated entities that may be rather big but rarely
6 * changed. Separating them from VirtualBoxImpl.cpp should speed up
7 * compilation a bit.
8 */
9
10/*
11 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
12 *
13 * This file is part of VirtualBox Open Source Edition (OSE), as
14 * available from http://www.virtualbox.org. This file is free software;
15 * you can redistribute it and/or modify it under the terms of the GNU
16 * General Public License (GPL) as published by the Free Software
17 * Foundation, in version 2 as it comes in the "COPYING" file of the
18 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
22 * Clara, CA 95054 USA or visit http://www.sun.com if you need
23 * additional information or have any questions.
24 */
25
26#include "VirtualBoxImpl.h"
27
28#include "VirtualBoxXMLUtil.h"
29
30/* embedded XML Schema documents for validating XML settings files */
31#include "xml_VirtualBox_settings_xsd.h"
32#include "xml_VirtualBox_settings_common_xsd.h"
33
34/* embedded settings converter template for updating settings files */
35#include "xml_SettingsConverter_xsl.h"
36
37static const unsigned char g_ab_xml_VirtualBox_settings_root_xsd[] =
38"<xsd:schema"
39" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
40" xmlns=\"http://www.innotek.de/VirtualBox-settings\""
41" xmlns:vb=\"http://www.innotek.de/VirtualBox-settings\""
42" targetNamespace=\"http://www.innotek.de/VirtualBox-settings\""
43" elementFormDefault=\"qualified\""
44">"
45"<xsd:element name=\"VirtualBox\">"
46" <xsd:complexType>"
47" <xsd:complexContent>"
48" <xsd:extension base=\"TVirtualBox\">"
49" <xsd:attribute name=\"version\" type=\"xsd:token\" fixed=\"" VBOX_XML_VERSION_FULL "\" use=\"required\"/>"
50" </xsd:extension>"
51" </xsd:complexContent>"
52" </xsd:complexType>"
53"</xsd:element>"
54"</xsd:schema>";
55
56static const unsigned g_cb_xml_VirtualBox_settings_root_xsd =
57 sizeof (g_ab_xml_VirtualBox_settings_root_xsd);
58
59/**
60 * Resolves external entities while parting and validating XML settings files.
61 *
62 * @param aURI URI of the external entity.
63 * @param aID ID of the external entity (may be NULL).
64 *
65 * @return Input stream created using @c new or NULL to indicate
66 * a wrong URI/ID pair.
67 */
68settings::Input *
69VirtualBox::SettingsTreeHelper::resolveEntity (const char *aURI, const char *aID)
70{
71 if (strcmp (aURI, VBOX_XML_SCHEMA_COMMON) == 0)
72 {
73 return new settings::
74 MemoryBuf ((const char *) g_ab_xml_VirtualBox_settings_common_xsd,
75 g_cb_xml_VirtualBox_settings_common_xsd, aURI);
76 }
77
78 if (strcmp (aURI, VBOX_XML_SCHEMA_ROOT) == 0)
79 {
80 return new settings::
81 MemoryBuf ((const char *) g_ab_xml_VirtualBox_settings_root_xsd,
82 g_cb_xml_VirtualBox_settings_root_xsd, aURI);
83 }
84
85 if (strcmp (aURI, VBOX_XML_SCHEMA) == 0)
86 {
87 return new settings::
88 MemoryBuf ((const char *) g_ab_xml_VirtualBox_settings_xsd,
89 g_cb_xml_VirtualBox_settings_xsd, aURI);
90 }
91
92 if (strcmp (aURI, VBOX_XML_SETTINGS_CONVERTER) == 0)
93 {
94 return new settings::
95 MemoryBuf ((const char *) g_ab_xml_SettingsConverter_xsl,
96 g_cb_xml_SettingsConverter_xsl, aURI);
97 }
98
99 AssertMsgFailed (("Unexpected entity: '%s' - knows: '%s' and '%s'\n", aURI,
100 VBOX_XML_SCHEMA_COMMON, VBOX_XML_SCHEMA));
101 return NULL;
102}
103
104/**
105 * Returns @true if the given tree needs to be converted using the XSLT
106 * template identified by #templateUri(), or @false if no conversion is
107 * required.
108 *
109 * The implementation normally checks for the "version" value of the
110 * root key to determine if the conversion is necessary. When the
111 * @a aOldVersion argument is not NULL, the implementation must return a
112 * non-NULL non-empty string representing the old version (before
113 * conversion) in it this string is used by XmlTreeBackend::oldVersion()
114 * and must be non-NULL to indicate that the conversion has been
115 * performed on the tree. The returned string must be allocated using
116 * RTStrDup() or such.
117 *
118 * This method is called again after the successful transformation to
119 * let the implementation retry the version check and request another
120 * transformation if necessary. This may be used to perform multi-step
121 * conversion like this: 1.1 => 1.2, 1.2 => 1.3 (instead of 1.1 => 1.3)
122 * which saves from the need to update all previous conversion
123 * templates to make each of them convert directly to the recent
124 * version.
125 *
126 * @note Multi-step transformations are performed in a loop that exits
127 * only when this method returns @false. It's up to the
128 * implementation to detect cycling (repeated requests to convert
129 * from the same version) wrong version order, etc. and throw an
130 * EConversionCycle exception to break the loop without returning
131 * @false (which means the transformation succeeded).
132 *
133 * @param aRoot Root settings key.
134 * @param aOldVersionString Where to store old version string
135 * pointer. May be NULL.
136 */
137bool VirtualBox::SettingsTreeHelper::
138needsConversion (const settings::Key &aRoot, char **aOldVersion) const
139{
140 if (strcmp (aRoot.name(), "VirtualBox") == 0)
141 {
142 const char *version = aRoot.stringValue ("version");
143 const char *dash = strchr (version, '-');
144 if (dash != NULL && strcmp (dash + 1, VBOX_XML_PLATFORM) == 0)
145 {
146 if (strcmp (version, VBOX_XML_VERSION_FULL) != 0)
147 {
148 /* version mismatch */
149 if (aOldVersion != NULL)
150 *aOldVersion = RTStrDup (version);
151
152 return true;
153 }
154 }
155 }
156
157 /* either the tree is invalid, or it's the other platform, or it's the same
158 * version */
159 return false;
160}
161
162/**
163 * Returns the URI of the XSLT template to perform the conversion.
164 * This template will be applied to the tree if #needsConversion()
165 * returns @c true for this tree.
166 */
167const char *VirtualBox::SettingsTreeHelper::templateUri() const
168{
169 return VBOX_XML_SETTINGS_CONVERTER;
170}
171
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette