Question

Suppose I want to design an Ecore metamodel that looks something like this, designed to be used to "run" a list of classes:

JavaClassRunnerList
   0..* JavaClass

And assume I have some Java project that has classes named PrintsHello, PrintsSeparator, and PrintsWorld.

I'd like to be able to then write models that look like this:

JavaClassRunnerList
   PrintsHello.class
   PrintsSeparator.class
   PrintsWorld.class
   PrintsSeparator.class
   PrintsSeparator.class

I want my model to be able to include a Java project and to recognize its classes as choices for the model references (possibly co-located in the same project the model is in.)

Is this possible?

Was it helpful?

Solution

Ed Merks said the following. See the thread for the remainder of the discussion.

You can use Ecore's EJavaClass data type to create a multi-valued attribute. You might be better just to use class names, and use a class loader to convert therm to actual class instances.

Same goes for wanting references to IProject; you can use a string and then resolve it to an IProject using the the workspace root.

OTHER TIPS

You should define additional EDatatypes to your ecore for each Java class you want to reference (with 'Instance Type Name' = java class qualified name), and simply use these datatypes to type some of your EAttributes.

Note that you will have to implement specific converters for each created EDatatype if you want to persist EAttribute values in your Resource files.

Example with an EDatatype named 'Date', with instanceTypeName='java.util.Date', you would have to give implementation for the following two methods in your factory implementation:

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Date createDateFromString(EDataType eDataType, String initialValue) {
    // TODO replace with your implementation
    return (Date)super.createFromString(eDataType, initialValue);
}

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public String convertDateToString(EDataType eDataType, Object instanceValue) {
    // TODO replace with your implementation
    return super.convertToString(eDataType, instanceValue);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top