src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/xmlschema/BindPurple.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 1921
7166269ef0f1
parent 0
373ffda63c9a
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset fdbe50121f48

     1 /*
     2  * Copyright (c) 1997, 2011, 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
    23  * questions.
    24  */
    26 package com.sun.tools.internal.xjc.reader.xmlschema;
    28 import com.sun.tools.internal.xjc.model.CClassInfo;
    29 import com.sun.tools.internal.xjc.model.CDefaultValue;
    30 import com.sun.tools.internal.xjc.model.CPropertyInfo;
    31 import com.sun.tools.internal.xjc.model.TypeUse;
    32 import com.sun.tools.internal.xjc.model.CClass;
    33 import com.sun.tools.internal.xjc.reader.Ring;
    34 import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIProperty;
    35 import com.sun.xml.internal.xsom.XSAttGroupDecl;
    36 import com.sun.xml.internal.xsom.XSAttributeDecl;
    37 import com.sun.xml.internal.xsom.XSAttributeUse;
    38 import com.sun.xml.internal.xsom.XSComplexType;
    39 import com.sun.xml.internal.xsom.XSContentType;
    40 import com.sun.xml.internal.xsom.XSElementDecl;
    41 import com.sun.xml.internal.xsom.XSModelGroup;
    42 import com.sun.xml.internal.xsom.XSModelGroupDecl;
    43 import com.sun.xml.internal.xsom.XSParticle;
    44 import com.sun.xml.internal.xsom.XSSimpleType;
    45 import com.sun.xml.internal.xsom.XSWildcard;
    47 /**
    48  * @author Kohsuke Kawaguchi
    49  */
    50 public class BindPurple extends ColorBinder {
    51     public void attGroupDecl(XSAttGroupDecl xsAttGroupDecl) {
    52         // TODO
    53         throw new UnsupportedOperationException();
    54     }
    56     public void attributeDecl(XSAttributeDecl xsAttributeDecl) {
    57         // TODO
    58         throw new UnsupportedOperationException();
    59     }
    61     /**
    62      * Attribute use always becomes a property.
    63      */
    64     public void attributeUse(XSAttributeUse use) {
    65         boolean hasFixedValue = use.getFixedValue()!=null;
    66         BIProperty pc = BIProperty.getCustomization(use);
    68         // map to a constant property ?
    69         boolean toConstant = pc.isConstantProperty() && hasFixedValue;
    70         TypeUse attType = bindAttDecl(use.getDecl());
    72         CPropertyInfo prop = pc.createAttributeProperty( use, attType );
    74         if(toConstant) {
    75             prop.defaultValue = CDefaultValue.create(attType,use.getFixedValue());
    76             prop.realization = builder.fieldRendererFactory.getConst(prop.realization);
    77         } else
    78         if(!attType.isCollection() && (prop.baseType == null ? true : !prop.baseType.isPrimitive())) {
    79             // don't support a collection default value. That's difficult to do.
    80             // primitive types default value is problematic too - we can't check whether it has been set or no ( ==null) isn't possible TODO: emit a waring in these cases
    82             if(use.getDefaultValue()!=null) {
    83                 // this attribute use has a default value.
    84                 // the item type is guaranteed to be a leaf type... or TODO: is it really so?
    85                 // don't support default values if it's a list
    86                 prop.defaultValue = CDefaultValue.create(attType,use.getDefaultValue());
    87             } else
    88             if(use.getFixedValue()!=null) {
    89                 prop.defaultValue = CDefaultValue.create(attType,use.getFixedValue());
    90             }
    91         } else if(prop.baseType != null && prop.baseType.isPrimitive()) {
    92             ErrorReporter errorReporter = Ring.get(ErrorReporter.class);
    94             errorReporter.warning(prop.getLocator(), Messages.WARN_DEFAULT_VALUE_PRIMITIVE_TYPE, prop.baseType.name());
    95         }
    97         getCurrentBean().addProperty(prop);
    98     }
   100     private TypeUse bindAttDecl(XSAttributeDecl decl) {
   101         SimpleTypeBuilder stb = Ring.get(SimpleTypeBuilder.class);
   102         stb.refererStack.push( decl );
   103         try {
   104             return stb.build(decl.getType());
   105         } finally {
   106             stb.refererStack.pop();
   107         }
   108     }
   111     public void complexType(XSComplexType ct) {
   112         CClass ctBean = selector.bindToType(ct,null,false);
   113         if(getCurrentBean()!=ctBean)
   114             // in some case complex type and element binds to the same class
   115             // don't make it has-a. Just make it is-a.
   116             getCurrentBean().setBaseClass(ctBean);
   117     }
   119     public void wildcard(XSWildcard xsWildcard) {
   120         // element wildcards are processed by particle binders,
   121         // so this one is for attribute wildcard.
   123         getCurrentBean().hasAttributeWildcard(true);
   124     }
   126     public void modelGroupDecl(XSModelGroupDecl xsModelGroupDecl) {
   127         // TODO
   128         throw new UnsupportedOperationException();
   129     }
   131     public void modelGroup(XSModelGroup xsModelGroup) {
   132         // TODO
   133         throw new UnsupportedOperationException();
   134     }
   136     public void elementDecl(XSElementDecl xsElementDecl) {
   137         // TODO
   138         throw new UnsupportedOperationException();
   139     }
   141     public void simpleType(XSSimpleType type) {
   142         createSimpleTypeProperty(type,"Value");
   143     }
   145     public void particle(XSParticle xsParticle) {
   146         // TODO
   147         throw new UnsupportedOperationException();
   148     }
   150     public void empty(XSContentType ct) {
   151         // empty generates nothing
   152     }
   153 }

mercurial