IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#TechXchangePresenter
 View Only
  • 1.  [IS 6.5] How to create a java service that renames a file?

    Posted Wed March 04, 2009 09:29 PM

    Hello,

    I looked for this kind of service in WMPublic in vain. The only service that I found is “getFile”!

    What are the steps to follow to create this service? Is there anybody who had created a similar one? Thanks for help :wink:


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 2.  RE: [IS 6.5] How to create a java service that renames a file?

    Posted Thu March 05, 2009 08:04 PM

    Try this one.

    [highlight=java]
    // Specify pathname or parent/child. If both specified, pathname
    // takes precedence. Renames a file specified by pathname or
    // parent/child to the file specified by destpathname or
    // destparent/destchild. Returns true if rename succeeds.
    // Uses java.io.File to do the work.

    public static final void renameTo (IData pipeline)
    throws ServiceException
    {
    // — <<IS-START(renameTo)>> —
    // @sigtype java 3.5
    // [i] field:0:required pathname
    // [i] field:0:required parent
    // [i] field:0:required child
    // [i] field:0:required destpathname
    // [i] field:0:required destparent
    // [i] field:0:required destchild
    // [o] field:0:required result

    IDataCursor pipelineCursor = pipeline.getCursor();
    String pathname = IDataUtil.getString( pipelineCursor, “pathname” );
    String parent = IDataUtil.getString( pipelineCursor, “parent” );
    String child = IDataUtil.getString( pipelineCursor, “child” );
    String destpathname = IDataUtil.getString( pipelineCursor, “destpathname” );
    String destparent = IDataUtil.getString( pipelineCursor, “destparent” );
    String destchild = IDataUtil.getString( pipelineCursor, “destchild” );

    java.io.File f = null;
    java.io.File dest = null;
    if(pathname != null)
    {
    f = new java.io.File(pathname);
    }
    else if(parent != null && child != null)
    {
    f = new java.io.File(parent, child);
    }

    if(destpathname != null)
    {
    dest = new java.io.File(destpathname);
    }
    else if(destparent != null && destchild != null)
    {
    dest = new java.io.File(destparent, destchild);
    }

    IDataUtil.put( pipelineCursor, “result”, (f.renameTo(dest)?“true”:“false”));
    pipelineCursor.destroy();
    // — <> —
    }
    [/highlight]


    #Integration-Server-and-ESB
    #Flow-and-Java-services
    #webMethods


  • 3.  RE: [IS 6.5] How to create a java service that renames a file?

    Posted Fri March 06, 2009 08:04 AM

    Reamon,

    can you please tell what values shoul we pass in parent/child string?


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: [IS 6.5] How to create a java service that renames a file?

    Posted Fri March 06, 2009 05:32 PM

    Pathname: fully-qualified path, such as c:\mydir\myfiile.txt or /application/etc/myfile; can also simply be directory, if you’re renaming a directory

    Parent: directory containing the element to be renamed
    Child: element (file or directory) within the parent to be renamed

    If the pathname vars are used, the parent/child vars are ignored (they can null/not set).

    Take a look at the Javadoc for the java.io.File constructors that are used for additional information.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB