/** * {@inheritDoc} * * @see Location#getUuid() */ @Override public UUID getUuid() { Property property = getIdProperties().get(0); // this is fast if (ModeShapeLexicon.UUID.equals(property.getName())) { Object value = property.getFirstValue(); if (value instanceof UUID) return (UUID)value; if (value instanceof String) return UUID.fromString((String)value); } return null; }
/** * {@inheritDoc} * * @see Location#getUuid() */ @Override public UUID getUuid() { Property property = getIdProperties().get(0); // this is fast if (ModeShapeLexicon.UUID.equals(property.getName())) { Object value = property.getFirstValue(); if (value instanceof UUID) return (UUID)value; if (value instanceof String) return UUID.fromString((String)value); } return null; }
private UUID uuidFor( Location location ) { UUID uuid = location.getUuid(); if (uuid != null) return uuid; Property idProp = location.getIdProperty(JcrLexicon.UUID); if (idProp == null) return null; return (UUID)idProp.getFirstValue(); }
/** * Get the first UUID that is in one of the {@link #getIdProperties() identification properties}. * * @return the UUID for this location, or null if there is no such identification property */ public UUID getUuid() { Property property = getIdProperty(ModeShapeLexicon.UUID); if (property != null && !property.isEmpty()) { Object value = property.getFirstValue(); if (value instanceof UUID) return (UUID)value; } return null; }
/** * Get the first UUID that is in one of the {@link #getIdProperties() identification properties}. * * @return the UUID for this location, or null if there is no such identification property */ @Override public UUID getUuid() { Property property = getIdProperty(ModeShapeLexicon.UUID); if (property != null && !property.isEmpty()) { Object value = property.getFirstValue(); if (value instanceof UUID) return (UUID)value; } return null; }
protected void print( WorkspaceType workspace, NodeType node, int level ) { StringBuilder sb = new StringBuilder(); sb.append(StringUtil.createString(' ', level * 2)); sb.append(readable(node.getName())).append(" (").append(node.getUuid()).append(") {"); boolean first = true; for (Property property : node.getProperties().values()) { if (first) first = false; else sb.append(','); sb.append(readable(property.getName())).append('='); if (property.isMultiple()) sb.append(property.getValuesAsArray()); else sb.append(readable(property.getFirstValue())); } sb.append('}'); System.out.println(sb); for (NodeType child : getChildren(workspace, node)) { print(workspace, child, level + 1); } }
protected void print( WorkspaceType workspace, NodeType node, int level ) { StringBuilder sb = new StringBuilder(); sb.append(StringUtil.createString(' ', level * 2)); sb.append(readable(node.getName())).append(" (").append(node.getUuid()).append(") {"); boolean first = true; for (Property property : node.getProperties().values()) { if (first) first = false; else sb.append(','); sb.append(readable(property.getName())).append('='); if (property.isMultiple()) sb.append(property.getValuesAsArray()); else sb.append(readable(property.getFirstValue())); } sb.append('}'); System.out.println(sb); for (NodeType child : getChildren(workspace, node)) { print(workspace, child, level + 1); } }
/** * {@inheritDoc} * * @see Location#with(Property) */ @Override public Location with( Property idProperty ) { if (idProperty == null || idProperty.isEmpty()) return this; if (ModeShapeLexicon.UUID.equals(idProperty.getName())) { if (idProperty.isSingle() && uuid.equals(idProperty.getFirstValue())) return this; return Location.create(getPath(), idProperty); } return Location.create(getPath(), getIdProperties().get(0), idProperty); }
/** * Create a location defined by a single identification property. * * @param idProperty the identification property * @return a new <code>Location</code> with no path and the given identification property. * @throws IllegalArgumentException if <code>idProperty</code> is null */ public static Location create( Property idProperty ) { CheckArg.isNotNull(idProperty, "idProperty"); if (ModeShapeLexicon.UUID.equals(idProperty.getName()) && idProperty.isSingle()) { Object uuid = idProperty.getFirstValue(); assert uuid instanceof UUID; return new LocationWithUuid((UUID)uuid); } return new LocationWithProperty(idProperty); }
@Override public String getDescription() { Property property = getProperty(ModeShapeLexicon.DESCRIPTION); if (property != null && !property.isEmpty()) { return context.getValueFactories().getStringFactory().create(property.getFirstValue()); } return null; }
protected long longValue( Object value ) { if (value instanceof Property) value = ((Property)value).getFirstValue(); return context.getValueFactories().getLongFactory().create(value); }
protected String string( Object value ) { if (value instanceof Property) value = ((Property)value).getFirstValue(); return context.getValueFactories().getStringFactory().create(value); }
protected DateTime date( Object value ) { if (value instanceof Property) value = ((Property)value).getFirstValue(); return context.getValueFactories().getDateFactory().create(value); }
protected Name name( Object value ) { if (value instanceof Property) value = ((Property)value).getFirstValue(); return context.getValueFactories().getNameFactory().create(value); }
private String stringValueOf( Node node, Name propertyName ) { Property property = node.getProperty(propertyName); if (property == null) { // Check whether the property exists with no namespace ... property = node.getProperty(context.getValueFactories().getNameFactory().create(propertyName.getLocalName())); if (property == null) return null; } if (property.isEmpty()) return null; return context.getValueFactories().getStringFactory().create(property.getFirstValue()); }
protected String readUriFor( String prefix ) { // Read the store ... try { PathFactory pathFactory = store.getContext().getValueFactories().getPathFactory(); Path pathToNamespaceNode = pathFactory.create(parentOfNamespaceNodes, prefix); Property uri = store.getProperty(uriPropertyName).on(pathToNamespaceNode); // Get the URI property value ... ValueFactory<String> stringFactory = store.getContext().getValueFactories().getStringFactory(); return stringFactory.create(uri.getFirstValue()); } catch (PathNotFoundException e) { // Nothing to read return null; } }
private UUID uuidFor( Node node ) { UUID uuid = null; if (node.getLocation().getUuid() != null) { uuid = node.getLocation().getUuid(); } if (uuid == null && (node.getProperty(JcrLexicon.UUID) != null)) { uuid = (UUID)node.getProperty(JcrLexicon.UUID).getFirstValue(); } return uuid; }
@Test public void shouldSetPropertyWithString() { String path1 = "/a"; String prop1_name = "prop1"; String value_1 = "blue"; output.setProperty(path1, prop1_name, value_1); String path2 = "/a/b"; String prop2_name = "prop2"; String value_2 = "red"; output.setProperty(path2, prop2_name, value_2); output.close(); Subgraph result = graph.getSubgraphOfDepth(10).at("/"); String v1 = (String)result.getNode(path1).getProperty(prop1_name).getFirstValue(); assertThat(v1, is(value_1)); String v2 = (String)result.getNode(path2).getProperty(prop2_name).getFirstValue(); assertThat(v2, is(value_2)); assertNull(result.getNode("/c")); }
@Test public void shouldSetReferenceWithString() { String path1 = "/a"; String prop1_name = "prop1"; String value_1 = "blue"; output.setReference(path1, prop1_name, value_1); String path2 = "/a/b"; String prop2_name = "prop2"; String value_2 = "red"; output.setReference(path2, prop2_name, value_2); output.close(); Subgraph result = graph.getSubgraphOfDepth(10).at("/"); String v1 = (String)result.getNode(path1).getProperty(prop1_name).getFirstValue(); assertThat(v1, is(value_1)); String v2 = (String)result.getNode(path2).getProperty(prop2_name).getFirstValue(); assertThat(v2, is(value_2)); assertNull(result.getNode("/c")); }
@Test public void shouldSetPropertyWithPath() { Path path1 = createPath("/a"); Name prop1_name = createName("prop1"); String value_1 = "blue"; output.setProperty(path1, prop1_name, value_1); Path path2 = createPath("/a/b"); Name prop2_name = createName("prop2"); String value_2 = "red"; output.setProperty(path2, prop2_name, value_2); output.close(); Subgraph result = graph.getSubgraphOfDepth(10).at("/"); String v1 = (String)result.getNode(path1).getProperty(prop1_name).getFirstValue(); assertThat(v1, is(value_1)); String v2 = (String)result.getNode(path2).getProperty(prop2_name).getFirstValue(); assertThat(v2, is(value_2)); assertNull(result.getNode("/c")); } }