Author: euluis Date: 2011-09-02 04:29:09-0700 New Revision: 19716 Added: trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestXmiReaderImpl.java (contents, props changed) Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java
Log: issue 5017: fix for MDR implementation. Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java?view=diff&pathrev=19716&r1=19715&r2=19716 ============================================================================== --- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java (original) +++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/FacadeMDRImpl.java 2011-09-02 04:29:09-0700 @@ -40,6 +40,7 @@ package org.argouml.model.mdr; +import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -4283,6 +4284,12 @@ .getObjectToId().get(mofId)); if (ref == null) { return mofId; + } + // FIXME: depends on internal behavior of XmiReaderImpl. + // Needed for solving issue 5017. + else if (!ref.getSystemId().startsWith( + XmiReaderImpl.getTempXMIFileURIPrefix())) { + return ref.getSystemId() + "#" + ref.getXmiId(); } else { return ref.getXmiId(); } Modified: trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java?view=diff&pathrev=19716&r1=19715&r2=19716 ============================================================================== --- trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java (original) +++ trunk/src/argouml-core-model-mdr/src/org/argouml/model/mdr/XmiReaderImpl.java 2011-09-02 04:29:09-0700 @@ -49,8 +49,12 @@ import java.net.URL; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import javax.jmi.reflect.InvalidObjectException; import javax.jmi.reflect.RefObject; @@ -95,11 +99,15 @@ class XmiReaderImpl implements XmiReader, UnknownElementsListener, XMIHeaderConsumer { + static final String TEMP_XMI_FILE_PREFIX = "zargo_model_"; + /** * Logger. */ private static final Logger LOG = Logger.getLogger(XmiReaderImpl.class); + private static String tempXMIFileURIPrefix; + private MDRModelImplementation modelImpl; private XmiReferenceResolverImpl resolver; @@ -368,12 +376,55 @@ .getSystemId(), extent); } + /** + * Defines the URI prefix of the temporary XMI file that is being read. + * + * @return the URI prefix of the temporary XMI file that is being read. + */ + static String getTempXMIFileURIPrefix() { + if (tempXMIFileURIPrefix == null) { + tempXMIFileURIPrefix = + new File(System.getProperty("java.io.tmpdir")).toURI() + + TEMP_XMI_FILE_PREFIX; + } + return tempXMIFileURIPrefix; + } + /* * @see org.argouml.model.XmiReader#getXMIUUIDToObjectMap() */ public Map<String, Object> getXMIUUIDToObjectMap() { if (resolver != null) { - return resolver.getIdToObjectMap(); + Map<String, Map<String, Object>> idToObjectMaps = + resolver.getIdToObjectMaps(); + Set<Entry<String,Map<String,Object>>> entrySet = null; + // I think that the synchronized access to idToObjectMaps is + // required in order to respect the thread safe nature of the + // object. + // FIXME: maybe this should be moved into XmiReferenceResolverImpl, + // because it depends on internal implementation details of it. + synchronized (idToObjectMaps) { + entrySet = + new HashSet<Entry<String,Map<String,Object>>>( + idToObjectMaps.entrySet()); + for (Entry<String, Map<String, Object>> entry : entrySet) { + entry.setValue(new HashMap<String,Object>(entry.getValue())); + } + } + HashMap<String, Object> globalXmiIdToObjectMap = + new HashMap<String, Object>(); + for (Entry<String, Map<String, Object>> entry : entrySet) { + String xmiIdPrefix = + entry.getKey().startsWith(getTempXMIFileURIPrefix()) ? "" : + entry.getKey() + "#"; + for (Entry<String, Object> innerMapEntry : + entry.getValue().entrySet()) { + globalXmiIdToObjectMap.put( + xmiIdPrefix + innerMapEntry.getKey(), + innerMapEntry.getValue()); + } + } + return globalXmiIdToObjectMap; } return null; } @@ -424,7 +475,7 @@ // Create temporary file for output // TODO: we should be able to chain this directly to XMI reader - File tmpFile = File.createTempFile("zargo_model_", ".xmi"); + File tmpFile = File.createTempFile(TEMP_XMI_FILE_PREFIX, ".xmi"); tmpFile.deleteOnExit(); StreamResult result = new StreamResult( @@ -472,7 +523,7 @@ xsltStreamSource.setSystemId(xsltUrl.toExternalForm()); // Create & set up temporary output file - File tmpOutFile = File.createTempFile("zargo_model_", ".xmi"); + File tmpOutFile = File.createTempFile(TEMP_XMI_FILE_PREFIX, ".xmi"); tmpOutFile.deleteOnExit(); StreamResult result = new StreamResult(new FileOutputStream( @@ -507,7 +558,7 @@ int len; // Create & set up temporary output file - File tmpOutFile = File.createTempFile("zargo_model_", ".xmi"); + File tmpOutFile = File.createTempFile(TEMP_XMI_FILE_PREFIX, ".xmi"); tmpOutFile.deleteOnExit(); FileOutputStream out = new FileOutputStream(tmpOutFile); Added: trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestXmiReaderImpl.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestXmiReaderImpl.java?view=markup&pathrev=19716 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-model-mdr/tests/org/argouml/model/mdr/TestXmiReaderImpl.java 2011-09-02 04:29:09-0700 @@ -0,0 +1,34 @@ +/* $Id$ + ******************************************************************************* + * Copyright (c) 2011 Contributors - see below + * 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: + * Luis Sergio Oliveira (euluis) + ******************************************************************************* + */ + +package org.argouml.model.mdr; + +import junit.framework.TestCase; + +/** + * Unit tests for {@link XmiReaderImpl}. + * + * @author Luis Sergio Oliveira (euluis) + */ +public class TestXmiReaderImpl extends TestCase { + + /** + * Test {@link XmiReaderImpl#getTempXMIFileURIPrefix()}. + */ + public void testGetTempXMIFileURIPrefix() { + assertTrue(XmiReaderImpl.getTempXMIFileURIPrefix().contains( + XmiReaderImpl.TEMP_XMI_FILE_PREFIX)); + assertTrue(XmiReaderImpl.getTempXMIFileURIPrefix().contains( + System.getProperty("java.io.tmpdir"))); + } +} ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2834556 To unsubscribe from this discussion, e-mail: [[email protected]].
