< prev index next >

src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/reader/xmlschema/parser/CustomizationContextChecker.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  28 import java.util.HashSet;
  29 import java.util.Set;
  30 import java.util.Stack;
  31 
  32 import javax.xml.namespace.QName;
  33 
  34 import com.sun.tools.internal.xjc.reader.Const;
  35 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
  36 
  37 import org.xml.sax.Attributes;
  38 import org.xml.sax.ErrorHandler;
  39 import org.xml.sax.Locator;
  40 import org.xml.sax.SAXException;
  41 import org.xml.sax.SAXParseException;
  42 import org.xml.sax.helpers.XMLFilterImpl;
  43 
  44 /**
  45  * Checks if binding declarations are placed where they are allowed.
  46  *
  47  * <p>
  48  * For example, if a &lt;jaxb:property> customization is given under
  49  * the &lt;xs:simpleContent> element, this class raises an error.
  50  *
  51  * <p>
  52  * our main checkpoint of misplaced customizations are in BGMBuilder.
  53  * There, we mark a customization whenever we use it. At the end of the
  54  * day, we look for unmarked customizations and raise errors for them.
  55  *
  56  * <p>
  57  * Between this approach and the JAXB spec 1.0 is a problem that
  58  * the spec allows/prohibits customizations at schema element level,
  59  * while BGMBuilder and XSOM works on schema component levels.
  60  *
  61  * <p>
  62  * For example, a property customization is allowed on a complex type
  63  * schema component, but it's only allowed on the &lt;complexType>
  64  * element. The spec team informed us that they would consider resolving
  65  * this discrepancy in favor of RI, but meanwhile we need to detect
  66  * errors correctly.
  67  *
  68  * <p>
  69  * This filter is implemented for this purpose.
  70  *
  71  *
  72  * <h2>Customization and allowed locations</h2>
  73  *
  74  * - globalBinding/schemaBinding
  75  *     schema
  76  *
  77  * - class
  78  *     complexType(*), modelGroupDecl, modelGroup, element
  79  *
  80  * - property
  81  *     attribute, element, any, modelGroup, modelGroupRef, complexType(*)
  82  *
  83  * - javaType
  84  *     simpleType(*)
  85  *
  86  * - typesafeEnumClass
  87  *     simpleType(*)
  88  *
  89  * - typesafeEnumMember
  90  *     simpleType(*), enumeration
  91  *
  92  * Components marked with '*' needs a check by this component
  93  * since more than one schema element corresponds to one schema component
  94  * of that type.
  95  *
  96  * <p>
  97  * For simple types, customizations are allowed only under the &lt;xs:simpleType>
  98  * element, and for complex types they are allowed only under the
  99  * &lt;xs:cimplexType> element.
 100  *
 101  * <p>
 102  * So the bottom line is that it would be suffice if we just make sure
 103  * that no customization will be attached under other elements of
 104  * simple types and complex types. Those are:
 105  *
 106  * - simpleType/restriction
 107  * - list
 108  * - union
 109  * - complexType/(simple or complex)Content
 110  * - complexType/(simple or complex)Content/(restriction of extension)
 111  *
 112  * @author
 113  *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
 114  */
 115 public class CustomizationContextChecker extends XMLFilterImpl {
 116 
 117     /** Keep names of all the ancestor elements. */
 118     private final Stack<QName> elementNames = new Stack<QName>();
 119 


   1 /*
   2  * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  28 import java.util.HashSet;
  29 import java.util.Set;
  30 import java.util.Stack;
  31 
  32 import javax.xml.namespace.QName;
  33 
  34 import com.sun.tools.internal.xjc.reader.Const;
  35 import com.sun.xml.internal.bind.v2.WellKnownNamespace;
  36 
  37 import org.xml.sax.Attributes;
  38 import org.xml.sax.ErrorHandler;
  39 import org.xml.sax.Locator;
  40 import org.xml.sax.SAXException;
  41 import org.xml.sax.SAXParseException;
  42 import org.xml.sax.helpers.XMLFilterImpl;
  43 
  44 /**
  45  * Checks if binding declarations are placed where they are allowed.
  46  *
  47  * <p>
  48  * For example, if a {@code <jaxb:property>} customization is given under
  49  * the {@code <xs:simpleContent>} element, this class raises an error.
  50  *
  51  * <p>
  52  * our main checkpoint of misplaced customizations are in BGMBuilder.
  53  * There, we mark a customization whenever we use it. At the end of the
  54  * day, we look for unmarked customizations and raise errors for them.
  55  *
  56  * <p>
  57  * Between this approach and the JAXB spec 1.0 is a problem that
  58  * the spec allows/prohibits customizations at schema element level,
  59  * while BGMBuilder and XSOM works on schema component levels.
  60  *
  61  * <p>
  62  * For example, a property customization is allowed on a complex type
  63  * schema component, but it's only allowed on the {@code <complexType>}
  64  * element. The spec team informed us that they would consider resolving
  65  * this discrepancy in favor of RI, but meanwhile we need to detect
  66  * errors correctly.
  67  *
  68  * <p>
  69  * This filter is implemented for this purpose.
  70  *
  71  *
  72  * <h2>Customization and allowed locations</h2>
  73  *
  74  * - globalBinding/schemaBinding
  75  *     schema
  76  *
  77  * - class
  78  *     complexType(*), modelGroupDecl, modelGroup, element
  79  *
  80  * - property
  81  *     attribute, element, any, modelGroup, modelGroupRef, complexType(*)
  82  *
  83  * - javaType
  84  *     simpleType(*)
  85  *
  86  * - typesafeEnumClass
  87  *     simpleType(*)
  88  *
  89  * - typesafeEnumMember
  90  *     simpleType(*), enumeration
  91  *
  92  * Components marked with '*' needs a check by this component
  93  * since more than one schema element corresponds to one schema component
  94  * of that type.
  95  *
  96  * <p>
  97  * For simple types, customizations are allowed only under the {@code <xs:simpleType>}
  98  * element, and for complex types they are allowed only under the
  99  * {@code <xs:cimplexType>} element.
 100  *
 101  * <p>
 102  * So the bottom line is that it would be suffice if we just make sure
 103  * that no customization will be attached under other elements of
 104  * simple types and complex types. Those are:
 105  *
 106  * - simpleType/restriction
 107  * - list
 108  * - union
 109  * - complexType/(simple or complex)Content
 110  * - complexType/(simple or complex)Content/(restriction of extension)
 111  *
 112  * @author
 113  *     Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
 114  */
 115 public class CustomizationContextChecker extends XMLFilterImpl {
 116 
 117     /** Keep names of all the ancestor elements. */
 118     private final Stack<QName> elementNames = new Stack<QName>();
 119 


< prev index next >