use of org.eclipse.emf.ecore.EPackage in project dsl-devkit by dsldevkit.
the class ImportImplCustom method getPackageName.
/**
* {@inheritDoc} Returns either the defined package alias, or the package's namespace prefix, or null if neither is set.
*/
@Override
public String getPackageName() {
final String result = getName();
if (result != null) {
return result;
}
final EPackage p = getPackage();
if (p != null) {
return p.getNsPrefix();
}
return null;
}
use of org.eclipse.emf.ecore.EPackage in project dsl-devkit by dsldevkit.
the class ImportImpl method setPackage.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setPackage(EPackage newPackage) {
EPackage oldPackage = package_;
package_ = newPackage;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, ValidPackage.IMPORT__PACKAGE, oldPackage, package_));
}
use of org.eclipse.emf.ecore.EPackage in project InformationSystem by ObeoNetwork.
the class ISMigrationParticipant method getType.
@Override
public EClassifier getType(EPackage ePackage, String name, String loadedVersion) {
String ePackageURI = ePackage.getNsURI();
String newEPackageURI = null;
String newEClassName = null;
EClassLocation newEClass = getNewEClass(ePackageURI, name);
if (newEClass != null) {
newEPackageURI = newEClass.getEPackageNsURI();
newEClassName = newEClass.getEClassName();
} else {
// Try to convert EPackage
newEPackageURI = ePackageURI;
newEClassName = name;
}
// Get Classifier from registry
if (newEPackageURI != null && newEClassName != null) {
EPackage newEPackage = getPackageFromRegistry(newEPackageURI);
if (newEPackage != null) {
EClassifier eClassifier = newEPackage.getEClassifier(newEClassName);
if (eClassifier != null) {
return eClassifier;
}
}
}
return super.getType(ePackage, name, loadedVersion);
}
use of org.eclipse.emf.ecore.EPackage in project InformationSystem by ObeoNetwork.
the class TypesServices method createTypesFromOtherTypes.
public Collection<StructuredType> createTypesFromOtherTypes(Namespace namespace, Collection<StructuredType> types, Collection<Reference> references, String sourceTypeName, String targetTypeName) {
String uri = PACKAGES_URI.get(targetTypeName);
EFactory factory = getEFactory(uri);
EPackage ePackage = factory.getEPackage();
EClass eClass = (EClass) ePackage.getEClassifier(targetTypeName);
Map<StructuredType, StructuredType> mappingsTypes = new HashMap<StructuredType, StructuredType>();
Map<Reference, Reference> mappingsReferences = new HashMap<Reference, Reference>();
Collection<StructuredType> result = new ArrayList<StructuredType>();
// Create types
for (StructuredType type : types) {
EObject eObject = factory.create(eClass);
if (eObject instanceof StructuredType) {
StructuredType type2 = (StructuredType) eObject;
type2.setName(type.getName());
type2.getAssociatedTypes().add(type);
type2.setDescription(type.getDescription());
namespace.getTypes().add(type2);
mappingsTypes.put(type, type2);
result.add(type2);
}
}
// Create references
for (Reference reference : references) {
StructuredType sourceType = mappingsTypes.get(reference.getContainingType());
StructuredType targetType = mappingsTypes.get(reference.getReferencedType());
Reference newReference = EnvironmentFactory.eINSTANCE.createReference();
sourceType.getOwnedReferences().add(newReference);
newReference.setReferencedType(targetType);
newReference.setDescription(reference.getDescription());
newReference.setIsComposite(reference.isIsComposite());
newReference.setIsIdentifier(reference.isIsIdentifier());
newReference.setMultiplicity(reference.getMultiplicity());
newReference.setName(reference.getName());
newReference.setNavigable(reference.isNavigable());
mappingsReferences.put(reference, newReference);
}
// Set opposite references
for (Reference reference : references) {
if (reference.getOppositeOf() != null) {
Reference newReference = mappingsReferences.get(reference);
if (newReference.getOppositeOf() == null) {
Reference newOppositeReference = mappingsReferences.get(reference.getOppositeOf());
newReference.setOppositeOf(newOppositeReference);
}
}
}
return result;
}
use of org.eclipse.emf.ecore.EPackage in project InformationSystem by ObeoNetwork.
the class EcorebindingModelWizardSpec method createInitialModel.
/**
* (non-Javadoc)
* @see org.obeonetwork.dsl.ecorebinding.presentation.EcorebindingModelWizard#createInitialModel()
*/
@Override
protected EObject createInitialModel() {
IPath ecoreFilePath = this.ecoreSelectionWizardPage.getEcoreFilePath();
ResourceSet ecorers = new ResourceSetImpl();
Resource ecoreResource = ecorers.getResource(URI.createFileURI(ecoreFilePath.toFile().getAbsolutePath()), true);
try {
ecoreResource.load(new HashMap<String, String>());
} catch (IOException e) {
e.printStackTrace();
}
ResourceSet rs = new ResourceSetImpl();
IPath ecoreBindingModelPath = ecoreFilePath;
ecoreBindingModelPath = ecoreFilePath.removeFileExtension().addFileExtension("ecorebinding");
Resource resource = rs.createResource(URI.createFileURI(ecoreBindingModelPath.toFile().getAbsolutePath()));
BModel ecoreBindingModel = EcorebindingFactory.eINSTANCE.createBModel();
List<EObject> contents = ecoreResource.getContents();
for (EObject eObject : contents) {
// We only support EPackage as root element.
if (eObject instanceof EPackage) {
EPackage rootPackage = (EPackage) eObject;
BPackage ecoreBindingPackage = EcorebindingFactory.eINSTANCE.createBPackage();
ecoreBindingPackage.setEcorePackage(rootPackage);
ecoreBindingModel.getBPackages().add(ecoreBindingPackage);
explore(rootPackage, ecoreBindingPackage);
} else {
throw new IllegalArgumentException("The Ecore Binding only supports EPackage as root element");
}
}
resource.getContents().add(ecoreBindingModel);
try {
resource.save(new HashMap<String, String>());
} catch (IOException e) {
e.printStackTrace();
}
return ecoreBindingModel;
}
Aggregations