blob: 04b97002c0ea3b1359ee73483a3d596a5e126161 [file] [log] [blame]
/*
* Copyright (c) 2004 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* IBM - Initial API and implementation
*
* $Id: UML2Handler.java,v 1.6 2004/06/17 15:04:29 khussey Exp $
*/
package org.eclipse.uml2.internal.util;
import java.util.Iterator;
import java.util.Map;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.ecore.resource.impl.ResourceImpl;
import org.eclipse.emf.ecore.xmi.XMLHelper;
import org.eclipse.emf.ecore.xmi.XMLResource;
import org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler;
/**
* The SAX handler for UML2 resources.
*/
public class UML2Handler
extends SAXXMIHandler {
/**
* Constructs a new UML2 handler for the specified resource with the
* specified helper and options.
*
* @param xmiResource
* The resource for the new handler.
* @param helper
* The helper for the new handler.
* @param options
* The load options for the new handler.
*/
public UML2Handler(XMLResource xmiResource, XMLHelper helper, Map options) {
super(xmiResource, helper, options);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#getURIConverter()
*/
protected URIConverter getURIConverter() {
return new UML2URIConverterImpl(super.getURIConverter());
}
/*
* (non-Javadoc)
*
* @see org.eclipse.emf.ecore.xmi.impl.XMLHandler#endDocument()
*/
public void endDocument() {
super.endDocument();
if (null != extendedMetaData) {
for (Iterator demandedPackages = extendedMetaData
.demandedPackages().iterator(); demandedPackages.hasNext();) {
EPackage ePackage = (EPackage) demandedPackages.next();
String nsURI = ePackage.getNsURI();
if (null != nsURI) {
if (null != urisToLocations) {
URI locationURI = (URI) urisToLocations.get(nsURI);
if (null != locationURI) {
Resource resource = new ResourceImpl();
resource.setURI(locationURI);
resource.getContents().add(ePackage);
}
}
for (Iterator entries = helper.getPrefixToNamespaceMap()
.iterator(); entries.hasNext();) {
Map.Entry entry = (Map.Entry) entries.next();
if (nsURI.equals(entry.getValue())) {
ePackage.setNsPrefix((String) entry.getKey());
}
}
}
}
}
}
}