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.model;
27:
28: import javax.activation.MimeType;
29: import javax.xml.bind.annotation.adapters.XmlAdapter;
30:
31: import com.sun.xml.internal.bind.v2.TODO;
32: import com.sun.xml.internal.bind.v2.model.core.Adapter;
33: import com.sun.xml.internal.bind.v2.model.core.ID;
34:
35: /**
36: * Factory methods to create a new {@link TypeUse} from an existing one.
37: *
38: * @author Kohsuke Kawaguchi
39: */
40: public final class TypeUseFactory {
41: private TypeUseFactory() {
42: }
43:
44: public static TypeUse makeID(TypeUse t, ID id) {
45: if (t.idUse() != ID.NONE)
46: // I don't think we let users tweak the idness, so
47: // this error must indicate an inconsistency within the RI/spec.
48: throw new IllegalStateException();
49: return new TypeUseImpl(t.getInfo(), t.isCollection(), id, t
50: .getExpectedMimeType(), t.getAdapterUse());
51: }
52:
53: public static TypeUse makeMimeTyped(TypeUse t, MimeType mt) {
54: if (t.getExpectedMimeType() != null)
55: // I don't think we let users tweak the idness, so
56: // this error must indicate an inconsistency within the RI/spec.
57: throw new IllegalStateException();
58: return new TypeUseImpl(t.getInfo(), t.isCollection(),
59: t.idUse(), mt, t.getAdapterUse());
60: }
61:
62: public static TypeUse makeCollection(TypeUse t) {
63: if (t.isCollection())
64: return t;
65: CAdapter au = t.getAdapterUse();
66: if (au != null && !au.isWhitespaceAdapter()) {
67: // we can't process this right now.
68: // for now bind to a weaker type
69: TODO.checkSpec();
70: return CBuiltinLeafInfo.STRING_LIST;
71: }
72: return new TypeUseImpl(t.getInfo(), true, t.idUse(), t
73: .getExpectedMimeType(), null);
74: }
75:
76: public static TypeUse adapt(TypeUse t, CAdapter adapter) {
77: assert t.getAdapterUse() == null; // TODO: we don't know how to handle double adapters yet.
78: return new TypeUseImpl(t.getInfo(), t.isCollection(),
79: t.idUse(), t.getExpectedMimeType(), adapter);
80: }
81:
82: /**
83: * Creates a new adapter {@link TypeUse} by using the existing {@link Adapter} class.
84: */
85: public static TypeUse adapt(TypeUse t,
86: Class<? extends XmlAdapter> adapter, boolean copy) {
87: return adapt(t, new CAdapter(adapter, copy));
88: }
89: }
|