• No results found

Implementing Custom Export Format for OData Models

6 Extensibility

6.8 Implementing Custom Export Format for OData Models

case Proxy: this.envUi = new ProxyEnvironmentUi();

break;

case Starter_Application: this.envUi = new StarterAppEnvironmentUi();

break;

default:

this.envUi = null;

} return this.envUi;

}

Recommendation: Each environment will implement an interface, and only that interface will be exposed in the exported packages.

From the IJavaSeModel interface:

public interface IJavaSeModel { • Returns the name of a project. public String getProject();

Returns the name of the main class of the project.

public String getMainClass(); • Returns the package name in the project. public String getPackage();

Returns the output path of the generated file.

public String getOutputPath();

Creates a new project for a Java Starter Application template.

public void createNewProject() throws EnvironmentException;

Updates the project to a proxy project, by adding the Client library, .project and .classpath files.

public void updateProxyProject() throws EnvironmentException; }

6.8 Implementing Custom Export Format for OData Models

A custom export format for OData models describes the set of coding patterns that can be reused to define your own custom export format for OData models in the productivity accelerator plug-in.

Make sure that you have the following:

● A new plug-in project.

● The productivity accelerator plug-in on which your custom export format is dependent. See the details for the required plug-in in the section below.

● The file, Manifest.mf, or plug-in.xml, is available in your new project.

Using the Export wizard of the productivity accelerator, you can export OData models into an XML file suitable for a specifed version of the Common Shema Definition Language (CSDL):

The productivity accelerator plug-in offers an extension point from which you can create a new extension for your custom export format. The outcome of each new extension is the generation of a class, in which you provide code for the specific implementation for a custom export format.

You create a custom export format for adding support for latest versions of the CSDL, that you want to use.

You create a new custom export format by extending the specific extension point, com.sap.odata.dt.framework.model.export.modelExport.

The following is the sequence of steps for creating a new export format for a model:

1. Add the plug-in for the framework as required dependency plug-in.

Before you create a new export format extension, you must specify the plug-in,

com.sap.odata.dt.framework.model. The plug-in is required in the classpath of the project in order to compile.

To define the required plug-in dependency:

1. Optionally create a new Plug-in Project in Java if you have not done so.

2. Double click the file, Manifest.mf, in your new plug-in project. The Manifest Editor opens.

3. Open the Dependency tab, and click Add under Required Plug-in. The Plug-in Selection dialog opens.

4. In Select a Plug-in, enter the term, *com.sap*, to search for all plug-ins containing the search term.

5. Select the plug-in, com.sap.odata.dt.framework.model.export, from the list and choose OK.

2. Create the New Export Format Extension

After adding the dependency plug-in, you can create a new export format extension that extends the extension point which is defined in the productivity accelerator plugin, (the equired plugin).

To create the export format class

1. Create a new Plug-in Project if you have not done so.

2. Double click the file, Manifest.mf, under META-INF in your new plug-in project.

3. Open the Extensions tab, and click Add under All Extensions. The Extension Points Selection dialog displays a list of all the extensions points.

4. In Extention Points filter, enter the term, *export*, to search for all extension points containing the search term.

5. Select the extension point, com.sap.odata.dt.framework.model.export.modelExport, from the list and choose Finish. A new extension element with the same name as the extension point is created.

6. Double click the new extension element, and then specify the type of export format you want.

Recommendation

We recommend that you save your changes after modifying the value of each attribute.

The following types are available:

○ id: A unique name that will be used to identify this export format.

○ displayName: A translatable name that will be used for the model export extension. It displays in the model export wizard.

○ description: Descriptive text that displays information about the new model export extension in the wizard. It displays in the model export wizard when this export format is selected.

○ ModelExportProvider: The Java class for ModelExportProvider. The specified class must implement the interface:

com.sap.odata.dt.framework.model.export.util.extensionpoint.IModelExportProvi der.

○ icon: The path of a graphic file that will visually represent the export format in the wizard.

7. Click the attribute (a link to the class), ModelExportProvider, under Extension elements details. The New Java Class dialog opens.

8. Enter a name for your ModelExportProvider class. The interface which has to be implemented has been added.

9. Click Finish, and then click Save in the Eclipse main menu.

The following code (empty method subs) is generated for the new export model in the specified class:

You must provide your implementation code.

public class ModelExportProvider2 implements IModelExportProvider { public ModelExportProvider2()

{

// TODO Auto-generated constructor stub

} @Override public void createFirstPageUI(Composite arg0, IModelExportFirstPage arg1)

{ // TODO Auto-generated method stub

} @Override public String getPageDescription() {

// TODO Auto-generated method stub return null;

} @Override public List<IWizardPage> getPages() { // TODO Auto-generated method stub return null;

}@Override public void performFinish(EDMXSet arg0) throws ModelExportException {

// TODO Auto-generated method stub }}

You must add your own code to implement your export format.

The following is an example of existing code. It is based on the code used for testing this feature.:

mport java.util.List;

import …

public class ModelExportProviderTest implements IModelExportProvider { private Text text1;

{ // TODO Auto-generated constructor stub

} @Override public void performFinish(EDMXSet edmxSet) throws ModelExportException {

// TODO Auto-generated method stub }

@Override

public void createFirstPageUI(Composite parent, IModelExportFirstPage wizardPage)

{this.wizardPage = wizardPage;

GridData gridData = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);

gridData.grabExcessHorizontalSpace = true;

parent.setLayoutData(gridData);

// create label 01

this.label1 = new Label(parent, SWT.NONE);

this.label1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

this.label1.setText("Label 01:");

// create text 01

this.text1 = new Text(parent, SWT.BORDER);

this.text1.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

// Set default text

GridLayout gridLayout2 = new GridLayout(2, false);

gridLayout2.marginWidth = 0;

parent.setLayout(gridLayout2);

GridData gridData2 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);

gridData2.grabExcessHorizontalSpace = true; parent.setLayoutData(gridData2);

// create label 02

this.label2 = new Label(parent, SWT.NONE);

this.label2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

this.label2.setText("Label 02:");

// create text 02

this.text2 = new Text(parent, SWT.BORDER);

this.text2.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

// Set default text

); this.text2.notifyListeners(SWT.Modify, new Event());

GridLayout gridLayout3 = new GridLayout(2, false);

gridLayout3.marginWidth = 0; parent.setLayout(gridLayout3);

GridData gridData3 = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);

gridData3.grabExcessHorizontalSpace = true; parent.setLayoutData(gridData3);

// create label 03

this.label3 = new Label(parent, SWT.NONE);

this.label3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1));

this.label3.setText("Label 03:");

// create text 03

this.text3 = new Text(parent, SWT.BORDER);

this.text3.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

this.text3.addModifyListener(new ModifyListener()

if (text1 == null || text1.getText() == null || text1.getText().isEmpty()) { status = new Status(IStatus.ERROR, "pluginId", "Fill Label 01");

} if (text2 == null || text2.isDisposed() || text2.getText() == null ||

text2.getText().isEmpty())

{status = new Status(IStatus.ERROR, "pluginId", "Fill Label 02");

}if (text3 == null || text3.isDisposed() || text3.getText() == null ||

text3.getText().isEmpty())

{ status = new Status(IStatus.ERROR, "pluginId", "Fill Label 03");

}wizardPage.updateExtensionValidations(status);

}

@Override public List<IWizardPage> getPages() { return null;

}

@Override public String getPageDescription() {

return "Test extension for export service model";

} }

3. Generating the New Export Format from Your Extension

You can export OData models based on your new export format for a specified version of OData Common Schema Definition Language (CDSL) formats; as the new export format is added to the productivity accelerator.

1. To run and test your new export model format, select Run from the main menu and choose Run.

2. Open the export model of the framework, and then select your new export format.