Suggestions how to re-write the following Java code snippet
<p>I was trying to convert this code into a more elegant or efficient way to code it. </p>

<pre><code>final ContentSlotForPageModel rel = modelService.create(ContentSlotForPageModel.class);
rel.setUid("rel_1");
rel.setPosition("no");
rel.setCatalogVersion(catalogVersionModel);
rel.setPage(firstContentPage);
rel.setContentSlot(slot);
modelService.save(rel);

final ContentSlotForTemplateModel relTemplate = modelService.create(ContentSlotForTemplateModel.class);
relTemplate.setUid("relTemplate_1");
relTemplate.setPosition("no");
relTemplate.setCatalogVersion(catalogVersionModel);
relTemplate.setPageTemplate(template);
relTemplate.setContentSlot(slot);
modelService.save(rel);
</code></pre>

<p>Where <code>ContentSlotForPageModel</code> and <code>ContentSlotForTemplateModel</code> are subtypes of <code>CMSRelationModel</code>. So I tried to create a method that sets these attributes by using its supertype like this: </p>

<pre><code>private void setRelationModel(final CMSRelationModel rel, final ContentSlotModel slot, final String id)
{
    rel.setUid(id);
    rel.setCatalogVersion(catalogVersionModel);

    if (rel instanceof ContentSlotForPageModel)
    {
        ((ContentSlotForPageModel) rel).setPage(firstContentPage);
        ((ContentSlotForPageModel) rel).setContentSlot(slot);
        ((ContentSlotForPageModel) rel).setPosition("no");
    }
    else if (rel instanceof ContentSlotForTemplateModel)
    {
        ((ContentSlotForTemplateModel) rel).setPageTemplate(template);
        ((ContentSlotForTemplateModel) rel).setContentSlot(slot);
        ((ContentSlotForTemplateModel) rel).setPosition("no");
    }

    modelService.save(rel);

}
</code></pre>

<p>However, many methods are not defined on CMSRelationModel and therefore I need to create a validation to make the right call. I cant define this methods on its superclass. Is there a nicer way to write this?</p>

<p>Thank you</p>
