001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: /*
038: * Use is subject to the license terms.
039: */
040: package com.sun.tools.xjc.outline;
041:
042: import java.util.List;
043:
044: import com.sun.codemodel.JClass;
045: import com.sun.codemodel.JDefinedClass;
046: import com.sun.tools.xjc.model.CClassInfo;
047: import com.sun.tools.xjc.model.CPropertyInfo;
048: import com.sun.istack.NotNull;
049:
050: /**
051: * Outline object that provides per-{@link CClassInfo} information
052: * for filling in methods/fields for a bean.
053: *
054: * This interface is accessible from {@link Outline}
055: *
056: * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
057: */
058: public abstract class ClassOutline {
059:
060: /**
061: * A {@link Outline} that encloses all the class outlines.
062: */
063: public abstract @NotNull
064: Outline parent();
065:
066: /**
067: * {@link PackageOutline} that contains this class.
068: */
069: public @NotNull
070: PackageOutline _package() {
071: return parent().getPackageContext(ref._package());
072: }
073:
074: /**
075: * This {@link ClassOutline} holds information about this {@link CClassInfo}.
076: */
077: public final @NotNull
078: CClassInfo target;
079:
080: /**
081: * The exposed aspect of the a bean.
082: *
083: * implClass is always assignable to this type.
084: * <p>
085: * Usually this is the public content interface, but
086: * it could be the same as the implClass.
087: */
088: public final @NotNull
089: JDefinedClass ref;
090:
091: /**
092: * The implementation aspect of a bean.
093: * The actual place where fields/methods should be generated into.
094: */
095: public final @NotNull
096: JDefinedClass implClass;
097:
098: /**
099: * The implementation class that shall be used for reference.
100: * <p>
101: * Usually this field holds the same value as the {@link #implClass} method,
102: * but sometimes it holds the user-specified implementation class
103: * when it is specified.
104: * <p>
105: * This is the type that needs to be used for generating fields.
106: */
107: public final @NotNull
108: JClass implRef;
109:
110: protected ClassOutline(CClassInfo _target,
111: JDefinedClass exposedClass, JClass implRef,
112: JDefinedClass _implClass) {
113: this .target = _target;
114: this .ref = exposedClass;
115: this .implRef = implRef;
116: this .implClass = _implClass;
117: }
118:
119: /**
120: * Gets all the {@link FieldOutline}s newly declared
121: * in this class.
122: */
123: public final FieldOutline[] getDeclaredFields() {
124: List<CPropertyInfo> props = target.getProperties();
125: FieldOutline[] fr = new FieldOutline[props.size()];
126: for (int i = 0; i < fr.length; i++)
127: fr[i] = parent().getField(props.get(i));
128: return fr;
129: }
130:
131: /**
132: * Returns the super class of this class, if it has the
133: * super class and it is also a JAXB-bound class.
134: * Otherwise null.
135: */
136: public final ClassOutline getSuperClass() {
137: CClassInfo s = target.getBaseClass();
138: if (s == null)
139: return null;
140: return parent().getClazz(s);
141: }
142: }
|