Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessor.java (working copy) @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +/** + * PropertyAccessor interface, classes implementing this interface to convert one + * {@link Property} to the specified target type (and vice versa). + * + * @param the target property type + * @since 2.6 + */ +public interface PropertyAccessor { + + /** + * Extract the input {@code Property} value and converts it to {@code T}. + * + * @param property the property from where the value has to be extracted + * @return the input property value + * @throws ValueFormatException if the property cannot be converted to {@code T} + * @throws RepositoryException if something goes wrong while accessing to the {@code Property} + */ + T get(Property property) throws ValueFormatException, RepositoryException; + + /** + * Set the input value in the target property. + * + * @param value the value of {@code T} type to be set in the target property + * @param target the property where setting the value + * @throws ValueFormatException if the input value cannot be set in the property + * @throws RepositoryException if something goes wrong while accessing to the {@code Property} + */ + void set(T value, Property target) throws ValueFormatException, RepositoryException; + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessorBinder.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessorBinder.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessorBinder.java (working copy) @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties; + +/** + * @since 2.6 + */ +public interface PropertyAccessorBinder { + + void with(PropertyAccessor propertyValueManipulator); + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessorBinder.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessorNotFoundException.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessorNotFoundException.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessorNotFoundException.java (working copy) @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties; + +import static java.lang.String.format; + +/** + * Exception thrown where a {@link PropertyAccessor} is not found + * where trying to set/get a {@code Property} value. + * + * @since 2.6 + */ +public final class PropertyAccessorNotFoundException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + private final Class targetType; + + /** + * Creates a new {@code PropertyAccessorNotFoundException} instance. + * + * @param targetType the property value type for which a {@link PropertyAccessor} doesn't exist + */ + public PropertyAccessorNotFoundException(Class targetType) { + super(format("Converter for type %s not set in the registry.", targetType.getName())); + this.targetType = targetType; + } + + /** + * Returns the property value type for which a {@link PropertyAccessor} doesn't exist. + * + * @return the targetType the property value type for which a {@link PropertyAccessor} doesn't exist + */ + public Class getTargetType() { + return targetType; + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessorNotFoundException.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessors.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessors.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessors.java (working copy) @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties; + +import javax.jcr.Property; + +/** + * A {@link PropertyAccessor} registry, implemented with an intuitive EDSL. + * + * @since 2.6 + */ +public interface PropertyAccessors { + + /** + * Configures a {@link PropertyAccessor} for the input target type. + * + * Null target types are not accepted. + * + * @param the {@code PropertyAccessor} type + * @param targetType the type used to bind the {@code PropertyAccessor} + * @return the EDSL chain ring to bind the {@code PropertyAccessor} + */ + PropertyAccessorBinder handle(Class targetType); + + /** + * Lookup the registry if a {@link PropertyAccessor} is bound for the input type; + * the method throws a {@link PropertyAccessorNotFoundException} if the {@link PropertyAccessor} + * does not exist. + * + * Null target types are not accepted. + * + * @param the looked-up {@link PropertyAccessor} type + * @param targetType the type used to lookup the {@link PropertyAccessor} + * @return the {@code PropertyAccessor} bound to the input type if any, + * throws {@link PropertyAccessorNotFoundException} otherwise + */ + PropertyAccessor lookup(Class targetType); + + /** + * Retrieves the input {@code Property} value. + * + * Null properties are not accepted. + * + * @param property the {@code Property} where extracting the value + * @return the EDSL chain ring to convert the {@code Property} value + */ + TargetTypeInvoker get(Property property); + + /** + * Allows setting the input value to a {@code Property}. + * + * Null values are not accepted. + * + * @param the {@code Property} value type + * @param value the value to be set in the {@code Property} + * @return the EDSL chain ring to set the input value to a {@code Property} + */ + TargetPropertyInvoker set(T value); + +} \ No newline at end of file Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/PropertyAccessors.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/TargetPropertyInvoker.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/TargetPropertyInvoker.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/TargetPropertyInvoker.java (working copy) @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +/** + * Set a value to the target {@code Property}. + * + * @param the target property type + * @since 2.6 + */ +public interface TargetPropertyInvoker { + + /** + * Sets the value in the target {@code Property}. + * + * @param property the property where setting the + * @throws ValueFormatException if the input value cannot be set in the property + * @throws RepositoryException if something goes wrong while accessing to the {@code Property} + */ + void to(Property property) throws ValueFormatException, RepositoryException; + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/TargetPropertyInvoker.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/TargetTypeInvoker.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/TargetTypeInvoker.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/TargetTypeInvoker.java (working copy) @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties; + +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +/** + * Extract a {@code Property} value in the specified type. + * + * @since 2.6 + */ +public interface TargetTypeInvoker { + + /** + * Extracts the {@code Property} value and converts to T. + * + * @param the target property type + * @param targetType the target property class type + * @return the converted property value + * @throws ValueFormatException if the property cannot be converted to {@code T} + * @throws RepositoryException if something goes wrong while accessing to the {@code Property} + */ + T to(Class targetType) throws ValueFormatException, RepositoryException; + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/TargetTypeInvoker.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BigDecimalAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BigDecimalAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BigDecimalAccessor.java (working copy) @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import java.math.BigDecimal; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class BigDecimalAccessor implements PropertyAccessor { + + @Override + public BigDecimal get(Property property) throws ValueFormatException, RepositoryException { + return property.getDecimal(); + } + + @Override + public void set(BigDecimal value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BigDecimalAccessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BinaryAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BinaryAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BinaryAccessor.java (working copy) @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Binary; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class BinaryAccessor implements PropertyAccessor { + + @Override + public Binary get(Property property) throws ValueFormatException, RepositoryException { + return property.getBinary(); + } + + @Override + public void set(Binary value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BinaryAccessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BooleanAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BooleanAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BooleanAccessor.java (working copy) @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class BooleanAccessor implements PropertyAccessor { + + @Override + public Boolean get(Property property) throws ValueFormatException, RepositoryException { + return property.getBoolean(); + } + + @Override + public void set(Boolean value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/BooleanAccessor.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/CalendarAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/CalendarAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/CalendarAccessor.java (working copy) @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import java.util.Calendar; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class CalendarAccessor implements PropertyAccessor { + + @Override + public Calendar get(Property property) throws ValueFormatException, RepositoryException { + return property.getDate(); + } + + @Override + public void set(Calendar value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/CalendarAccessor.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultPropertyAccessorBinder.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultPropertyAccessorBinder.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultPropertyAccessorBinder.java (working copy) @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import java.util.concurrent.ConcurrentMap; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; +import org.apache.jackrabbit.commons.properties.PropertyAccessorBinder; + +/** + * @since 2.6 + */ +final class DefaultPropertyAccessorBinder + implements PropertyAccessorBinder { + + private final ConcurrentMap, PropertyAccessor> accessorsRegistry; + + private final Class targetType; + + public DefaultPropertyAccessorBinder(final ConcurrentMap, PropertyAccessor> accessorsRegistry, + final Class targetType) { + this.accessorsRegistry = accessorsRegistry; + this.targetType = targetType; + } + + @Override + public void with(final PropertyAccessor propertyConverter) { + if (propertyConverter == null) { + throw new IllegalArgumentException("Argument 'propertyConverter' must be not null."); + } + accessorsRegistry.putIfAbsent(targetType, propertyConverter); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultPropertyAccessorBinder.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultPropertyAccessors.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultPropertyAccessors.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultPropertyAccessors.java (working copy) @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import java.math.BigDecimal; +import java.util.Calendar; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; + +import javax.jcr.Binary; +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.Value; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; +import org.apache.jackrabbit.commons.properties.PropertyAccessorBinder; +import org.apache.jackrabbit.commons.properties.PropertyAccessorNotFoundException; +import org.apache.jackrabbit.commons.properties.PropertyAccessors; +import org.apache.jackrabbit.commons.properties.TargetPropertyInvoker; +import org.apache.jackrabbit.commons.properties.TargetTypeInvoker; + +/** + * Default {@code PropertyAccessors} implementation. + * + * @since 2.6 + */ +public final class DefaultPropertyAccessors implements PropertyAccessors { + + private final ConcurrentMap, PropertyAccessor> accessorsRegistry = new ConcurrentHashMap, PropertyAccessor>(); + + /** + * Creates a new {@code PropertyAccessors} instance; + */ + public DefaultPropertyAccessors() { + handle(Binary.class).with(new BinaryAccessor()); + + // long + PropertyAccessor longConverter = new LongAccessor(); + handle(long.class).with(longConverter); + handle(Long.class).with(longConverter); + + // double + PropertyAccessor doubleConverter = new DoubleAccessor(); + handle(double.class).with(doubleConverter); + handle(Double.class).with(doubleConverter); + + handle(BigDecimal.class).with(new BigDecimalAccessor()); + + handle(Calendar.class).with(new CalendarAccessor()); + + // boolean + PropertyAccessor booleanConverter = new BooleanAccessor(); + handle(boolean.class).with(booleanConverter); + handle(Boolean.class).with(booleanConverter); + + handle(String.class).with(new StringAccessor()); + + handle(Value.class).with(new ValueAccessor()); + handle(Value[].class).with(new ValueArrayAccessor()); + + handle(Node.class).with(new NodeAccessor()); + } + + @Override + public PropertyAccessorBinder handle( final Class targetType ) { + if (targetType == null) { + throw new IllegalArgumentException("Argument 'targetType' must be not null."); + } + return new DefaultPropertyAccessorBinder(accessorsRegistry, targetType); + } + + @Override + public PropertyAccessor lookup(Class targetType) { + Class typeFound = null; + + // try if the registry already contains the input type + if (accessorsRegistry.containsKey(targetType)) { + typeFound = targetType; + } else if (!targetType.isPrimitive() && !targetType.isInterface()) { // try understand by implementing interfaces + Class superType = targetType.getSuperclass(); + + // search within the implementing interfaces + for (Class interfaceType : targetType.getInterfaces()) { + if (accessorsRegistry.containsKey(interfaceType)) { + typeFound = interfaceType; + break; + } + } + + // last chance: traverse the hierarchy + while (Object.class != superType || typeFound == null) { + if (accessorsRegistry.containsKey(superType)) { + typeFound = superType; + } + superType = superType.getSuperclass(); + } + } + + if (typeFound == null) { + throw new PropertyAccessorNotFoundException(targetType); + } + + @SuppressWarnings("unchecked") // type driven by the input class + PropertyAccessor propertyAccessor = (PropertyAccessor) accessorsRegistry.get(typeFound); + return propertyAccessor; + } + + @Override + public TargetTypeInvoker get(Property property) { + if (property == null) { + throw new IllegalArgumentException("Argument 'property' must be not null."); + } + return new DefaultTargetTypeInvoker(this, property); + } + + @Override + public TargetPropertyInvoker set(T value) { + if (value == null) { + throw new IllegalArgumentException("Argument 'value' must be not null."); + } + return new DefaultTargetPropertyInvoker(value, this); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultPropertyAccessors.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultTargetPropertyInvoker.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultTargetPropertyInvoker.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultTargetPropertyInvoker.java (working copy) @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessors; +import org.apache.jackrabbit.commons.properties.TargetPropertyInvoker; + +/** + * @since 2.6 + */ +final class DefaultTargetPropertyInvoker implements TargetPropertyInvoker { + + private final T value; + + private final PropertyAccessors propertyAccessors; + + public DefaultTargetPropertyInvoker(final T value, final PropertyAccessors propertyAccessors) { + this.value = value; + this.propertyAccessors = propertyAccessors; + } + + @Override + public void to(Property target) throws ValueFormatException, RepositoryException { + if (target == null) { + throw new IllegalArgumentException("Argument 'target' must be not null."); + } + + @SuppressWarnings("unchecked") // T is of type Class + Class targetType = (Class) value.getClass(); + propertyAccessors.lookup(targetType).set(value, target); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultTargetPropertyInvoker.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultTargetTypeInvoker.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultTargetTypeInvoker.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultTargetTypeInvoker.java (working copy) @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessors; +import org.apache.jackrabbit.commons.properties.TargetTypeInvoker; + +/** + * @since 2.6 + */ +final class DefaultTargetTypeInvoker implements TargetTypeInvoker { + + private final PropertyAccessors propertiesConverter; + + private final Property property; + + public DefaultTargetTypeInvoker(final PropertyAccessors propertyAccessors, final Property property) { + this.propertiesConverter = propertyAccessors; + this.property = property; + } + + @Override + public T to(Class targetType) throws ValueFormatException, RepositoryException { + return propertiesConverter.lookup(targetType).get(property); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DefaultTargetTypeInvoker.java ___________________________________________________________________ Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DoubleAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DoubleAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DoubleAccessor.java (working copy) @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class DoubleAccessor implements PropertyAccessor { + + @Override + public Double get(Property property) throws ValueFormatException, RepositoryException { + return property.getDouble(); + } + + @Override + public void set(Double value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/DoubleAccessor.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/LongAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/LongAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/LongAccessor.java (working copy) @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class LongAccessor implements PropertyAccessor { + + @Override + public Long get(Property property) throws ValueFormatException, RepositoryException { + return property.getLong(); + } + + @Override + public void set(Long value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/LongAccessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/NodeAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/NodeAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/NodeAccessor.java (working copy) @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class NodeAccessor implements PropertyAccessor { + + @Override + public Node get(Property property) throws ValueFormatException, RepositoryException { + return property.getNode(); + } + + @Override + public void set(Node value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/NodeAccessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/StringAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/StringAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/StringAccessor.java (working copy) @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class StringAccessor implements PropertyAccessor { + + @Override + public String get(Property property) throws ValueFormatException, RepositoryException { + return property.getString(); + } + + @Override + public void set(String value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/StringAccessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/ValueAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/ValueAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/ValueAccessor.java (working copy) @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Value; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class ValueAccessor implements PropertyAccessor { + + @Override + public Value get(Property property) throws ValueFormatException, RepositoryException { + return property.getValue(); + } + + @Override + public void set(Value value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/ValueAccessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/ValueArrayAccessor.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/ValueArrayAccessor.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/ValueArrayAccessor.java (working copy) @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties.accessors; + +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Value; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.PropertyAccessor; + +/** + * @since 2.6 + */ +final class ValueArrayAccessor implements PropertyAccessor { + + @Override + public Value[] get(Property property) throws ValueFormatException, RepositoryException { + return property.getValues(); + } + + @Override + public void set(Value[] value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value); + } + +} Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/ValueArrayAccessor.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/package-info.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/package-info.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/package-info.java (working copy) @@ -0,0 +1,23 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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. + */ + +/** + * Default {@code org.apache.jackrabbit.commons.properties} implementations. + * + * @since 2.6 + */ +package org.apache.jackrabbit.commons.properties.accessors; Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/accessors/package-info.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Index: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/package-info.java =================================================================== --- jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/package-info.java (revision 0) +++ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/package-info.java (working copy) @@ -0,0 +1,18 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ +@aQute.bnd.annotation.Version("2.6") +package org.apache.jackrabbit.commons.properties; Property changes on: jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/properties/package-info.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Index: jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/properties/MockProperty.java =================================================================== --- jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/properties/MockProperty.java (revision 0) +++ jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/properties/MockProperty.java (working copy) @@ -0,0 +1,340 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties; + +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.Calendar; + +import javax.jcr.AccessDeniedException; +import javax.jcr.Binary; +import javax.jcr.InvalidItemStateException; +import javax.jcr.Item; +import javax.jcr.ItemExistsException; +import javax.jcr.ItemNotFoundException; +import javax.jcr.ItemVisitor; +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.ReferentialIntegrityException; +import javax.jcr.RepositoryException; +import javax.jcr.Session; +import javax.jcr.Value; +import javax.jcr.ValueFormatException; +import javax.jcr.lock.LockException; +import javax.jcr.nodetype.ConstraintViolationException; +import javax.jcr.nodetype.NoSuchNodeTypeException; +import javax.jcr.nodetype.PropertyDefinition; +import javax.jcr.version.VersionException; + +final class MockProperty implements Property { + + private Node aNode; + + private Value aValue; + + private Value[] aValueArray; + + private Binary binary; + + private long aLong; + + private double aDouble; + + private BigDecimal bigDecimal; + + private Calendar calendar; + + private boolean aBoolean; + + private String aString; + + @Override + public String getPath() throws RepositoryException { + // not needed + return null; + } + + @Override + public String getName() throws RepositoryException { + // not needed + return null; + } + + @Override + public Item getAncestor(int depth) throws ItemNotFoundException, + AccessDeniedException, RepositoryException { + // not needed + return null; + } + + @Override + public Node getParent() throws ItemNotFoundException, + AccessDeniedException, RepositoryException { + // not needed + return null; + } + + @Override + public int getDepth() throws RepositoryException { + // not needed + return 0; + } + + @Override + public Session getSession() throws RepositoryException { + // not needed + return null; + } + + @Override + public boolean isNode() { + // not needed + return false; + } + + @Override + public boolean isNew() { + // not needed + return false; + } + + @Override + public boolean isModified() { + // not needed + return false; + } + + @Override + public boolean isSame(Item otherItem) throws RepositoryException { + // not needed + return false; + } + + @Override + public void accept(ItemVisitor visitor) throws RepositoryException { + // not needed + + } + + @Override + public void save() throws AccessDeniedException, ItemExistsException, + ConstraintViolationException, InvalidItemStateException, + ReferentialIntegrityException, VersionException, LockException, + NoSuchNodeTypeException, RepositoryException { + // not needed + + } + + @Override + public void refresh(boolean keepChanges) throws InvalidItemStateException, + RepositoryException { + // not needed + + } + + @Override + public void remove() throws VersionException, LockException, + ConstraintViolationException, AccessDeniedException, + RepositoryException { + // not needed + + } + + @Override + public void setValue(Value value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + aValue = value; + } + + @Override + public void setValue(Value[] values) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + aValueArray = values; + } + + @Override + public void setValue(String value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + aString = value; + } + + @Override + public void setValue(String[] values) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + // not needed + + } + + @Override + public void setValue(InputStream value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + // not needed + + } + + @Override + public void setValue(Binary value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + binary = value; + } + + @Override + public void setValue(long value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + aLong = value; + } + + @Override + public void setValue(double value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + aDouble = value; + } + + @Override + public void setValue(BigDecimal value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + bigDecimal = value; + } + + @Override + public void setValue(Calendar value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + calendar = value; + } + + @Override + public void setValue(boolean value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + aBoolean = value; + } + + @Override + public void setValue(Node value) throws ValueFormatException, + VersionException, LockException, ConstraintViolationException, + RepositoryException { + aNode = value; + } + + @Override + public Value getValue() throws ValueFormatException, RepositoryException { + return aValue; + } + + @Override + public Value[] getValues() throws ValueFormatException, RepositoryException { + return aValueArray; + } + + @Override + public String getString() throws ValueFormatException, RepositoryException { + return aString; + } + + @Override + public InputStream getStream() throws ValueFormatException, + RepositoryException { + // not needed + return null; + } + + @Override + public Binary getBinary() throws ValueFormatException, RepositoryException { + return binary; + } + + @Override + public long getLong() throws ValueFormatException, RepositoryException { + return aLong; + } + + @Override + public double getDouble() throws ValueFormatException, RepositoryException { + return aDouble; + } + + @Override + public BigDecimal getDecimal() throws ValueFormatException, + RepositoryException { + return bigDecimal; + } + + @Override + public Calendar getDate() throws ValueFormatException, RepositoryException { + return calendar; + } + + @Override + public boolean getBoolean() throws ValueFormatException, + RepositoryException { + return aBoolean; + } + + @Override + public Node getNode() throws ItemNotFoundException, ValueFormatException, + RepositoryException { + return aNode; + } + + @Override + public Property getProperty() throws ItemNotFoundException, + ValueFormatException, RepositoryException { + // not needed + return null; + } + + @Override + public long getLength() throws ValueFormatException, RepositoryException { + // not needed + return 0; + } + + @Override + public long[] getLengths() throws ValueFormatException, RepositoryException { + // not needed + return null; + } + + @Override + public PropertyDefinition getDefinition() throws RepositoryException { + // not needed + return null; + } + + @Override + public int getType() throws RepositoryException { + // not needed + return 0; + } + + @Override + public boolean isMultiple() throws RepositoryException { + // not needed + return false; + } + +} Property changes on: jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/properties/MockProperty.java ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Index: jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/properties/PropertiesAccessorTestCase.java =================================================================== --- jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/properties/PropertiesAccessorTestCase.java (revision 0) +++ jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/properties/PropertiesAccessorTestCase.java (working copy) @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with this + * work for additional information regarding copyright ownership. The ASF + * licenses this file to You 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.apache.jackrabbit.commons.properties; + +import static java.lang.String.format; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.math.BigDecimal; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Calendar; +import java.util.GregorianCalendar; + +import javax.jcr.Binary; +import javax.jcr.Node; +import javax.jcr.Property; +import javax.jcr.RepositoryException; +import javax.jcr.Value; +import javax.jcr.ValueFormatException; + +import org.apache.jackrabbit.commons.properties.accessors.DefaultPropertyAccessors; +import org.apache.jackrabbit.value.BinaryImpl; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public final class PropertiesAccessorTestCase { + + private PropertyAccessors propertiesAccessor; + + @Before + public void setUp() { + propertiesAccessor = new DefaultPropertyAccessors(); + } + + @After + public void tearDown() { + propertiesAccessor = null; + } + + @Test + public void binaryAccessorLookup() { + accessorExists(Binary.class); + } + + @Test + public void primitiveLongAccessorLookup() { + accessorExists(long.class); + } + + @Test + public void longAccessorLookup() { + accessorExists(Long.class); + } + + @Test + public void primitiveDoubleAccessorLookup() { + accessorExists(double.class); + } + + @Test + public void doubleAccessorLookup() { + accessorExists(Double.class); + } + + @Test + public void bigDecimalAccessorLookup() { + accessorExists(BigDecimal.class); + } + + @Test + public void calendarAccessorLookup() { + accessorExists(Calendar.class); + } + + @Test + public void primitiveBooleanAccessorLookup() { + accessorExists(boolean.class); + } + + @Test + public void booleanAccessorLookup() { + accessorExists(Boolean.class); + } + + @Test + public void stringAccessorLookup() { + accessorExists(String.class); + } + + @Test + public void valueAccessorLookup() { + accessorExists(Value.class); + } + + @Test + public void valueArrayAccessorLookup() { + accessorExists(Value[].class); + } + + @Test + public void nodeAccessorLookup() { + accessorExists(Node.class); + } + + @Test + public void registerURIAccessorAndVerifySetAndGetValue() throws ValueFormatException, RepositoryException { + propertiesAccessor.handle(URI.class).with(new PropertyAccessor() { + + @Override + public void set(URI value, Property target) throws ValueFormatException, RepositoryException { + target.setValue(value.toString()); + } + + @Override + public URI get(Property property) throws ValueFormatException, RepositoryException { + try { + return new URI(property.getString()); + } catch (URISyntaxException e) { + throw new ValueFormatException(e); + } + } + + }); + + accessorExists(URI.class); + assertSetAndGet(URI.create("http://jackrabbit.apache.org/")); + } + + private void accessorExists(Class targetType) { + try { + propertiesAccessor.lookup(targetType); + } catch (PropertyAccessorNotFoundException cnfe) { + fail(cnfe.getMessage()); + } + } + + @Test + public void binarySetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(new BinaryImpl(new byte[]{})); + } + + @Test + public void primitiveLongSetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(1L); + } + + @Test + public void longSetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(Long.valueOf(1L)); + } + + @Test + public void primitiveDoubleSetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(1.5D); + } + + @Test + public void doubleSetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(Double.valueOf(1.5D)); + } + + @Test + public void bigDecimalSetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(new BigDecimal(123)); + } + + @Test + public void calendarSetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(new GregorianCalendar()); + } + + @Test + public void primitiveBooleanSetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(true); + } + + @Test + public void booleanSetAndGet() throws ValueFormatException, RepositoryException { + assertSetAndGet(Boolean.TRUE); + } + + private void assertSetAndGet(T expected) throws ValueFormatException, RepositoryException { + Property property = new MockProperty(); + + propertiesAccessor.set(expected).to(property); + + @SuppressWarnings("unchecked") // T is of type Class + Class valueType = (Class) expected.getClass(); + T actual = propertiesAccessor.get(property).to(valueType); + + assertTrue(format("Expected <%s> but found <%s>", expected, actual), expected == actual || expected.equals(actual)); + } + +} Property changes on: jackrabbit-jcr-commons/src/test/java/org/apache/jackrabbit/commons/properties/PropertiesAccessorTestCase.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +Date Author Id Revision HeadURL \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property