View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.common.impex.schema;
17  
18  import java.io.Writer;
19  
20  import javax.xml.bind.JAXBContext;
21  import javax.xml.bind.JAXBException;
22  import javax.xml.bind.Marshaller;
23  
24  import org.kuali.common.impex.model.Schema;
25  
26  public class DefaultExportSchemaService implements ExportSchemaService {
27  
28  	@Override
29  	public void exportSchema(Schema schema, Writer writer) {
30  		try {
31  			JAXBContext context = JAXBContext.newInstance(Schema.class);
32  			Marshaller marshaller = context.createMarshaller();
33  			marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
34  			marshaller.marshal(schema, writer);
35  		} catch (JAXBException e) {
36  			throw new IllegalStateException("Could not persist given schema", e);
37  		}
38  	}
39  
40  }