Examples

Constants for namespace and context:

DEMO.java
public class DEMO {
    public static final String NS = "http://www.mysema.com/rdfbean/demo#";
    public static final String CONTEXT = "http://www.mysema.com/rdfbean/demo";
}

Abstract base class for parties with id and searchable abstract property for display name:

Party.java
@ClassMapping(ns=DEMO.NS)
public abstract class Party {
    
    @Id
    private String id;

    public String getId() {
        return id;
    }

    @Predicate
    public abstract String getDisplayName();

}

A Person class with immutable firstName and lastName. It uses property injection through constructor parameters to enforce that it's state is always valid. The abstract method getDisplayName() is overridden to get a natural representation of persons display name. Notice that displayName is persisted and kept update for searches but never actually loaded into beans. A person may be an employee of one company.

Person.java
@ClassMapping(ns=DEMO.NS)
public class Person extends Party {

    @Predicate
    @Required
    private String firstName;

    @Predicate
    @Required
    private String lastName;

    @Predicate
    private Company company;

    public Person(
            @InjectProperty("firstName") String firstName, 
            @InjectProperty("lastName")  String lastName
            ) {
        this.firstName = Assert.hasText(firstName);
        this.lastName = Assert.hasText(lastName);
    }

    public String getFirstName() {
        return firstName;
    }
    
    public void setFirstName(String name) {
        this.firstName = name;
    }

    @Override
    public String getDisplayName() {
        return "" + firstName + " " + lastName;
    }

    public Company getCompany() {
        return company;
    }

    void setCompany(Company company) {
        this.company = company;
    }

}

A company has an officialName that is also used as it's displayName. Public Java Bean empty constructor is provided for Company and the required officialName is mapped using both getter and setter. Mapping of a single property may be splitted between field, getter and setter. If field is annotated, then property's access type is field. Otherwise RDFBean uses getter and setter for property access.

Company.java
@ClassMapping(ns=DEMO.NS)
public class Company extends Party {
    
    private String officialName;
    
    @Predicate(ln="company", inv=true)
    private Set<Person> employees = new LinkedHashSet<Person>();

    public Company() {
        // Java Bean constructor
    }

    @Predicate
    public String getOfficialName() {
        return officialName;
    }

    @Required
    public void setOfficialName(String officialName) {
        this.officialName = Assert.hasText(officialName);
    }

    public Set<Person> getEmployees() {
        return employees;
    }

    public void addEmployee(Person employee) {
        employee.setCompany(this);
        this.employees.add(employee);
    }

    @Override
    public String getDisplayName() {
        return officialName;
    }

}

The easiest way to configure RDFBean is through package annotation @MappedClasses that defines a set of mapped classes:

class-info.java
@Context(DEMO.CONTEXT)
@MappedClasses({
    Party.class,
    Person.class,
    Company.class
})
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.