directToType.put(mappedPath.get(0).getUID(), type);
private Set<NODE> findPathValues(ID resource, MappedPath path, int index, PropertiesMap properties, UID context) { MappedPredicate predicate = path.get(index); if (predicate.getContext() != null) { context = predicate.getContext(); } Set<NODE> values; if (!predicate.inv() && properties.getDirect() != null) { values = findValues(predicate.getUID(), properties.getDirect(), context, predicate.inv()); } else if (predicate.inv() && properties.getInverse() != null) { values = findValues(predicate.getUID(), properties.getInverse(), null, predicate.inv()); } else { values = findValues(resource, predicate.getUID(), predicate.inv(), predicate.includeInferred(), context); } if (path.size() > index + 1) { Set<NODE> nestedValues = new LinkedHashSet<NODE>(); for (NODE value : values) { if (value.isResource()) { nestedValues.addAll(findPathValues((ID) value, path, index + 1, new PropertiesMap(null, null), context)); } } return nestedValues; } return values; }
@Test public void VverrideWithinClass() { Configuration configuration = new DefaultConfiguration(TEST.NS, WithinClass.class); MappedClass mappedClass = configuration.getMappedClass(WithinClass.class); MappedPath path = mappedClass.getMappedPath("reference"); assertEquals(new UID(TEST.NS, "reference"), path.get(0).getUID()); MappedProperty<?> property = path.getMappedProperty(); assertTrue(property.isInjection()); }
@Test public void Namespaces() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Labeled.class) .addProperty("label", RDFS.label) .addProperty("comment", RDFS.comment); Configuration configuration = builder.build(); // labeled MappedClass labeled = configuration.getMappedClass(Labeled.class); MappedPath labeled_label = labeled.getMappedPath("label"); assertEquals(RDFS.label, labeled_label.getPredicatePath().get(0).getUID()); MappedPath labeled_comment = labeled.getMappedPath("comment"); assertEquals(RDFS.comment, labeled_comment.getPredicatePath().get(0).getUID()); }
@Test public void AddProperty() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Person.class) .addId("id") .addProperty("firstName") .addProperty("lastName", new UID(TEST.NS, "surName")) .addProperty("superior") .addProperty("department"); Configuration configuration = builder.build(); // person MappedClass person = configuration.getMappedClass(Person.class); MappedPath person_id = person.getMappedPath("id"); assertTrue(person_id.getPredicatePath().isEmpty()); MappedPath person_firstName = person.getMappedPath("firstName"); assertEquals(TEST.NS, person_firstName.getPredicatePath().get(0).getUID().ns()); assertEquals("firstName", person_firstName.getPredicatePath().get(0).getUID().ln()); MappedPath person_lastName = person.getMappedPath("lastName"); assertEquals("surName", person_lastName.getPredicatePath().get(0).getUID().ln()); MappedPath person_superior = person.getMappedPath("superior"); assertEquals("superior", person_superior.getPredicatePath().get(0).getUID().ln()); MappedPath person_department = person.getMappedPath("department"); assertEquals("department", person_department.getPredicatePath().get(0).getUID().ln()); }
if (path.isSimpleProperty()) { MappedPredicate mappedPredicate = path.get(0); UID predicate = mappedPredicate.getUID(); if (mappedPredicate.getContext() != null) { context = mappedPredicate.getContext();
@Test public void Inverse() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Company.class) .addId("id") .addProperty("departments", new UID(TEST.NS, "company"), true) .addProperties(); Configuration configuration = builder.build(); // company MappedClass company = configuration.getMappedClass(Company.class); MappedPath company_departments = company.getMappedPath("departments"); assertEquals(TEST.NS, company_departments.getPredicatePath().get(0).getUID().ns()); assertEquals("company", company_departments.getPredicatePath().get(0).getUID().ln()); assertTrue(company_departments.getPredicatePath().get(0).inv()); }
@Test public void Without_namespace() { ConfigurationBuilder builder = new ConfigurationBuilder(); for (Class<?> cl : Arrays.<Class<?>> asList(Person.class, Department.class, Company.class, Labeled.class)) { builder.addClass(cl).addProperties(); } Configuration configuration = builder.build(); MappedClass person = configuration.getMappedClass(Person.class); String ns = "java:com.mysema.rdfbean.object.ConfigurationBuilderTest.Person#"; assertEquals(new UID(ns, "Person"), person.getUID()); assertEquals(new UID(ns, "labeled"), person.getMappedPath("labeled").getPredicatePath().get(0).getUID()); }
@Test public void Container() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Company.class) .addId("id") .addProperty("departments", new UID(TEST.NS, "company"), ContainerType.SEQ) .addProperties(); Configuration configuration = builder.build(); // company MappedClass company = configuration.getMappedClass(Company.class); MappedPath company_departments = company.getMappedPath("departments"); assertEquals(TEST.NS, company_departments.getPredicatePath().get(0).getUID().ns()); assertEquals("company", company_departments.getPredicatePath().get(0).getUID().ln()); assertEquals(ContainerType.SEQ, company_departments.getMappedProperty().getContainerType()); }
assertTrue(person_id.getPredicatePath().isEmpty()); MappedPath person_firstName = person.getMappedPath("firstName"); assertEquals("firstName", person_firstName.getPredicatePath().get(0).getUID().ln()); MappedPath person_lastName = person.getMappedPath("lastName"); assertEquals("lastName", person_lastName.getPredicatePath().get(0).getUID().ln()); MappedPath person_superior = person.getMappedPath("superior"); assertEquals("superior", person_superior.getPredicatePath().get(0).getUID().ln()); MappedPath person_department = person.getMappedPath("department"); assertEquals("department", person_department.getPredicatePath().get(0).getUID().ln()); assertTrue(department_id.getPredicatePath().isEmpty()); MappedPath department_name = department.getMappedPath("name"); assertEquals("name", department_name.getPredicatePath().get(0).getUID().ln()); MappedPath department_company = department.getMappedPath("company"); assertEquals("company", department_company.getPredicatePath().get(0).getUID().ln()); assertTrue(company_id.getPredicatePath().isEmpty()); MappedPath company_name = company.getMappedPath("name"); assertEquals("name", company_name.getPredicatePath().get(0).getUID().ln());
MappedProperty<?> mappedProperty = mappedPath.getMappedProperty(); MappedPredicate mappedPredicate = mappedPath.get(0); UID puid = mappedPredicate.getUID(); String predicateNs = puid.ns();
@Test public void Localized() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Labeled.class) .addLocalized("label", RDFS.label) .addProperty("comment", RDFS.comment); Configuration configuration = builder.build(); // labeled MappedClass labeled = configuration.getMappedClass(Labeled.class); MappedPath labeled_label = labeled.getMappedPath("label"); assertTrue(labeled_label.getMappedProperty().isLocalized()); assertEquals(RDFS.label, labeled_label.getPredicatePath().get(0).getUID()); MappedPath labeled_comment = labeled.getMappedPath("comment"); assertFalse(labeled_comment.getMappedProperty().isLocalized()); assertEquals(RDFS.comment, labeled_comment.getPredicatePath().get(0).getUID()); }