Search in sources :

Example 6 with SimpleMethod

use of org.apache.ofbiz.minilang.SimpleMethod 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 7 with SimpleMethod

use of org.apache.ofbiz.minilang.SimpleMethod 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

SimpleMethod (org.apache.ofbiz.minilang.SimpleMethod)7 MiniLangException (org.apache.ofbiz.minilang.MiniLangException)4 MethodContext (org.apache.ofbiz.minilang.method.MethodContext)3 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 ArtifactInfoContext (org.apache.ofbiz.minilang.artifact.ArtifactInfoContext)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Test (junit.framework.Test)1 TestCase (junit.framework.TestCase)1 TestSuite (junit.framework.TestSuite)1 GeneralException (org.apache.ofbiz.base.util.GeneralException)1 EntityTestCase (org.apache.ofbiz.entity.testtools.EntityTestCase)1 MiniLangRuntimeException (org.apache.ofbiz.minilang.MiniLangRuntimeException)1 GroupModel (org.apache.ofbiz.service.group.GroupModel)1 GroupServiceModel (org.apache.ofbiz.service.group.GroupServiceModel)1