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.operation.element; 009 010import javax.jmi.reflect.RefEnum; 011import javax.jmi.reflect.RefPackage; 012 013import net.mdatools.modelant.core.api.Function; 014import net.mdatools.modelant.core.util.Navigator; 015 016/** 017 * Retrieve an enumerated literal of a (meta)type provided 018 * @author Rusi Popov (popovr@mdatools.net) 019 */ 020public class GetEnum implements Function<RefPackage, RefEnum> { 021 022 /** 023 * Path in the metamodel to the metaPackage whose instances (in the model/extent) are to be 024 * processed. Format of metaPackage attribute: {<package>::} <meta class> 025 */ 026 private String metaPackage; 027 028 /** 029 * The name of the enumerated type 030 */ 031 private String type; 032 033 /** 034 * The name of the enumerated literal to retrieve 035 */ 036 private String literal; 037 038 /** 039 * The task's execution method. This method filters the model classes associated with metaPackage and 040 * executes the nested <template> tasks for the filtered classes collection. This 041 * methods invokes the internal formatting tasks with the metaPackage itself. 042 */ 043 public RefEnum execute(RefPackage sourceExtent) throws IllegalArgumentException { 044 RefEnum result; 045 RefPackage refPackage; 046 047 if ( sourceExtent == null ) { 048 throw new IllegalArgumentException("Expected a non-null extent"); 049 } 050 051 refPackage = Navigator.getMetaPackage( sourceExtent, metaPackage ); // non-null 052 053 result = refPackage.refGetEnum( type, literal ); 054 055 return result; 056 } 057}