public MappedClassBuilder addProperties() { String ns = mappedClass.getUID().getNamespace(); for (Field field : mappedClass.getJavaClass().getDeclaredFields()) { if (!handled.contains(field.getName())) { Predicate predicate = new PredicateImpl("", ns, field.getName(), false); MappedPredicate mappedPredicate = new MappedPredicate(ns, predicate, null); addMappedPath(field, Collections.singletonList(mappedPredicate), predicate); } } return this; }
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; }
public MappedPath(MappedProperty<?> property, List<MappedPredicate> predicatePath, boolean inherited) { this.mappedProperty = property; this.predicatePath = predicatePath; this.inherited = inherited; Path path = property.getAnnotation(Path.class); if (path != null) { this.ignoreInvalid = path.ignoreInvalid(); } else { if (predicatePath.size() > 0) { this.ignoreInvalid = predicatePath.get(0).ignoreInvalid(); } else { this.ignoreInvalid = false; } } validate(); }
public boolean isSimpleProperty() { return predicatePath.size() == 1 && !get(0).inv() && !get(0).includeInferred(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(mappedProperty.toString()); sb.append(" {"); boolean first = true; for (MappedPredicate predicate : predicatePath) { sb.append(' '); if (predicate.inv()) { sb.append('^'); } else if (!first) { sb.append('.'); } // sb.append(predicate.getReadableURI()); sb.append(predicate.toString()); first = false; } sb.append(" }"); return sb.toString(); }
directToType.put(mappedPath.get(0).getUID(), type);
if (path.isSimpleProperty()) { MappedPredicate mappedPredicate = path.get(0); UID predicate = mappedPredicate.getUID(); if (mappedPredicate.getContext() != null) { context = mappedPredicate.getContext(); } else { context = parentContext;
public boolean isInverse(int index) { return predicatePath.get(index).inv(); }
@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 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()); }
if (predPath.size() > 0) { MappedPredicate last = predPath.get(predPath.size() - 1); if (last.includeInferred()) { pathToContext.put(path, context = null); } else if (last.getContext() != null) { pathToContext.put(path, context = last.getContext()); } else if (configuration.isMapped(path.getType())) { MappedClass mappedClass = configuration.getMappedClass(path.getType()); UID c = pred.getContext() != null ? pred.getContext() : context; if (rdfPath != null && (i == predPath.size() - 1)) { pathNode = rdfPath; pathNode = var(varNames.next()); if (!pred.inv()) { filters.add(Blocks.pattern(parent, pred.getUID(), pathNode, c)); } else { filters.add(Blocks.pattern(pathNode, pred.getUID(), parent, c));
@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()); }
private MappedClassBuilder add(String propertyName, UID uid, boolean inv, Annotation... ann) { try { handled.add(propertyName); Field field = mappedClass.getJavaClass().getDeclaredField(propertyName); List<Annotation> annotations = new ArrayList<Annotation>(); Predicate predicate = new PredicateImpl("", uid.ns(), uid.ln(), inv); annotations.add(predicate); annotations.addAll(Arrays.asList(ann)); MappedPredicate mappedPredicate = new MappedPredicate(defaultNamespace, predicate, null); return addMappedPath(field, Collections.singletonList(mappedPredicate), annotations.toArray(new Annotation[annotations.size()])); } catch (SecurityException e) { throw new ConfigurationException(e); } catch (NoSuchFieldException e) { throw new ConfigurationException(e); } }
@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()); }
for (Predicate predicate : predicates) { predicatePath.add( new MappedPredicate(parentNs, predicate, first ? property.getName() : null)); first = false;
@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 ToString() throws SecurityException, NoSuchMethodException { Configuration configuration = new DefaultConfiguration(TEST.NS, MappedPathTest.class); MappedClass mappedClass = configuration.getMappedClass(MappedPathTest.class); MethodProperty property = new MethodProperty(MappedPathTest.class.getMethod("getProperty"), mappedClass); MappedPredicate predicate = new MappedPredicate(TEST.NS, new DummyPredicate(RDF.type), null); MappedPath path = new MappedPath(property, Collections.<MappedPredicate> singletonList(predicate), false); assertEquals("public java.lang.String com.mysema.rdfbean.object.MappedPathTest.getProperty() { http://www.w3.org/1999/02/22-rdf-syntax-ns#type }", path.toString()); }
@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()); }
MappedProperty<?> mappedProperty = mappedPath.getMappedProperty(); MappedPredicate mappedPredicate = mappedPath.get(0); UID puid = mappedPredicate.getUID(); String predicateNs = puid.ns();