Copying a physical resource

This sample demonstrates how to copy a physical resource.

Sample scenario

To copy a physical resource, select a remote resource and then select the API Sample Actions > Copy Physical Resource action.

Creating a logical resource from a physical resource

This sample demonstrates how to create a logical resource from a physical resource.

Sample scenario

To create a logical resource from a physical resource, select a remote resource and then select the API Sample Actions > Create Logical Resource action.

Allocating a partitioned data set

This sample demonstrates how to programmatically allocate a partitioned data set with a particular set of data set characteristics.

Sample scenario

Right-click the MVS Files subsystem for the appropriate connection and then select the API Sample Actions > Allocate PDS action.

A sample partitioned data set is allocated. The name of the allocated data set is hardcoded in the action as the constant DATASET_NAME.

If the data set exists, it is deleted and then reallocated. The following messages are sent to system output.

Artwork for allocatePdsConsole

Checking for the existence of a data set on the MVS file system

The run method of the sample starts by making sure that the data set it is about to create does not exist. First, it obtains the ZOSCatalog for the MVS file system by calling getCatalog for the selected ISystemReference.

 ZOSCatalog catalog = getCatalog((ZOSSystemReference)selectedItem);

After the ZOSCatalog is obtained, its findMember method is started to see whether a partitioned data set with the specified name exists. If the data set exists already, the sample attempts to delete the existing data set by using the delete method. It is important to catch the OperationFailedException in case something goes wrong during the delete.

 ZOSPartitionedDataSet newPDS = null;
	......
	newPDS = (ZOSPartitionedDataSet)
		catalog.findMember(DATASET_NAME);
	if(newPDS != null){
		try {
			......
			newPDS.delete(true, null);
		} catch (OperationFailedException ofe) {
			System.err.println("Allocate PDS Action - PDS (" 
				+ DATASET_NAME + 
				") already exists and could not be deleted.");
			return;
		}
	}

Allocate the partitioned data set

 IPhysicalResourceFactory physicalFactory = 
		PhysicalResourceFactoryFactory.getFactory(
		  ZOSCatalog.class, ZOSDataSet.class);
	......
	ZOSDataSet res = (ZOSDataSet)physicalFactory.getPhysicalResource(catalog,ZOSPartitionedDataSet.class,DATASET_NAME);
	res.setCharacteristics(getCharacteristics());
	try {
		res.allocate(null);
	} catch (OperationFailedException e) {
		System.out.println("Allocate PDS Action - PDS allocation failed" + e.getMessage());
	}

Creating a member in a partitioned data set

This sample demonstrates how to create a data set member under a partitioned data set. It also demonstrates how to contribute a menu item in the menu for remote artifacts in the navigator views.

Sample scenario

To use this sample, right-click a partitioned data set in the Remote Systems Explorer View, and select the API Sample Actions > Create Member action.

A member with the name TEMP is created in the selected data set.

Creating a data set member IPhysicalResource

The createPhysicalMember sample method starts by checking to make sure that the member to be created does not exist, by using the method findMember. The findMember method returns null if the resource is not found.

 IPhysicalFile resource = (IPhysicalFile) 
		dataSet.findMember(MEMBER_NAME);
	if (resource != null) {
		System.err.println("Resource " + MEMBER_NAME + 
			" already exists");
		return;
	}

The member is then created as follows. An IPhysicalResource object that references the member is created by using the getPhysicalResource method of the ZOSPhysicalResourceFactory class. (The resource object that is returned by the getPhysicalResource method is not required to represent an actual existing remote system resource.) After you have the IPhysicalResource, the actual member can then be created on the remote system by starting create method.

 ZOSPhysicalResourceFactory factory = 
		ZOSPhysicalResourceFactory.eINSTANCE;
	resource = (IPhysicalFile) factory.getPhysicalResource(dataSet,
		ZOSDataSetMember.class, MEMBER_NAME);
	try {
		resource.create(
				new ByteArrayInputStream(MEMBER_CONTENT.getBytes()), 
					true, null);
	} catch (OperationFailedException e) {
		......
	}

The create method expects an InputStream containing the content for the file to be created.

Creating a data set member ILogicalResource

The process of creating a data set member in an MVS subproject is similar. Consider the createLogicalMember method in the CreateMemberAction sample class. It starts by obtaining the IPhysicalResource object that is referred to by the selected ILogicalResource, by using the getPhysicalResource method.

 IPhysicalContainer container = null;
	if (dataSet.getState().isOnline()) {
		container = (IPhysicalContainer) dataSet.
			getPhysicalResource();
	} else {
		System.err.println("DataSet " + dataSet.getName() + 
			" should not be offline.");
		return;
	}

Processing of offline resources by using the Remote Access API is not yet supported.

The code then proceeds to create a data set member IPhysicalResource as in Creating a data set member IPhysicalResource.

 IPhysicalFile resource = (IPhysicalFile) factory.getPhysicalResource(
			container, ZOSDataSetMember.class, MEMBER_NAME);
	try {
		resource.create(
				new ByteArrayInputStream(MEMBER_CONTENT.getBytes()),
				true, null);
	} catch (OperationFailedException e) {
		......
	}

The following code snippet then adds the resource to the appropriate subproject obtained through the getSubProject method. The code snippet accomplishes this purpose by using the LogicalResourceFactory class. This method can be used to add any physical resource to a project, by using the Add to Subproject menu action.

 ILogicalSubProject subProject = dataSet.getSubProject();
	if (project != null && resource != null) {
		LogicalResourceFactoryFactory.getSingleton().getLogicalResource( 	
			subProject, resource);
	}

Responding to selection changed events

This example also demonstrates how to react to selection change events in Eclipse. The CreateMemberAction class implements the ISelectionListener interface. Its selectionChanged method implementation reacts to events that refer to an IStructuredSelection, typically caused by a change in the current selection in a tree navigator. The sample code iterates through the items that are contained in the current selection by using an iterator that is associated with it. In this example, the first item that is selected is chosen.

 selectedItem = null;
	if (selection instanceof IStructuredSelection) {
		IStructuredSelection currentSelection = 
			(IStructuredSelection) selection;
		Iterator iterator = currentSelection.iterator();
		while (iterator.hasNext()) {
			Object item = iterator.next();
			if (item instanceof LZOSPartitionedDataSet) {
				selectedItem = item;
				break;
			} else if (item instanceof ZOSResourceReference) {
				item = ((ZOSResourceReference) item).getReferent();
				if (item instanceof ZOSPartitionedDataSet) {
					selectedItem = item;
					break;
				}
			}
		}
	}

An ILogicalResource object (LZOSPartitionedDataSet in this case) is returned in the selection object, if an object in a z/OS project is selected. If an object in the MVS file system is selected on the Remote Systems Explorer View, a ZOSResourceReference is returned. In the latter case, you can retrieve the corresponding IPhysicalResource by using the getReferent method.

Contributing menu items to the menu

Menu items can be contributed to the menu by using the org.eclipse.ui.popupMenus extension point. This sample defines two object contributions, one against LZOSPartitionedDataSet for the z/OS Projects View, and another against ZOSResourceReference for the Remote Systems Explorer View. In both cases, selecting the menu item causes CreateMemberAction to be started.

 <extension
      id="com.ibm.ftt.api.samples.popupMenus"
      name="%apiSample.popupMenus"
      point="org.eclipse.ui.popupMenus">
      <objectContribution
         adaptable="false"
         objectClass= "com.ibm.ftt.resources.zos.zosphysical.ZOSResourceReference"
         id="com.ibm.ftt.api.samples.physical.patitionedDataset">
         ......
         <action
            label="%apiMenu.samples.createMember"
            class= "com.ibm.ftt.api.samples.resources.CreateMemberAction"
            menubarPath="com.ibm.ftt.api.samples.PopupMenu/group1"
            id="com.ibm.ftt.api.samples.physical.createMember"/>
      </objectContribution>
      ......
      <objectContribution
         adaptable="false"
         objectClass= "com.ibm.ftt.projects.zos.zoslogical.LZOSPartitionedDataSet"
         id="com.ibm.ftt.api.samples.logical.patitionedDataset">
         <menu
            id="com.ibm.ftt.api.samples.PopupMenu"
            label="
            <separator name="group1"/>
         </menu>
         <action
            label="%apiMenu.samples.createMember"
            class= "com.ibm.ftt.api.samples.resources.CreateMemberAction"
            menubarPath="com.ibm.ftt.api.samples.PopupMenu/group1"
            id="com.ibm.ftt.api.samples.logical.createMember"/>
      </objectContribution>

Subscribing to events related to remote resources

This sample demonstrates how to subscribe to events related to remote resources.

Sample scenario

To subscribe to events related to remote resources, select a remote resource and then select the API Sample Actions > Subscribe to Events action.