001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package com.sun.tools.internal.xjc.model;
027:
028: import javax.activation.MimeType;
029:
030: import com.sun.codemodel.internal.JCodeModel;
031: import com.sun.codemodel.internal.JExpression;
032: import com.sun.tools.internal.xjc.model.nav.NType;
033: import com.sun.tools.internal.xjc.outline.Outline;
034: import com.sun.xml.internal.bind.v2.model.core.ID;
035: import com.sun.xml.internal.xsom.XmlString;
036:
037: /**
038: * Information about how another type is referenced.
039: *
040: * <p>
041: * In practice it is often easier to use {@link CTypeInfo}
042: * instead of {@link NType}, so this interface defines {@link #getInfo()}.
043: *
044: * @author Kohsuke Kawaguchi
045: * @see TypeUseImpl
046: */
047: public interface TypeUse {
048: /**
049: * If the use can hold multiple values of the specified type.
050: */
051: boolean isCollection();
052:
053: /**
054: * If this type use is adapting the type, returns the adapter.
055: * Otherwise return null.
056: */
057: CAdapter getAdapterUse();
058:
059: /**
060: * Individual item type.
061: */
062: CTypeInfo getInfo();
063:
064: /**
065: * Whether the referenced type (individual item type in case of collection)
066: * is ID/IDREF.
067: *
068: * <p>
069: * ID is a property of a relationship. When a bean Foo has an ID property
070: * called 'bar' whose type is String, Foo isn't an ID, String isn't an ID,
071: * but this relationship is an ID (in the sense that Foo uses this String
072: * as an ID.)
073: *
074: * <p>
075: * The same thing can be said with IDREF. When Foo refers to Bar by means of
076: * IDREF, neither Foo nor Bar is IDREF.
077: *
078: * <p>
079: * That's why we have this method in {@link TypeUse}.
080: */
081: ID idUse();
082:
083: /**
084: * A {@link TypeUse} can have an associated MIME type.
085: */
086: MimeType getExpectedMimeType();
087:
088: /**
089: * Creates a constant for the given lexical value.
090: *
091: * <p>
092: * For example, to create a constant 1 for <tt>xs:int</tt>, you'd do:
093: * <pre>
094: * CBuiltinLeafInfo.INT.createConstant( codeModel, "1", null );
095: * </pre>
096: *
097: * <p>
098: * This method is invoked at the backend as a part of the code generation process.
099: *
100: * @throws IllegalStateException
101: * if the type isn't bound to a text in XML.
102: *
103: * @return null
104: * if the constant cannot be created for this {@link TypeUse}
105: * (such as when it's a collection)
106: */
107: JExpression createConstant(Outline outline, XmlString lexical);
108: }
|