Search in sources :

Example 1 with MappingFile

use of com.sun.jdo.api.persistence.mapping.ejb.MappingFile in project Payara by payara.

the class MappingGenerator method writeSunCmpMappingFile.

/**
 * Writes to sun-cmp-mappings.xml from mappings classes
 * @param mappingClasses a set of mapping classes
 * @param cmpMappingFile corresponds to sun-cmp-mappings.xml
 * @throws IOException
 * @throws ConversionException
 * @throws Schema2BeansException
 */
private void writeSunCmpMappingFile(Set mappingClasses, File cmpMappingFile) throws IOException, ConversionException, Schema2BeansException {
    // Construct the input to MappingFile.fromMappingClasses(): a Map
    // object containing ejbName and MappingClassElement.  Use the
    // elements of iteration and NameMapper to create the input for
    // MappingFile.
    Map mappingMap = new HashMap();
    AbstractNameMapper nameMapper = getNameMapper();
    Iterator iter = mappingClasses.iterator();
    while (iter.hasNext()) {
        MappingClassElement mappingClass = (MappingClassElement) iter.next();
        String ejbName = nameMapper.getEjbNameForPersistenceClass(mappingClass.getName());
        mappingMap.put(ejbName, mappingClass);
    }
    MappingFile mf = new MappingFile();
    OutputStream sunCmpMapping = null;
    try {
        sunCmpMapping = new FileOutputStream(cmpMappingFile);
        mf.fromMappingClasses(sunCmpMapping, mappingMap, getConversionHelper());
    } catch (IOException ex) {
        throw ex;
    } finally {
        try {
            if (sunCmpMapping != null) {
                sunCmpMapping.close();
            }
        } catch (IOException ex) {
            if (logger.isLoggable(Logger.FINE))
                logger.fine(ex.toString());
        }
    }
}
Also used : HashMap(java.util.HashMap) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) AbstractNameMapper(com.sun.jdo.api.persistence.mapping.ejb.AbstractNameMapper) Iterator(java.util.Iterator) MappingFile(com.sun.jdo.api.persistence.mapping.ejb.MappingFile) MappingClassElement(com.sun.jdo.api.persistence.model.mapping.MappingClassElement) IOException(java.io.IOException) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

AbstractNameMapper (com.sun.jdo.api.persistence.mapping.ejb.AbstractNameMapper)1 MappingFile (com.sun.jdo.api.persistence.mapping.ejb.MappingFile)1 MappingClassElement (com.sun.jdo.api.persistence.model.mapping.MappingClassElement)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1