/** * @see javax.jcr.Value#getType() */ @Override public int getType() { return type.tag(); }
/** * Determine the array type which has this type as base type * @return array type with this type as base type * @throws IllegalStateException if {@code isArray} is true. */ public Type<?> getArrayType() { checkState(!isArray(), "Not a simply type"); return fromTag(tag, true); }
/** * @see Object#equals(Object) */ @Override public boolean equals(Object other) { if (other instanceof ValueImpl) { ValueImpl that = (ValueImpl) other; Type<?> thisType = this.type; if (thisType.isArray()) { thisType = thisType.getBaseType(); } Type<?> thatType = that.type; if (thatType.isArray()) { thatType = thatType.getBaseType(); } try { return thisType == thatType && Objects.equal( getValue(thatType, index), that.getValue(thatType, that.index)); } catch (RepositoryException e) { LOG.warn("Error while comparing values", e); return false; } } else { return false; } }
@Override public String getFieldNameFor(Type<?> propertyType) { for (String typeMapping : typeMappings) { String[] mapping = typeMapping.split("="); if (mapping.length == 2 && mapping[0] != null && mapping[1] != null) { Type<?> type = Type.fromString(mapping[0]); if (type != null && type.tag() == propertyType.tag()) { return mapping[1]; } } } return null; }
/** * Returns the numeric constant value of the type with the specified name. * * In contrast to {@link javax.jcr.PropertyType#valueFromName(String)} this method * requires all type names to be all upper case. * See also: OAK-294 and http://java.net/jira/browse/JSR_283-811 * * @param name the name of the property type. * @return the numeric constant value. * @throws IllegalStateException if {@code name} is not a valid property type name. */ public static int valueFromName(String name) { Type<?> type = Type.fromString(name); if (type.isArray()) { throw new IllegalStateException("unknown property type: " + name); } return type.tag(); }
@NotNull @Override public PropertyDefinition getDefinition( Tree parent, PropertyState property, boolean exactTypeMatch) throws RepositoryException { Type<?> type = property.getType(); EffectiveNodeType effective = getEffectiveNodeType(parent); return effective.getPropertyDefinition( property.getName(), type.isArray(), type.tag(), exactTypeMatch); }
private boolean addTypedOrderedFields(D doc, PropertyState property, String pname, PropertyDefinition pd) { // Ignore and warn if property multi-valued as not supported if (property.getType().isArray()) { log.warn( "[{}] Ignoring ordered property {} of type {} for path {} as multivalued ordered property not supported", getIndexName(), pname, Type.fromTag(property.getType().tag(), true), path); return false; } int tag = property.getType().tag(); int idxDefinedTag = pd.getType(); // Try converting type to the defined type in the index definition if (tag != idxDefinedTag) { log.debug( "[{}] Ordered property defined with type {} differs from property {} with type {} in " + "path {}", getIndexName(), Type.fromTag(idxDefinedTag, false), property.toString(), Type.fromTag(tag, false), path); tag = idxDefinedTag; } return indexTypeOrderedFields(doc, pname, tag, property, pd); }
@NotNull protected PropertyState createMultiState( String oakName, List<Value> values, Type<?> type) throws RepositoryException { if (values.isEmpty()) { Type<?> base = type.getBaseType(); if (base == UNDEFINED) { base = STRING; } return PropertyBuilder.array(base) .setName(oakName).getPropertyState(); } if (type == UNDEFINEDS) { type = Type.fromTag(values.get(0).getType(), true); } if (type == NAMES || type == PATHS) { Type<?> base = type.getBaseType(); List<String> strings = newArrayListWithCapacity(values.size()); for (Value value : values) { strings.add(getOakValue(value, base)); } return createProperty(oakName, strings, type); } else { return createProperty(oakName, values, type.tag()); } }
public void serialize(PropertyState property) { Type<?> type = property.getType(); if (!type.isArray()) { serialize(property, type, 0); } else { Type<?> base = type.getBaseType(); int count = property.count(); if (base == STRING || count > 0) { json.array(); for (int i = 0; i < count; i++) { serialize(property, base, i); } json.endArray(); } else { // type-safe encoding of an empty array json.value(TypeCodes.EMPTY_ARRAY + PropertyType.nameFromValue(type.tag())); } } }
private void assertTypeLessThan(Type<?> a, Type<?> b) { assertTrue(a.compareTo(b) < 0); assertTrue(b.compareTo(a) > 0); if (a.tag() > b.tag()) { fail("Types should be ordered by increasing tag value"); } if (b.tag() == a.tag() && a.isArray() && !b.isArray()) { fail("If their tag is the same, types should be ordered by multiplicity"); } }
Type.fromString(TreeUtil.getString(definition, JCR_REQUIREDTYPE)); if (requiredType != Type.UNDEFINED) { if (TreeUtil.getBoolean(definition, JCR_MULTIPLE)) { requiredType = requiredType.getArrayType(); ValueHelper.checkSupportedConversion(propertyState.getType().tag(), requiredType.tag()); propertyState = PropertyStates.convert(propertyState, requiredType);
/** * Create a new instance for building {@code PropertyState} instances * of the given {@code type}. * @param type type of the {@code PropertyState} instances to be built. * @throws IllegalArgumentException if {@code type.isArray()} is {@code true}. */ public PropertyBuilder(Type<T> type) { checkArgument(!type.isArray(), "type must not be array"); this.type = type; }
private boolean indexFacets(D doc, PropertyState property, String pname, PropertyDefinition pd) { int tag = property.getType().tag(); int idxDefinedTag = pd.getType(); // Try converting type to the defined type in the index definition if (tag != idxDefinedTag) { log.debug("[{}] Facet property defined with type {} differs from property {} with type {} in " + "path {}", getIndexName(), Type.fromTag(idxDefinedTag, false), property.toString(), Type.fromTag(tag, false), path); tag = idxDefinedTag; } return indexFacetProperty(doc, tag, property, pname); }
@NotNull protected PropertyState createSingleState( String oakName, Value value, Type<?> type) throws RepositoryException { if (type == UNDEFINED) { type = Type.fromTag(value.getType(), false); } if (type == NAME || type == PATH) { return createProperty(oakName, getOakValue(value, type), type); } else { return createProperty(oakName, value); } }
@Override public Converter getConverter(String value) { return Conversions.convert(value, type.getBaseType()); }
@Override public String toString() { StringBuilder builder = new StringBuilder("- "); if (getOakName() == null) { builder.append(RESIDUAL_NAME); } else { builder.append(getOakName()); } if (requiredType != PropertyType.STRING) { builder.append(" ("); builder.append(Type.fromTag(requiredType, false).toString()); builder.append(")"); } if (isAutoCreated()) { builder.append(" a"); } if (isProtected()) { builder.append(" p"); } if (isMandatory()) { builder.append(" m"); } if (getOnParentVersion() != OnParentVersionAction.COPY) { builder.append(" "); builder.append(OnParentVersionAction.nameFromValue(getOnParentVersion())); } return builder.toString(); }
@Override public boolean equals(Object object) { if (this == object) { return true; } else if (object instanceof PropertyTemplate) { PropertyTemplate that = (PropertyTemplate) object; return name.equals(that.name) && type.equals(that.type); } else { return false; } }
result = PropertyStates.createProperty("value", values.get(0), type); } else { type = type.getArrayType(); result = PropertyStates.createProperty("value", values, type);
@Nonnull @Override public PropertyDefinition getDefinition( Tree parent, PropertyState property, boolean exactTypeMatch) throws RepositoryException { Type<?> type = property.getType(); EffectiveNodeType effective = getEffectiveNodeType(parent); return effective.getPropertyDefinition( property.getName(), type.isArray(), type.tag(), exactTypeMatch); }
/** * Returns the numeric constant value of the type with the specified name. * * In contrast to {@link javax.jcr.PropertyType#valueFromName(String)} this method * requires all type names to be all upper case. * See also: OAK-294 and http://java.net/jira/browse/JSR_283-811 * * @param name the name of the property type. * @return the numeric constant value. * @throws IllegalStateException if {@code name} is not a valid property type name. */ public static int valueFromName(String name) { Type<?> type = Type.fromString(name); if (type.isArray()) { throw new IllegalStateException("unknown property type: " + name); } return type.tag(); }