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: /*
027: * Use is subject to the license terms.
028: */
029: package com.sun.tools.internal.xjc.outline;
030:
031: import java.util.List;
032:
033: import com.sun.codemodel.internal.JClass;
034: import com.sun.codemodel.internal.JDefinedClass;
035: import com.sun.tools.internal.xjc.model.CClassInfo;
036: import com.sun.tools.internal.xjc.model.CPropertyInfo;
037:
038: /**
039: * Outline object that provides per-{@link CClassInfo} information
040: * for filling in methods/fields for a bean.
041: *
042: * This interface is accessible from {@link Outline}
043: *
044: * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
045: */
046: public abstract class ClassOutline {
047:
048: /**
049: * A {@link Outline} that encloses all the class outlines.
050: */
051: public abstract Outline parent();
052:
053: /**
054: * {@link PackageOutline} that contains this class.
055: */
056: public PackageOutline _package() {
057: return parent().getPackageContext(ref._package());
058: }
059:
060: /**
061: * This {@link ClassOutline} holds information about this {@link CClassInfo}.
062: */
063: public final CClassInfo target;
064:
065: /**
066: * The exposed aspect of the a bean.
067: *
068: * implClass is always assignable to this type.
069: * <p>
070: * Usually this is the public content interface, but
071: * it could be the same as the implClass.
072: */
073: public final JDefinedClass ref;
074:
075: /**
076: * The implementation aspect of a bean.
077: * The actual place where fields/methods should be generated into.
078: */
079: public final JDefinedClass implClass;
080:
081: /**
082: * The implementation class that shall be used for reference.
083: * <p>
084: * Usually this field holds the same value as the impl method,
085: * but sometimes it holds the user-specified implementation class
086: * when it is specified.
087: * <p>
088: * This is the type that needs to be used for generating fields.
089: */
090: public final JClass implRef;
091:
092: protected ClassOutline(CClassInfo _target,
093: JDefinedClass exposedClass, JClass implRef,
094: JDefinedClass _implClass) {
095: this .target = _target;
096: this .ref = exposedClass;
097: this .implRef = implRef;
098: this .implClass = _implClass;
099: }
100:
101: /**
102: * Gets all the {@link FieldOutline}s newly declared
103: * in this class.
104: */
105: public final FieldOutline[] getDeclaredFields() {
106: List<CPropertyInfo> props = target.getProperties();
107: FieldOutline[] fr = new FieldOutline[props.size()];
108: for (int i = 0; i < fr.length; i++)
109: fr[i] = parent().getField(props.get(i));
110: return fr;
111: }
112:
113: /**
114: * Returns the super class of this class, if it has the
115: * super class and it is also a JAXB-bound class.
116: * Otherwise null.
117: */
118: public final ClassOutline getSuperClass() {
119: CClassInfo s = target.getBaseClass();
120: if (s == null)
121: return null;
122: return parent().getClazz(s);
123: }
124: }
|