Java - GetModuleName

0
I am trying to get the current module name in a java action. I see core.getModuleName in version 3. But nothing in the API docs for Mendix version 7. Any advice?    
asked
2 answers
0

haven't used it myself, but I see getModuleName is still in the API docs for Mx 7:

https://apidocs.mendix.com/7/runtime/com/mendix/systemwideinterfaces/core/meta/IMetaObject.html#getModuleName--

answered
0

I have some Java action which gets the n-th level microflow + modulename it is called from. This I have used to incorporate generic exception handling. The microflowName output parameter will have both the microflowname and the modulename separated by a dot:

 

		int intLevel = LevelParameter1 != null ? LevelParameter1.intValue() : null;
		IContext context = this.getContext();
		Stack<CoreAction<?>> coreAction;
		CoreAction<?> nthCoreAction;
		String microflowName = "";
		if (context!=null){
			Core.getLogger(this.toString()).trace("Context exists");
			coreAction = context.getActionStack();

			if (coreAction!=null){
				int actionStackSize = coreAction.size();
				Core.getLogger(this.toString()).trace("coreAction exists with size: " + actionStackSize);
				// determine the level to get the stackaction from. The actionStack contains all levels of microflows currently active, so also all sublevels. 
				int Level = (actionStackSize - intLevel) - 1;
				// make sure the ArrayIndexOutOfBounds exception can't occur
				if ((Level >= 0) && (Level < actionStackSize)){
					Core.getLogger(this.toString()).trace("get on " + Level + " nth element");
					nthCoreAction = coreAction.get(Level);
					if (nthCoreAction!=null){
						Core.getLogger(this.toString()).trace("nthCoreAction exists with name " + nthCoreAction.getMetaInfo().toString());
						microflowName = nthCoreAction.getActionName();
					}
				}
			}
		}
	
		return microflowName;

 

answered