ClassOutline.java revision 582:f31835b59035
1/* 2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26/* 27 * Use is subject to the license terms. 28 */ 29package com.sun.tools.internal.xjc.outline; 30 31import java.util.List; 32 33import com.sun.codemodel.internal.JClass; 34import com.sun.codemodel.internal.JDefinedClass; 35import com.sun.tools.internal.xjc.model.CClassInfo; 36import com.sun.tools.internal.xjc.model.CCustomizable; 37import com.sun.tools.internal.xjc.model.CPropertyInfo; 38import com.sun.istack.internal.NotNull; 39 40/** 41 * Outline object that provides per-{@link CClassInfo} information 42 * for filling in methods/fields for a bean. 43 * 44 * This interface is accessible from {@link Outline} 45 * 46 * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) 47 */ 48public abstract class ClassOutline implements CustomizableOutline { 49 50 /** 51 * A {@link Outline} that encloses all the class outlines. 52 */ 53 public abstract @NotNull Outline parent(); 54 55 /** 56 * {@link PackageOutline} that contains this class. 57 */ 58 public @NotNull PackageOutline _package() { 59 return parent().getPackageContext(ref._package()); 60 } 61 62 /** 63 * This {@link ClassOutline} holds information about this {@link CClassInfo}. 64 */ 65 public final @NotNull CClassInfo target; 66 67 /** 68 * The exposed aspect of the a bean. 69 * 70 * implClass is always assignable to this type. 71 * <p> 72 * Usually this is the public content interface, but 73 * it could be the same as the implClass. 74 */ 75 public final @NotNull JDefinedClass ref; 76 77 /** 78 * The implementation aspect of a bean. 79 * The actual place where fields/methods should be generated into. 80 */ 81 public final @NotNull JDefinedClass implClass; 82 83 /** 84 * The implementation class that shall be used for reference. 85 * <p> 86 * Usually this field holds the same value as the {@link #implClass} method, 87 * but sometimes it holds the user-specified implementation class 88 * when it is specified. 89 * <p> 90 * This is the type that needs to be used for generating fields. 91 */ 92 public final @NotNull JClass implRef; 93 94 95 96 97 protected ClassOutline( CClassInfo _target, JDefinedClass exposedClass, JClass implRef, JDefinedClass _implClass) { 98 this.target = _target; 99 this.ref = exposedClass; 100 this.implRef = implRef; 101 this.implClass = _implClass; 102 } 103 104 /** 105 * Gets all the {@link FieldOutline}s newly declared 106 * in this class. 107 */ 108 public final FieldOutline[] getDeclaredFields() { 109 List<CPropertyInfo> props = target.getProperties(); 110 FieldOutline[] fr = new FieldOutline[props.size()]; 111 for( int i=0; i<fr.length; i++ ) 112 fr[i] = parent().getField(props.get(i)); 113 return fr; 114 } 115 116 /** 117 * Returns the super class of this class, if it has the 118 * super class and it is also a JAXB-bound class. 119 * Otherwise null. 120 */ 121 public final ClassOutline getSuperClass() { 122 CClassInfo s = target.getBaseClass(); 123 if(s==null) return null; 124 return parent().getClazz(s); 125 } 126 127 @Override 128 public JDefinedClass getImplClass() { 129 return implClass; 130 } 131 132 @Override 133 public CCustomizable getTarget() { 134 return target; 135 } 136} 137