Git Product home page Git Product logo

jfm's Introduction

Java Filesystem Mapper

Build Status Codacy Badge Maintainability Release

What is it?

This is a library used to map filesystem resources to Java objects and vice-versa.

Features

  • mapping filesystem resources to Java objects,
  • mapping Java objects to filesystem resources,
  • registering custom type handlers.

Example

Interface:

@FilesystemResource
interface PersonInfo {
    @Read
    @Path("first-name")
    String getFirstName();

    @Read
    @Path("last-name")
    String getLastName();
}

Filesystem to Java mapping

Filesystem:

persons
|- person1
|  |- first-name
|  \- last-name
\- person2
   |- first-name
   \- last-name

The following code maps the above filesystem into instances of PersonInfo.

Path root = Paths.get("persons");
FilesystemMapper fsmapper = FilesystemMapper.instance();

FilesystemMapperTarget person1Target = fsmapper.getTarget(root.resolve("person1"));
FilesystemMapperTarget person2Target = fsmapper.getTarget(root.resolve("person2"));

PersonInfo person1 = person1Target.proxy(PersonInfo.class);
PersonInfo person2 = person2Target.proxy(PersonInfo.class);

// print contents of persons/person1/first-name
System.out.println(person1.getFirstName());
// print contents of persons/person1/last-name
System.out.println(person1.getLastName());

// print contents of persons/person2/first-name
System.out.println(person2.getFirstName());
// print contents of persons/person2/last-name
System.out.println(person2.getLastName());

Java to filesystem mapping

Implementation:

class PersonInfoImpl implements PersonInfo {
    public String getFirstName() {
        return "John";
    }

    public String getLastName() {
        return "Smith";
    }
}

The following code maps the above implementation into the filesystem.

Path root = Paths.get("person");
FilesystemMapper fsmapper = FilesystemMapper.instance();

FilesystemMapperTarget personTarget = fsmapper.getTarget(root);

PersonInfo person = new PersonInfoImpl();
personTarget.mount(person);

The resulting filesystem:

person
|- first-name
\- last-name

The contents of person/first-name and person/last-name should be John and Smith respectively.

jfm's People

Contributors

kjarosh avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.