/*******************************************************************************
 * Copyright (c) 1998, 2007 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0, which accompanies this distribution
 * and is available at http://www.eclipse.org/legal/epl-v10.html.
 *
 * Contributors:
 *     Oracle - initial API and implementation from Oracle TopLink
 ******************************************************************************/
package org.eclipse.persistence.testing.sdo.helper.xsdhelper.define;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.util.HashMap;
import java.util.List;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import junit.textui.TestRunner;
import org.eclipse.persistence.sdo.helper.SDOXSDHelper;
import org.eclipse.persistence.sdo.helper.SchemaResolver;
import org.eclipse.persistence.testing.sdo.helper.xsdhelper.XSDHelperTestCases;
import org.xml.sax.InputSource;

public class ComplexImportsAndIncludesTestCases extends XSDHelperTestCases {
    public ComplexImportsAndIncludesTestCases(String name) {
        super(name);
    }

    public static void main(String[] args) {
        TestRunner.run(ComplexImportsAndIncludesTestCases.class);
    }

    public String getSchemaToDefine() {
        return "org/eclipse/persistence/testing/sdo/helper/xsdhelper/define/complexincludesandimports/xsdfile6.txt";
    }

    public void testDefineTest() throws Exception {
        InputStream is = new FileInputStream(getSchemaToDefine());
        StreamSource ss = new StreamSource(is);
        ss.setSystemId("includeDeptAndEmp.xsd");
        List types = ((SDOXSDHelper) xsdHelper).define(ss, new TestSchemaResolver());

        log("\nActual:\n");
        log(types);
        assertEquals(15, types.size());
    }

    public static class TestSchemaResolver implements SchemaResolver {
        private java.util.Map fileIndex = new HashMap();

        public TestSchemaResolver() throws IOException {
            FileInputStream indexFIS = new FileInputStream("org/eclipse/persistence/testing/sdo/helper/xsdhelper/define/complexincludesandimports/index.txt");

            java.util.Properties fileProps = new java.util.Properties();
            fileProps.load(indexFIS);

            java.util.Enumeration keyEnum = fileProps.keys();
            while (keyEnum.hasMoreElements()) {
                String s = (String) keyEnum.nextElement();
                fileIndex.put(fileProps.get(s), s);
            }
        }

        public Source resolveSchema(Source sourceXSD, String namespace, String schemaLocation) {
            if (schemaLocation == null) {
                return null;
            }

            try {
                URI destURI = new URI(schemaLocation);

                if (!destURI.isAbsolute()) {
                    if ((sourceXSD.getSystemId() == null) || "".equals(sourceXSD.getSystemId())) {
                        throw new IllegalArgumentException("Cannot find source URI to resolve a relative schemaLocation: " + schemaLocation);
                    } else {
                        URI sourceURI = new URI((sourceXSD.getSystemId()));
                        destURI = sourceURI.resolve(destURI);
                    }
                }

                String destSysId = destURI.toString();

                String s = (String) this.fileIndex.get(destSysId);
                if (s == null) {
                    throw new IllegalArgumentException("cannot find " + destSysId);
                }
                InputStream iStream = new FileInputStream("org/eclipse/persistence/testing/sdo/helper/xsdhelper/define/complexincludesandimports/" + s + ".txt");

                StreamSource sSrc = new StreamSource(iStream);
                sSrc.setSystemId(destSysId);
                return sSrc;

            } catch (Exception e) {
                return null;
            }
        }

        /**
         * Satisfy EntityResolver interface implementation.
         * Allow resolution of external entities.
         * 
         * @param publicId
         * @param systemId
         * @return null
         */
        public InputSource resolveEntity(String publicId, String systemId) {
            return null;
        }
    }
}
@@ -104,9 +104,9 @@
  200
-7
+8
  Ora
@@ -206,16 +206,17 @@
 nder the
+ 
 %0A * term
@@ -251,17 +251,60 @@
 nse v1.0
-,
+ and Eclipse Distribution License v. 1.0 %0A *
  which a
@@ -335,15 +335,40 @@
 tion
+. 
 %0A * 
-and
+The Eclipse Public License
  is 
@@ -425,96 +425,200 @@
 html
-.%0A *%0A * Contributors:%0A *     Oracle - initial API and implementation from Oracle TopLink
+%0A * and the Eclipse Distribution License is available at %0A * http://www.eclipse.org/org/documents/edl-v10.php.%0A *%0A * Contributors:%0A *     Denise Smith - Feb 20 2008 Initial test case creation 
 %0A **
@@ -694,16 +694,18 @@
 *******/
+ %0A
 %0Apackage

Update EPL header