Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Immutable Object Graph Instantiation
Java
Branch: master
Pull request Compare This branch is 90 commits behind rafaeldff:master.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
buildLib
lib
src/br/com/caelum/iogi
test
testLib
.gitignore
.hgignore
README.textile
build.properties
build.xml
pom.xml

README.textile

What is Iogi

Iogi is a small library for instantiating objects (and graphs therof) in Java. It’s primary motivation is to help with
unmarshalling request parameters in Web applications.

The project was born as a spin-off of the VRaptor Web Framework. Many frameworks use OGLN
to construct objects, but, as it’s name atests, OGNL is most useful as a language for navigating object graphs. As such,
it is oriented around properties as getter/setter pairs. Iogi, on the other hand, is able to instantiate objects through
constructor parameters or setters. Iogi also supports dependency injection, so you can inject arbitrary objects (perhaps with
the help of a DI framework) into your domain objects as they are instantiated.

Sample code

Here are some sample classes that you might want to instantiate:

   public static class House {
        private Cat cat;

        public void setCat(final Cat cat) {
            this.cat = cat;
        }

        public Cat getCat() {
            return cat;
        }
    }

	public static class Cat {
        private Leg firstLeg;

        public void setFirstLeg(final Leg firstLeg) {
            this.firstLeg = firstLeg;
        }

        public Leg getFirstLeg() {
            return firstLeg;
        }
    }

    public static class Leg {
        private Integer id;

        public void setId(final Integer id) {
            this.id = id;
        }

    }

And here is how you can instantiate them with Iogi:

final Target<House> target = Target.create(House.class, "house");
final Parameter parameter = new Parameter("house.cat.firstLeg.id", "42");
final House house = iogi.instantiate(target, parameter);
assertThat(house.cat.firstLeg.id, is(equalTo(42)));


Something went wrong with that request. Please try again.