How to generate Castor mapping.xml file from given

2019-08-22 09:51发布

How to generate Castor mapping.xml file from given multiple XSDs?

1条回答
我命由我不由天
2楼-- · 2019-08-22 10:07

import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer;

//import org.exolab.castor.builder.SourceGenerator; import org.exolab.castor.mapping.MappingException; import org.exolab.castor.tools.MappingTool;

public class CastorMappingToolUtil {

public static void generate() throws MappingException, FileNotFoundException {
    MappingTool tool = new MappingTool();
    tool.setInternalContext(new org.castor.xml.BackwardCompatibilityContext());
    tool.addClass(ClassType.class);
    OutputStream file = new FileOutputStream("/path/to/xmlFile/gen_mapping.xml" ); 

    Writer writer = new OutputStreamWriter(file);
    tool.write(writer);
    //SourceGenerator.main(options);
}

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        CastorMappingToolUtil.generate();
    } catch (MappingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

查看更多
登录 后发表回答