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.

Profile: ale89e1
About
User Name: ale89e1
Forum Rank: Newbie
Real Name:
Location
Occupation:
Interests:
Gender: None Specified
Statistics
Joined: Tuesday, December 15, 2015
Last Visit: Tuesday, December 15, 2015 2:23:46 PM
Number of Posts: 1
[0.01% of all post / 0.00 posts per day]
Avatar
Last 10 Posts
Topic: Problem Creation Custom Function Java
Posted: Tuesday, December 15, 2015 10:22:15 AM
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();        
    }
}

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