src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/Internalizer.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 515
6cd506508147
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
34 import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants; 34 import com.sun.tools.internal.ws.wsdl.document.jaxws.JAXWSBindingsConstants;
35 import com.sun.tools.internal.xjc.util.DOMUtils; 35 import com.sun.tools.internal.xjc.util.DOMUtils;
36 import com.sun.xml.internal.bind.v2.util.EditDistance; 36 import com.sun.xml.internal.bind.v2.util.EditDistance;
37 import com.sun.xml.internal.ws.util.DOMUtil; 37 import com.sun.xml.internal.ws.util.DOMUtil;
38 import com.sun.xml.internal.ws.util.JAXWSUtils; 38 import com.sun.xml.internal.ws.util.JAXWSUtils;
39 import org.w3c.dom.Attr; 39 import com.sun.xml.internal.ws.util.xml.XmlUtil;
40 import org.w3c.dom.Document; 40 import org.w3c.dom.*;
41 import org.w3c.dom.Element;
42 import org.w3c.dom.NamedNodeMap;
43 import org.w3c.dom.Node;
44 import org.w3c.dom.NodeList;
45 import org.xml.sax.SAXParseException; 41 import org.xml.sax.SAXParseException;
46 42
47 import javax.xml.namespace.NamespaceContext; 43 import javax.xml.namespace.NamespaceContext;
48 import javax.xml.xpath.XPath; 44 import javax.xml.xpath.XPath;
49 import javax.xml.xpath.XPathConstants; 45 import javax.xml.xpath.XPathConstants;
50 import javax.xml.xpath.XPathExpressionException; 46 import javax.xml.xpath.XPathExpressionException;
51 import javax.xml.xpath.XPathFactory; 47 import javax.xml.xpath.XPathFactory;
52 import java.net.MalformedURLException; 48 import java.net.MalformedURLException;
53 import java.net.URL; 49 import java.net.URL;
54 import java.util.ArrayList; 50 import java.util.ArrayList;
55 import java.util.HashMap;
56 import java.util.HashSet; 51 import java.util.HashSet;
57 import java.util.Iterator; 52 import java.util.Iterator;
58 import java.util.Map;
59 import java.util.Set; 53 import java.util.Set;
60 54
61 55
62 /** 56 /**
63 * Internalizes external binding declarations. 57 * Internalizes external binding declarations.
64 * 58 *
65 * @author Vivek Pandey 59 * @author Vivek Pandey
66 */ 60 */
67 public class Internalizer { 61 public class Internalizer {
68 private static final XPathFactory xpf = XPathFactory.newInstance(); 62
63 private static final XPathFactory xpf = XmlUtil.newXPathFactory(true);
69 private final XPath xpath = xpf.newXPath(); 64 private final XPath xpath = xpf.newXPath();
70 private final WsimportOptions options;
71 private final DOMForest forest; 65 private final DOMForest forest;
72 private final ErrorReceiver errorReceiver; 66 private final ErrorReceiver errorReceiver;
73 67
74 68
75 public Internalizer(DOMForest forest, WsimportOptions options, ErrorReceiver errorReceiver) { 69 public Internalizer(DOMForest forest, WsimportOptions options, ErrorReceiver errorReceiver) {
76 this.forest = forest; 70 this.forest = forest;
77 this.options = options;
78 this.errorReceiver = errorReceiver; 71 this.errorReceiver = errorReceiver;
79 } 72 }
80 73
81 public void transform() { 74 public void transform() {
82 for (Element jaxwsBinding : forest.outerMostBindings) { 75 for (Element jaxwsBinding : forest.outerMostBindings) {
83 internalize(jaxwsBinding, jaxwsBinding); 76 internalize(jaxwsBinding, jaxwsBinding);
84 } 77 }
85 /*
86 Map<Element, Node> targetNodes = new HashMap<Element, Node>();
87 for (Element jaxwsBinding : forest.outerMostBindings) {
88 buildTargetNodeMap(jaxwsBinding, jaxwsBinding, targetNodes);
89 }
90 for (Element jaxwsBinding : forest.outerMostBindings) {
91 move(jaxwsBinding, targetNodes);
92 }
93 */
94 } 78 }
95 79
96 /** 80 /**
97 * Validates attributes of a &lt;JAXWS:bindings> element. 81 * Validates attributes of a &lt;JAXWS:bindings> element.
98 */ 82 */
99 private void validate(Element bindings) { 83 private void validate(Element bindings) {
100 NamedNodeMap atts = bindings.getAttributes(); 84 NamedNodeMap atts = bindings.getAttributes();
101 for (int i = 0; i < atts.getLength(); i++) { 85 for (int i = 0; i < atts.getLength(); i++) {
102 Attr a = (Attr) atts.item(i); 86 Attr a = (Attr) atts.item(i);
103 if (a.getNamespaceURI() != null) 87 if (a.getNamespaceURI() != null) {
104 continue; // all foreign namespace OK. 88 continue; // all foreign namespace OK.
105 if (a.getLocalName().equals("node")) 89 }
90 if (a.getLocalName().equals("node")) {
106 continue; 91 continue;
107 if (a.getLocalName().equals("wsdlLocation")) 92 }
93 if (a.getLocalName().equals("wsdlLocation")) {
108 continue; 94 continue;
95 }
109 96
110 // TODO: flag error for this undefined attribute 97 // TODO: flag error for this undefined attribute
111 } 98 }
112 } 99 }
113 100
179 targetNodes = getWSDLDefintionNode(bindings, target); 166 targetNodes = getWSDLDefintionNode(bindings, target);
180 } 167 }
181 168
182 //if target is null or empty it means the xpath evaluation has some problem, 169 //if target is null or empty it means the xpath evaluation has some problem,
183 // just return 170 // just return
184 if (targetNodes == null && hasNode && !isToplevelBinding) 171 if (targetNodes == null && hasNode && !isToplevelBinding) {
185 return; 172 return;
186 173 }
187 174
188 if (hasNode) { 175 if (hasNode) {
189 if (targetNodes != null) { 176 if (targetNodes != null) {
190 for (int i = 0; i < targetNodes.getLength(); i++) { 177 for (int i = 0; i < targetNodes.getLength(); i++) {
191 insertBinding(bindings, targetNodes.item(i)); 178 insertBinding(bindings, targetNodes.item(i));
192 // look for child <JAXWS:bindings> and process them recursively 179 // look for child <JAXWS:bindings> and process them recursively
193 Element[] children = getChildElements(bindings); 180 Element[] children = getChildElements(bindings);
194 for (Element child : children) 181 for (Element child : children) {
195 if("bindings".equals(child.getLocalName())) { 182 if ("bindings".equals(child.getLocalName())) {
196 internalize(child, targetNodes.item(i)); 183 internalize(child, targetNodes.item(i));
197 } 184 }
185 }
198 } 186 }
199 } 187 }
200 } 188 }
201 if (targetNodes == null) { 189 if (targetNodes == null) {
202 // look for child <JAXWS:bindings> and process them recursively 190 // look for child <JAXWS:bindings> and process them recursively
203 Element[] children = getChildElements(bindings); 191 Element[] children = getChildElements(bindings);
204 192
205 for (Element child : children) 193 for (Element child : children) {
206 internalize(child, target); 194 internalize(child, target);
195 }
207 } 196 }
208 } 197 }
209 198
210 /** 199 /**
211 * Moves JAXWS customizations under their respective target nodes. 200 * Moves JAXWS customizations under their respective target nodes.
224 } else { 213 } else {
225 moveUnder(bindings, (Element) target); 214 moveUnder(bindings, (Element) target);
226 } 215 }
227 } 216 }
228 217
229
230 /**
231 * Determines the target node of the "bindings" element
232 * by using the inherited target node, then put
233 * the result into the "result" map.
234 */
235 /* TODO Remove this logic if there are no regressions with new internalization logic
236 private void buildTargetNodeMap(Element bindings, Node inheritedTarget, Map<Element, Node> result) {
237 // start by the inherited target
238 Node target = inheritedTarget;
239
240 validate(bindings); // validate this node
241
242 // look for @wsdlLocation
243 if (isTopLevelBinding(bindings)) {
244 String wsdlLocation;
245 if (bindings.getAttributeNode("wsdlLocation") != null) {
246 wsdlLocation = bindings.getAttribute("wsdlLocation");
247
248 try {
249 // absolutize this URI.
250 // TODO: use the URI class
251 // TODO: honor xml:base
252 wsdlLocation = new URL(new URL(forest.getSystemId(bindings.getOwnerDocument())),
253 wsdlLocation).toExternalForm();
254 } catch (MalformedURLException e) {
255 wsdlLocation = JAXWSUtils.absolutize(JAXWSUtils.getFileOrURLName(wsdlLocation));
256 }
257 } else {
258 //the node does not have
259 wsdlLocation = forest.getFirstRootDocument();
260 }
261 target = forest.get(wsdlLocation);
262
263 if (target == null) {
264 reportError(bindings, WsdlMessages.INTERNALIZER_INCORRECT_SCHEMA_REFERENCE(wsdlLocation, EditDistance.findNearest(wsdlLocation, forest.listSystemIDs())));
265 return; // abort processing this <JAXWS:bindings>
266 }
267 }
268
269 //if the target node is xs:schema, declare the jaxb version on it as latter on it will be
270 //required by the inlined schema bindings
271
272 Element element = DOMUtil.getFirstElementChild(target);
273 if (element != null && element.getNamespaceURI().equals(Constants.NS_WSDL) && element.getLocalName().equals("definitions")) {
274 //get all schema elements
275 Element type = DOMUtils.getFirstChildElement(element, Constants.NS_WSDL, "types");
276 if (type != null) {
277 for (Element schemaElement : DOMUtils.getChildElements(type, Constants.NS_XSD, "schema")) {
278 if (!schemaElement.hasAttributeNS(Constants.NS_XMLNS, "jaxb")) {
279 schemaElement.setAttributeNS(Constants.NS_XMLNS, "xmlns:jaxb", JAXWSBindingsConstants.NS_JAXB_BINDINGS);
280 }
281
282 //add jaxb:bindings version info. Lets put it to 1.0, may need to change latter
283 if (!schemaElement.hasAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "version")) {
284 schemaElement.setAttributeNS(JAXWSBindingsConstants.NS_JAXB_BINDINGS, "jaxb:version", JAXWSBindingsConstants.JAXB_BINDING_VERSION);
285 }
286 }
287 }
288 }
289
290
291 boolean hasNode = true;
292 if ((isJAXWSBindings(bindings) || isJAXBBindings(bindings)) && bindings.getAttributeNode("node") != null) {
293 target = evaluateXPathNode(bindings, target, bindings.getAttribute("node"), new NamespaceContextImpl(bindings));
294 } else
295 if (isJAXWSBindings(bindings) && (bindings.getAttributeNode("node") == null) && !isTopLevelBinding(bindings)) {
296 hasNode = false;
297 } else
298 if (isGlobalBinding(bindings) && !isWSDLDefinition(target) && isTopLevelBinding(bindings.getParentNode())) {
299 target = getWSDLDefintionNode(bindings, target);
300 }
301
302 //if target is null it means the xpath evaluation has some problem,
303 // just return
304 if (target == null)
305 return;
306
307 // update the result map
308 if (hasNode)
309 result.put(bindings, target);
310
311 // look for child <JAXWS:bindings> and process them recursively
312 Element[] children = getChildElements(bindings);
313 for (Element child : children)
314 buildTargetNodeMap(child, target, result);
315 }
316 */
317 private NodeList getWSDLDefintionNode(Node bindings, Node target) { 218 private NodeList getWSDLDefintionNode(Node bindings, Node target) {
318 return evaluateXPathMultiNode(bindings, target, "wsdl:definitions", 219 return evaluateXPathMultiNode(bindings, target, "wsdl:definitions",
319 new NamespaceContext() { 220 new NamespaceContext() {
221 @Override
320 public String getNamespaceURI(String prefix) { 222 public String getNamespaceURI(String prefix) {
321 return "http://schemas.xmlsoap.org/wsdl/"; 223 return "http://schemas.xmlsoap.org/wsdl/";
322 } 224 }
323 225
226 @Override
324 public String getPrefix(String nsURI) { 227 public String getPrefix(String nsURI) {
325 throw new UnsupportedOperationException(); 228 throw new UnsupportedOperationException();
326 } 229 }
327 230
231 @Override
328 public Iterator getPrefixes(String namespaceURI) { 232 public Iterator getPrefixes(String namespaceURI) {
329 throw new UnsupportedOperationException(); 233 throw new UnsupportedOperationException();
330 } 234 }
331 }); 235 });
332 } 236 }
333 237
334 private boolean isWSDLDefinition(Node target) { 238 private boolean isWSDLDefinition(Node target) {
335 if (target == null) 239 if (target == null) {
336 return false; 240 return false;
241 }
337 String localName = target.getLocalName(); 242 String localName = target.getLocalName();
338 String nsURI = target.getNamespaceURI(); 243 String nsURI = target.getNamespaceURI();
339 return fixNull(localName).equals("definitions") && fixNull(nsURI).equals("http://schemas.xmlsoap.org/wsdl/"); 244 return fixNull(localName).equals("definitions") && fixNull(nsURI).equals("http://schemas.xmlsoap.org/wsdl/");
340 } 245 }
341 246
367 private static Element[] getChildElements(Element parent) { 272 private static Element[] getChildElements(Element parent) {
368 ArrayList<Element> a = new ArrayList<Element>(); 273 ArrayList<Element> a = new ArrayList<Element>();
369 NodeList children = parent.getChildNodes(); 274 NodeList children = parent.getChildNodes();
370 for (int i = 0; i < children.getLength(); i++) { 275 for (int i = 0; i < children.getLength(); i++) {
371 Node item = children.item(i); 276 Node item = children.item(i);
372 if (!(item instanceof Element)) continue; 277 if (!(item instanceof Element)) {
373 278 continue;
279 }
374 if (JAXWSBindingsConstants.NS_JAXWS_BINDINGS.equals(item.getNamespaceURI()) || 280 if (JAXWSBindingsConstants.NS_JAXWS_BINDINGS.equals(item.getNamespaceURI()) ||
375 JAXWSBindingsConstants.NS_JAXB_BINDINGS.equals(item.getNamespaceURI())) 281 JAXWSBindingsConstants.NS_JAXB_BINDINGS.equals(item.getNamespaceURI())) {
376 a.add((Element) item); 282 a.add((Element) item);
283 }
377 } 284 }
378 return a.toArray(new Element[a.size()]); 285 return a.toArray(new Element[a.size()]);
379 }
380
381 private Node evaluateXPathNode(Node bindings, Node target, String expression, NamespaceContext namespaceContext) {
382 NodeList nlst;
383 try {
384 xpath.setNamespaceContext(namespaceContext);
385 nlst = (NodeList) xpath.evaluate(expression, target, XPathConstants.NODESET);
386 } catch (XPathExpressionException e) {
387 reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATION_ERROR(e.getMessage()), e);
388 return null; // abort processing this <jaxb:bindings>
389 }
390
391 if (nlst.getLength() == 0) {
392 reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NO_TARGET(expression));
393 return null; // abort
394 }
395
396 if (nlst.getLength() != 1) {
397 reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVAULATES_TO_TOO_MANY_TARGETS(expression, nlst.getLength()));
398 return null; // abort
399 }
400
401 Node rnode = nlst.item(0);
402 if (!(rnode instanceof Element)) {
403 reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NON_ELEMENT(expression));
404 return null; // abort
405 }
406 return rnode;
407 } 286 }
408 287
409 private NodeList evaluateXPathMultiNode(Node bindings, Node target, String expression, NamespaceContext namespaceContext) { 288 private NodeList evaluateXPathMultiNode(Node bindings, Node target, String expression, NamespaceContext namespaceContext) {
410 NodeList nlst; 289 NodeList nlst;
411 try { 290 try {
420 reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NO_TARGET(expression)); 299 reportError((Element) bindings, WsdlMessages.INTERNALIZER_X_PATH_EVALUATES_TO_NO_TARGET(expression));
421 return null; // abort 300 return null; // abort
422 } 301 }
423 302
424 return nlst; 303 return nlst;
425 }
426
427 /**
428 * Moves JAXWS customizations under their respective target nodes.
429 */
430 private void move(Element bindings, Map<Element, Node> targetNodes) {
431 Node target = targetNodes.get(bindings);
432 if (target == null)
433 // this must be the result of an error on the external binding.
434 // recover from the error by ignoring this node
435 return;
436
437 Element[] children = DOMUtils.getChildElements(bindings);
438
439 for (Element item : children) {
440 if ("bindings".equals(item.getLocalName())) {
441 // process child <jaxws:bindings> recursively
442 move(item, targetNodes);
443 } else if (isGlobalBinding(item)) {
444 target = targetNodes.get(item);
445 moveUnder(item, (Element) target);
446 } else {
447 if (!(target instanceof Element)) {
448 return; // abort
449 }
450 // move this node under the target
451 moveUnder(item, (Element) target);
452 }
453 }
454 } 304 }
455 305
456 private boolean isJAXBBindingElement(Element e) { 306 private boolean isJAXBBindingElement(Element e) {
457 return fixNull(e.getNamespaceURI()).equals(JAXWSBindingsConstants.NS_JAXB_BINDINGS); 307 return fixNull(e.getNamespaceURI()).equals(JAXWSBindingsConstants.NS_JAXB_BINDINGS);
458 } 308 }
534 NamedNodeMap atts = p.getAttributes(); 384 NamedNodeMap atts = p.getAttributes();
535 for (int i = 0; i < atts.getLength(); i++) { 385 for (int i = 0; i < atts.getLength(); i++) {
536 Attr a = (Attr) atts.item(i); 386 Attr a = (Attr) atts.item(i);
537 if (Constants.NS_XMLNS.equals(a.getNamespaceURI())) { 387 if (Constants.NS_XMLNS.equals(a.getNamespaceURI())) {
538 String prefix; 388 String prefix;
539 if (a.getName().indexOf(':') == -1) prefix = ""; 389 if (a.getName().indexOf(':') == -1) {
540 else prefix = a.getLocalName(); 390 prefix = "";
391 } else {
392 prefix = a.getLocalName();
393 }
541 394
542 if (inscopes.add(prefix) && p != e) { 395 if (inscopes.add(prefix) && p != e) {
543 // if this is the first time we see this namespace bindings, 396 // if this is the first time we see this namespace bindings,
544 // copy the declaration. 397 // copy the declaration.
545 // if p==decl, there's no need to. Note that 398 // if p==decl, there's no need to. Note that
548 e.setAttributeNodeNS((Attr) a.cloneNode(true)); 401 e.setAttributeNodeNS((Attr) a.cloneNode(true));
549 } 402 }
550 } 403 }
551 } 404 }
552 405
553 if (p.getParentNode() instanceof Document) 406 if (p.getParentNode() instanceof Document) {
554 break; 407 break;
408 }
555 409
556 p = (Element) p.getParentNode(); 410 p = (Element) p.getParentNode();
557 } 411 }
558 412
559 if (!inscopes.contains("")) { 413 if (!inscopes.contains("")) {
565 } 419 }
566 420
567 public Element refineSchemaTarget(Element target) { 421 public Element refineSchemaTarget(Element target) {
568 // look for existing xs:annotation 422 // look for existing xs:annotation
569 Element annotation = DOMUtils.getFirstChildElement(target, Constants.NS_XSD, "annotation"); 423 Element annotation = DOMUtils.getFirstChildElement(target, Constants.NS_XSD, "annotation");
570 if (annotation == null) 424 if (annotation == null) {
571 // none exists. need to make one 425 // none exists. need to make one
572 annotation = insertXMLSchemaElement(target, "annotation"); 426 annotation = insertXMLSchemaElement(target, "annotation");
427 }
573 428
574 // then look for appinfo 429 // then look for appinfo
575 Element appinfo = DOMUtils.getFirstChildElement(annotation, Constants.NS_XSD, "appinfo"); 430 Element appinfo = DOMUtils.getFirstChildElement(annotation, Constants.NS_XSD, "appinfo");
576 if (appinfo == null) 431 if (appinfo == null) {
577 // none exists. need to make one 432 // none exists. need to make one
578 appinfo = insertXMLSchemaElement(annotation, "appinfo"); 433 appinfo = insertXMLSchemaElement(annotation, "appinfo");
434 }
579 435
580 return appinfo; 436 return appinfo;
581 } 437 }
582 438
583 public Element refineWSDLTarget(Element target) { 439 public Element refineWSDLTarget(Element target) {
584 // look for existing xs:annotation 440 // look for existing xs:annotation
585 Element JAXWSBindings = DOMUtils.getFirstChildElement(target, JAXWSBindingsConstants.NS_JAXWS_BINDINGS, "bindings"); 441 Element JAXWSBindings = DOMUtils.getFirstChildElement(target, JAXWSBindingsConstants.NS_JAXWS_BINDINGS, "bindings");
586 if (JAXWSBindings == null) 442 if (JAXWSBindings == null) {
587 // none exists. need to make one 443 // none exists. need to make one
588 JAXWSBindings = insertJAXWSBindingsElement(target, "bindings"); 444 JAXWSBindings = insertJAXWSBindingsElement(target, "bindings");
445 }
589 return JAXWSBindings; 446 return JAXWSBindings;
590 } 447 }
591 448
592 /** 449 /**
593 * Creates a new XML Schema element of the given local name 450 * Creates a new XML Schema element of the given local name
598 private Element insertXMLSchemaElement(Element parent, String localName) { 455 private Element insertXMLSchemaElement(Element parent, String localName) {
599 // use the same prefix as the parent node to avoid modifying 456 // use the same prefix as the parent node to avoid modifying
600 // the namespace binding. 457 // the namespace binding.
601 String qname = parent.getTagName(); 458 String qname = parent.getTagName();
602 int idx = qname.indexOf(':'); 459 int idx = qname.indexOf(':');
603 if (idx == -1) qname = localName; 460 if (idx == -1) {
604 else qname = qname.substring(0, idx + 1) + localName; 461 qname = localName;
462 } else {
463 qname = qname.substring(0, idx + 1) + localName;
464 }
605 465
606 Element child = parent.getOwnerDocument().createElementNS(Constants.NS_XSD, qname); 466 Element child = parent.getOwnerDocument().createElementNS(Constants.NS_XSD, qname);
607 467
608 NodeList children = parent.getChildNodes(); 468 NodeList children = parent.getChildNodes();
609 469
610 if (children.getLength() == 0) 470 if (children.getLength() == 0) {
611 parent.appendChild(child); 471 parent.appendChild(child);
612 else 472 } else {
613 parent.insertBefore(child, children.item(0)); 473 parent.insertBefore(child, children.item(0));
474 }
614 475
615 return child; 476 return child;
616 } 477 }
617 478
618 private Element insertJAXWSBindingsElement(Element parent, String localName) { 479 private Element insertJAXWSBindingsElement(Element parent, String localName) {
620 481
621 Element child = parent.getOwnerDocument().createElementNS(JAXWSBindingsConstants.NS_JAXWS_BINDINGS, qname); 482 Element child = parent.getOwnerDocument().createElementNS(JAXWSBindingsConstants.NS_JAXWS_BINDINGS, qname);
622 483
623 NodeList children = parent.getChildNodes(); 484 NodeList children = parent.getChildNodes();
624 485
625 if (children.getLength() == 0) 486 if (children.getLength() == 0) {
626 parent.appendChild(child); 487 parent.appendChild(child);
627 else 488 } else {
628 parent.insertBefore(child, children.item(0)); 489 parent.insertBefore(child, children.item(0));
490 }
629 491
630 return child; 492 return child;
631 } 493 }
632 494
633 private static
634 @NotNull 495 @NotNull
635 String fixNull(@Nullable String s) { 496 static String fixNull(@Nullable String s) {
636 if (s == null) return ""; 497 if (s == null) {
637 else return s; 498 return "";
638 } 499 } else {
639 500 return s;
501 }
502 }
640 503
641 private void reportError(Element errorSource, String formattedMsg) { 504 private void reportError(Element errorSource, String formattedMsg) {
642 reportError(errorSource, formattedMsg, null); 505 reportError(errorSource, formattedMsg, null);
643 } 506 }
644 507

mercurial