/** * This method finds the metapackage with the name provided * * @param rootPackage is the top-most package / the model's extent * @param metaPackageName a meta package name with syntax [<package>{::<package>}] * @return the non-null meta package * @throws JmiException if the meta package name is not a valid one */ public static RefPackage getMetaPackage(RefPackage rootPackage, String metaPackageName) throws JmiException { RefPackage result; String[] parsedPath; String itemName; assert rootPackage != null : "Expected a non-null package"; result = rootPackage; // parse syntax [<package>{::<package>}] parsedPath = Name.parseQualifiedName( metaPackageName ); for (int i = 0; i < parsedPath.length; i++) { itemName = parsedPath[i]; try { result = result.refPackage( itemName ); } catch (JmiException ex) { throw new IllegalArgumentException("Looking up the package "+ metaPackageName + " down the path: " + Arrays.asList( Arrays.copyOf( parsedPath, i ) ) + " reached " + PRINT_MODEL_ELEMENT.execute( result ) + " for which retrieving the nested package '"+itemName+"'" + " caused ", ex); } } return result; }
rootPackage = rootPackage.refPackage( itemName );
/** * @param qualifiedName not null, not empty qualified name of the Enum Class * @param targetExtent not null * @return the class name of that Enum */ private static Name<?> constructOwnerClassName(List<String> qualifiedName, RefPackage targetExtent) { Name<?> result; String name; RefBaseObject namespace; namespace = targetExtent; result = null; for (int i=0; i<qualifiedName.size()-1; i++) { name = qualifiedName.get( i ); if ( namespace instanceof RefPackage ) { // the current name is a name of a package or class, packageName is a name of a package so far try { namespace = ((RefPackage) namespace).refPackage( name ); result = new PackageNameImpl((PackageName) result, name); } catch (InvalidNameException ex) { // name is not a package, it could be only a class namespace = ((RefPackage) namespace).refClass( name ); result = new ClassNameImpl((PackageName) result, name); } } else { // namespace is a Class owning at most an enumeration throw new IllegalArgumentException("Resolving "+qualifiedName +" struct name, reached "+PRINT_MODEL_ELEMENT.execute( namespace ) +" which cannot contain nested "+name); } } return result; }
namespace = ((RefPackage) namespace).refPackage( name ); packageName = new PackageNameImpl((PackageName) packageName, name);
/** * @param rootPackage the extent or another instance of a package proxy (class) to start navigating form * @return the metamodel package this describes, starting from the rootPackage extent * @throws JmiException * @see net.mdatools.modelant.core.api.name.PackageName#getMetaPackage(javax.jmi.reflect.RefPackage) */ public RefPackage getMetaPackage(RefPackage rootPackage) throws JmiException { RefPackage result; assert rootPackage != null : "Expected a non-null package"; if ( getOwner() == null ) { result = rootPackage; } else { result = getOwner().getMetaPackage( rootPackage ); } try { result = result.refPackage( getName() ); } catch (JmiException ex) { throw new IllegalArgumentException("Looking up the package "+ this + " reached " + PRINT_MODEL_ELEMENT.execute( result ) + " for which retrieving the nested package '"+getName()+"'" + " caused ",ex); } return result; }
structClassPackage = structClassNamespacePackage.refPackage( structClassNamespace.getName() ); result = structClassPackage.refCreateStruct(getName(), fieldValues );
enumClassPackage = enumClassNamespacePackage.refPackage( enumClassNamespace.getName() ); result = enumClassPackage.refGetEnum( enumClassName.getName(), getName() );