Skip to content

Commit

Permalink
add PythonLiberies Variable in DOM. (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
TorbenSiegismund-GIP authored Aug 21, 2024
1 parent e45bc4e commit 651c35a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
25 changes: 25 additions & 0 deletions server/src/com/gip/xyna/xprc/xfractwfe/generation/DOM.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public class DOM extends DomOrExceptionGenerationBase {
private Set<GenerationBase> additionalDependenciesSet = new HashSet<GenerationBase>();

private Set<String> additionalLibNames = new TreeSet<String>();
private List<String> pythonLibNames = new ArrayList<String>();
private Set<String> sharedLibs = new HashSet<String>();

private PersistenceInformation persistenceInformation;
Expand Down Expand Up @@ -539,6 +540,15 @@ protected void parseXmlInternally(Element rootElement) throws XPRC_InconsistentF
}
}
}
List<Element> pythonLibElements = XMLUtils.getChildElementsByName(rootElement, EL.PYTHONLIBRARIES);
if (pythonLibElements != null) {
for (Element element : pythonLibElements) {
String content = XMLUtils.getTextContent(element);
if (!GenerationBase.isEmpty(content)) {
pythonLibNames.add(content.trim());
}
}
}

// parse operations
List<Element> ss = XMLUtils.getChildElementsByName(rootElement, GenerationBase.EL.SERVICE);
Expand Down Expand Up @@ -650,6 +660,21 @@ public String deleteAdditionalLibrary(int index) {

return null;
}

public List<String> getPythonLibraries() {
return pythonLibNames;
}

public void addPythonLibrary(int index, String libName) {
pythonLibNames.add(index, libName);
}

public String deletePythonLibrary(int index) {
if (index < 0 || index >= pythonLibNames.size()) {
return null;
}
return pythonLibNames.remove(index);
}

public void addSharedLib(String libName) {
sharedLibs.add(libName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ public static interface EL {
public static final String PREFERED_EXCEPTION_TYPE = "PreferedExceptionType";
public static final String EXCEPTION = "Exception";
public static final String LIBRARIES = "Libraries";
public static final String PYTHONLIBRARIES = "PythonLibraries";
public static final String VALUE = "Value";
public static final String SHAREDLIB = "SharedLibraries";
public static final String PARAMETER = "Parameter";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ protected void getImports(Set<String> imports) {
imports.add("com.gip.xyna.XynaFactory");
imports.add("com.gip.xyna.xdev.xfractmod.xmdm.Container");
imports.add("com.gip.xyna.xprc.xfractwfe.python.PythonInterpreter");
imports.add("com.gip.xyna.xfmg.xfctrl.versionmgmt.VersionManagement.PathType");
}


Expand Down Expand Up @@ -111,10 +112,15 @@ protected void generateJavaImplementationInternally(CodeBuffer cb) {
}
cb.addLine("com.gip.xyna.xprc.xfractwfe.python.Context context = new com.gip.xyna.xprc.xfractwfe.python.Context()");
cb.addLine("context.revision = ((com.gip.xyna.xfmg.xfctrl.classloading.ClassLoaderBase)getClass().getClassLoader()).getRevision()");
String servicePath = getParent().getOriginalFqName();
cb.addLine("context.servicePath = XynaFactory.getInstance().getFactoryManagement().getXynaFactoryControl().getRevisionManagement().getPathForRevision(PathType.SERVICE, context.revision)"
+ " + \"/" + servicePath + "\"");
cb.addLine("try (PythonInterpreter interpreter = pyMgmt.createPythonInterpreter(getClass().getClassLoader())) {");
cb.addLine("interpreter.set(\"_context\", context)");
addLoadMdm(cb);
cb.addLine("interpreter.exec(\"mdm.XynaObject._context = _context\")");

cb.addLine("interpreter.exec(\"sys.path.append(_context.servicePath)\")");

if(!isStatic()) {
cb.addLine("interpreter.set(\"this\", pyMgmt.convertToPython(this))");
Expand Down
1 change: 1 addition & 0 deletions server/src/com/gip/xyna/xprc/xfractwfe/python/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@

public class Context {
public Long revision;
public String servicePath;
}

0 comments on commit 651c35a

Please sign in to comment.