# BO-Based MO

The `com.splwg.base.api.maintenanceObject.BOBasedMaintenanceObjectCHandlerHelper` can be used for the BO-based MO Change Handler validations.

The following standard validations are provided by this helper class:

- The Business Object cannot be changed.
- The Business Object must be for the correct MO.
- Status is required if the Business Object has a lifecycle.
- Status must be a valid lifecycle status.

The following methods are provided by this helper class:

- Adding log entries for entity creation and entity status change (if the MO does not already have a transition algorithm).

To use the validations, create an instance of the helper class in the MO Change Handler and get the validation rules from the Helper, as illustrated in the following sample code.

## Change Handler Sample Code

    public class OutboundCrossReferenceMessage_CHandler extends AbstractChangeHandler<OutboundCrossReferenceMessage>
    	{
    	private final BOBasedMaintenanceObjectCHandlerHelper helper = new BOBasedMaintenanceObjectCHandlerHelper<
    	OutboundCrossReferenceMessage> ( new MaintenanceObject_Id("O2-OXREFMSG"),
    	OutboundCrossReferenceMessage.properties,
    	OutboundCrossReferenceMessage.properties.lookOnBusinessObject() );
    	...
    	public void handleAddOrChange ( OutboundCrossReferenceMessage changedOutboundCrossReferenceMessage,
    	DataTransferObject< OutboundCrossReferenceMessage> oldDTO )
    		{
    		helper.handleAddOrChange(changedOutboundCrossReferenceMessage, oldDTO);
    		}
    	public ValidationRule[] getValidationRules()
    		{
    		return helper.getValidationRules();
    		}
    	}

## Change Handler Junit Test Code

    public void testBoCannotBeChanged()
    	{
    	startChanges();
    	OutboundCrossReferenceMessage_DTO dto = (OutboundCrossReferenceMessage_DTO)
    	createDTO(OutboundCrossReferenceMessage.class);
    	dto.setBusinessObjectId(new BusinessObject_Id("ZZ-OXREFBO"));
    	setDtoData(dto);
    	OutboundCrossReferenceMessage outboundCrossReferenceMessage = dto.newEntity();
    	saveChanges();
    	try
    		{
    		dto.setBusinessObjectId(new BusinessObject_Id("ZZ-CASE"));
    		outboundCrossReferenceMessage.setDTO(dto);
    		saveChanges();
    		fail("An error should have been thrown");
    		}
    	catch (ApplicationError e)
    		{
    		verifyViolatedRule(BOBasedMaintenanceObjectCHandlerHelper.boCannotBeChanged(
    		OutboundCrossReferenceMessage.properties, OutboundCrossReferenceMessage.properties
    		.lookOnBusinessObject()), e);
    		}
    	}

Parent topic: Change Handler Helpers for Maintenance Objects