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 com.sun.tools.internal.xjc.Options;
29: import com.sun.codemodel.internal.JClass;
30:
31: /**
32: * Factory for {@link FieldRenderer}.
33: *
34: * <p>
35: * This class can be overridden by a plugin to change the code generation
36: * behavior of XJC. Note that such changes aren't composable; for a given
37: * schema compilation, only one instance of {@link FieldRendererFactory} is
38: * used.
39: *
40: * <p>
41: * See {@link Options#fieldRendererFactory}
42: *
43: * <p>
44: * To be more precise, since {@link FieldRenderer} is just a strategy pattern
45: * and by itself is stateless, the "factory methods" don't necessarily need
46: * to create new instances of {@link FieldRenderer} --- it can just return
47: * a set of pre-created instances.
48: *
49: * @author Kohsuke Kawaguchi
50: */
51: public class FieldRendererFactory {
52:
53: public FieldRenderer getDefault() {
54: return DEFAULT;
55: }
56:
57: public FieldRenderer getArray() {
58: return ARRAY;
59: }
60:
61: public FieldRenderer getRequiredUnboxed() {
62: return REQUIRED_UNBOXED;
63: }
64:
65: public FieldRenderer getSingle() {
66: return SINGLE;
67: }
68:
69: public FieldRenderer getSinglePrimitiveAccess() {
70: return SINGLE_PRIMITIVE_ACCESS;
71: }
72:
73: public FieldRenderer getList(JClass coreList) {
74: return new UntypedListFieldRenderer(coreList);
75: }
76:
77: public FieldRenderer getConst(FieldRenderer fallback) {
78: return new ConstFieldRenderer(fallback);
79: }
80:
81: private final FieldRenderer DEFAULT = new DefaultFieldRenderer(this );
82:
83: private static final FieldRenderer ARRAY = new GenericFieldRenderer(
84: ArrayField.class);
85:
86: private static final FieldRenderer REQUIRED_UNBOXED = new GenericFieldRenderer(
87: UnboxedField.class);
88:
89: private static final FieldRenderer SINGLE = new GenericFieldRenderer(
90: SingleField.class);
91:
92: private static final FieldRenderer SINGLE_PRIMITIVE_ACCESS = new GenericFieldRenderer(
93: SinglePrimitiveAccessField.class);
94: }
|