0N/A/*
239N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
157N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
157N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
157N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
157N/A * or visit www.oracle.com if you need additional information or have any
157N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.tools.internal.xjc.model;
0N/A
0N/Aimport java.util.Collection;
0N/Aimport java.util.HashSet;
0N/Aimport java.util.Set;
0N/Aimport java.util.Map;
0N/A
0N/Aimport javax.activation.MimeType;
0N/Aimport javax.xml.bind.annotation.W3CDomHandler;
0N/Aimport javax.xml.namespace.QName;
0N/A
0N/Aimport com.sun.tools.internal.xjc.model.nav.NClass;
0N/Aimport com.sun.tools.internal.xjc.model.nav.NType;
0N/Aimport com.sun.tools.internal.xjc.model.nav.NavigatorImpl;
0N/Aimport com.sun.xml.internal.bind.v2.model.core.ID;
0N/Aimport com.sun.xml.internal.bind.v2.model.core.PropertyKind;
0N/Aimport com.sun.xml.internal.bind.v2.model.core.ReferencePropertyInfo;
0N/Aimport com.sun.xml.internal.bind.v2.model.core.WildcardMode;
0N/Aimport com.sun.xml.internal.xsom.XSComponent;
0N/A
0N/Aimport org.xml.sax.Locator;
0N/A
0N/A/**
0N/A * {@link ReferencePropertyInfo} for the compiler.
0N/A *
0N/A * @author Kohsuke Kawaguchi
0N/A */
0N/Apublic final class CReferencePropertyInfo extends CPropertyInfo implements ReferencePropertyInfo<NType,NClass> {
0N/A
0N/A /**
0N/A * True if this property can never be absent legally.
0N/A */
0N/A private final boolean required;
0N/A
0N/A /**
0N/A * List of referenced elements.
0N/A */
0N/A private final Set<CElement> elements = new HashSet<CElement>();
0N/A
0N/A private final boolean isMixed;
0N/A private WildcardMode wildcard;
0N/A private boolean dummy;
0N/A private boolean content;
0N/A private boolean isMixedExtendedCust = false;
0N/A
0N/A public CReferencePropertyInfo(String name, boolean collection, boolean required, boolean isMixed, XSComponent source,
0N/A CCustomizations customizations, Locator locator, boolean dummy, boolean content, boolean isMixedExtended) { // 'dummy' and 'content' here for NHIN fix - a hack in order to be able to handle extended mixed types better
0N/A super(name, (collection||isMixed) && (!dummy), source, customizations, locator);
0N/A this.isMixed = isMixed;
0N/A this.required = required;
0N/A this.dummy = dummy;
0N/A this.content = content;
0N/A this.isMixedExtendedCust = isMixedExtended;
0N/A }
0N/A
0N/A public Set<? extends CTypeInfo> ref() {
0N/A// if(wildcard==null && !isMixed())
0N/A// return getElements();
0N/A
0N/A // ugly hack to get the signature right for substitution groups
0N/A // when a class is generated for elements,they don't form a nice type hierarchy,
0N/A // so the Java types of the substitution members need to be taken into account
0N/A // when computing the signature
0N/A
0N/A final class RefList extends HashSet<CTypeInfo> {
0N/A RefList() {
0N/A super(elements.size());
0N/A addAll(elements);
0N/A }
0N/A @Override
0N/A public boolean addAll( Collection<? extends CTypeInfo> col ) {
0N/A boolean r = false;
0N/A for (CTypeInfo e : col) {
0N/A if(e instanceof CElementInfo) {
0N/A // UGLY. element substitution is implemented in a way that
0N/A // the derived elements are not assignable to base elements.
0N/A // so when we compute the signature, we have to take derived types
0N/A // into account
0N/A r |= addAll( ((CElementInfo)e).getSubstitutionMembers());
0N/A }
0N/A r |= add(e);
0N/A }
0N/A return r;
0N/A }
0N/A }
0N/A
0N/A RefList r = new RefList();
0N/A if(wildcard!=null) {
0N/A if(wildcard.allowDom)
0N/A r.add(CWildcardTypeInfo.INSTANCE);
0N/A if(wildcard.allowTypedObject)
0N/A // we aren't really adding an AnyType.
0N/A // this is a kind of hack to generate Object as a signature
0N/A r.add(CBuiltinLeafInfo.ANYTYPE);
0N/A }
0N/A if(isMixed())
0N/A r.add(CBuiltinLeafInfo.STRING);
0N/A
0N/A return r;
0N/A }
0N/A
0N/A public Set<CElement> getElements() {
0N/A return elements;
0N/A }
0N/A
0N/A public boolean isMixed() {
0N/A return isMixed;
0N/A }
0N/A
0N/A public boolean isDummy() {
0N/A return dummy;
0N/A }
0N/A
0N/A public boolean isContent() {
0N/A return content;
0N/A }
0N/A
0N/A public boolean isMixedExtendedCust() {
0N/A return isMixedExtendedCust;
0N/A }
0N/A
0N/A /**
0N/A * We'll never use a wrapper element in XJC. Always return null.
0N/A */
0N/A @Deprecated
0N/A public QName getXmlName() {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Reference properties refer to elements, and none of the Java primitive type
0N/A * maps to an element. Thus a reference property is always unboxable.
0N/A */
0N/A @Override
0N/A public boolean isUnboxable() {
0N/A return false;
0N/A }
0N/A
134N/A // the same as above
0N/A @Override
0N/A public boolean isOptionalPrimitive() {
0N/A return false;
0N/A }
0N/A
0N/A public <V> V accept(CPropertyVisitor<V> visitor) {
0N/A return visitor.onReference(this);
0N/A }
0N/A
0N/A public CAdapter getAdapter() {
0N/A return null;
0N/A }
0N/A
0N/A public final PropertyKind kind() {
0N/A return PropertyKind.REFERENCE;
0N/A }
0N/A
0N/A /**
0N/A * A reference property can never be ID/IDREF because they always point to
0N/A * other element classes.
0N/A */
0N/A public ID id() {
0N/A return ID.NONE;
0N/A }
0N/A
0N/A public WildcardMode getWildcard() {
0N/A return wildcard;
0N/A }
0N/A
0N/A public void setWildcard(WildcardMode mode) {
0N/A this.wildcard = mode;
0N/A }
0N/A
0N/A public NClass getDOMHandler() {
0N/A // TODO: support other DOM handlers
0N/A if(getWildcard()!=null)
0N/A return NavigatorImpl.create(W3CDomHandler.class);
0N/A else
0N/A return null;
0N/A }
0N/A
0N/A public MimeType getExpectedMimeType() {
0N/A return null;
0N/A }
0N/A
0N/A public boolean isCollectionNillable() {
0N/A // in XJC, we never recognize a nillable collection pattern, so this is always false.
0N/A return false;
0N/A }
0N/A
0N/A public boolean isCollectionRequired() {
0N/A // in XJC, we never recognize a nillable collection pattern, so this is always false.
0N/A return false;
0N/A }
0N/A
0N/A // reference property cannot have a type.
0N/A public QName getSchemaType() {
0N/A return null;
0N/A }
0N/A
0N/A public boolean isRequired() {
0N/A return required;
0N/A }
0N/A
0N/A @Override
0N/A public QName collectElementNames(Map<QName, CPropertyInfo> table) {
0N/A for (CElement e : elements) {
0N/A QName n = e.getElementName();
0N/A if(table.containsKey(n))
0N/A return n;
0N/A table.put(n,this);
0N/A }
0N/A return null;
0N/A }
0N/A}
0N/A