Skip to content
Snippets Groups Projects
Commit 4b85bb4e authored by Simon Barner's avatar Simon Barner
Browse files

Ensure that kernel is not aware of any products built based on it:

- Move internal.storage.Eclipse.AF3ResourceFactory -> utils.ResourceUtils.KernelResourceFactory
- Move registration of KernelResourceFactory for .af3_23 files to org.fortiss.af3.project
- Remove registration for .sfit files (should be handled in an appropriate plugin there)
refs 2309
parent 43bf53d9
No related branches found
No related tags found
No related merge requests found
......@@ -30,14 +30,4 @@
provider="org.fortiss.tooling.kernel.internal.LibraryPrototypeProvider">
</modelPrototypeProvider>
</extension>
<!-- Resource factories. Keep registration in sync with AF3 model file extension. -->
<extension point = "org.eclipse.emf.ecore.extension_parser">
<parser type="af3_23" class="org.fortiss.tooling.kernel.internal.storage.eclipse.AF3ResourceFactory"/>
<parser
class="org.fortiss.tooling.kernel.internal.storage.eclipse.AF3ResourceFactory"
type="sfit">
</parser>
</extension>
</plugin>
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2015 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.internal.storage.eclipse;
import static java.lang.System.identityHashCode;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.fortiss.tooling.kernel.model.IIdLabeled;
/**
* {@link org.eclipse.emf.ecore.resource.Resource.Factory} that creates {@link Resource}s using the
* {@code id} filed of {@link IIdLabeled} model elements.
*
* One effect of using this that {@link EReference}s are encoded based on these IDs,
* and hence cross-references between multiple resources are more reliable (the
* fragment-based encoding breaks as soon as the structure of of the referenced
* model changes).
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: FC2FB6F94F632A4E942D2C5085348710
*/
public class AF3ResourceFactory extends ResourceFactoryImpl {
/**
* {@link XMIResourceImpl} used to persist AF3 models.
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
private final class AF3XMIResource extends XMIResourceImpl {
/** Constructs a new {@link AF3XMIResource}. */
private AF3XMIResource(URI uri) {
super(uri);
}
/** {@inheritDoc} */
@Override
protected boolean useIDs() {
return true;
}
/** {@inheritDoc} */
@Override
public String getID(EObject eObject) {
String id = super.getID(eObject);
if(id == null && eObject instanceof IIdLabeled) {
id = new Integer(((IIdLabeled)eObject).getId()).toString();
setID(eObject, id);
}
return id;
}
/** {@inheritDoc} */
@Override
public Map<EObject, String> getEObjectToIDMap() {
if(eObjectToIDMap == null) {
// See IDENTITY_HASH_COMPARATOR why an alternative map implementation is required
eObjectToIDMap = new TreeMap<EObject, String>(IDENTITY_HASH_COMPARATOR);
}
return eObjectToIDMap;
}
// No override is required for getIDToEObjectMap() since its key type is String
/** {@inheritDoc} */
@Override
public Map<EObject, AnyType> getEObjectToExtensionMap() {
if(eObjectToExtensionMap == null) {
// See IDENTITY_HASH_COMPARATOR why an alternative map implementation is required.
eObjectToExtensionMap = new TreeMap<EObject, AnyType>(IDENTITY_HASH_COMPARATOR);
}
return eObjectToExtensionMap;
}
}
/**
* Comparator based on the {@link System#identityHashCode(Object)} function.
* See {@link AF3ResourceFactory#IDENTITY_HASH_COMPARATOR} for more details.
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
private static final class IdentityHashComparator implements Comparator<EObject> {
/** {@inheritDoc} */
@Override
public int compare(EObject o1, EObject o2) {
Integer h1 = identityHashCode(o1);
Integer h2 = identityHashCode(o2);
return h1.compareTo(h2);
}
}
/**
* <p>
* {@link IdentityHashComparator} used to implement alternative {@link EObject} -> ID /
* ExtensionMaps. This is required because {@link XMIResourceImpl} is based on {@link HashMap}s
* may not work correctly for keys whose {@link #hashCode()} and {@link #equals(Object)} methods
* have been overridden in such a way that different instances of the same object cannot be
* distinguished.
* </p>
*
* <p>
* Since it is not possible to provide an alternative {@link #hashCode()} and
* {@link #equals(Object)} implementation to a {@link HashMap}, a {@link TreeMap} is used (in
* contrast to the implementation in {@link XMIResourceImpl}). Coincidentally, the
* implementation {@link IdentityHashComparator#compare(EObject, EObject)} is based on
* {@link System#identityHashCode(Object)}.
* </p>
*/
private static final IdentityHashComparator IDENTITY_HASH_COMPARATOR =
new IdentityHashComparator();
/** {@inheritDoc} */
@Override
public Resource createResource(URI uri) {
return new AF3XMIResource(uri);
}
}
......@@ -17,23 +17,152 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.utils;
import static java.lang.System.identityHashCode;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceImpl;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.fortiss.tooling.kernel.model.IIdLabeled;
/**
* Utility class for eclipse relevant tasks
* Utility class for dealing with EMF {@link Resource}s.
*
* @author mou
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 12F5BE532F0151DD11B20E198884443A
* @ConQAT.Rating YELLOW Hash: F36B592322BBC784ACE2FD7F32D37DAB
*/
public final class ResourceUtils {
/**
* {@link org.eclipse.emf.ecore.resource.Resource.Factory} that creates {@link Resource}s using
* the {@code id} filed of {@link IIdLabeled} model elements.
*
* One effect of using this that {@link EReference}s are encoded based on these IDs,
* and hence cross-references between multiple resources are more reliable (the
* fragment-based encoding breaks as soon as the structure of of the referenced
* model changes).
*/
public static class KernelResourceFactory extends ResourceFactoryImpl {
/**
* {@link XMIResourceImpl} used to persist models managed by the tooling kernel.
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
private final class KernelXMIResource extends XMIResourceImpl {
/** Constructs a new {@link KernelXMIResource}. */
private KernelXMIResource(URI uri) {
super(uri);
}
/** {@inheritDoc} */
@Override
protected boolean useIDs() {
return true;
}
/** {@inheritDoc} */
@Override
public String getID(EObject eObject) {
String id = super.getID(eObject);
if(id == null && eObject instanceof IIdLabeled) {
id = new Integer(((IIdLabeled)eObject).getId()).toString();
setID(eObject, id);
}
return id;
}
/** {@inheritDoc} */
@Override
public Map<EObject, String> getEObjectToIDMap() {
if(eObjectToIDMap == null) {
// See IDENTITY_HASH_COMPARATOR why an alternative map implementation is
// required
eObjectToIDMap = new TreeMap<EObject, String>(IDENTITY_HASH_COMPARATOR);
}
return eObjectToIDMap;
}
// No override is required for getIDToEObjectMap() since its key type is String
/** {@inheritDoc} */
@Override
public Map<EObject, AnyType> getEObjectToExtensionMap() {
if(eObjectToExtensionMap == null) {
// See IDENTITY_HASH_COMPARATOR why an alternative map implementation is
// required.
eObjectToExtensionMap = new TreeMap<EObject, AnyType>(IDENTITY_HASH_COMPARATOR);
}
return eObjectToExtensionMap;
}
}
/**
* Comparator based on the {@link System#identityHashCode(Object)} function.
* See {@link KernelResourceFactory#IDENTITY_HASH_COMPARATOR} for more details.
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
private static final class IdentityHashComparator implements Comparator<EObject> {
/** {@inheritDoc} */
@Override
public int compare(EObject o1, EObject o2) {
Integer h1 = identityHashCode(o1);
Integer h2 = identityHashCode(o2);
return h1.compareTo(h2);
}
}
/**
* <p>
* {@link IdentityHashComparator} used to implement alternative {@link EObject} -> ID /
* ExtensionMaps. This is required because {@link XMIResourceImpl} is based on
* {@link HashMap}s may not work correctly for keys whose {@link #hashCode()} and
* {@link #equals(Object)} methods have been overridden in such a way that different
* instances of the same object cannot be distinguished.
* </p>
*
* <p>
* Since it is not possible to provide an alternative {@link #hashCode()} and
* {@link #equals(Object)} implementation to a {@link HashMap}, a {@link TreeMap} is used
* (in contrast to the implementation in {@link XMIResourceImpl}). Coincidentally, the
* implementation {@link IdentityHashComparator#compare(EObject, EObject)} is based on
* {@link System#identityHashCode(Object)}.
* </p>
*/
private static final IdentityHashComparator IDENTITY_HASH_COMPARATOR =
new IdentityHashComparator();
/** {@inheritDoc} */
@Override
public Resource createResource(URI uri) {
return new KernelXMIResource(uri);
}
}
/**
* Generate the platform URI based on the given plugin ID and an absolute
* path.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment