Search in sources :

Example 1 with SDOClassLoader

use of org.eclipse.persistence.sdo.helper.SDOClassLoader in project eclipselink by eclipse-ee4j.

the class SDOType method getInstanceClass.

@Override
public Class<?> getInstanceClass() {
    if ((javaClass == null) && (javaClassName != null)) {
        try {
            SDOClassLoader loader = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getLoader();
            Class<?> clazz = loader.getParent().loadClass(javaClassName);
            if (isValidInstanceClass(clazz)) {
                javaClass = clazz;
            } else {
                javaClass = getClass();
            }
        } catch (ClassNotFoundException e) {
            javaClass = getClass();
        } catch (SecurityException e) {
            throw SDOException.classNotFound(e, getURI(), getName());
        }
    }
    if (javaClass == getClass()) {
        return null;
    }
    return javaClass;
}
Also used : SDOClassLoader(org.eclipse.persistence.sdo.helper.SDOClassLoader) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper)

Example 2 with SDOClassLoader

use of org.eclipse.persistence.sdo.helper.SDOClassLoader in project eclipselink by eclipse-ee4j.

the class SDOType method getImplClass.

/**
 * INTERNAL:
 */
public Class<?> getImplClass() {
    if ((javaImplClass == null) && (getImplClassName() != null)) {
        try {
            SDOClassLoader loader = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getLoader();
            javaImplClass = loader.loadClass(getImplClassName(), this);
            xmlDescriptor.setJavaClass(javaImplClass);
        } catch (ClassNotFoundException e) {
            throw SDOException.classNotFound(e, getURI(), getName());
        } catch (SecurityException e) {
            throw SDOException.classNotFound(e, getURI(), getName());
        }
    }
    return javaImplClass;
}
Also used : SDOClassLoader(org.eclipse.persistence.sdo.helper.SDOClassLoader) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper)

Example 3 with SDOClassLoader

use of org.eclipse.persistence.sdo.helper.SDOClassLoader in project eclipselink by eclipse-ee4j.

the class SDOXMLHelperDelegate method reset.

@Override
public void reset() {
    setTopLinkProject(null);
    setXmlContext(null);
    this.xmlMarshallerMap.clear();
    this.xmlUnmarshallerMap.clear();
    setLoader(new SDOClassLoader(getClass().getClassLoader(), aHelperContext));
}
Also used : SDOClassLoader(org.eclipse.persistence.sdo.helper.SDOClassLoader)

Example 4 with SDOClassLoader

use of org.eclipse.persistence.sdo.helper.SDOClassLoader in project eclipselink by eclipse-ee4j.

the class LoadAndSaveTestCases method testClassGenerationLoadAndSave.

public void testClassGenerationLoadAndSave() throws Exception {
    // TODO: hard coded path should be parameterized as an option to the test suite
    String tmpDirName = tempFileDir + "/tmp/";
    File f = new File(tmpDirName);
    f.mkdir();
    f.deleteOnExit();
    generateClasses(tmpDirName);
    setUp();
    compileFiles(tmpDirName, getPackages());
    URL[] urls = new URL[1];
    urls[0] = f.toURI().toURL();
    URLClassLoader myURLLoader = new URLClassLoader(urls);
    String package1 = getPackages().get(0);
    String className = package1 + "/" + getRootInterfaceName();
    className = className.replaceAll("/", ".");
    Class<?> urlLoadedClass = myURLLoader.loadClass(className);
    ((SDOXMLHelper) xmlHelper).setLoader(new SDOClassLoader(myURLLoader, aHelperContext));
    Class<?> loadedClass2 = ((SDOXMLHelper) xmlHelper).getLoader().loadClass(className);
    defineTypes();
    assertEquals(urlLoadedClass, loadedClass2);
    FileInputStream inputStream = new FileInputStream(getControlFileName());
    XMLDocument document = xmlHelper.load(inputStream);
    Class<?> loadedClass = document.getRootObject().getType().getInstanceClass();
    assertEquals(urlLoadedClass, loadedClass);
    verifyAfterLoad(document);
    StringWriter writer = new StringWriter();
    xmlHelper.save(document, writer, null);
    compareXML(getControlWriteFileName(), writer.toString());
}
Also used : StringWriter(java.io.StringWriter) URLClassLoader(java.net.URLClassLoader) SDOClassLoader(org.eclipse.persistence.sdo.helper.SDOClassLoader) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) File(java.io.File) URL(java.net.URL) FileInputStream(java.io.FileInputStream) XMLDocument(commonj.sdo.helper.XMLDocument)

Aggregations

SDOClassLoader (org.eclipse.persistence.sdo.helper.SDOClassLoader)4 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)3 XMLDocument (commonj.sdo.helper.XMLDocument)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1