IMPORTANT:
this is not a Support Forum! Experienced users might answer from time to time questions posted here. If you need a professional and reliable answer, or if you want to report a bug, please contact Altova Support instead.

Problem Creation Custom Function Java Options · View
ale89e1
Posted: Tuesday, December 15, 2015 10:22:15 AM
Rank: Newbie

Joined: 12/15/2015
Posts: 1
I', new to Mapforce and I'm trying to create a simple java function, but when i add its, mapforce tells me:
Quote:
"The function 'FilesFromDirectory.filesfromdirectory' will not be available for the builtin execution engine. The return type 'xs:string' of 'result' is invalid!"


What did I do wrong?


This is my code:

FilesFromDirectory.mfd

Code:
<?xml version="1.0" encoding="UTF-8"?>
    <mapping xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://
    www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="mff.xsd" version="8"
    library="FilesFromDirectory">
        <implementations>
            <implementation language="java">
            <setting name="package" value="FilesFromDirectory.FilesFromDirectory.getFilesName"/>
            <setting name="class" value="FilesFromDirectory"/>
            </implementation>
        </implementations>
        <group name="string functions">
            <component name="filesfromdirectory">
                <sources>
                    <datapoint name="folder" type="xs:string"/>
                </sources>
                <targets>
                    <datapoint name="result" type="xs:string"/>
                </targets>
                <implementations>
                    <implementation language="java">
                        <function name="FilesFromDirectoryFunction"/>
                    </implementation>
                </implementations>
                <description>
                    <short>filesname = filesfromdirectory(folder)</short>
                    <long>Returns folder's filename.</long>
                </description>
            </component>
        </group>
    </mapping>



FilesFromDirectory.java:

Code:
public class FilesFromDirectory {

    public static String getFilesName(String folder) throws IOException{
        
        ArrayList<Path> listOfFiles = new ArrayList<Path>();
        
        Files.walk(Paths.get(folder)).forEach(filePath -> {
            if(Files.isRegularFile(filePath)){
                listOfFiles.add(filePath.getFileName());
            }
        });
        
        
        System.out.println("Numero File Trovati: " + listOfFiles.size());
        
        for(int i=0;i<listOfFiles.size();i++)
            System.out.println(listOfFiles.get(i));
        
        return listOfFiles.toString();        
    }
}

Users browsing this topic
guest

Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Use of the Altova User Forum(s) is governed by the Altova Terms of Use.