@@ -39,24 +39,28 @@ public interface UpgradeHandler {
3939
4040 /**
4141 * root tag for the cgen extension
42+ *
4243 * @since 5.0-M1
4344 */
4445 String CGEN = "cgen" ;
4546
4647 /**
4748 * root tag for the dbImport extension
49+ *
4850 * @since 5.0-M1
4951 */
5052 String DB_IMPORT = "dbImport" ;
5153
5254 /**
5355 * root tag for the graph extension
56+ *
5457 * @since 5.0-M1
5558 */
5659 String GRAPH = "graph" ;
5760
5861 /**
5962 * root tag for the validation extension
63+ *
6064 * @since 5.0-M2
6165 */
6266 String VALIDATION = "validation" ;
@@ -86,71 +90,99 @@ default void processModel(DataChannelDescriptor dataChannelDescriptor) {
8690
8791 /**
8892 * Upgrade Domain schema and version info
93+ *
8994 * @param upgradeUnit for the datamap
9095 */
9196 default void updateDomainSchemaAndVersion (UpgradeUnit upgradeUnit ) {
9297 Element domain = upgradeUnit .getDocument ().getDocumentElement ();
9398 // update schema
94- domain .setAttribute ("xmlns" ,"http://cayenne.apache.org/schema/" + getVersion ()+ "/domain" );
95- domain .setAttribute ("xmlns:xsi" ,"http://www.w3.org/2001/XMLSchema-instance" );
96- domain .setAttribute ("xsi:schemaLocation" , "http://cayenne.apache.org/schema/" + getVersion ()+ "/domain " +
97- "https://cayenne.apache.org/schema/" + getVersion ()+ "/domain.xsd" );
99+ domain .setAttribute ("xmlns" , "http://cayenne.apache.org/schema/" + getVersion () + "/domain" );
100+ domain .setAttribute ("xmlns:xsi" , "http://www.w3.org/2001/XMLSchema-instance" );
101+ domain .setAttribute ("xsi:schemaLocation" , "http://cayenne.apache.org/schema/" + getVersion () + "/domain " +
102+ "https://cayenne.apache.org/schema/" + getVersion () + "/domain.xsd" );
98103 // update version
99104 domain .setAttribute ("project-version" , getVersion ());
100105 }
101106
102107 /**
103108 * Upgrade DataMap schema and version info
109+ *
104110 * @param upgradeUnit for the datamap
105111 */
106112 default void updateDataMapSchemaAndVersion (UpgradeUnit upgradeUnit ) {
107113 Element dataMap = upgradeUnit .getDocument ().getDocumentElement ();
108114 // update schema
109- dataMap .setAttribute ("xmlns" ,"http://cayenne.apache.org/schema/" + getVersion ()+ "/modelMap" );
110- dataMap .setAttribute ("xsi:schemaLocation" , "http://cayenne.apache.org/schema/" + getVersion ()+ "/modelMap " +
111- "https://cayenne.apache.org/schema/" + getVersion ()+ "/modelMap.xsd" );
115+ dataMap .setAttribute ("xmlns" , "http://cayenne.apache.org/schema/" + getVersion () + "/modelMap" );
116+ dataMap .setAttribute ("xsi:schemaLocation" , "http://cayenne.apache.org/schema/" + getVersion () + "/modelMap " +
117+ "https://cayenne.apache.org/schema/" + getVersion () + "/modelMap.xsd" );
112118 // update version
113119 dataMap .setAttribute ("project-version" , getVersion ());
114120 }
115121
116122 /**
117123 * Update schema for the given extension in a datamap file (root element: data-map)
124+ *
118125 * @param upgradeUnit a unit to work with
119- * @param extension name of the extension (cgen, dbImport, etc.)
126+ * @param extension name of the extension (cgen, dbImport, etc.)
120127 */
121128 default void updateExtensionSchema (UpgradeUnit upgradeUnit , String extension ) {
122129 XPath xpath = XPathFactory .newInstance ().newXPath ();
123130 NodeList nodes ;
124131 try {
125- nodes = (NodeList ) xpath .evaluate ("/data-map/*[local-name()='" + extension + "']" ,
132+ nodes = (NodeList ) xpath .evaluate ("/data-map/*[local-name()='" + extension + "']" ,
126133 upgradeUnit .getDocument (), XPathConstants .NODESET );
127134 } catch (XPathExpressionException e ) {
128135 return ;
129136 }
130137 for (int j = 0 ; j < nodes .getLength (); j ++) {
131138 Element element = (Element ) nodes .item (j );
132- element .setAttribute ("xmlns" , "http://cayenne.apache.org/schema/" + getVersion ()+ "/" + extension .toLowerCase ());
139+ element .setAttribute ("xmlns" , "http://cayenne.apache.org/schema/" + getVersion () + "/" + extension .toLowerCase ());
133140 }
134141 }
135142
136143 /**
137144 * Update schema for the given extension in a project file (root element: domain)
145+ *
138146 * @param upgradeUnit a unit to work with
139- * @param extension name of the extension (e.g. validation)
147+ * @param extension name of the extension (e.g. validation)
140148 * @since 5.0-M2
141149 */
142150 default void updateDomainExtensionSchema (UpgradeUnit upgradeUnit , String extension ) {
143151 XPath xpath = XPathFactory .newInstance ().newXPath ();
144152 NodeList nodes ;
145153 try {
146- nodes = (NodeList ) xpath .evaluate ("/domain/*[local-name()='" + extension + "']" ,
154+ nodes = (NodeList ) xpath .evaluate ("/domain/*[local-name()='" + extension + "']" ,
147155 upgradeUnit .getDocument (), XPathConstants .NODESET );
148156 } catch (XPathExpressionException e ) {
149157 return ;
150158 }
151159 for (int j = 0 ; j < nodes .getLength (); j ++) {
152160 Element element = (Element ) nodes .item (j );
153- element .setAttribute ("xmlns" , "http://cayenne.apache.org/schema/" +getVersion ()+"/" +extension .toLowerCase ());
161+ element .setAttribute ("xmlns" , "http://cayenne.apache.org/schema/" + getVersion () + "/" + extension .toLowerCase ());
162+ }
163+ }
164+
165+ /**
166+ * Update the version-stamped namespace on {@code info:property} elements
167+ * (entity/attribute comments) in a datamap file.
168+ *
169+ * @param upgradeUnit a unit to work with
170+ * @since 5.0
171+ */
172+ default void updateInfoSchema (UpgradeUnit upgradeUnit ) {
173+ XPath xpath = XPathFactory .newInstance ().newXPath ();
174+ NodeList nodes ;
175+ try {
176+ nodes = (NodeList ) xpath .evaluate ("//*[local-name()='property']" ,
177+ upgradeUnit .getDocument (), XPathConstants .NODESET );
178+ } catch (XPathExpressionException e ) {
179+ return ;
180+ }
181+ for (int j = 0 ; j < nodes .getLength (); j ++) {
182+ Element element = (Element ) nodes .item (j );
183+ if (element .hasAttribute ("xmlns:info" )) {
184+ element .setAttribute ("xmlns:info" , "http://cayenne.apache.org/schema/" + getVersion () + "/info" );
185+ }
154186 }
155187 }
156188}
0 commit comments