001/* 002 * Copyright c 2018 Rusi Popov, MDA Tools.net All rights reserved. 003 * 004 * This program and the accompanying materials are made available under the terms of the 005 * Eclipse Public License v2.0 which accompanies this distribution, and is available at 006 * http://www.eclipse.org/legal/epl-v20.html 007 */ 008package net.mdatools.modelant.core.selector; 009 010import java.util.ArrayList; 011import java.util.Collection; 012 013import javax.jmi.reflect.JmiException; 014import javax.jmi.reflect.RefObject; 015import javax.jmi.reflect.RefPackage; 016 017import net.mdatools.modelant.core.api.Selector; 018import net.mdatools.modelant.core.util.Navigator; 019 020/** 021 * Selector of a metamodel package with the provided qualified name 022 * @author popovr 023 */ 024public class SelectMetaPackage implements Selector<RefPackage, RefObject> { 025 026 /** 027 * The qualified name of a metaclass 028 * not null 029 */ 030 private final String qualifiedName; 031 032 /** 033 * @param qualifiedName not null, not empty name of a MOF Class instance in the metamodel 034 */ 035 public SelectMetaPackage(String qualifiedName) { 036 if ( qualifiedName == null || qualifiedName.trim().isEmpty() ) { // iteration on model class instances 037 throw new IllegalArgumentException( "Empty name provided "); 038 } 039 040 this.qualifiedName = qualifiedName; 041 } 042 043 /** 044 * @param sourceExtent not null 045 * @return non-null list of one element - the metaobject, describing the metapackage 046 */ 047 public Collection<RefObject> execute(RefPackage sourceExtent) throws JmiException { 048 Collection<RefObject> result; 049 050 // locate the meta class (in metaClass) within the metamodel 051 result = new ArrayList<>(); 052 result.add(Navigator.getMetaPackage( sourceExtent, qualifiedName ).refMetaObject()); 053 054 return result; 055 } 056}