325N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 325N/A * This code is free software; you can redistribute it and/or modify it 325N/A * under the terms of the GNU General Public License version 2 only, as 325N/A * published by the Free Software Foundation. Oracle designates this 325N/A * particular file as subject to the "Classpath" exception as provided 325N/A * by Oracle in the LICENSE file that accompanied this code. 325N/A * This code is distributed in the hope that it will be useful, but WITHOUT 325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 325N/A * version 2 for more details (a copy is included in the LICENSE file that 325N/A * accompanied this code). 325N/A * You should have received a copy of the GNU General Public License version 325N/A * 2 along with this work; if not, write to the Free Software Foundation, 325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 325N/A * or visit www.oracle.com if you need additional information or have any 325N/A * Builds {@link TypeUse} from simple types. 325N/A * This code consists of two main portions. The {@link #compose(XSSimpleType)} method 325N/A * and {@link #composer} forms an outer cycle, which gradually ascends the type 325N/A * inheritance chain until it finds the suitable binding. When it does this 325N/A * {@link #initiatingType} is set to the type which started binding, so that we can refer 325N/A * to the actual constraint facets and such that are applicable on the type. 325N/A * For each intermediate type in the chain, the {@link #find(XSSimpleType)} method 325N/A * is used to find the binding on that type, sine the outer loop is doing the ascending, 325N/A * this method only sees if the current type has some binding available. 325N/A * There is at least one ugly code that you need to aware of 325N/A * when you are modifying the code. See the documentation 325N/A * "simple type customization at the point of reference."</a> 325N/A * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) 325N/A * The component that is refering to the simple type 325N/A * which we are building. This is ugly but necessary 325N/A * to support the customization of simple types at 325N/A * its point of reference. See my comment at the header 325N/A * of this class for details. 325N/A * UGLY: Implemented as a Stack of XSComponent to fix a bug 325N/A * Records what xmime:expectedContentTypes annotations we honored and processed, 325N/A * so that we can later check if the user had these annotations in the places 325N/A * where we didn't anticipate them. 325N/A * The type that was originally passed to this {@link SimpleTypeBuilder#build(XSSimpleType)}. 325N/A /** {@link TypeUse}s for the built-in types. Read-only. */ 325N/A * Entry point from outside. Builds a BGM type expression 325N/A * from a simple type schema component. 325N/A * the simple type to be bound. 325N/A * A version of the {@link #build(XSSimpleType)} method 325N/A * used to bind the definition of a class generated from 325N/A * the given simple type. 325N/A * Returns a javaType customization specified to the referer, if present. 325N/A * Checks if the referer has a conversion customization or not. 325N/A * If it does, use it to bind this simple type. Otherwise 325N/A // assertion check. referer must be set properly 325N/A // before the build method is called. 325N/A // since the handling of the simple type point-of-reference 325N/A // customization is very error prone, it deserves a strict 325N/A // if the parent is element type, its content type must be us. 325N/A // for elements, you can't use <property>, 325N/A // so we allow javaType to appear directly. 325N/A // the conversion is given. 325N/A // this means the simple type is built by itself and 325N/A // not because it's referenced by something. 325N/A // unexpected referer type. 325N/A // now we are certain that the referer is OK. 325N/A // see if it has a conversion customization. 325N/A // the conversion is given. 325N/A * Detect "javaType" customizations placed directly on simple types, rather 325N/A * than being enclosed by "property" and "baseType" customizations (see 325N/A * sec 6.8.1 of the spec). 325N/A * Report an error if any exist. 325N/A // ack this conversion to prevent further error messages 325N/A * Recursively decend the type inheritance chain to find a binding. 325N/A // bind item type individually and then compose them into a list 325N/A // facets on the list shouldn't be taken account when binding item types, 325N/A // so weed to call build(), not compose(). 325N/A // just process the base type. 325N/A * Checks if there's any binding available on the given type. 325N/A * null if not (which causes the {@link #compose(XSSimpleType)} method 325N/A // check for user specified conversion 325N/A // a conversion was found 325N/A // look for enum customization, which is another user specified conversion 325N/A // if an enum customization is specified, make sure 325N/A // recover by ignoring this customization 325N/A // recover by ignoring @ref 325N/A // list and union cannot be mapped to a type-safe enum, 325N/A // so in this stage we can safely cast it to XSRestrictionSimpleType 325N/A // if the type is built in, look for the default binding 325N/A // also check for swaRef 325N/A // see if this type should be mapped to a type-safe enumeration by default. 325N/A // if so, built a EnumXDucer from it and return it. 325N/A * Returns true if a type-safe enum should be created from 325N/A * the given simple type by default without an explicit <jaxb:enum> customization. 325N/A // if not, there will be a problem wrt the class name of this type safe enum type. 325N/A // if redefined, we should map the new definition, not the old one. 325N/A // if the type itself doesn't have the enumeration facet, 325N/A // it won't be mapped to a type-safe enum. 325N/A // if there are too many facets, it's not very useful 325N/A // produce warning when simple type is not mapped to enum 325N/A // we simply can't map this to an enumeration 325N/A // check for collisions among constant names. if a collision will happen, 325N/A // don't try to bind it to an enum. 325N/A // return true only when this type is derived from one of the "enum base type". 325N/A // see a bullet of 6.5.1 of the spec. 325N/A "string",
"boolean",
"float",
"decimal",
"double",
"anyURI" 325N/A * Returns true if the given simple type can be mapped to a 325N/A * type-safe enum class. 325N/A * JAXB spec places a restrictrion as to what type can be 325N/A * mapped to a type-safe enum. This method enforces this 325N/A // type must be derived from one of these types 325N/A return false;
// catch all case 325N/A * Builds a type-safe enum conversion from a simple type 325N/A * with enumeration facets. 325N/A * The class name of the type-safe enum. Or null to 325N/A * create a default name. 325N/A * Additional javadoc that will be added at the beginning of the 325N/A * class, or null if none is necessary. 325N/A * A map from enumeration values (as String) to BIEnumMember objects. 325N/A * if some of the value names need to be overrided. 325N/A * Cannot be null, but the map may not contain entries 325N/A * for all enumeration values. 325N/A * The source location where the above customizations are 325N/A * specified, or null if none is available. 325N/A if(
loc==
null )
// use the location of the simple type as the default 325N/A // infer the class name. For this to be possible, 325N/A // the simple type must be a global one. 325N/A // recover by returning a meaningless conversion 325N/A // we apply name conversion in any case 325N/A return null;
// can't bind a list to enum constant 325N/A return null;
// can't bind to an enum if the base is a class, since we don't have the value constrctor 325N/A // if the member names collide, re-generate numbered constant names. 325N/A // use the name of the simple type as the name of the class. 325N/A // attach this new conversion object to this simple type 325N/A // so that successive look up will use the same object. 325N/A * if constant names couldn't be generated, return a reference to that enum facet. 325N/A * null if unable to generate names for some of the constants. 325N/A continue;
// ignore the 2nd occasion 325N/A // generate names for all member names. 325N/A // this will even override names specified by the user. that's crazy. 325N/A // look at the one attached to the facet object 325N/A * Returns non-null if {@link CEnumConstant}s have name collisions among them. 325N/A * if there's a collision, return two {@link CEnumConstant}s that collided. 325N/A * otherwise return null. 325N/A attempt an optimization so that we can 325N/A improve the binding for types like this: 325N/A <restriciton baseType="integer"> 325N/A <maxInclusive value="100" /> 325N/A ... to int, not BigInteger. 325N/A // this is seen in the SOAP schema and too common to ignore 325N/A * Decides the way xs:base64Binary binds. 325N/A * This method checks the expected media type. 325N/A // see spec table I-1 in appendix I section 2.1.1 for bindings 325N/A // recover by using the default 325N/A * Returns true if the specified sub-type is an XML type. 325N/A * Returns true if the {@link #initiatingType} is restricted 325N/A * to '0' and '1'. This logic is not complete, but it at least 325N/A * finds the such definition in SOAP @mustUnderstand. 325N/A // list of datatypes which have built-in conversions. 325N/A // note that although xs:token and xs:normalizedString are not 325N/A // specified in the spec, they need to be here because they 325N/A // have different whitespace normalization semantics. 325N/A // TODO: this is so dumb 325N/A // we'll also look at the expected media type, so don't just add this to the map 325N/A // m.put("base64Binary", CBuiltinLeafInfo.BASE64_BYTE_ARRAY); 325N/A // TODO: handling dateTime, time, and date type 325N/A// "date", "dateTime", "time", "hexBinary" };