All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.eclipse.persistence.sessions.factories.XMLProjectWriter Maven / Gradle / Ivy

There is a newer version: 5.0.0-B03
Show newest version
/*
 * Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0,
 * or the Eclipse Distribution License v. 1.0 which is available at
 * http://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 */

// Contributors:
//     Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.sessions.factories;

import java.io.*;
import java.nio.charset.StandardCharsets;

import org.eclipse.persistence.exceptions.*;
import org.eclipse.persistence.internal.sessions.factories.MissingDescriptorListener;
import org.eclipse.persistence.internal.sessions.factories.ObjectPersistenceWorkbenchXMLProject;
import org.eclipse.persistence.oxm.*;
import org.eclipse.persistence.sessions.*;

/**
 * 

Purpose: Write the deployment XML (object persistence meta-data) for the TopLink project instance to a file. * Note the TopLink deployment XML format has change as of the OracleAS TopLink 10g (10.0.3) release to use XML schema. * * @since TopLink 3.0 * @author James Sutherland */ public class XMLProjectWriter { /** * Default constructor. */ private XMLProjectWriter() { super(); } /** * PUBLIC: * Given the file name (including path), and a project, * this writes out the deployment XML file storing the project's descriptor and mapping information. * * @param fileName file to write to (including path) * @param project the project instance to write */ public static void write(Project project, String fileName) { Writer writer; try { FileOutputStream stream = new FileOutputStream(fileName); writer = new OutputStreamWriter(stream, StandardCharsets.UTF_8); write(project, writer); writer.close(); } catch (IOException exception) { throw ValidationException.fileError(exception); } } /** * PUBLIC: * Given the writer, and a project, * this writes out the deployment XML file storing the project's descriptor and mapping information. * * @param writer writer to writer to * @param project the project instance to write */ public static void write(Project project, Writer writer) { XMLContext context = new XMLContext(new ObjectPersistenceWorkbenchXMLProject()); context.getSession(project).getEventManager().addListener(new MissingDescriptorListener()); XMLMarshaller marshaller = context.createMarshaller(); marshaller.marshal(project, writer); try { writer.flush(); } catch (IOException exception) { throw ValidationException.fileError(exception); } } /** * INTERNAL: * This should not be used. * @see #write(Project, String) */ public static void write(String fileName, Project project) { write(project, fileName); } /** * INTERNAL: * This should not be used. * @see #write(Project, Writer) * @see #write(Project, String) */ public static void write(String fileName, Project project, Writer writer) { if (writer != null) { write(project, writer); } else { write(project, fileName); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy