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: import com.sun.tools.internal.xjc.model.CBuiltinLeafInfo; aoqi@0: import com.sun.tools.internal.xjc.model.CClass; aoqi@0: import com.sun.tools.internal.xjc.model.CPropertyInfo; aoqi@0: import com.sun.tools.internal.xjc.reader.RawTypeSet; aoqi@0: import com.sun.tools.internal.xjc.reader.xmlschema.RawTypeSetBuilder; aoqi@0: import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIProperty; aoqi@0: import static com.sun.tools.internal.xjc.reader.xmlschema.ct.ComplexTypeBindingMode.FALLBACK_CONTENT; 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: import java.util.List; aoqi@0: aoqi@0: /** aoqi@0: * @author Kohsuke Kawaguchi aoqi@0: */ aoqi@0: final class MixedComplexTypeBuilder extends CTBuilder { aoqi@0: aoqi@0: public boolean isApplicable(XSComplexType ct) { aoqi@0: XSType bt = ct.getBaseType(); aoqi@0: if(bt ==schemas.getAnyType() && ct.isMixed()) aoqi@0: return true; // fresh mixed complex type aoqi@0: aoqi@0: // there's no complex type in the inheritance tree yet aoqi@0: if (bt.isComplexType() && aoqi@0: !bt.asComplexType().isMixed() && aoqi@0: ct.isMixed() && aoqi@0: ct.getDerivationMethod() == XSType.EXTENSION) { aoqi@0: if (!bgmBuilder.isGenerateMixedExtensions() && (ct.getContentType().asParticle() == null)) { aoqi@0: return false; aoqi@0: } aoqi@0: return true; aoqi@0: } aoqi@0: aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: public void build(XSComplexType ct) { aoqi@0: XSContentType contentType = ct.getContentType(); aoqi@0: aoqi@0: boolean generateMixedExtensions = bgmBuilder.isGenerateMixedExtensions(); aoqi@0: if (generateMixedExtensions) { aoqi@0: if (!(ct.getBaseType() == schemas.getAnyType() && ct.isMixed())) { aoqi@0: XSComplexType baseType = ct.getBaseType().asComplexType(); aoqi@0: // build the base class aoqi@0: CClass baseClass = selector.bindToType(baseType, ct, true); aoqi@0: selector.getCurrentBean().setBaseClass(baseClass); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: builder.recordBindingMode(ct, FALLBACK_CONTENT); aoqi@0: BIProperty prop = BIProperty.getCustomization(ct); aoqi@0: aoqi@0: CPropertyInfo p; aoqi@0: aoqi@0: if (generateMixedExtensions) { aoqi@0: List cType = ct.getSubtypes(); aoqi@0: boolean isSubtyped = (cType != null) && (cType.size() > 0); aoqi@0: aoqi@0: if (contentType.asEmpty() != null) { aoqi@0: if (isSubtyped) { aoqi@0: p = prop.createContentExtendedMixedReferenceProperty("Content", ct, null); aoqi@0: } else { aoqi@0: p = prop.createValueProperty("Content",false,ct,CBuiltinLeafInfo.STRING,null); aoqi@0: } aoqi@0: } else if (contentType.asParticle() == null) { aoqi@0: p = prop.createContentExtendedMixedReferenceProperty("Content", ct, null); aoqi@0: } else { aoqi@0: RawTypeSet ts = RawTypeSetBuilder.build(contentType.asParticle(), false); aoqi@0: p = prop.createContentExtendedMixedReferenceProperty("Content", ct, ts); aoqi@0: } aoqi@0: aoqi@0: } else { aoqi@0: if(contentType.asEmpty()!=null) { aoqi@0: p = prop.createValueProperty("Content",false,ct,CBuiltinLeafInfo.STRING,null); aoqi@0: } else { aoqi@0: RawTypeSet ts = RawTypeSetBuilder.build(contentType.asParticle(),false); aoqi@0: p = prop.createReferenceProperty("Content", false, ct, ts, true, false, true, false); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: selector.getCurrentBean().addProperty(p); aoqi@0: aoqi@0: // adds attributes and we are through. aoqi@0: green.attContainer(ct); aoqi@0: } aoqi@0: aoqi@0: }