|
1 /* |
|
2 * Copyright (c) 1997, 2011, 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 */ |
|
29 package com.sun.tools.internal.xjc.outline; |
|
30 |
|
31 import java.util.List; |
|
32 |
|
33 import com.sun.codemodel.internal.JClass; |
|
34 import com.sun.codemodel.internal.JDefinedClass; |
|
35 import com.sun.tools.internal.xjc.model.CClassInfo; |
|
36 import com.sun.tools.internal.xjc.model.CPropertyInfo; |
|
37 import com.sun.istack.internal.NotNull; |
|
38 |
|
39 /** |
|
40 * Outline object that provides per-{@link CClassInfo} information |
|
41 * for filling in methods/fields for a bean. |
|
42 * |
|
43 * This interface is accessible from {@link Outline} |
|
44 * |
|
45 * @author Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com) |
|
46 */ |
|
47 public abstract class ClassOutline { |
|
48 |
|
49 /** |
|
50 * A {@link Outline} that encloses all the class outlines. |
|
51 */ |
|
52 public abstract @NotNull Outline parent(); |
|
53 |
|
54 /** |
|
55 * {@link PackageOutline} that contains this class. |
|
56 */ |
|
57 public @NotNull PackageOutline _package() { |
|
58 return parent().getPackageContext(ref._package()); |
|
59 } |
|
60 |
|
61 /** |
|
62 * This {@link ClassOutline} holds information about this {@link CClassInfo}. |
|
63 */ |
|
64 public final @NotNull CClassInfo target; |
|
65 |
|
66 /** |
|
67 * The exposed aspect of the a bean. |
|
68 * |
|
69 * implClass is always assignable to this type. |
|
70 * <p> |
|
71 * Usually this is the public content interface, but |
|
72 * it could be the same as the implClass. |
|
73 */ |
|
74 public final @NotNull JDefinedClass ref; |
|
75 |
|
76 /** |
|
77 * The implementation aspect of a bean. |
|
78 * The actual place where fields/methods should be generated into. |
|
79 */ |
|
80 public final @NotNull JDefinedClass implClass; |
|
81 |
|
82 /** |
|
83 * The implementation class that shall be used for reference. |
|
84 * <p> |
|
85 * Usually this field holds the same value as the {@link #implClass} method, |
|
86 * but sometimes it holds the user-specified implementation class |
|
87 * when it is specified. |
|
88 * <p> |
|
89 * This is the type that needs to be used for generating fields. |
|
90 */ |
|
91 public final @NotNull JClass implRef; |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 protected ClassOutline( CClassInfo _target, JDefinedClass exposedClass, JClass implRef, JDefinedClass _implClass) { |
|
97 this.target = _target; |
|
98 this.ref = exposedClass; |
|
99 this.implRef = implRef; |
|
100 this.implClass = _implClass; |
|
101 } |
|
102 |
|
103 /** |
|
104 * Gets all the {@link FieldOutline}s newly declared |
|
105 * in this class. |
|
106 */ |
|
107 public final FieldOutline[] getDeclaredFields() { |
|
108 List<CPropertyInfo> props = target.getProperties(); |
|
109 FieldOutline[] fr = new FieldOutline[props.size()]; |
|
110 for( int i=0; i<fr.length; i++ ) |
|
111 fr[i] = parent().getField(props.get(i)); |
|
112 return fr; |
|
113 } |
|
114 |
|
115 /** |
|
116 * Returns the super class of this class, if it has the |
|
117 * super class and it is also a JAXB-bound class. |
|
118 * Otherwise null. |
|
119 */ |
|
120 public final ClassOutline getSuperClass() { |
|
121 CClassInfo s = target.getBaseClass(); |
|
122 if(s==null) return null; |
|
123 return parent().getClazz(s); |
|
124 } |
|
125 } |