Package org.exolab.castor.mapping.xml

Examples of org.exolab.castor.mapping.xml.MappingRoot


     *            the Writer to serialize the mapping to
     * @throws MappingException if writing the mapping information fails
     */
    public void write(final Writer writer) throws MappingException {
        Marshaller marshal;
        MappingRoot mapping;
        Enumeration enumeration;

        try {
            mapping = new MappingRoot();
            mapping.setDescription("Castor generated mapping file");
            enumeration = _mappings.elements();
            while (enumeration.hasMoreElements()) {
                mapping.addClassMapping((ClassMapping) enumeration.nextElement());
            }
            marshal = new Marshaller(writer);
            marshal.setNamespaceMapping(null, "http://castor.exolab.org/");
            marshal.setNamespaceMapping("cst", "http://castor.exolab.org/");
            marshal.marshal(mapping);
View Full Code Here


        Mapping[] mappings = _database.getMapping();

        for (int i = 0; i < mappings.length; ++i) {
            try {
            URL mappingURL = new URL(new URL(databaseURL), mappings[i].getHref());
            MappingRoot mr = (MappingRoot) munm.unmarshal(new InputSource(mappingURL.openStream()));
            ClassMapping[] classMaps = mr.getClassMapping();

            for (int j = 0; j < classMaps.length; j++) {
                _classMappings.put(classMaps[j].getName(), classMaps[j]);
            }
            } catch (Exception e) {
View Full Code Here

            // create a class mapping
            String pkg = state.getPackageName();
            if (pkg == null) {
                pkg = "";
            }
            MappingRoot mapping = state.getMapping(pkg);
            if (mapping == null) {
                mapping = new MappingRoot();
                state.setMapping(pkg, mapping);
            }
            mapping.addClassMapping(_mappingSourceFactory.createMapping(classInfo));
        }
    }
View Full Code Here

     *
     * @throws GeneratorException If failed to create schema objects.
     */
    public final void createSchema() throws GeneratorException {
        // Create schema.
        MappingRoot root = _mapping.getRoot();
        _schema = _schemaFactory.createSchema();
        _schema.setConfiguration(_configuration);

        // Create key generators.
        Enumeration ekg = root.enumerateKeyGeneratorDef();
        while (ekg.hasMoreElements()) {
            KeyGeneratorDef definition = (KeyGeneratorDef) ekg.nextElement();
            _keyGenRegistry.createKeyGenerator(definition);
        }

        // Create tables.
        Enumeration ec = root.enumerateClassMapping();
        while (ec.hasMoreElements()) {
            ClassMapping cm = (ClassMapping) ec.nextElement();
            Table table = createTable(cm);
            if (table != null) { _schema.addTable(table); }
        }
View Full Code Here

            //mark the mapping as being processed
            mapping.markAsProcessed(id);
        }
       
        MappingRoot root = mapping.getRoot();
        _idResolver.setMapping(root);

        try {
            // Load the specificed mapping source
            Unmarshaller unm = new Unmarshaller(MappingRoot.class);
            unm.setValidation(false);
            unm.setEntityResolver(resolver);
            unm.setClassLoader(Mapping.class.getClassLoader());
            unm.setIDResolver(_idResolver);
            unm.setUnmarshalListener(
                    new MappingUnmarshallListener(this, mapping, resolver));

            MappingRoot loaded = (MappingRoot) unm.unmarshal(source);
               
            // Load all the included mapping by reference
            //-- note: this is just for processing any
            //-- includes which may have previously failed
            //-- using the IncludeListener...and to
            //-- report any potential errors.
            Enumeration includes = loaded.enumerateInclude();
            while (includes.hasMoreElements()) {
                Include include = (Include) includes.nextElement();
                if (!mapping.processed(include.getHref())) {
                    try {
                        loadMappingInternal(mapping, resolver, include.getHref());
                    } catch (Exception ex) {
                        throw new MappingException(ex);
                    }
                }
            }
           
            // gather "class" tags
            Enumeration enumeration = loaded.enumerateClassMapping();
            while (enumeration.hasMoreElements()) {
                root.addClassMapping((ClassMapping) enumeration.nextElement());
            }

            // gather "key-generator" tags
            enumeration = loaded.enumerateKeyGeneratorDef();
            while (enumeration.hasMoreElements()) {
                root.addKeyGeneratorDef((KeyGeneratorDef) enumeration.nextElement());
            }
           
            // gather "field-handler" tags
            root.setFieldHandlerDef(loaded.getFieldHandlerDef());

        } catch (Exception ex) {
            throw new MappingException(ex);
        }
    }
View Full Code Here

        // --------------------------------------------------------------------

        LOG.info( "Begin: Walking the mapping descriptor via objects" );

        MappingRoot mappingRoot = _mapping.getRoot();
        ClassMapping classMap;
        FieldMapping fieldMap;
        FieldMapping[] fieldMaps;

        int mappingCount = mappingRoot.getClassMappingCount();

        // loop over the classes
        for ( int i = 0; i < mappingCount; ++i )
        {
            classMap = mappingRoot.getClassMapping( i );
            LOG.debug( "Class name: " + classMap.getName() );

            fieldMaps = classMap.getClassChoice().getFieldMapping();

            LOG.debug( "fieldMaps.length: " + fieldMaps.length );
View Full Code Here

     * @throws IOException if this Exception occurs while generating the mapping file
     */
    private void generateMappingFile(final String packageName, final SGStateInfo sInfo)
                                                                      throws IOException {
        String pkg = (packageName != null) ? packageName : "";
        MappingRoot mapping = sInfo.getMapping(pkg);
        if (mapping == null) {
            return;
        }

        FileWriter writer = new FileWriter(_mappingFilename);
View Full Code Here

     * @throws MappingException The mapping file is invalid
     */
    private void loadMappingInternal( InputSource source )
        throws IOException, MappingException
    {
        MappingRoot  loaded;
        Unmarshaller unm;
        Enumeration  enumeration;

        // Clear all the cached resolvers, so they can be reconstructed a
        // second time based on the new mappings loaded
        _resolvers.clear();
       
        //check that the mapping has already been processed
        if ((source.getSystemId()!=null) && _state.processed(source.getSystemId()) ) {
            //-- already processed...just return
            return;
        }
        try {
            if ( _mapping == null ) {
                _mapping = new MappingRoot();
                _idResolver.setMapping(_mapping);
            }

            //mark the mapping as being processed
            if (source.getSystemId() != null)
                _state.markAsProcessed(source.getSystemId(), _mapping);
               
            // Load the specificed mapping source
            unm = new Unmarshaller( MappingRoot.class );
            unm.setEntityResolver( _resolver );
            if ( _logWriter != null )
                unm.setLogWriter( _logWriter );
            unm.setClassLoader( Mapping.class.getClassLoader() );
            unm.setIDResolver(_idResolver);
            unm.setUnmarshalListener(new IncludeListener());

            loaded = (MappingRoot) unm.unmarshal( source );

               
            // Load all the included mapping by reference
            //-- note: this is just for processing any
            //-- includes which may have previously failed
            //-- using the IncludeListener...and to
            //-- report any potential errors.
            Enumeration includes = loaded.enumerateInclude();
            while ( includes.hasMoreElements() ) {
                Include include = (Include) includes.nextElement();
                if (!_state.processed( include.getHref() )) {
                    try {
                        loadMappingInternal( include.getHref() );
                    }
                    catch ( Exception except ) {
                        throw new MappingException( except );
                    }
                }
            }
           
            // gather "class" tags
            enumeration = loaded.enumerateClassMapping();
            while ( enumeration.hasMoreElements() )
                _mapping.addClassMapping( (ClassMapping) enumeration.nextElement() );

            // gather "key-generator" tags
            enumeration = loaded.enumerateKeyGeneratorDef();
            while ( enumeration.hasMoreElements() ) {
                _mapping.addKeyGeneratorDef( (KeyGeneratorDef) enumeration.nextElement() );
            }
        } catch ( Exception except ) {
            throw new MappingException( except );
View Full Code Here

    **/
    public void write( Writer writer )
        throws MappingException
    {
        Marshaller  marshal;
        MappingRoot mapping;
        Enumeration enumeration;

        try {
            mapping = new MappingRoot();
            mapping.setDescription( "Castor generated mapping file" );
            enumeration = _mappings.elements();
            while ( enumeration.hasMoreElements() )
                mapping.addClassMapping( (ClassMapping) enumeration.nextElement() );
            marshal = new Marshaller( writer );
            marshal.setNamespaceMapping(null, "http://castor.exolab.org/");
            marshal.setNamespaceMapping("cst", "http://castor.exolab.org/");
            marshal.marshal( mapping );
        } catch ( Exception except ) {
View Full Code Here

   Mapping mappings[] = _database.getMapping();

  for ( int i = 0 ; i < mappings.length ; ++i ) {
      try {
    URL mappingURL = new URL(new URL(databaseURL), mappings[i].getHref());
    MappingRoot mr = (MappingRoot) munm.unmarshal(new InputSource((mappingURL).openStream()));
    ClassMapping[] classMaps = mr.getClassMapping();

    for (int j = 0; j < classMaps.length; j++) {
        _classMappings.put(classMaps[j].getName(), classMaps[j]);
        if (_logWriter != null) {
      _logWriter.println("Got class: " + classMaps[j].getName());
View Full Code Here

TOP

Related Classes of org.exolab.castor.mapping.xml.MappingRoot

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.