aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. Oracle designates this aoqi@0: * particular file as subject to the "Classpath" exception as provided aoqi@0: * by Oracle in the LICENSE file that accompanied this code. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: package com.sun.tools.internal.xjc.reader.xmlschema.ct; aoqi@0: aoqi@0: aoqi@0: import com.sun.tools.internal.xjc.model.CClass; aoqi@0: import com.sun.xml.internal.xsom.XSComplexType; aoqi@0: import com.sun.xml.internal.xsom.XSContentType; aoqi@0: import com.sun.xml.internal.xsom.XSType; aoqi@0: aoqi@0: aoqi@0: /** aoqi@0: * Binds a complex type derived from another complex type by extension. aoqi@0: * aoqi@0: * @author aoqi@0: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) aoqi@0: */ aoqi@0: final class ExtendedComplexTypeBuilder extends AbstractExtendedComplexTypeBuilder { aoqi@0: aoqi@0: public boolean isApplicable(XSComplexType ct) { aoqi@0: XSType baseType = ct.getBaseType(); aoqi@0: return baseType!=schemas.getAnyType() aoqi@0: && baseType.isComplexType() aoqi@0: && ct.getDerivationMethod()==XSType.EXTENSION; aoqi@0: } aoqi@0: aoqi@0: public void build(XSComplexType ct) { aoqi@0: XSComplexType baseType = ct.getBaseType().asComplexType(); aoqi@0: aoqi@0: // build the base class aoqi@0: CClass baseClass = selector.bindToType(baseType, ct, true); aoqi@0: assert baseClass != null; // global complex type must map to a class aoqi@0: aoqi@0: selector.getCurrentBean().setBaseClass(baseClass); aoqi@0: aoqi@0: // derivation by extension. aoqi@0: ComplexTypeBindingMode baseTypeFlag = builder.getBindingMode(baseType); aoqi@0: aoqi@0: XSContentType explicitContent = ct.getExplicitContent(); aoqi@0: aoqi@0: if (!checkIfExtensionSafe(baseType, ct)) { aoqi@0: // error. We can't handle any further extension aoqi@0: errorReceiver.error(ct.getLocator(), aoqi@0: Messages.ERR_NO_FURTHER_EXTENSION.format( aoqi@0: baseType.getName(), ct.getName() ) aoqi@0: ); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // explicit content is always either empty or a particle. aoqi@0: if (explicitContent != null && explicitContent.asParticle() != null) { aoqi@0: if (baseTypeFlag == ComplexTypeBindingMode.NORMAL) { aoqi@0: // if we have additional explicit content, process them. aoqi@0: builder.recordBindingMode(ct, aoqi@0: bgmBuilder.getParticleBinder().checkFallback(explicitContent.asParticle()) aoqi@0: ? ComplexTypeBindingMode.FALLBACK_REST aoqi@0: : ComplexTypeBindingMode.NORMAL); aoqi@0: aoqi@0: bgmBuilder.getParticleBinder().build(explicitContent.asParticle()); aoqi@0: aoqi@0: } else { aoqi@0: // the base class has already done the fallback. aoqi@0: // don't add anything new aoqi@0: builder.recordBindingMode(ct, baseTypeFlag ); aoqi@0: } aoqi@0: } else { aoqi@0: // if it's empty, no additional processing is necessary aoqi@0: builder.recordBindingMode(ct, baseTypeFlag); aoqi@0: } aoqi@0: aoqi@0: // adds attributes and we are through. aoqi@0: green.attContainer(ct); aoqi@0: } aoqi@0: aoqi@0: }