Search in sources :

Example 1 with ArtifactInfoContext

use of org.apache.ofbiz.minilang.artifact.ArtifactInfoContext in project ofbiz-framework by apache.

the class SimpleMethod method getAllEntityNamesUsed.

@Deprecated
public Set<String> getAllEntityNamesUsed() throws MiniLangException {
    ArtifactInfoContext aic = new ArtifactInfoContext();
    gatherArtifactInfo(aic);
    return aic.getEntityNames();
}
Also used : ArtifactInfoContext(org.apache.ofbiz.minilang.artifact.ArtifactInfoContext)

Example 2 with ArtifactInfoContext

use of org.apache.ofbiz.minilang.artifact.ArtifactInfoContext in project ofbiz-framework by apache.

the class SimpleMethod method getAllServiceNamesCalled.

@Deprecated
public Set<String> getAllServiceNamesCalled() throws MiniLangException {
    ArtifactInfoContext aic = new ArtifactInfoContext();
    gatherArtifactInfo(aic);
    return aic.getServiceNames();
}
Also used : ArtifactInfoContext(org.apache.ofbiz.minilang.artifact.ArtifactInfoContext)

Example 3 with ArtifactInfoContext

use of org.apache.ofbiz.minilang.artifact.ArtifactInfoContext in project ofbiz-framework by apache.

the class ServiceArtifactInfo method populateUsedEntities.

protected void populateUsedEntities() throws GeneralException {
    // populate entitiesUsedByThisService and for each the reverse-associate cache in the aif
    if ("simple".equals(this.modelService.engineName)) {
        // we can do something with this!
        SimpleMethod simpleMethodToCall = null;
        try {
            simpleMethodToCall = SimpleMethod.getSimpleMethod(this.modelService.location, this.modelService.invoke, null);
        } catch (MiniLangException e) {
            Debug.logWarning("Error getting Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "]: " + e.toString(), module);
        }
        if (simpleMethodToCall == null) {
            Debug.logWarning("Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "] not found", module);
            return;
        }
        ArtifactInfoContext aic = new ArtifactInfoContext();
        simpleMethodToCall.gatherArtifactInfo(aic);
        populateEntitiesFromNameSet(aic.getEntityNames());
    } else if ("java".equals(this.modelService.engineName)) {
        String fullClassPathAndFile = UtilJavaParse.findRealPathAndFileForClass(this.modelService.location);
        if (fullClassPathAndFile != null) {
            String javaFile = null;
            try {
                javaFile = FileUtil.readTextFile(fullClassPathAndFile, true).toString();
            } catch (FileNotFoundException e) {
                Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
                return;
            } catch (IOException e) {
                Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
                return;
            }
            javaFile = UtilJavaParse.stripComments(javaFile);
            int methodBlockStart = UtilJavaParse.findServiceMethodBlockStart(this.modelService.invoke, javaFile);
            int methodBlockEnd = UtilJavaParse.findEndOfBlock(methodBlockStart, javaFile);
            Set<String> allEntityNameSet = UtilJavaParse.findEntityUseInBlock(methodBlockStart, methodBlockEnd, javaFile);
            populateEntitiesFromNameSet(allEntityNameSet);
        }
    } else if ("group".equals(this.modelService.engineName)) {
    // nothing to do, there won't be entities referred to in these
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) FileNotFoundException(java.io.FileNotFoundException) SimpleMethod(org.apache.ofbiz.minilang.SimpleMethod) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) IOException(java.io.IOException) ArtifactInfoContext(org.apache.ofbiz.minilang.artifact.ArtifactInfoContext)

Example 4 with ArtifactInfoContext

use of org.apache.ofbiz.minilang.artifact.ArtifactInfoContext in project ofbiz-framework by apache.

the class ServiceArtifactInfo method populateCalledServices.

protected void populateCalledServices() throws GeneralException {
    // populate servicesCalledByThisService and for each the reverse-associate cache in the aif
    if ("simple".equals(this.modelService.engineName)) {
        // we can do something with this!
        SimpleMethod simpleMethodToCall = null;
        try {
            simpleMethodToCall = SimpleMethod.getSimpleMethod(this.modelService.location, this.modelService.invoke, null);
        } catch (MiniLangException e) {
            Debug.logWarning("Error getting Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "]: " + e.toString(), module);
        }
        if (simpleMethodToCall == null) {
            Debug.logWarning("Simple-method [" + this.modelService.invoke + "] in [" + this.modelService.location + "] referenced in service [" + this.modelService.name + "] not found", module);
            return;
        }
        ArtifactInfoContext aic = new ArtifactInfoContext();
        simpleMethodToCall.gatherArtifactInfo(aic);
        populateServicesFromNameSet(aic.getServiceNames());
    } else if ("java".equals(this.modelService.engineName)) {
        String fullClassPathAndFile = UtilJavaParse.findRealPathAndFileForClass(this.modelService.location);
        if (fullClassPathAndFile != null) {
            String javaFile = null;
            try {
                javaFile = FileUtil.readTextFile(fullClassPathAndFile, true).toString();
            } catch (FileNotFoundException e) {
                Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
                return;
            } catch (IOException e) {
                Debug.logWarning("Error reading java file [" + fullClassPathAndFile + "] for service implementation: " + e.toString(), module);
                return;
            }
            javaFile = UtilJavaParse.stripComments(javaFile);
            int methodBlockStart = UtilJavaParse.findServiceMethodBlockStart(this.modelService.invoke, javaFile);
            int methodBlockEnd = UtilJavaParse.findEndOfBlock(methodBlockStart, javaFile);
            Set<String> allServiceNameSet = UtilJavaParse.findServiceCallsInBlock(methodBlockStart, methodBlockEnd, javaFile);
            populateServicesFromNameSet(allServiceNameSet);
        }
    } else if ("group".equals(this.modelService.engineName)) {
        Set<String> allServiceNameSet = new HashSet<String>();
        GroupModel groupModel = modelService.internalGroup;
        if (groupModel == null) {
            groupModel = ServiceGroupReader.getGroupModel(this.modelService.location);
        }
        if (groupModel != null) {
            List<GroupServiceModel> groupServiceModels = groupModel.getServices();
            for (GroupServiceModel groupServiceModel : groupServiceModels) {
                allServiceNameSet.add(groupServiceModel.getName());
            }
        }
        populateServicesFromNameSet(allServiceNameSet);
    }
}
Also used : TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) GroupServiceModel(org.apache.ofbiz.service.group.GroupServiceModel) FileNotFoundException(java.io.FileNotFoundException) SimpleMethod(org.apache.ofbiz.minilang.SimpleMethod) MiniLangException(org.apache.ofbiz.minilang.MiniLangException) GroupModel(org.apache.ofbiz.service.group.GroupModel) IOException(java.io.IOException) ArtifactInfoContext(org.apache.ofbiz.minilang.artifact.ArtifactInfoContext) HashSet(java.util.HashSet)

Aggregations

ArtifactInfoContext (org.apache.ofbiz.minilang.artifact.ArtifactInfoContext)4 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 MiniLangException (org.apache.ofbiz.minilang.MiniLangException)2 SimpleMethod (org.apache.ofbiz.minilang.SimpleMethod)2 GroupModel (org.apache.ofbiz.service.group.GroupModel)1 GroupServiceModel (org.apache.ofbiz.service.group.GroupServiceModel)1