01: /*
02: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.tools.internal.xjc.generator.bean.field;
27:
28: import java.util.ArrayList;
29:
30: import com.sun.tools.internal.xjc.generator.bean.ClassOutlineImpl;
31: import com.sun.tools.internal.xjc.model.CPropertyInfo;
32: import com.sun.tools.internal.xjc.outline.FieldOutline;
33:
34: /**
35: * Default implementation of the FieldRendererFactory
36: * that faithfully implements the semantics demanded by the JAXB spec.
37: *
38: * <p>
39: * This class is just a facade --- it just determines which
40: * {@link FieldRenderer} to use and just delegate the work.
41: *
42: * @author
43: * Kohsuke Kawaguchi (kohsuke.kawaguchi@sun.com)
44: */
45: final class DefaultFieldRenderer implements FieldRenderer {
46:
47: private final FieldRendererFactory frf;
48:
49: /**
50: * Use {@link FieldRendererFactory#getDefault()}.
51: */
52: DefaultFieldRenderer(FieldRendererFactory frf) {
53: this .frf = frf;
54: }
55:
56: public DefaultFieldRenderer(FieldRendererFactory frf,
57: FieldRenderer defaultCollectionFieldRenderer) {
58: this .frf = frf;
59: this .defaultCollectionFieldRenderer = defaultCollectionFieldRenderer;
60: }
61:
62: private FieldRenderer defaultCollectionFieldRenderer;
63:
64: public FieldOutline generate(ClassOutlineImpl outline,
65: CPropertyInfo prop) {
66: return decideRenderer(outline, prop).generate(outline, prop);
67: }
68:
69: private FieldRenderer decideRenderer(ClassOutlineImpl outline,
70: CPropertyInfo prop) {
71: if (!prop.isCollection()) {
72: // non-collection field
73:
74: // TODO: check for bidning info for optionalPrimitiveType=boxed or
75: // noHasMethod=false and noDeletedMethod=false
76: if (prop.isUnboxable())
77: // this one uses a primitive type as much as possible
78: return frf.getRequiredUnboxed();
79: else
80: // otherwise use the default non-collection field
81: return frf.getSingle();
82: }
83:
84: if (defaultCollectionFieldRenderer == null) {
85: return frf.getList(outline.parent().getCodeModel().ref(
86: ArrayList.class));
87: }
88:
89: // this field is a collection field.
90: // use untyped list as the default. This is consistent
91: // to the JAXB spec.
92: return defaultCollectionFieldRenderer;
93: }
94: }
|