Java Code Examples for org.eclipse.emf.ecore.EPackage.getEClassifier()

The following are Jave code examples for showing how to use getEClassifier() of the org.eclipse.emf.ecore.EPackage class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: BIMplatform   File: CatalogServiceImpl.java   View Source Code Vote up 6 votes
public EClassifier getEClassifier(String packageName, String classifierName) {
	if (packageName == null) {
		return null;
	}
	if (packageName.contains(".")) {
		packageName = packageName.substring(packageName.lastIndexOf(".") + 1);
	}
	EPackage ePackage = server.getMetaDataManager().getPackageMetaData(packageName).getEPackage();
	if (ePackage == null) {
		return null;
	}
	if (ePackage.getEClassifier(classifierName) != null) {
		return ePackage.getEClassifier(classifierName);
	}
	throw null;
}
 
Example 2
Project: OCCI-Studio   File: OCCIExtension2Ecore.java   View Source Code Vote up 6 votes
/**
 * Get the EMF data type associated to an OCCI data type.
 * 
 * @param type
 *            the given OCCI data type.
 * @return the EMF data type.
 */
private EClassifier getMappedType(DataType type) {
	EClassifier res = null;
	if (type == null) {
		res = EcorePackage.eINSTANCE.getEString();
	} else {
		// retrieve from currently converted data types
		res = occiType2emfType.get(type);
		if (res == null) {
			// retrieve from installed extensions.
			EPackage p = ConverterUtils.getEPackage(type);
			res = p.getEClassifier(type.getName());
			// Cache it for optimizing next searches.
			occiType2emfType.put(type, res);
		}
	}
	return res;
}
 
Example 3
Project: OCCI-Studio   File: GenUtils.java   View Source Code Vote up 6 votes
/**
 * Get the Java type of an OCCI attribute.
 */
public String getJavaTypeName(Attribute attribute)
{
	// Get the data type of this attribute.
	DataType attributeType = (DataType) attribute.getType();
	//System.out.println("attributeType "+attributeType);
	// Get the extension containing this attribute type.
	Extension extension = (Extension)(attributeType.eContainer());
	//System.out.println("extension "+extension);
	// Get the Epackage for this extension.
	EPackage ePackage = getEPackage(extension);
	//System.out.println("ePackage "+ePackage);
	// Get the data type.
	EDataType eDataType = (EDataType)ePackage.getEClassifier(attributeType.getName());
	// Return the instance class name of this data type.
	return eDataType.getName();
}
 
Example 4
Project: OCCI-Studio   File: OcciHelper.java   View Source Code Vote up 5 votes
/**
 * Create an entity of a given kind.
 * 
 * @param kind
 *            The kind of the entity to create.
 * @return The created entity, else null.
 */
public static Entity createEntity(Kind kind) {
	Entity createdEntity = null;

	// Get the name space of the Ecore package for this kind.
	String epackageNS = Occi2Ecore.convertOcciScheme2EcoreNamespace(kind.getScheme());
	// Get the Ecore package associated to the kind.
	EPackage epackage = EPackage.Registry.INSTANCE.getEPackage(epackageNS);
	if (epackage == null) {
		LOGGER.warn("EPackage " + epackageNS + " not found!");
	} else {
		String classname = Occi2Ecore.convertOcciCategoryTerm2EcoreClassName(kind.getTerm());
		// Get the Ecore class associated to the kind.
		EClass eclass = (EClass) epackage.getEClassifier(classname);
		if (eclass == null) {
			LOGGER.warn("EClass " + classname + " not found!");
		} else {
			// Get the Ecore factory associated to the kind.
			EFactory efactory = EPackage.Registry.INSTANCE.getEFactory(epackageNS);
			if (efactory == null) {
				LOGGER.warn("EFactory " + epackageNS + " not found!");
			} else {
				// Create the EObject for this kind.
				createdEntity = (Entity) efactory.create(eclass);
			}
		}
	}
	if (createdEntity == null) {
		LOGGER.warn("Create OCCI Core Resource!");
		createdEntity = OCCIFactory.eINSTANCE.createResource();
		createdEntity.setKind(kind);
	}

	LOGGER.debug("created entity=" + createdEntity);
	// Return the new entity.
	return createdEntity;
}
 
Example 5
Project: OCCI-Studio   File: GenUtils.java   View Source Code Vote up 5 votes
public EClass getEClass(Type type) {
	Extension extension = (Extension) type.eContainer();
	EPackage ePackage = getEPackage(extension);
	EClass eclass = (EClass) ePackage
			.getEClassifier(ConverterUtils.toU1Case(ConverterUtils.formatName(type.getTerm())));
	return eclass;
}
 
Example 6
Project: OCCI-Studio   File: GenUtils.java   View Source Code Vote up 5 votes
public EClass getEClass(Type type) {
	Extension extension = (Extension) type.eContainer();
	EPackage ePackage = getEPackage(extension);
	EClass eclass = (EClass) ePackage
			.getEClassifier(ConverterUtils.toU1Case(ConverterUtils.formatName(type.getTerm())));
	return eclass;
}
 
Example 7
Project: OCCI-Studio   File: OCCIExtension2Ecore.java   View Source Code Vote up 5 votes
private void addSuperTypeFromOCCI(EClass subClass, String esuperClassName) {
	Resource oCCIEcoreResource = createAndLoadOCCIEcoreResource("org.eclipse.cmf.occi.core/model/OCCI.ecore");
	// of course, in production code we would fail here if there were no
	// contents or they weren't of type EPackage.
	final EPackage oCCIEPackage = (EPackage) oCCIEcoreResource.getContents().get(0);
	final EClass eSuperClass = (EClass) oCCIEPackage.getEClassifier(esuperClassName);
	subClass.getESuperTypes().add(eSuperClass);
}
 
Example 8
Project: OCCI-Studio   File: OcciHelper.java   View Source Code Vote up 4 votes
/**
 * Create an entity of a given kind.
 * 
 * @param kind
 *            The kind of the entity to create.
 * @return The created entity, else null.
 */
public static MixinBase createMixinBase(Entity entity, Mixin mixin) {
	MixinBase createdMixinBase = null;

	// Get the name space of the Ecore package for this mixin.
	String epackageNS = null;
	// If the mixin is a new mixin tag (doesnt exist on extension so, the method
	// eContainer() will return a Configuration object.
	EPackage epackage = null;
	if (mixin.eContainer() instanceof Extension) {
		// Establish that this is an extension.
		epackageNS = Occi2Ecore.convertOcciScheme2EcoreNamespace(((Extension) mixin.eContainer()).getScheme());
		// Get the Ecore package associated to the mixin.
		epackage = EPackage.Registry.INSTANCE.getEPackage(epackageNS);
	}
	// String epackageNS =
	// Occi2Ecore.convertOcciScheme2EcoreNamespace(((Extension)mixin.eContainer()).getScheme());
	if (epackage == null) {
		LOGGER.warn("EPackage " + epackageNS + " not found ! and this is a mixin tag");
	} else {
		String classname = Occi2Ecore.convertOcciCategoryTerm2EcoreClassName(mixin.getTerm());
		// Get the Ecore class associated to the mixin.
		EClass eclass = (EClass) epackage.getEClassifier(classname);
		if (eclass == null) {
			LOGGER.warn("EClass " + classname + " not found!");
		} else {
			// Get the Ecore factory associated to the mixinbase.
			EFactory efactory = EPackage.Registry.INSTANCE.getEFactory(epackageNS);
			if (efactory == null) {
				LOGGER.warn("EFactory " + epackageNS + " not found!");
			} else {
				// Create the EObject for this kind.
				createdMixinBase = (MixinBase) efactory.create(eclass);
			}
		}
	}
	if (createdMixinBase == null) {
		LOGGER.warn("Couldnt create mixin base for mixin : " + mixin.getScheme() + mixin.getTerm());
		createdMixinBase = OCCIFactory.eINSTANCE.createMixinBase();
	}
	createdMixinBase.setMixin(mixin);
	createdMixinBase.setEntity(entity);
	entity.getParts().add(createdMixinBase);

	LOGGER.debug("created MixinBase=" + createdMixinBase);
	// Return the new entity.
	return createdMixinBase;
}