1 <?xml version="1.0"?> 2 <!-- 3 Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 4 DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 6 This code is free software; you can redistribute it and/or modify it 7 under the terms of the GNU General Public License version 2 only, as 8 published by the Free Software Foundation. Oracle designates this 9 particular file as subject to the "Classpath" exception as provided 10 by Oracle in the LICENSE file that accompanied this code. 11 12 This code is distributed in the hope that it will be useful, but WITHOUT 13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15 version 2 for more details (a copy is included in the LICENSE file that 16 accompanied this code). 17 18 You should have received a copy of the GNU General Public License version 19 2 along with this work; if not, write to the Free Software Foundation, 20 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 21 22 Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 23 or visit www.oracle.com if you need additional information or have any 24 questions. 25 --> 26 27 <!DOCTYPE grammar [ 28 29 30 <!ENTITY XJCURI "http://java.sun.com/xml/ns/jaxb/xjc"> 31 ]> 32 <grammar 33 xmlns="http://relaxng.org/ns/structure/1.0" 34 xmlns:cc="http://www.xml.gr.jp/xmlns/relaxngcc" 35 xmlns:xs="http://www.w3.org/2001/XMLSchema" 36 xmlns:xjc="&XJCURI;" 37 xmlns:p="post-processor-to-build-schema-for-validation" 38 39 ns="http://java.sun.com/xml/ns/jaxb" 40 41 cc:runtime-type="com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.NGCCRuntimeEx" 42 cc:package="com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.parser" 43 datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> 44 <!-- cc:$runtime-type="com.sun.xml.internal.xsom.impl.parser.NGCCRuntimeEx">--> 45 46 <cc:java-import> 47 import com.sun.codemodel.internal.*; 48 import com.sun.tools.internal.xjc.generator.bean.field.*; 49 import com.sun.tools.internal.xjc.model.*; 50 import com.sun.xml.internal.bind.api.impl.NameConverter; 51 import com.sun.xml.internal.bind.v2.WellKnownNamespace; 52 import com.sun.xml.internal.bind.marshaller.SAX2DOMEx; 53 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.*; 54 import com.sun.tools.internal.xjc.reader.Const; 55 import org.xml.sax.*; 56 import org.w3c.dom.Document; 57 import org.xml.sax.helpers.DefaultHandler; 58 import java.util.*; 59 import javax.xml.namespace.QName; 60 import javax.xml.parsers.ParserConfigurationException; 61 </cc:java-import> 62 63 <start cc:class="Root"> 64 <choice> 65 <!-- root of the external binding file. --> 66 <ref name="declaration"/> 67 <!-- root of the internal binding --> 68 <ref name="annotation"/> 69 </choice> 70 </start> 71 72 <!-- 73 in context of XML Schema annotation 74 --> 75 <define name="annotation" cc:access="public" cc:class="AnnotationState" 76 cc:return-type="BindInfo" cc:return-value="bi"> 77 78 <cc:java-import> 79 import java.io.StringWriter; 80 import com.sun.xml.internal.bind.marshaller.DataWriter; 81 </cc:java-import> 82 <cc:java-body> 83 // customization declarations 84 public BindInfo bi; 85 86 private StringWriter w; 87 88 private SAX2DOMEx sax2dom; 89 </cc:java-body> 90 91 <element name="xs:annotation"> 92 bi = new BindInfo($runtime.copyLocator()); 93 $runtime.currentBindInfo = bi; 94 95 <p:ignore><ref name="anyAttributes"/></p:ignore> 96 <zeroOrMore> 97 <choice> 98 <element name="xs:appinfo"> 99 <p:ignore><ref name="anyAttributes"/></p:ignore> 100 <zeroOrMore> 101 <choice> 102 <group> 103 result = <ref name="declaration" /> 104 bi.addDecl(result); 105 </group> 106 <element> 107 <anyName><except> 108 <nsName ns="&XJCURI;"/> 109 <nsName /><!-- JAXB namespace URI --> 110 <nsName ns="http://www.w3.org/2001/XMLSchema" /> 111 </except></anyName> 112 113 if($runtime.isExtensionURI($uri)) { 114 // parse this sub-tree as an extension 115 try { 116 sax2dom = new SAX2DOMEx(); 117 } catch( ParserConfigurationException e ) { 118 throw new Error(e); // impossible 119 } 120 $runtime.redirectSubtree(sax2dom,$uri,$localName,$qname); 121 } else { 122 // ignore this sub-tree 123 sax2dom = null; 124 $runtime.redirectSubtree(new DefaultHandler(),$uri,$localName,$qname); 125 } 126 <empty/> 127 <p:ignore><ref name="anyContents"/></p:ignore> 128 if(sax2dom!=null) { 129 bi.addDecl(new BIXPluginCustomization(((Document)sax2dom.getDOM()).getDocumentElement(),$runtime.copyLocator())); 130 } 131 </element> 132 <text/> 133 </choice> 134 </zeroOrMore> 135 </element> 136 <!-- ignore documentations --> 137 <element name="xs:documentation"> 138 <p:ignore><ref name="anyAttributes"/></p:ignore> 139 <zeroOrMore> 140 <choice> 141 <group> 142 msg = <text /> 143 bi.appendDocumentation($runtime.truncateDocComment(msg),true); 144 </group> 145 <group> 146 <element> 147 <anyName /> 148 w = new StringWriter(); 149 DataWriter xw = new DataWriter(w,"UTF-8"); 150 xw.setXmlDecl(false); 151 $runtime.redirectSubtree(xw,$uri,$localName,$qname); 152 <empty/> 153 <p:ignore><ref name="anyContents"/></p:ignore> 154 </element> 155 <![CDATA[ 156 bi.appendDocumentation("<pre>"+ 157 $runtime.escapeMarkup($runtime.truncateDocComment(w.toString()))+ 158 "</pre>", 159 false ); 160 w=null; 161 ]]> 162 </group> 163 </choice> 164 </zeroOrMore> 165 </element> 166 </choice> 167 </zeroOrMore> 168 </element> 169 </define> 170 171 172 173 <!-- 174 175 Individual customization declarations 176 177 --> 178 179 <define name="declaration" 180 cc:return-type="BIDeclaration" cc:return-value="result"> 181 182 <cc:java-body> 183 private BIDeclaration result; 184 </cc:java-body> 185 <!-- result field will have the parsed object --> 186 <choice> 187 result = <ref name="globalBindings" /> 188 result = <ref name="schemaBindings" /> 189 result = <ref name="class"/> 190 result = <ref name="conversion"/> 191 result = <ref name="property"/> 192 result = <ref name="typesafeEnum"/> 193 result = <ref name="enumMember"/> 194 <!-- result = <ref name="idSymbolSpace"/--> 195 <!-- result = <ref name="dom"/--> 196 </choice> 197 </define> 198 199 200 <define name="globalBindings" 201 cc:return-type="BIGlobalBinding" cc:return-value="makeResult()"> 202 203 <cc:java-body> 204 private Locator loc; 205 private Map globalConvs = new HashMap(); 206 private NameConverter nameConverter = NameConverter.standard; 207 private String enableJavaNamingConvention = "true"; 208 private String fixedAttrToConstantProperty = "false"; 209 private String needIsSetMethod = "false"; 210 private String simpleTypeSubstitution = "false"; 211 private boolean flattenClasses = false; 212 private Set enumBaseTypes = new HashSet(); 213 private int defaultEnumSizeCap = 256; 214 private boolean generateEnumMemberName = false; 215 private boolean choiceContentPropertyWithModelGroupBinding = false; 216 private boolean xSmartWildcardDefaultBinding = false; 217 private boolean xSimpleMode; 218 private boolean generateValueClass = true; 219 private boolean generateElementClass = false; 220 private boolean generateMixedExtensions = false; 221 222 public BIGlobalBinding makeResult() { 223 if( enumBaseTypes.size()==0 ) 224 enumBaseTypes.add(new QName(WellKnownNamespace.XML_SCHEMA,"NCName")); // defaults to NCName 225 226 return new BIGlobalBinding( 227 globalConvs,nameConverter, 228 choiceContentPropertyWithModelGroupBinding, 229 generateValueClass, 230 generateElementClass, 231 $runtime.parseBoolean(enableJavaNamingConvention), 232 $runtime.parseBoolean(fixedAttrToConstantProperty), 233 $runtime.parseBoolean(needIsSetMethod), 234 $runtime.parseBoolean(simpleTypeSubstitution), 235 generateEnumMemberName, 236 flattenClasses, 237 enumBaseTypes, 238 defaultEnumSizeCap, 239 ct, 240 serializable, 241 xSuperClass, 242 xSuperInterface, 243 xSimpleMode, 244 xSmartWildcardDefaultBinding, 245 loc); 246 } 247 </cc:java-body> 248 <element name="globalBindings"> 249 loc = $runtime.copyLocator(); 250 251 <optional> 252 <attribute name="underscoreBinding"> 253 <choice> 254 <value>asWordSeparator</value><!-- default --> 255 <group> 256 <value>asCharInWord</value> 257 nameConverter = NameConverter.jaxrpcCompatible; 258 </group> 259 </choice> 260 </attribute> 261 </optional> 262 263 <optional> 264 <attribute name="enableJavaNamingConventions"> 265 enableJavaNamingConvention = <data type="boolean"/> 266 </attribute> 267 </optional> 268 269 <optional> 270 <attribute name="fixedAttributeAsConstantProperty"> 271 fixedAttrToConstantProperty = <data type="boolean"/> 272 </attribute> 273 </optional> 274 275 <optional> 276 <attribute name="generateIsSetMethod"> 277 needIsSetMethod = <data type="boolean"/> 278 </attribute> 279 </optional> 280 281 <optional> 282 <attribute name="mapSimpleTypeDef"> 283 simpleTypeSubstitution = <data type="boolean"/> 284 </attribute> 285 </optional> 286 287 <optional> 288 <attribute name="localScoping"> 289 <choice> 290 <group> 291 <value>nested</value> 292 flattenClasses = false; 293 </group> 294 <group> 295 <value>toplevel</value> 296 flattenClasses = true; 297 </group> 298 </choice> 299 </attribute> 300 </optional> 301 302 <optional> 303 <attribute name="collectionType"> 304 ct = <ref name="collectionType" /> 305 </attribute> 306 </optional> 307 308 <optional> 309 <attribute name="typesafeEnumMemberName"> 310 <choice> 311 <value>generateError</value> <!-- default --> 312 <group> 313 <value>generateName</value> 314 generateEnumMemberName = true; 315 </group> 316 </choice> 317 </attribute> 318 </optional> 319 320 <optional> 321 <attribute name="typesafeEnumBase"> 322 <list> 323 <oneOrMore> 324 value = <data type="QName"/> 325 QName qn = $runtime.parseQName(value); 326 enumBaseTypes.add( qn ); 327 </oneOrMore> 328 </list> 329 </attribute> 330 </optional> 331 332 <optional> 333 <attribute name="typesafeEnumMaxMembers"> 334 <list> 335 <oneOrMore> 336 value = <data type="int"/> 337 defaultEnumSizeCap = Integer.parseInt(value); 338 </oneOrMore> 339 </list> 340 </attribute> 341 </optional> 342 343 344 <optional> 345 <attribute name="choiceContentProperty"> 346 value = <data type="boolean"/> 347 choiceContentPropertyWithModelGroupBinding = $runtime.parseBoolean(value); 348 </attribute> 349 </optional> 350 351 <optional> 352 <attribute name="generateValueClass"> 353 value = <data type="boolean"/> 354 generateValueClass = $runtime.parseBoolean(value); 355 </attribute> 356 </optional> 357 358 <optional> 359 <attribute name="generateElementClass"> 360 value = <data type="boolean"/> 361 generateElementClass = $runtime.parseBoolean(value); 362 </attribute> 363 </optional> 364 365 <optional> 366 <attribute name="generateMixedExtensions"> 367 value = <data type="boolean"/> 368 generateMixedExtensions = $runtime.parseBoolean(value); 369 </attribute> 370 </optional> 371 372 <!-- unimplemented attributes --> 373 <optional> 374 <attribute name="enableValidation"> 375 value = <data type="boolean"/> 376 if( $runtime.parseBoolean(value)==true ) 377 $runtime.reportUnsupportedFeature("enableValidation"); 378 </attribute> 379 </optional> 380 <optional> 381 <attribute name="enableFailFastCheck"> 382 value = <data type="boolean"/> 383 if( $runtime.parseBoolean(value)==true ) 384 $runtime.reportUnsupportedFeature("enableFailFastCheck"); 385 </attribute> 386 </optional> 387 388 <!-- body --> 389 <zeroOrMore> 390 <choice> 391 <element name="javaType"> 392 <attribute name="xmlType"> 393 xmlType = <data type="QName"/> 394 </attribute> 395 conv = <ref name="conversionBody" /> 396 397 globalConvs.put( $runtime.parseQName(xmlType), conv ); 398 </element> 399 <element name="serializable"> 400 <optional> 401 <attribute name="uid"> 402 serialuid = <data type="long"/> 403 </attribute> 404 </optional> 405 if(serialuid!=null) 406 serializable = new BISerializable(Long.parseLong(serialuid)); 407 else 408 serializable = new BISerializable(null); 409 </element> 410 411 <!-- global vendor extensions --> 412 serializable = <ref name="serializable"/> 413 xSuperClass = <ref name="superClass"/> 414 xSuperInterface = <ref name="superInterface"/> 415 <ref name="typeSubstitution" /> 416 <element name="xjc:smartWildcardDefaultBinding"> 417 <!-- 418 changes the default binding of wildcards so that unknown elements will be 419 bound to DOM. This feature is not publicly available, and we may change it 420 later. 421 --> 422 xSmartWildcardDefaultBinding = true; 423 <empty /> 424 </element> 425 426 <element name="xjc:simple"> 427 xSimpleMode = true; 428 <empty /> 429 </element> 430 431 <!-- 432 light-weight runtime. we no longer support them, 433 but we don't issue an error when we see them. 434 --> 435 <element name="xjc:noMarshaller"> 436 <empty /> 437 </element> 438 <element name="xjc:noUnmarshaller"> 439 <empty /> 440 </element> 441 <element name="xjc:noValidator"> 442 <empty /> 443 </element> 444 <element name="xjc:noValidatingUnmarshaller"> 445 <empty /> 446 </element> 447 </choice> 448 </zeroOrMore> 449 </element> 450 </define> 451 452 453 <define name="schemaBindings" 454 cc:return-type="BISchemaBinding" cc:return-value="makeResult()"> 455 456 <cc:java-body> 457 private Locator loc; 458 public BISchemaBinding makeResult() { 459 return new BISchemaBinding(packageName,javadoc,tt,et,at,mt,nt,loc); 460 } 461 </cc:java-body> 462 463 <element name="schemaBindings"> 464 loc = $runtime.copyLocator(); 465 466 <optional> 467 <element name="package"> 468 <optional> 469 packageName = <attribute name="name"/> 470 </optional> 471 <optional> 472 javadoc = <ref name="javadoc"/> 473 </optional> 474 </element> 475 </optional> 476 477 <optional> 478 <element name="nameXmlTransform"> 479 <!-- use newer version of RELAXNGCC and wrap them by <interleave> --> 480 <zeroOrMore> 481 <choice> 482 <element name="typeName"> 483 tt = <ref name="nameXmlTransformRule"/> 484 </element> 485 <element name="elementName"> 486 et = <ref name="nameXmlTransformRule"/> 487 </element> 488 <element name="attributeName"> 489 at = <ref name="nameXmlTransformRule"/> 490 </element> 491 <element name="modelGroupName"> 492 mt = <ref name="nameXmlTransformRule"/> 493 </element> 494 <element name="anonymousTypeName"> 495 nt = <ref name="nameXmlTransformRule"/> 496 </element> 497 </choice> 498 </zeroOrMore> 499 </element> 500 </optional> 501 </element> 502 </define> 503 504 <define name="nameXmlTransformRule" 505 cc:return-type="BISchemaBinding.NamingRule" 506 cc:return-value="new BISchemaBinding.NamingRule(prefix,suffix)"> 507 508 <cc:java-body> 509 private String prefix=""; 510 private String suffix=""; 511 </cc:java-body> 512 513 514 <optional> 515 <attribute name="prefix"> 516 prefix = <data type="NCName"/> 517 </attribute> 518 </optional> 519 <optional> 520 <attribute name="suffix"> 521 suffix = <data type="NCName"/> 522 </attribute> 523 </optional> 524 </define> 525 526 527 528 <define name="javadoc" cc:return-type="String" cc:return-value="javadoc"> 529 <element name="javadoc"> 530 javadoc = <text /> 531 javadoc = $runtime.truncateDocComment(javadoc); 532 </element> 533 </define> 534 535 <define name="collectionType" cc:class="CollectionTypeState" 536 cc:return-type="FieldRenderer" cc:return-value="r"> 537 <cc:java-body> 538 private FieldRenderer r = null; 539 </cc:java-body> 540 type = <data type="token"/> 541 542 if( type.equals("indexed") ) 543 r = FieldRenderer.ARRAY; 544 else 545 try { 546 r = new UntypedListFieldRenderer( $runtime.codeModel.ref(type) ); 547 } catch( ClassNotFoundException e ) { 548 throw new NoClassDefFoundError(e.getMessage()); 549 } 550 </define> 551 552 553 554 <define name="class" cc:class="BIClassState" 555 cc:return-type="BIClass" cc:return-value="makeResult()"> 556 557 <cc:java-body> 558 private Locator loc; 559 public BIClass makeResult() { 560 return new BIClass(loc,name,implClass,javadoc); 561 } 562 </cc:java-body> 563 564 <element name="class"> 565 loc = $runtime.copyLocator(); 566 <optional> 567 javadoc = <ref name="javadoc"/> 568 </optional> 569 <optional> 570 <attribute name="name"> 571 name = <data type="identifier" datatypeLibrary="http://java.sun.com/xml/ns/relaxng/java-datatypes"/> 572 </attribute> 573 </optional> 574 <optional> 575 implClass = <attribute name="implClass"/> 576 </optional> 577 </element> 578 </define> 579 580 <define name="property" 581 cc:return-type="BIProperty" cc:return-value="makeResult()"> 582 583 <cc:java-body> 584 private Locator loc; 585 private Boolean isConst = null; 586 private Boolean isSet = null; 587 private Boolean genElemProp = null; 588 589 public BIProperty makeResult() throws SAXException { 590 JType baseTypeRef = null; 591 if(baseType!=null) 592 baseTypeRef = $runtime.getType(baseType); 593 594 return new BIProperty(loc,name,javadoc,baseTypeRef,conv,ct,isConst,isSet,genElemProp); 595 } 596 </cc:java-body> 597 598 <element name="property"> 599 loc = $runtime.copyLocator(); 600 <optional> 601 name = <attribute name="name"/> 602 </optional> 603 <optional> 604 baseType = <attribute name="baseType"/> 605 </optional> 606 <optional> 607 <attribute name="collectionType"> 608 ct = <ref name="collectionType" /> 609 </attribute> 610 </optional> 611 <optional> 612 <attribute name="fixedAttributeAsConstantProperty"> 613 isConstStr = <data type="boolean"/> 614 isConst = $runtime.parseBoolean(isConstStr)?Boolean.TRUE:Boolean.FALSE; 615 </attribute> 616 </optional> 617 <optional> 618 <attribute name="generateIsSetMethod"> 619 isSetStr = <data type="boolean"/> 620 isSet = $runtime.parseBoolean(isSetStr)?Boolean.TRUE:Boolean.FALSE; 621 </attribute> 622 </optional> 623 <optional> 624 <attribute name="generateElementProperty"> 625 genElemPropStr = <data type="boolean"/> 626 genElemProp = $runtime.parseBoolean(genElemPropStr)?Boolean.TRUE:Boolean.FALSE; 627 </attribute> 628 </optional> 629 <optional> 630 <attribute name="generateFailFastSetterMethod"> 631 failFast = <data type="boolean"/> 632 </attribute> 633 if( $runtime.parseBoolean(failFast) ) { 634 $runtime.reportUnimplementedFeature("generateFailFastSetterMethod"); 635 } 636 </optional> 637 638 639 <interleave> 640 <optional> 641 javadoc = <ref name="javadoc"/> 642 </optional> 643 <optional> 644 <element name="baseType"> 645 conv = <ref name="conversion"/> 646 </element> 647 </optional> 648 </interleave> 649 </element> 650 </define> 651 652 <define name="conversion" 653 cc:return-type="BIConversion" cc:return-value="r"> 654 <element name="javaType"> 655 r = <ref name="conversionBody"/> 656 </element> 657 </define> 658 659 660 <define name="conversionBody" 661 cc:return-type="BIConversion" cc:return-value="makeResult()"> 662 663 <cc:java-import> 664 import com.sun.tools.internal.xjc.generator.util.WhitespaceNormalizer; 665 </cc:java-import> 666 <cc:java-body><![CDATA[ 667 public BIConversion makeResult() throws SAXException { 668 return new BIConversion.User( $runtime.copyLocator(), parse, print, $runtime.getType(type) ); 669 } 670 671 // initialize with default values. 672 private String type = "java.lang.String"; // in case a schema has an error 673 private String parse = null; 674 private String print = null; 675 private boolean context = false; 676 ]]></cc:java-body> 677 678 679 <optional> 680 parse = <attribute name="parseMethod" /> 681 </optional> 682 <optional> 683 print = <attribute name="printMethod" /> 684 </optional> 685 <attribute name="name" cc:alias="type"/> 686 <optional> 687 <attribute name="hasNsContext"> 688 _context = <data type="boolean"/> 689 context = $runtime.parseBoolean(_context); 690 </attribute> 691 </optional> 692 </define> 693 694 695 <!-- type safe enum customization --> 696 <define name="typesafeEnum" 697 cc:return-type="BIEnum" cc:return-value="makeResult()"> 698 699 <cc:java-import> 700 import java.util.HashMap; 701 </cc:java-import> 702 <cc:java-body> 703 private HashMap members = new HashMap(); 704 private boolean dontBind = false; 705 private Locator loc,loc2; 706 707 private BIEnum makeResult() { 708 return new BIEnum(loc,dontBind,name,javadoc,members); 709 } 710 </cc:java-body> 711 712 <element name="typesafeEnumClass"> 713 loc = $runtime.copyLocator(); 714 <choice> 715 <attribute name="map"> 716 <value>false</value> 717 dontBind = true; 718 </attribute> 719 <group> 720 <optional> 721 name = <attribute name="name"/> 722 </optional> 723 <optional> 724 javadoc = <ref name="javadoc" /> 725 </optional> 726 <zeroOrMore> 727 jname = null; 728 javadoc = null; 729 <element name="typesafeEnumMember"> 730 loc2 = $runtime.copyLocator(); 731 <optional> 732 jname = <attribute name="name"/> 733 </optional> 734 value = <attribute name="value"/> 735 <optional> 736 javadoc = <ref name="javadoc" /> 737 </optional> 738 members.put( value, new BIEnumMember(loc2,jname,javadoc) ); 739 </element> 740 </zeroOrMore> 741 </group> 742 </choice> 743 </element> 744 </define> 745 746 747 <!-- stand-alone type safe enum member customization --> 748 <!-- 749 Note that only the name attribute is allowed here, and the same element 750 under the typesafeEnumClass is handled differently. 751 --> 752 <define name="enumMember" 753 cc:return-type="BIEnumMember" cc:return-value="makeResult()"> 754 <cc:java-body> 755 private Locator loc; 756 private BIEnumMember makeResult() { 757 return new BIEnumMember(loc,name,javadoc); 758 } 759 </cc:java-body> 760 761 <element name="typesafeEnumMember"> 762 loc = $runtime.copyLocator(); 763 name = <attribute name="name"/> 764 <optional> 765 javadoc = <ref name="javadoc" /> 766 </optional> 767 </element> 768 </define> 769 770 771 <!-- XJC-exntension: root class support --> 772 <define name="superClass" cc:return-type="JDefinedClass" cc:return-value="makeResult()"> 773 <cc:java-body> 774 private JDefinedClass makeResult() { 775 try { 776 JDefinedClass c = $runtime.codeModel._class(name); 777 c.hide(); 778 return c; 779 } catch( JClassAlreadyExistsException e ) { 780 return e.getExistingClass(); 781 } 782 } 783 </cc:java-body> 784 785 <element name="xjc:superClass"> 786 name = <attribute name="name" /> 787 </element> 788 </define> 789 790 <!-- XJC-exntension: root interface support --> 791 <define name="superInterface" cc:return-type="JDefinedClass" cc:return-value="makeResult()"> 792 <cc:java-body> 793 private JDefinedClass makeResult() { 794 try { 795 JDefinedClass c = $runtime.codeModel._class(name,ClassType.INTERFACE); 796 c.hide(); 797 return c; 798 } catch( JClassAlreadyExistsException e ) { 799 return e.getExistingClass(); 800 } 801 } 802 </cc:java-body> 803 804 <element name="xjc:superInterface"> 805 name = <attribute name="name" /> 806 </element> 807 </define> 808 809 <!-- XJC-exntension: serialization support --> 810 <define name="serializable" cc:return-type="BISerializable" cc:return-value="makeResult()"> 811 <cc:java-body> 812 private long uid = 1; 813 private BISerializable makeResult() { 814 return new BISerializable(uid); 815 } 816 </cc:java-body> 817 818 <element name="xjc:serializable"> 819 // loc = $runtime.copyLocator(); 820 <optional> 821 <attribute name="uid"> 822 v = <data type="long"/> 823 uid = Long.parseLong(v); 824 </attribute> 825 </optional> 826 </element> 827 </define> 828 829 830 <!-- XJC extension: type substitution --> 831 <define name="typeSubstitution" cc:return-type="boolean" cc:return-value="true"> 832 <element name="xjc:typeSubstitution"> 833 <attribute name="type"><value>complex</value></attribute> 834 </element> 835 </define> 836 837 838 <!-- XJC extension: ID symbol space support --> 839 <!--define name="idSymbolSpace" cc:return-type="BIXIdSymbolSpace" cc:return-value="makeResult()"> 840 <cc:java-body> 841 private Locator loc; 842 private BIXIdSymbolSpace makeResult() { 843 return new BIXIdSymbolSpace(loc,name); 844 } 845 </cc:java-body> 846 847 <element name="xjc:idSymbolSpace"> 848 loc = $runtime.copyLocator(); 849 name = <attribute name="name"/> 850 </element> 851 </define--> 852 853 854 <!-- XJC extension: DOM support --> 855 <!--define name="dom" cc:return-type="BIXDom" cc:return-value="makeResult()"> 856 <cc:java-import> 857 import com.sun.tools.internal.xjc.grammar.ext.*; 858 </cc:java-import> 859 <cc:java-body> 860 private String factoryName = "w3c"; 861 private Locator loc; 862 private BIXDom makeResult() { 863 try { 864 return new BIXDom(DOMItemFactory.getInstance(factoryName),loc); 865 } catch( DOMItemFactory.UndefinedNameException e ) { 866 throw new InternalError(); // impossible since we use validation to reject incorrect values 867 } 868 } 869 </cc:java-body> 870 871 <element name="xjc:dom"> 872 loc = $runtime.copyLocator(); 873 <optional> 874 <attribute name="type"> 875 <choice> 876 factoryName = <value>dom4j</value> 877 factoryName = <value>w3c</value> 878 </choice> 879 </attribute> 880 </optional> 881 </element> 882 </define--> 883 884 885 886 887 888 889 <p:ignore> 890 <!-- these patterns are ignored when using RelaxNGCC --> 891 <define name="anyContents"> 892 <zeroOrMore> 893 <choice> 894 <text/> 895 <ref name="anyAttributes"/> 896 <element> 897 <anyName/> 898 <ref name="anyContents"/> 899 </element> 900 </choice> 901 </zeroOrMore> 902 </define> 903 904 <define name="anyAttributes"> 905 <zeroOrMore> 906 <attribute> 907 <anyName/> 908 <text/> 909 </attribute> 910 </zeroOrMore> 911 </define> 912 </p:ignore> 913 </grammar>