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.xml.internal.bind.v2.schemagen;
27:
28: import java.io.IOException;
29: import java.util.logging.Logger;
30:
31: import javax.xml.bind.SchemaOutputResolver;
32: import javax.xml.transform.Result;
33:
34: import com.sun.xml.internal.bind.Util;
35:
36: /**
37: * {@link SchemaOutputResolver} that wraps the user-specified resolver
38: * and makes sure that it's following the contract.
39: *
40: * <p>
41: * This protects the rest of the {@link XmlSchemaGenerator} from client programming
42: * error.
43: */
44: final class FoolProofResolver extends SchemaOutputResolver {
45: private static final Logger logger = Util.getClassLogger();
46: private final SchemaOutputResolver resolver;
47:
48: public FoolProofResolver(SchemaOutputResolver resolver) {
49: assert resolver != null;
50: this .resolver = resolver;
51: }
52:
53: public Result createOutput(String namespaceUri,
54: String suggestedFileName) throws IOException {
55: logger.entering(getClass().getName(), "createOutput",
56: new Object[] { namespaceUri, suggestedFileName });
57: Result r = resolver.createOutput(namespaceUri,
58: suggestedFileName);
59: if (r != null) {
60: String sysId = r.getSystemId();
61: logger.finer("system ID = " + sysId);
62: if (sysId != null) {
63: // TODO: make sure that the system Id is absolute
64:
65: // don't use java.net.URI, because it doesn't allow some characters (like SP)
66: // which can legally used as file names.
67:
68: // but don't use java.net.URL either, because it doesn't allow a made-up URI
69: // like kohsuke://foo/bar/zot
70: } else
71: throw new AssertionError("system ID cannot be null");
72: }
73: logger.exiting(getClass().getName(), "createOutput", r);
74: return r;
75: }
76: }
|