org.modeshape.jcr.value.Property Maven / Gradle / Ivy
/*
* ModeShape (http://www.modeshape.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.modeshape.jcr.value;
import java.io.Serializable;
import java.util.Iterator;
import org.modeshape.common.annotation.Immutable;
import org.modeshape.jcr.api.value.DateTime;
/**
* Representation of a property consisting of a name and value(s). Note that this property is immutable, meaning that the property
* values may not be changed through this interface.
*
* This class is designed to be used with the {@link ValueFactories} interface and the particular {@link ValueFactory} that
* corresponds to the type of value you'd like to use. The ValueFactory
will then return the values (if no type
* conversion is required) or will convert the values using the appropriate conversion algorithm.
*
*
* The following example shows how to obtain the {@link String} representations of the {@link #getValues() property values}:
*
*
* ValueFactories valueFactories = ...
* Property property = ...
* Iterator<String> iter = valueFactories.getStringFactory().create(property.getValues());
* while ( iter.hasNext() ) {
* System.out.println(iter.next());
* }
*
*
* Meanwhile, the {@link ValueFactories#getLongFactory() long value factory} converts the values to long
, the
* {@link ValueFactories#getDateFactory() date value factory} converts the values to {@link DateTime} instances, and so on.
*
*
* This technique is much better and far safer than casting the values. It is possible that some Property instances contain
* heterogeneous values, so casting may not always work. Also, this technique guarantees that the values are properly converted if
* the type is not what you expected.
*
*/
@Immutable
public interface Property extends Iterable