001: /*
002: * Copyright (c) 1998-2007 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Emil Ong
027: */
028:
029: package com.caucho.xml.schema;
030:
031: import java.io.*;
032: import java.net.*;
033: import java.util.*;
034: import static javax.xml.XMLConstants.*;
035: import javax.xml.bind.*;
036: import javax.xml.bind.annotation.*;
037: import javax.xml.stream.Location;
038:
039: import com.caucho.jaxb.annotation.XmlLocation;
040:
041: /**
042: * JAXB annotated Schema data structure.
043: */
044: @XmlAccessorType(XmlAccessType.FIELD)
045: @XmlRootElement(name="import",namespace=W3C_XML_SCHEMA_NS_URI)
046: public class Import {
047: /** the imported schema */
048: @XmlTransient
049: private Schema _schema;
050:
051: @XmlAttribute(name="namespace")
052: private String _namespace;
053:
054: @XmlAttribute(name="schemaLocation")
055: private String _schemaLocation;
056:
057: @XmlLocation
058: private Location _location;
059:
060: public String getNamespace() {
061: return _namespace;
062: }
063:
064: public String getSchemaLocation() {
065: return _schemaLocation;
066: }
067:
068: public void resolve(Unmarshaller u) throws JAXBException {
069: Object obj = null;
070:
071: try {
072: obj = u.unmarshal(new URL(getSchemaLocation()));
073: } catch (MalformedURLException e) {
074: }
075:
076: File file = new File(getSchemaLocation());
077:
078: if (!file.exists()) {
079: if (!file.getName().startsWith("/")) {
080: file = new File(_location.getSystemId());
081:
082: file = file.getParentFile();
083:
084: if (file == null)
085: throw new JAXBException("File not found: "
086: + getSchemaLocation());
087:
088: file = new File(file, getSchemaLocation());
089: }
090: }
091:
092: obj = u.unmarshal(file);
093:
094: if (obj instanceof Schema)
095: _schema = (Schema) obj;
096: }
097:
098: public Schema getSchema() {
099: return _schema;
100: }
101: }
|