/** * {@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); }
assert property1 != null; assert property2 != null; assert property1.getName().equals(property2.getName()); if (property1.isEmpty()) return property2; if (property2.isEmpty()) return property1; if (property1.isSingle() && property2.isSingle()) { Object value1 = property1.getValues().next(); Object value2 = property2.getValues().next(); if (removeDuplicates && ValueComparators.OBJECT_COMPARATOR.compare(value1, value2) == 0) return property1; return factory.create(property1.getName(), new Object[] {value1, value2}); Iterator<?> valueIterator = new DualIterator(property1.getValues(), property2.getValues()); return factory.create(property1.getName(), valueIterator); Object[] values = new Object[property1.size() + property2.size()]; int index = 0; for (Object property1Value : property1) { values[index++] = property1Value; assert index == property1.size(); values = newValues; return factory.create(property1.getName(), values);
private String getPropertyString( Property property ) { // Surround property value in double quotes so final property looks like: // color = "blue" (single valued property) // colors = ["blue", "red", "green"] (multi-valued property) StringBuilder sb = new StringBuilder(); sb.append(getContext().getValueFactories().getStringFactory().create(property.getName())); sb.append(" = "); if (property.isEmpty()) { sb.append("null"); } else if (property.isSingle()) { String valueStr = getContext().getValueFactories().getStringFactory().create(property.getValues().next()); sb.append('\"').append(valueStr).append('\"'); } else { sb.append('['); boolean first = true; for (Object value : property.getValuesAsArray()) { if (first) first = false; else sb.append(","); String valueStr = getContext().getValueFactories().getStringFactory().create(value); sb.append('\"').append(valueStr).append('\"'); } if (property.isMultiple()) sb.append(']'); } return sb.toString(); } }
/** * 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; }
/** * {@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#with(Property) */ @Override public Location with( Property newIdProperty ) { if (newIdProperty == null || newIdProperty.isEmpty()) return this; List<Property> newIdProperties; assert hasIdProperties(); newIdProperties = new ArrayList<Property>(idProperties.size() + 1); for (Property property : idProperties) { if (!newIdProperty.getName().equals(property.getName())) newIdProperties.add(property); } newIdProperties.add(newIdProperty); newIdProperties = Collections.unmodifiableList(newIdProperties); return create(newIdProperties); }
/** * 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); }
/** * Get the name of the property. * * @return the propert name; never null */ public Name getName() { return property.getName(); }
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); } }
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(); }
Property desired ) { if (desired.size() == 0) { Iterator<?> actualValues = actual.getValues(); while (actualValues.hasNext()) { Object value = actualValues.next(); Iterator<?> desiredValues = desired.getValues(); while (desiredValues.hasNext()) { Object value = desiredValues.next(); batch.set(actual.getName()).on(path).to(unionedValues).and();
String classname = stringFactory.create(classnameProperty.getValues().next()); String[] classpath = classpathProperty == null ? new String[] {} : stringFactory.create(classpathProperty.getValuesAsArray()); ClassLoader classLoader = context.getClassLoader(classpath); Object instance = null; Property property = entry.getValue(); String javaPropertyName = propertyName.getLocalName(); if (property.isEmpty()) continue; if (paramType.isArray()) { if (paramType.getComponentType().isArray()) continue; // array of array, which we don't do Object[] values = factory.create(property.getValuesAsArray()); value = factory.create(property.getFirstValue());
if (sourceNameProperty != null && !sourceNameProperty.isEmpty()) { sourceName = strings.create(sourceNameProperty.getFirstValue()); if (workspaceNameProperty != null && !workspaceNameProperty.isEmpty()) { workspaceName = strings.create(workspaceNameProperty.getFirstValue()); if (projectionRulesProperty != null && !projectionRulesProperty.isEmpty()) { String[] projectionRuleStrs = strings.create(projectionRulesProperty.getValuesAsArray()); if (projectionRuleStrs != null && projectionRuleStrs.length != 0) { projectionRules = projectionParser.rulesFromStrings(context, projectionRuleStrs); if (readOnlyProperty != null && !readOnlyProperty.isEmpty()) { readOnly = context.getValueFactories().getBooleanFactory().create(readOnlyProperty.getFirstValue());
/** * {@inheritDoc} * * @see GraphSession.Operations#materializeProperties(org.modeshape.graph.Node, GraphSession.Node) */ public void materializeProperties( org.modeshape.graph.Node persistentNode, Node<Payload, PropertyPayload> node ) { // Create the map of property info objects ... Map<Name, PropertyInfo<PropertyPayload>> properties = new HashMap<Name, PropertyInfo<PropertyPayload>>(); for (Property property : persistentNode.getProperties()) { Name propertyName = property.getName(); PropertyInfo<PropertyPayload> info = new PropertyInfo<PropertyPayload>(property, property.isMultiple(), Status.UNCHANGED, null); properties.put(propertyName, info); } // Set only the children ... node.loadedWith(properties); }
/** * {@inheritDoc} */ @Override public boolean equals( Object obj ) { if (this == obj) return true; if (obj instanceof Property) { Property that = (Property)obj; if (!this.getName().equals(that.getName())) return false; if (this.size() != that.size()) return false; Iterator<?> thisIter = iterator(); Iterator<?> thatIter = that.iterator(); while (thisIter.hasNext()) { // && thatIter.hasNext() Object thisValue = thisIter.next(); Object thatValue = thatIter.next(); if (ValueComparators.OBJECT_COMPARATOR.compare(thisValue, thatValue) != 0) return false; } return true; } return false; }
/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { Object[] values = property().getValuesAsArray(); String workspaceName = this.workspaceName != null ? "'" + this.workspaceName + "'" : "default"; return "set " + printable(on()) + " (in " + workspaceName + " workspace) the property '" + property().getName() + "' to " + (values == null ? "null" : Arrays.asList(values).toString()); }
/** * {@inheritDoc} * * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(getName()); // if (payload != null) sb.append(payload); if (property.isSingle()) { sb.append(" with value "); } else { sb.append(" with values "); } sb.append(Arrays.asList(property.getValuesAsArray())); return sb.toString(); } }
protected void assertInitialData() { // Now check that the data is all there ... Subgraph subgraph = graph.getSubgraphOfDepth(10).at("/"); assertThat(subgraph, is(notNullValue())); assertThat(subgraph.getNode("/a").getProperty("propB").isSingle(), is(true)); assertThat(subgraph.getNode("/a").getProperty("propB").getFirstValue(), is((Object)"valueB")); assertThat(subgraph.getNode("/a").getProperty("propC").isSingle(), is(true)); assertThat(subgraph.getNode("/a").getProperty("propC").getFirstValue(), is((Object)"valueC")); assertThat(subgraph.getNode("/a/b").getProperty("propB").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b").getProperty("propB").getFirstValue(), is((Object)"valueB")); assertThat(subgraph.getNode("/a/b").getProperty("propC").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b").getProperty("propC").getFirstValue(), is((Object)"valueC")); assertThat(subgraph.getNode("/a/b/c").getProperty("propB").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b/c").getProperty("propB").getFirstValue(), is((Object)"valueB")); assertThat(subgraph.getNode("/a/b/c").getProperty("propC").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b/c").getProperty("propC").getFirstValue(), is((Object)"valueC")); assertThat(subgraph.getNode("/a/b/d").getProperty("propB").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b/d").getProperty("propB").getFirstValue(), is((Object)"valueB")); assertThat(subgraph.getNode("/a/b/d").getProperty("propC").isSingle(), is(true)); assertThat(subgraph.getNode("/a/b/d").getProperty("propC").getFirstValue(), is((Object)"valueC")); assertThat(subgraph.getNode("/a").getChildrenSegments().size(), is(1)); assertThat(subgraph.getNode("/a").getChildrenSegments().get(0), is(segment("b"))); assertThat(subgraph.getNode("/a/b").getChildrenSegments().size(), is(2)); assertThat(subgraph.getNode("/a/b").getChildrenSegments().get(0), is(segment("c"))); assertThat(subgraph.getNode("/a/b").getChildrenSegments().get(1), is(segment("d"))); assertThat(subgraph.getNode("/a/b/c").getChildrenSegments().isEmpty(), is(true)); assertThat(subgraph.getNode("/a/b/d").getChildrenSegments().isEmpty(), is(true)); }