@Nullable private MappedPath getPathMapping(MappedClass mappedClass, Constructor<?> constructor, int parameterIndex, String property) { boolean reference = mappedClass.hasProperty(property); ConstructorParameter constructorParameter = new ConstructorParameter(constructor, parameterIndex, mappedClass, property, reference); if (mappedClass.hasProperty(property)) { return mappedClass.getMappedPath(property); } else { List<MappedPredicate> path = getPredicatePath(mappedClass.getClassNs(), constructorParameter); return getMappedPath(constructorParameter, path); } }
private MappedPath getMappedPath(Path<?> path) { PathMetadata<?> md = path.getMetadata(); if (path.getMetadata().getPathType() != PathType.PROPERTY) { md = md.getParent().getMetadata(); } MappedClass mc = configuration.getMappedClass(md.getParent().getType()); return mc.getMappedPath(md.getElement().toString()); }
@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()); }
MappedPath person_id = person.getMappedPath("id"); 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()); MappedPath department_id = department.getMappedPath("id"); 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()); MappedPath company_id = company.getMappedPath("id"); assertTrue(company_id.getPredicatePath().isEmpty()); MappedPath company_name = company.getMappedPath("name"); assertEquals("name", company_name.getPredicatePath().get(0).getUID().ln());
@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()); }
@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 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()); }
@Test public void Mixin() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.addClass(TEST.NS, Person.class) .addMixin("labeled"); Configuration configuration = builder.build(); // labeled MappedClass person = configuration.getMappedClass(Person.class); MappedPath person_labeled = person.getMappedPath("labeled"); assertTrue(person_labeled.getMappedProperty().isMixin()); }
@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()); }
MappedPath path = mappedClass.getMappedPath("parent"); assertEquals(Parent.class, path.getMappedProperty().getType()); assertFalse(path.isInherited()); path = mappedClass.getMappedPath("property"); assertEquals(Object.class, path.getMappedProperty().getType()); assertFalse(path.getMappedProperty().isRequired()); assertFalse(path.isInherited()); path = mappedClass.getMappedPath("children"); assertEquals(Parent.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited()); path = mappedClass.getMappedPath("parentProperty"); assertFalse(path.isInherited()); path = mappedClass.getMappedPath("parent"); assertEquals(FirstChild.class, path.getMappedProperty().getType()); assertFalse(path.isInherited()); path = mappedClass.getMappedPath("property"); assertEquals(Integer.class, path.getMappedProperty().getType()); assertFalse(path.getMappedProperty().isRequired()); assertFalse(path.isInherited()); path = mappedClass.getMappedPath("children"); assertEquals(FirstChild.class, path.getMappedProperty().getComponentType()); assertFalse(path.isInherited());
@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()); }