/**
 * Copyright (c) 2009 IBM Corporation
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *
 * $Id$
 */
package org.openhealthtools.mdht.uml.cda.ccd.tests;

import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.openhealthtools.mdht.uml.cda.CDAFactory;
import org.openhealthtools.mdht.uml.cda.CDAPackage;
import org.openhealthtools.mdht.uml.cda.Section;
import org.openhealthtools.mdht.uml.cda.ccd.CCDFactory;
import org.openhealthtools.mdht.uml.cda.ccd.ContinuityOfCareDocument;
import org.openhealthtools.mdht.uml.cda.ccd.EpisodeObservation;
import org.openhealthtools.mdht.uml.cda.ccd.ProblemAct;
import org.openhealthtools.mdht.uml.cda.ccd.ProblemHealthStatus;
import org.openhealthtools.mdht.uml.cda.ccd.ProblemObservation;
import org.openhealthtools.mdht.uml.cda.ccd.ProblemStatus;
import org.openhealthtools.mdht.uml.cda.resource.CDAResource;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
import org.w3c.dom.Document;

public class Main {
	public static void main(String[] args) throws Exception {	
		ProblemAct problemAct = CCDFactory.eINSTANCE.createProblemAct().init();
		ProblemObservation problemObservation = CCDFactory.eINSTANCE.createProblemObservation().init();	
		ProblemStatus problemStatus = CCDFactory.eINSTANCE.createProblemStatus().init();
		ProblemHealthStatus problemHealthStatus = CCDFactory.eINSTANCE.createProblemHealthStatus().init();
		EpisodeObservation episodeObservation = CCDFactory.eINSTANCE.createEpisodeObservation().init();
		
		Section sect = CDAFactory.eINSTANCE.createSection();
		sect.addAct(problemAct);
		sect.addObservation(problemObservation);
		sect.addObservation(problemStatus);
		sect.addObservation(problemHealthStatus);
		sect.addObservation(episodeObservation);
		
		ContinuityOfCareDocument doc = CCDFactory.eINSTANCE.createContinuityOfCareDocument().init();
		doc.addSection(sect);

		Resource.Factory factory = CDAResource.Factory.INSTANCE;
		CDAResource resource = (CDAResource) factory.createResource(URI.createURI(CDAPackage.eNS_URI));
		resource.getContents().add(doc);
		
		Document document = CDAUtil.newDocument();
		resource.save(document, null, null);
		CDAUtil.adjustNamespace(document);
		CDAUtil.setSchemaLocation(document);
		CDAUtil.writeDocument(document, System.out);
		
		resource = (CDAResource) factory.createResource(URI.createURI(CDAPackage.eNS_URI));
		resource.load(document, null);
		CDAUtil.writeDocument(document, System.out);
		
		System.out.println(resource.getContents().get(0));
	}
}

@@ -479,60 +479,18 @@
 til.
-URI;%0D%0Aimport org.eclipse.emf.ecore.resource.Resource
+Diagnostic
 ;%0D%0Ai
@@ -545,61 +545,8 @@
 y;%0D%0A
-import org.openhealthtools.mdht.uml.cda.CDAPackage;%0D%0A
 impo
@@ -1076,28 +1076,35 @@
 cda.
-resource.CDAResource
+util.BasicValidationHandler
 ;%0D%0Ai
@@ -1160,38 +1160,8 @@
 il;%0D
-%0Aimport org.w3c.dom.Document;%0D
 %0A%0D%0Ap
@@ -2094,594 +2094,169 @@
 %0D%0A%09%09
-Resource.Factory factory = CDAResource.Factory.INSTANCE;%0D%0A%09%09CDAResource resource = (CDAResource) factory.createResource(URI.createURI(CDAPackage.eNS_URI));%0D%0A%09%09resource.getContents().add(doc);%0D%0A%09%09%0D%0A%09%09Document document = CDAUtil.newDocument();%0D%0A%09%09resource.save(document, null, null);%0D%0A%09%09CDAUtil.adjustNamespace(document);%0D%0A%09%09CDAUtil.setSchemaLocation(document);%0D%0A%09%09CDAUtil.writeDocument(document, System.out);%0D%0A%09%09%0D%0A%09%09resource = (CDAResource) factory.createResource(URI.createURI(CDAPackage.eNS_URI));%0D%0A%09%09resource.load(document, null);%0D%0A%09%09CDAUtil.writeDocument(document, System.out);
+CDAUtil.save(doc, System.out);%0D%0A%09%09%0D%0A%09%09CDAUtil.validate(doc, new BasicValidationHandler() %7B%0D%0A%09%09%09@Override%0D%0A%09%09%09public void handleError(Diagnostic diagnostic) %7B
 %0D%0A%09%09
-%0D%0A
 %09%09Sy
@@ -2276,37 +2276,56 @@
 tln(
-resource.getContents().get(0)
+%22ERROR: %22 + diagnostic.getMessage());%0D%0A%09%09%09%7D%0D%0A%09%09%7D
 );%0D%0A

Add problem section templates.