You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stanbol.apache.org by sf...@apache.org on 2010/12/12 16:13:37 UTC
svn commit: r1044832 [13/14] - in /incubator/stanbol/trunk/rick:
indexing/dbPedia/src/main/java/eu/iksproject/rick/indexing/dbPedia/cli/
indexing/genericRdf/src/main/java/eu/iksproject/rick/indexing/rdf/
indexing/geonames/src/main/java/eu/iksproject/ri...
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/IndexValueFactory.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/IndexValueFactory.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/IndexValueFactory.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/IndexValueFactory.java Sun Dec 12 15:13:35 2010
@@ -35,793 +35,793 @@ import eu.iksproject.rick.yard.solr.defa
* @author Rupert Westenthaler
*/
public class IndexValueFactory {
-
- private static Logger log = LoggerFactory.getLogger(IndexValueFactory.class);
- private static ValueFactory valueFactory = InMemoryValueFactory.getInstance();
- private static IndexValueFactory instance = new IndexValueFactory();
- static {
- //register the default converters
- instance.registerConverter(new BigDecimalConverter());
- instance.registerConverter(new BigIntegerConverter());
- instance.registerConverter(new DateConverter());
- instance.registerConverter(new BooleanConverter());
- instance.registerConverter(new DoubleConverter());
- instance.registerConverter(new FloatConverter());
- instance.registerConverter(new IntegerConverter());
- instance.registerConverter(new LongConverter());
- instance.registerConverter(new ReferenceConverter(valueFactory));
- instance.registerConverter(new StringConverter());
- instance.registerConverter(new TextConverter(valueFactory));
- }
- /**
- * Get a <code>IndexValueFactory</code>.
- *
- * @return the <code>IndexValueFactory</code> instance
- */
- public static IndexValueFactory getInstance() {
- return instance;
- }
-
- //TODO: add support for IndexTypeConverter
-// private Map<IndexType,TypeConverter<?>> indexTypeConverters =
-// new HashMap<IndexType, TypeConverter<?>>();
- /**
- * Holds the java class to {@link TypeConverter} mapping for all converters
- * registered for a Java Class.<p>
- * NOTE: this implementation distinguishes between classed and interfaces,
- * because for Classes a simple get lookup in the Map can be used while for
- * Interfaces we need to Iterate over the entries of the Map and check with
- * {@link Class#isAssignableFrom(Class)}.
- */
- private Map<Class<?>,TypeConverter<?>> javaClassConverters =
- Collections.synchronizedMap(new HashMap<Class<?>, TypeConverter<?>>());
- /**
- * Holds the java interface to {@link TypeConverter} mappings for all
- * converters registered for a Java Interface<p>
- * NOTE: this implementation distinguishes between classed and interfaces,
- * because for Classes a simple get lookup in the Map can be used while for
- * Interfaces we need to Iterate over the entries of the Map and check with
- * {@link Class#isAssignableFrom(Class)}.
- */
- private Map<Class<?>,TypeConverter<?>> javaInterfaceConverters =
- new HashMap<Class<?>, TypeConverter<?>>();
- /**
- * Registers a converter to this factory. Note that only one converter per
- * java type can be registered
- * @see TypeConverter#getJavaType()
- * @param converter the converter to be registered
- */
- public void registerConverter(TypeConverter<?> converter){
- if(converter == null){ return;}
- Class<?> javaType = converter.getJavaType();
- if(javaType.isInterface()){
- //NOTE: To ensure thread save iterations over Entries of this Map
- //create new map instance, add to the new instance and replace reference
- // ... i know this is slow, but such calls are very uncommon
- Map<Class<?>,TypeConverter<?>> javaInterfaceConverters =
- new HashMap<Class<?>,TypeConverter<?>>(this.javaInterfaceConverters);
- javaInterfaceConverters.put(javaType,converter);
- //TODO: add support for IndexTypeConverter
- this.javaInterfaceConverters = javaInterfaceConverters;
- } else {
- //there are no Iterations over this Map!
- javaClassConverters.put(javaType,converter);
- }
- }
- /**
- * Removes the converter for the parsed java type
- * @param type the java type
- * @return the removed converter or <code>null</code> if none was registered
- * for the parsed type.
- */
- @SuppressWarnings("unchecked")
- public <T> TypeConverter<T> removeConverter(Class<T> type){
- if(type == null){ return null;}
- TypeConverter<T> converter;
- if(type.isInterface()){
- if(javaInterfaceConverters.containsKey(type)){
- //create new map instance, remove to the converter and replace reference
- // ... i know this is slow, but such calls are very uncommon
- Map<Class<?>,TypeConverter<?>> javaInterfaceConverters =
- new HashMap<Class<?>,TypeConverter<?>>(this.javaInterfaceConverters);
- converter = (TypeConverter<T>)javaInterfaceConverters.remove(type);
- this.javaInterfaceConverters = javaInterfaceConverters;
- } else {
- converter = null;
- }
- } else {
- converter = (TypeConverter<T>)javaClassConverters.remove(type);
- }
- return converter;
- }
- /**
- * Creates the value as used to index the parsed object
- *
- * @param value the value to be indexed
- * @return the index representation of the parsed value
- * @throws NoConverterException thrown if <code>value</code> is of an invalid type
- * @throws IllegalArgumentException if the parsed value is null
- */
- @SuppressWarnings("unchecked")
- public IndexValue createIndexValue(Object value) throws NoConverterException,IllegalArgumentException {
- if(value == null){
- throw new IllegalArgumentException("Parameter value MUST NOT be NULL!");
- }
- //first try to get the class and find a converter registered for a class
- TypeConverter<Object> converter = (TypeConverter<Object>)javaClassConverters.get(value.getClass());
- if(converter != null){
- return converter.createIndexValue(value);
- }
- //if not successful we need still to search for converters registered for interfaces
- for(Entry<Class<?>, TypeConverter<?>> entry : javaInterfaceConverters.entrySet()){
- if(entry.getKey().isAssignableFrom(value.getClass())){
- return ((TypeConverter<Object>)entry.getValue()).createIndexValue(value);
- }
- }
- throw new NoConverterException(value.getClass());
- }
-
- /**
- * Converts a IndexValue instance to an instance of the specified class
- *
- * @param <T>
- * @param type the <code>Class</code> of the returned object
- * @param indexValue the index value instance
- * @return a java object representing the value of the index value
- * @throws NoConverterException thrown if <code>type</code> is unsupported
- * @throws UnsupportedIndexTypeException if the {@link IndexDataType} of the parsed
- * {@link IndexValue} is not supported by the registered converter
- * @throws IllegalArgumentException if any of the two parameter is <code>null</code>
- */
- public <T> T createValue(Class<T> type, IndexValue indexValue)
- throws NoConverterException,UnsupportedIndexTypeException,IllegalArgumentException {
- return createValue(type, indexValue.getType(),indexValue.getType(), indexValue.getLanguage());
- }
- /**
- * Converts a IndexValue instance to an instance of the specified class
- *
- * @param <T>
- * @param javaType the requested java type
- * @param indexType the index type
- * @param indexValue the value in the index
- * @param language the language of the value in the index
- * @return a java object representing the value of the index value
- * @throws NoConverterException thrown if <code>type</code> is unsupported
- * @throws UnsupportedIndexTypeException if the {@link IndexDataType} of the parsed
- * {@link IndexValue} is not supported by the registered converter
- * @throws IllegalArgumentException if any of the two parameter is <code>null</code>
- */
- @SuppressWarnings("unchecked")
- public <T> T createValue(Class<T> javaType, IndexDataType indexType, Object indexValue,String language)
- throws NoConverterException,UnsupportedIndexTypeException,IllegalArgumentException {
- if(javaType == null){
- throw new IllegalArgumentException("Parameter Class<T> type MUST NOT be NULL");
- }
- if(indexValue == null){
- throw new IllegalArgumentException("Parameter IndexValue MUST NOT be NULL");
- }
- //search interface converter map if the parsed type is an interface
- TypeConverter<T> converter = (TypeConverter<T>)(javaType.isInterface()?javaInterfaceConverters.get(javaType):javaClassConverters.get(javaType));
- if(converter != null){
- return converter.createObject(indexType,indexValue,language);
- } else {
- throw new NoConverterException(javaType);
- }
- }
-
- //TODO: add support for IndexTypeConverter
-// /**
-// * Converts a IndexValue instance to an java object. The type of the java
-// * object.
-// * @param indexValue the index value instance
-// * @return a java object representing the value of the index value
-// * @throws NoConverterException if no converter for the index value is registered
-// */
-// public Object createObject(IndexValue indexValue) throws NoConverterException {
-//
-// }
-
- /*
- * ==== Internal Classes for the default converter Implementations ====
- */
-
- public static class DateConverter implements TypeConverter<Date> {
- private static final DateTimeFormatter XML_DATE_TIME_FORMAT = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
- private static final DateTimeFormatter XML_DATE_TIME_FORMAT_noMillis = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC);
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DATE.getIndexType();
-
- @Override
- public IndexValue createIndexValue(Date value) {
- return new IndexValue(XML_DATE_TIME_FORMAT.print(value.getTime()),INDEX_TYPE);
- }
-
- @Override
- public Date createObject(IndexValue indexValue) {
- if(indexValue == null){
- return null;
- }
- return createObject(indexValue.getType(), indexValue, indexValue.getLanguage());
- }
- @Override
- public Class<Date> getJavaType() {
- return Date.class;
- }
- @Override
- public IndexDataType getIndexType(){
- return INDEX_TYPE;
- }
-
- @Override
- public Date createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(value == null){
- return null;
- }
- if(type == null || !type.equals(INDEX_TYPE)){
- throw new UnsupportedIndexTypeException(this,type);
- }
- if(value instanceof Date){
- return (Date) value;
- } else if(value instanceof Calendar){
- return ((Calendar)value).getTime();
- } else {
- DateTime date;
- try {
- //NOTE: Solr only support UTC ... so we need to change the Timezone
- date = XML_DATE_TIME_FORMAT.parseDateTime(value.toString());
- } catch (IllegalArgumentException e) {
- try {
- date = XML_DATE_TIME_FORMAT_noMillis.parseDateTime(value.toString());
- } catch (IllegalArgumentException e1) {
- log.warn("Unable to parse Date/Time for Value "+value.toString()+" (use ISO date format (milliseconds optional))! -> no Date Mapping added!",e1);
- throw new UnsupportedValueException(this, type, value,e);
- }
- }
- return date.toDate();
- }
- }
-
- }
-
- public static class BooleanConverter implements TypeConverter<Boolean> {
-
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.BOOLEAN.getIndexType();
-
- @Override
- public IndexValue createIndexValue(Boolean value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.toString(), INDEX_TYPE);
- }
-
- @Override
- public Boolean createObject(IndexValue value) {
- if(value == null){
- return null;
- }
- return createObject(value.getType(), value.getValue(), value.getLanguage());
- }
- @Override
- public Class<Boolean> getJavaType() {
- return Boolean.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
-
- @Override
- public Boolean createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(value == null){
- return null;
- }
- if(type == null || !type.equals(INDEX_TYPE)){
- throw new UnsupportedIndexTypeException(this,type);
- }
- if(value instanceof Boolean){
- return (Boolean)value;
- } else {
- return Boolean.valueOf(value.toString());
- }
- }
- }
-
- public static class StringConverter implements TypeConverter<String> {
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.STR.getIndexType();
- private boolean acceptAllIndexTypes;
- public final boolean isAcceptAllIndexTypes() {
- return acceptAllIndexTypes;
- }
- public final void setAcceptAllIndexTypes(boolean acceptAllIndexTypes) {
- this.acceptAllIndexTypes = acceptAllIndexTypes;
- }
- public StringConverter() {
- this(true);
- }
- public StringConverter(boolean acceptAllIndexTypes){
- this.acceptAllIndexTypes = acceptAllIndexTypes;
- }
- @Override
- public IndexValue createIndexValue(String value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value, INDEX_TYPE);
- }
-
- @Override
- public String createObject(IndexValue value) {
- if(value == null){
- return null;
- }
- //for now accept any IndexValue regardless of type
-// if(!value.getType().equals(INDEX_TYPE)){
-// new UnsupportedIndexTypeException(this, value);
-// }
- return value.getValue();
- }
- @Override
- public Class<String> getJavaType() {
- return String.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
- @Override
- public String createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- return value!=null?value.toString():null;
- }
- }
-
- public static class IntegerConverter implements TypeConverter<Integer> {
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.INT.getIndexType();
- private boolean acceptLong;
- public final boolean isAcceptLong() {
- return acceptLong;
- }
- public final void setAcceptLong(boolean acceptLong) {
- this.acceptLong = acceptLong;
- }
- public IntegerConverter() {
- this(true);
- }
- public IntegerConverter(boolean acceptLongIndexType){
- this.acceptLong = acceptLongIndexType;
- }
- @Override
- public IndexValue createIndexValue(Integer value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.toString(), INDEX_TYPE);
- }
-
- @Override
- public Integer createObject(IndexValue value) {
- if(value == null){
- return null;
- }
- return createObject(value.getType(), value.getValue(), value.getLanguage());
- }
- @Override
- public Class<Integer> getJavaType() {
- // TODO Auto-generated method stub
- return Integer.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
- @Override
- public Integer createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(type == null){
- throw new UnsupportedIndexTypeException(this,type);
- }
- if(value == null){
- return null;
- }
- if(type.equals(INDEX_TYPE)){
- if(value instanceof Integer){
- return (Integer)value;
- } else {
- try {
- return new Integer(value.toString());
- } catch (NumberFormatException e) {
- throw new UnsupportedValueException(this, type, value, e);
- }
- }
- } else if(acceptLong && type.equals(IndexDataTypeEnum.LONG.getIndexType())){
- long longValue;
- if(value instanceof Long){
- longValue = ((Long)value).longValue();
- } else {
- try {
- longValue = Long.parseLong(value.toString());
- } catch (NumberFormatException e) {
- throw new UnsupportedValueException(this, type, value, e);
- }
- }
- if(Integer.MAX_VALUE >= longValue && Integer.MIN_VALUE <= longValue){
- return new Integer((int)longValue);
- } else {
- //parsed long value outside of the int range
- throw new UnsupportedValueException(this, type, value,
- new IllegalStateException("Unable to convert LONG Value to Integer, because the value is outside of the Integer Range!"));
- }
- } else {
- throw new UnsupportedIndexTypeException(this,type);
- }
- }
- }
-
- public static class LongConverter implements TypeConverter<Long> {
-
- public static final IndexDataType LONG_TYPE = IndexDataTypeEnum.LONG.getIndexType();
- private static final IndexDataType INT_TYPE = IndexDataTypeEnum.INT.getIndexType();
-
- @Override
- public IndexValue createIndexValue(Long value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.toString(), LONG_TYPE);
- }
-
- @Override
- public Long createObject(IndexValue value) {
- if(value == null){
- return null;
- }
- return createObject(value.getType(), value.getValue(), value.getLanguage());
- }
- @Override
- public Class<Long> getJavaType() {
- return Long.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return LONG_TYPE;
- }
-
- @Override
- public Long createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(type == null){
- throw new UnsupportedIndexTypeException(this, type);
- }
- if(value == null){
- return null;
- }
- if(type.equals(LONG_TYPE) || type.equals(INT_TYPE)){
- if(value instanceof Long){
- return (Long) value;
- } else if(value instanceof Integer){
- return ((Integer)value).longValue();
- } else {
- try {
- return new Long(value.toString());
- } catch (NumberFormatException e) {
- throw new UnsupportedValueException(this, type, value, e);
- }
- }
- } else {
- throw new UnsupportedIndexTypeException(this, type);
- }
- }
- }
-
- public static class DoubleConverter implements TypeConverter<Double> {
-
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DOUBLE.getIndexType();
- private static Set<IndexDataType> SUPPORTED = new HashSet<IndexDataType>(
- Arrays.asList(
- IndexDataTypeEnum.FLOAT.getIndexType(),
- IndexDataTypeEnum.INT.getIndexType(),
- IndexDataTypeEnum.LONG.getIndexType(),
- INDEX_TYPE));
-
- @Override
- public IndexValue createIndexValue(Double value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.toString(), INDEX_TYPE);
- }
-
- @Override
- public Double createObject(IndexValue value) {
- if(value == null){
- return null;
- }
- return createObject(value.getType(), value.getValue(), value.getLanguage());
- }
- @Override
- public Class<Double> getJavaType() {
- return Double.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
-
- @Override
- public Double createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(value == null){
- return null;
- }
- if(SUPPORTED.contains(type)){
- if(value instanceof Double){
- return (Double) value;
- } else if(value instanceof Float){
- return ((Float)value).doubleValue();
- } else {
- try {
- return new Double(value.toString());
- } catch (NumberFormatException e) {
- throw new UnsupportedValueException(this,type, value, e);
- }
- }
- } else {
- throw new UnsupportedIndexTypeException(this,type);
- }
- }
- }
- public static class FloatConverter implements TypeConverter<Float> {
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.FLOAT.getIndexType();
- private static final Collection<IndexDataType> DOUBLE_LONG_TYPES = Arrays.asList(
- IndexDataTypeEnum.LONG.getIndexType(),
- IndexDataTypeEnum.DOUBLE.getIndexType());
- private final Set<IndexDataType> supported = Collections.synchronizedSet(new HashSet<IndexDataType>());
- public FloatConverter() {
- this(true);
- }
- public FloatConverter(boolean acceptDoubleAndLongIndexType){
- supported.addAll(Arrays.asList(
- IndexDataTypeEnum.INT.getIndexType(),
- INDEX_TYPE));
- setAcceptDoubleAndLongIndexTypes(acceptDoubleAndLongIndexType);
- }
- public boolean isAcceptDoubleAndLongIndexTypes(){
- return supported.containsAll(DOUBLE_LONG_TYPES);
- }
- public void setAcceptDoubleAndLongIndexTypes(boolean state){
- if(state){
- supported.addAll(DOUBLE_LONG_TYPES);
- } else {
- supported.removeAll(DOUBLE_LONG_TYPES);
- }
- }
- @Override
- public IndexValue createIndexValue(Float value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.toString(), INDEX_TYPE);
- }
-
- @Override
- public Float createObject(IndexValue value) {
- if(value == null){
- return null;
- }
- return createObject(value.getType(), value.getValue(), value.getLanguage());
- }
- @Override
- public Class<Float> getJavaType() {
- return Float.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
- @Override
- public Float createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(value == null){
- return null;
- }
- if(supported.contains(type)){
- if(value instanceof Float){
- return (Float) value;
- } else if(value instanceof Double){
- return ((Double)value).floatValue();
- } else {
- try {
- return new Float(value.toString());
- } catch (NumberFormatException e) {
- throw new UnsupportedValueException(this, type, value, e);
- }
- }
- } else {
- throw new UnsupportedIndexTypeException(this,type);
- }
- }
- }
- public static class BigIntegerConverter implements TypeConverter<BigInteger> {
-
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.LONG.getIndexType();
- private static final IndexDataType INT_TYPE = IndexDataTypeEnum.INT.getIndexType();
-
- @Override
- public IndexValue createIndexValue(BigInteger value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.toString(), INDEX_TYPE);
- }
-
- @Override
- public BigInteger createObject(IndexValue value) {
- if(value == null){
- return null;
- }
- return createObject(value.getType(), value.getValue(),value.getLanguage());
- }
- @Override
- public Class<BigInteger> getJavaType() {
- return BigInteger.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
-
- @Override
- public BigInteger createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(type == null){
- throw new UnsupportedIndexTypeException(this, type);
- }
- if(value == null){
- return null;
- }
- if(type.equals(INDEX_TYPE) || type.equals(INT_TYPE)){
- try {
- return new BigInteger(value.toString());
- }catch (NumberFormatException e) {
- throw new UnsupportedValueException(this, type,value, e);
- }
- } else {
- throw new UnsupportedIndexTypeException(this, type);
- }
- }
- }
- public static class BigDecimalConverter implements TypeConverter<BigDecimal> {
-
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DOUBLE.getIndexType();
- private static Set<IndexDataType> SUPPORTED = new HashSet<IndexDataType>(
- Arrays.asList(
- IndexDataTypeEnum.FLOAT.getIndexType(),
- IndexDataTypeEnum.INT.getIndexType(),
- IndexDataTypeEnum.LONG.getIndexType(),
- INDEX_TYPE));
-
- @Override
- public IndexValue createIndexValue(BigDecimal value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.toString(), INDEX_TYPE);
- }
-
- @Override
- public BigDecimal createObject(IndexValue value) {
- return createObject(value.getType(),value.getValue(), value.getLanguage());
- }
- @Override
- public BigDecimal createObject(IndexDataType type,Object value, String lang) {
- if(value == null){
- return null;
- }
- if(SUPPORTED.contains(type)){
- try {
- return new BigDecimal(value.toString());
- } catch (NumberFormatException e) {
- throw new UnsupportedValueException(this, type,value, e);
- }
- } else {
- throw new UnsupportedIndexTypeException(type);
- }
- }
-
- @Override
- public Class<BigDecimal> getJavaType() {
- return BigDecimal.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
- }
- public static class TextConverter implements TypeConverter<Text> {
-
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.TXT.getIndexType();
- private static final IndexDataType STRING_TYPE = IndexDataTypeEnum.STR.getIndexType();
- protected final ValueFactory valueFactory;
- public TextConverter(ValueFactory valueFactory) {
- if(valueFactory == null){
- throw new IllegalArgumentException("Parameter ValueFactory MUST NOT be NULL!");
- }
- this.valueFactory = valueFactory;
- }
- @Override
- public IndexValue createIndexValue(Text value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.getText(), INDEX_TYPE,value.getLanguage());
- }
- @Override
- public Text createObject(IndexValue value) throws UnsupportedIndexTypeException {
- if(value == null){
- return null;
- }
- return createObject(value.getType(), value.getValue(), value.getLanguage());
- }
- @Override
- public Class<Text> getJavaType() {
- return Text.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
- @Override
- public Text createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(type == null){
- throw new UnsupportedIndexTypeException(this, type);
- }
- if(value == null){
- return null;
- }
- if(type.equals(INDEX_TYPE) || type.equals(STRING_TYPE)){
- return valueFactory.createText(value.toString(), lang);
- } else {
- throw new UnsupportedIndexTypeException(this, type);
- }
- }
- }
- public static class ReferenceConverter implements TypeConverter<Reference> {
- public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.REF.getIndexType();
- protected final ValueFactory valueFactory;
- public ReferenceConverter(ValueFactory valueFactory) {
- if(valueFactory == null){
- throw new IllegalArgumentException("Parameter ValueFactory MUST NOT be NULL!");
- }
- this.valueFactory = valueFactory;
- }
- @Override
- public IndexValue createIndexValue(Reference value) {
- if(value == null){
- return null;
- }
- return new IndexValue(value.getReference(), INDEX_TYPE);
- }
- @Override
- public Reference createObject(IndexValue value) throws UnsupportedIndexTypeException {
- if(value == null){
- return null;
- }
- return createObject(value.getType(), value.getValue(), value.getLanguage());
- }
- @Override
- public Class<Reference> getJavaType() {
- return Reference.class;
- }
- @Override
- public IndexDataType getIndexType() {
- return INDEX_TYPE;
- }
- @Override
- public Reference createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
- if(value == null){
- return null;
- }
- if(type != null && type.equals(INDEX_TYPE)){
- return valueFactory.createReference(value.toString());
- } else {
- throw new UnsupportedIndexTypeException(this, type);
- }
- }
- }
+ private static Logger log = LoggerFactory.getLogger(IndexValueFactory.class);
+
+ private static ValueFactory valueFactory = InMemoryValueFactory.getInstance();
+ private static IndexValueFactory instance = new IndexValueFactory();
+ static {
+ //register the default converters
+ instance.registerConverter(new BigDecimalConverter());
+ instance.registerConverter(new BigIntegerConverter());
+ instance.registerConverter(new DateConverter());
+ instance.registerConverter(new BooleanConverter());
+ instance.registerConverter(new DoubleConverter());
+ instance.registerConverter(new FloatConverter());
+ instance.registerConverter(new IntegerConverter());
+ instance.registerConverter(new LongConverter());
+ instance.registerConverter(new ReferenceConverter(valueFactory));
+ instance.registerConverter(new StringConverter());
+ instance.registerConverter(new TextConverter(valueFactory));
+ }
+ /**
+ * Get a <code>IndexValueFactory</code>.
+ *
+ * @return the <code>IndexValueFactory</code> instance
+ */
+ public static IndexValueFactory getInstance() {
+ return instance;
+ }
+
+ //TODO: add support for IndexTypeConverter
+// private Map<IndexType,TypeConverter<?>> indexTypeConverters =
+// new HashMap<IndexType, TypeConverter<?>>();
+ /**
+ * Holds the java class to {@link TypeConverter} mapping for all converters
+ * registered for a Java Class.<p>
+ * NOTE: this implementation distinguishes between classed and interfaces,
+ * because for Classes a simple get lookup in the Map can be used while for
+ * Interfaces we need to Iterate over the entries of the Map and check with
+ * {@link Class#isAssignableFrom(Class)}.
+ */
+ private Map<Class<?>,TypeConverter<?>> javaClassConverters =
+ Collections.synchronizedMap(new HashMap<Class<?>, TypeConverter<?>>());
+ /**
+ * Holds the java interface to {@link TypeConverter} mappings for all
+ * converters registered for a Java Interface<p>
+ * NOTE: this implementation distinguishes between classed and interfaces,
+ * because for Classes a simple get lookup in the Map can be used while for
+ * Interfaces we need to Iterate over the entries of the Map and check with
+ * {@link Class#isAssignableFrom(Class)}.
+ */
+ private Map<Class<?>,TypeConverter<?>> javaInterfaceConverters =
+ new HashMap<Class<?>, TypeConverter<?>>();
+ /**
+ * Registers a converter to this factory. Note that only one converter per
+ * java type can be registered
+ * @see TypeConverter#getJavaType()
+ * @param converter the converter to be registered
+ */
+ public void registerConverter(TypeConverter<?> converter){
+ if(converter == null){ return;}
+ Class<?> javaType = converter.getJavaType();
+ if(javaType.isInterface()){
+ //NOTE: To ensure thread save iterations over Entries of this Map
+ //create new map instance, add to the new instance and replace reference
+ // ... i know this is slow, but such calls are very uncommon
+ Map<Class<?>,TypeConverter<?>> javaInterfaceConverters =
+ new HashMap<Class<?>,TypeConverter<?>>(this.javaInterfaceConverters);
+ javaInterfaceConverters.put(javaType,converter);
+ //TODO: add support for IndexTypeConverter
+ this.javaInterfaceConverters = javaInterfaceConverters;
+ } else {
+ //there are no Iterations over this Map!
+ javaClassConverters.put(javaType,converter);
+ }
+ }
+ /**
+ * Removes the converter for the parsed java type
+ * @param type the java type
+ * @return the removed converter or <code>null</code> if none was registered
+ * for the parsed type.
+ */
+ @SuppressWarnings("unchecked")
+ public <T> TypeConverter<T> removeConverter(Class<T> type){
+ if(type == null){ return null;}
+ TypeConverter<T> converter;
+ if(type.isInterface()){
+ if(javaInterfaceConverters.containsKey(type)){
+ //create new map instance, remove to the converter and replace reference
+ // ... i know this is slow, but such calls are very uncommon
+ Map<Class<?>,TypeConverter<?>> javaInterfaceConverters =
+ new HashMap<Class<?>,TypeConverter<?>>(this.javaInterfaceConverters);
+ converter = (TypeConverter<T>)javaInterfaceConverters.remove(type);
+ this.javaInterfaceConverters = javaInterfaceConverters;
+ } else {
+ converter = null;
+ }
+ } else {
+ converter = (TypeConverter<T>)javaClassConverters.remove(type);
+ }
+ return converter;
+ }
+ /**
+ * Creates the value as used to index the parsed object
+ *
+ * @param value the value to be indexed
+ * @return the index representation of the parsed value
+ * @throws NoConverterException thrown if <code>value</code> is of an invalid type
+ * @throws IllegalArgumentException if the parsed value is null
+ */
+ @SuppressWarnings("unchecked")
+ public IndexValue createIndexValue(Object value) throws NoConverterException,IllegalArgumentException {
+ if(value == null){
+ throw new IllegalArgumentException("Parameter value MUST NOT be NULL!");
+ }
+ //first try to get the class and find a converter registered for a class
+ TypeConverter<Object> converter = (TypeConverter<Object>)javaClassConverters.get(value.getClass());
+ if(converter != null){
+ return converter.createIndexValue(value);
+ }
+ //if not successful we need still to search for converters registered for interfaces
+ for(Entry<Class<?>, TypeConverter<?>> entry : javaInterfaceConverters.entrySet()){
+ if(entry.getKey().isAssignableFrom(value.getClass())){
+ return ((TypeConverter<Object>)entry.getValue()).createIndexValue(value);
+ }
+ }
+ throw new NoConverterException(value.getClass());
+ }
+
+ /**
+ * Converts a IndexValue instance to an instance of the specified class
+ *
+ * @param <T>
+ * @param type the <code>Class</code> of the returned object
+ * @param indexValue the index value instance
+ * @return a java object representing the value of the index value
+ * @throws NoConverterException thrown if <code>type</code> is unsupported
+ * @throws UnsupportedIndexTypeException if the {@link IndexDataType} of the parsed
+ * {@link IndexValue} is not supported by the registered converter
+ * @throws IllegalArgumentException if any of the two parameter is <code>null</code>
+ */
+ public <T> T createValue(Class<T> type, IndexValue indexValue)
+ throws NoConverterException,UnsupportedIndexTypeException,IllegalArgumentException {
+ return createValue(type, indexValue.getType(),indexValue.getType(), indexValue.getLanguage());
+ }
+ /**
+ * Converts a IndexValue instance to an instance of the specified class
+ *
+ * @param <T>
+ * @param javaType the requested java type
+ * @param indexType the index type
+ * @param indexValue the value in the index
+ * @param language the language of the value in the index
+ * @return a java object representing the value of the index value
+ * @throws NoConverterException thrown if <code>type</code> is unsupported
+ * @throws UnsupportedIndexTypeException if the {@link IndexDataType} of the parsed
+ * {@link IndexValue} is not supported by the registered converter
+ * @throws IllegalArgumentException if any of the two parameter is <code>null</code>
+ */
+ @SuppressWarnings("unchecked")
+ public <T> T createValue(Class<T> javaType, IndexDataType indexType, Object indexValue,String language)
+ throws NoConverterException,UnsupportedIndexTypeException,IllegalArgumentException {
+ if(javaType == null){
+ throw new IllegalArgumentException("Parameter Class<T> type MUST NOT be NULL");
+ }
+ if(indexValue == null){
+ throw new IllegalArgumentException("Parameter IndexValue MUST NOT be NULL");
+ }
+ //search interface converter map if the parsed type is an interface
+ TypeConverter<T> converter = (TypeConverter<T>)(javaType.isInterface()?javaInterfaceConverters.get(javaType):javaClassConverters.get(javaType));
+ if(converter != null){
+ return converter.createObject(indexType,indexValue,language);
+ } else {
+ throw new NoConverterException(javaType);
+ }
+ }
+
+ //TODO: add support for IndexTypeConverter
+// /**
+// * Converts a IndexValue instance to an java object. The type of the java
+// * object.
+// * @param indexValue the index value instance
+// * @return a java object representing the value of the index value
+// * @throws NoConverterException if no converter for the index value is registered
+// */
+// public Object createObject(IndexValue indexValue) throws NoConverterException {
+//
+// }
+
+ /*
+ * ==== Internal Classes for the default converter Implementations ====
+ */
+
+ public static class DateConverter implements TypeConverter<Date> {
+ private static final DateTimeFormatter XML_DATE_TIME_FORMAT = ISODateTimeFormat.dateTime().withZone(DateTimeZone.UTC);
+ private static final DateTimeFormatter XML_DATE_TIME_FORMAT_noMillis = ISODateTimeFormat.dateTimeNoMillis().withZone(DateTimeZone.UTC);
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DATE.getIndexType();
+
+ @Override
+ public IndexValue createIndexValue(Date value) {
+ return new IndexValue(XML_DATE_TIME_FORMAT.print(value.getTime()),INDEX_TYPE);
+ }
+
+ @Override
+ public Date createObject(IndexValue indexValue) {
+ if(indexValue == null){
+ return null;
+ }
+ return createObject(indexValue.getType(), indexValue, indexValue.getLanguage());
+ }
+ @Override
+ public Class<Date> getJavaType() {
+ return Date.class;
+ }
+ @Override
+ public IndexDataType getIndexType(){
+ return INDEX_TYPE;
+ }
+
+ @Override
+ public Date createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(value == null){
+ return null;
+ }
+ if(type == null || !type.equals(INDEX_TYPE)){
+ throw new UnsupportedIndexTypeException(this,type);
+ }
+ if(value instanceof Date){
+ return (Date) value;
+ } else if(value instanceof Calendar){
+ return ((Calendar)value).getTime();
+ } else {
+ DateTime date;
+ try {
+ //NOTE: Solr only support UTC ... so we need to change the Timezone
+ date = XML_DATE_TIME_FORMAT.parseDateTime(value.toString());
+ } catch (IllegalArgumentException e) {
+ try {
+ date = XML_DATE_TIME_FORMAT_noMillis.parseDateTime(value.toString());
+ } catch (IllegalArgumentException e1) {
+ log.warn("Unable to parse Date/Time for Value "+value.toString()+" (use ISO date format (milliseconds optional))! -> no Date Mapping added!",e1);
+ throw new UnsupportedValueException(this, type, value,e);
+ }
+ }
+ return date.toDate();
+ }
+ }
+
+ }
+
+ public static class BooleanConverter implements TypeConverter<Boolean> {
+
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.BOOLEAN.getIndexType();
+
+ @Override
+ public IndexValue createIndexValue(Boolean value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.toString(), INDEX_TYPE);
+ }
+
+ @Override
+ public Boolean createObject(IndexValue value) {
+ if(value == null){
+ return null;
+ }
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
+ }
+ @Override
+ public Class<Boolean> getJavaType() {
+ return Boolean.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+
+ @Override
+ public Boolean createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(value == null){
+ return null;
+ }
+ if(type == null || !type.equals(INDEX_TYPE)){
+ throw new UnsupportedIndexTypeException(this,type);
+ }
+ if(value instanceof Boolean){
+ return (Boolean)value;
+ } else {
+ return Boolean.valueOf(value.toString());
+ }
+ }
+ }
+
+ public static class StringConverter implements TypeConverter<String> {
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.STR.getIndexType();
+ private boolean acceptAllIndexTypes;
+ public final boolean isAcceptAllIndexTypes() {
+ return acceptAllIndexTypes;
+ }
+ public final void setAcceptAllIndexTypes(boolean acceptAllIndexTypes) {
+ this.acceptAllIndexTypes = acceptAllIndexTypes;
+ }
+ public StringConverter() {
+ this(true);
+ }
+ public StringConverter(boolean acceptAllIndexTypes){
+ this.acceptAllIndexTypes = acceptAllIndexTypes;
+ }
+ @Override
+ public IndexValue createIndexValue(String value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value, INDEX_TYPE);
+ }
+
+ @Override
+ public String createObject(IndexValue value) {
+ if(value == null){
+ return null;
+ }
+ //for now accept any IndexValue regardless of type
+// if(!value.getType().equals(INDEX_TYPE)){
+// new UnsupportedIndexTypeException(this, value);
+// }
+ return value.getValue();
+ }
+ @Override
+ public Class<String> getJavaType() {
+ return String.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+ @Override
+ public String createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ return value!=null?value.toString():null;
+ }
+ }
+
+ public static class IntegerConverter implements TypeConverter<Integer> {
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.INT.getIndexType();
+ private boolean acceptLong;
+ public final boolean isAcceptLong() {
+ return acceptLong;
+ }
+ public final void setAcceptLong(boolean acceptLong) {
+ this.acceptLong = acceptLong;
+ }
+ public IntegerConverter() {
+ this(true);
+ }
+ public IntegerConverter(boolean acceptLongIndexType){
+ this.acceptLong = acceptLongIndexType;
+ }
+ @Override
+ public IndexValue createIndexValue(Integer value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.toString(), INDEX_TYPE);
+ }
+
+ @Override
+ public Integer createObject(IndexValue value) {
+ if(value == null){
+ return null;
+ }
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
+ }
+ @Override
+ public Class<Integer> getJavaType() {
+ // TODO Auto-generated method stub
+ return Integer.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+ @Override
+ public Integer createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(type == null){
+ throw new UnsupportedIndexTypeException(this,type);
+ }
+ if(value == null){
+ return null;
+ }
+ if(type.equals(INDEX_TYPE)){
+ if(value instanceof Integer){
+ return (Integer)value;
+ } else {
+ try {
+ return new Integer(value.toString());
+ } catch (NumberFormatException e) {
+ throw new UnsupportedValueException(this, type, value, e);
+ }
+ }
+ } else if(acceptLong && type.equals(IndexDataTypeEnum.LONG.getIndexType())){
+ long longValue;
+ if(value instanceof Long){
+ longValue = ((Long)value).longValue();
+ } else {
+ try {
+ longValue = Long.parseLong(value.toString());
+ } catch (NumberFormatException e) {
+ throw new UnsupportedValueException(this, type, value, e);
+ }
+ }
+ if(Integer.MAX_VALUE >= longValue && Integer.MIN_VALUE <= longValue){
+ return new Integer((int)longValue);
+ } else {
+ //parsed long value outside of the int range
+ throw new UnsupportedValueException(this, type, value,
+ new IllegalStateException("Unable to convert LONG Value to Integer, because the value is outside of the Integer Range!"));
+ }
+ } else {
+ throw new UnsupportedIndexTypeException(this,type);
+ }
+ }
+ }
+
+ public static class LongConverter implements TypeConverter<Long> {
+
+ public static final IndexDataType LONG_TYPE = IndexDataTypeEnum.LONG.getIndexType();
+ private static final IndexDataType INT_TYPE = IndexDataTypeEnum.INT.getIndexType();
+
+ @Override
+ public IndexValue createIndexValue(Long value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.toString(), LONG_TYPE);
+ }
+
+ @Override
+ public Long createObject(IndexValue value) {
+ if(value == null){
+ return null;
+ }
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
+ }
+ @Override
+ public Class<Long> getJavaType() {
+ return Long.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return LONG_TYPE;
+ }
+
+ @Override
+ public Long createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(type == null){
+ throw new UnsupportedIndexTypeException(this, type);
+ }
+ if(value == null){
+ return null;
+ }
+ if(type.equals(LONG_TYPE) || type.equals(INT_TYPE)){
+ if(value instanceof Long){
+ return (Long) value;
+ } else if(value instanceof Integer){
+ return ((Integer)value).longValue();
+ } else {
+ try {
+ return new Long(value.toString());
+ } catch (NumberFormatException e) {
+ throw new UnsupportedValueException(this, type, value, e);
+ }
+ }
+ } else {
+ throw new UnsupportedIndexTypeException(this, type);
+ }
+ }
+ }
+
+ public static class DoubleConverter implements TypeConverter<Double> {
+
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DOUBLE.getIndexType();
+ private static Set<IndexDataType> SUPPORTED = new HashSet<IndexDataType>(
+ Arrays.asList(
+ IndexDataTypeEnum.FLOAT.getIndexType(),
+ IndexDataTypeEnum.INT.getIndexType(),
+ IndexDataTypeEnum.LONG.getIndexType(),
+ INDEX_TYPE));
+
+ @Override
+ public IndexValue createIndexValue(Double value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.toString(), INDEX_TYPE);
+ }
+
+ @Override
+ public Double createObject(IndexValue value) {
+ if(value == null){
+ return null;
+ }
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
+ }
+ @Override
+ public Class<Double> getJavaType() {
+ return Double.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+
+ @Override
+ public Double createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(value == null){
+ return null;
+ }
+ if(SUPPORTED.contains(type)){
+ if(value instanceof Double){
+ return (Double) value;
+ } else if(value instanceof Float){
+ return ((Float)value).doubleValue();
+ } else {
+ try {
+ return new Double(value.toString());
+ } catch (NumberFormatException e) {
+ throw new UnsupportedValueException(this,type, value, e);
+ }
+ }
+ } else {
+ throw new UnsupportedIndexTypeException(this,type);
+ }
+ }
+ }
+ public static class FloatConverter implements TypeConverter<Float> {
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.FLOAT.getIndexType();
+ private static final Collection<IndexDataType> DOUBLE_LONG_TYPES = Arrays.asList(
+ IndexDataTypeEnum.LONG.getIndexType(),
+ IndexDataTypeEnum.DOUBLE.getIndexType());
+ private final Set<IndexDataType> supported = Collections.synchronizedSet(new HashSet<IndexDataType>());
+ public FloatConverter() {
+ this(true);
+ }
+ public FloatConverter(boolean acceptDoubleAndLongIndexType){
+ supported.addAll(Arrays.asList(
+ IndexDataTypeEnum.INT.getIndexType(),
+ INDEX_TYPE));
+ setAcceptDoubleAndLongIndexTypes(acceptDoubleAndLongIndexType);
+ }
+ public boolean isAcceptDoubleAndLongIndexTypes(){
+ return supported.containsAll(DOUBLE_LONG_TYPES);
+ }
+ public void setAcceptDoubleAndLongIndexTypes(boolean state){
+ if(state){
+ supported.addAll(DOUBLE_LONG_TYPES);
+ } else {
+ supported.removeAll(DOUBLE_LONG_TYPES);
+ }
+ }
+ @Override
+ public IndexValue createIndexValue(Float value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.toString(), INDEX_TYPE);
+ }
+
+ @Override
+ public Float createObject(IndexValue value) {
+ if(value == null){
+ return null;
+ }
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
+ }
+ @Override
+ public Class<Float> getJavaType() {
+ return Float.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+ @Override
+ public Float createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(value == null){
+ return null;
+ }
+ if(supported.contains(type)){
+ if(value instanceof Float){
+ return (Float) value;
+ } else if(value instanceof Double){
+ return ((Double)value).floatValue();
+ } else {
+ try {
+ return new Float(value.toString());
+ } catch (NumberFormatException e) {
+ throw new UnsupportedValueException(this, type, value, e);
+ }
+ }
+ } else {
+ throw new UnsupportedIndexTypeException(this,type);
+ }
+ }
+ }
+ public static class BigIntegerConverter implements TypeConverter<BigInteger> {
+
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.LONG.getIndexType();
+ private static final IndexDataType INT_TYPE = IndexDataTypeEnum.INT.getIndexType();
+
+ @Override
+ public IndexValue createIndexValue(BigInteger value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.toString(), INDEX_TYPE);
+ }
+
+ @Override
+ public BigInteger createObject(IndexValue value) {
+ if(value == null){
+ return null;
+ }
+ return createObject(value.getType(), value.getValue(),value.getLanguage());
+ }
+ @Override
+ public Class<BigInteger> getJavaType() {
+ return BigInteger.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+
+ @Override
+ public BigInteger createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(type == null){
+ throw new UnsupportedIndexTypeException(this, type);
+ }
+ if(value == null){
+ return null;
+ }
+ if(type.equals(INDEX_TYPE) || type.equals(INT_TYPE)){
+ try {
+ return new BigInteger(value.toString());
+ }catch (NumberFormatException e) {
+ throw new UnsupportedValueException(this, type,value, e);
+ }
+ } else {
+ throw new UnsupportedIndexTypeException(this, type);
+ }
+ }
+ }
+ public static class BigDecimalConverter implements TypeConverter<BigDecimal> {
+
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.DOUBLE.getIndexType();
+ private static Set<IndexDataType> SUPPORTED = new HashSet<IndexDataType>(
+ Arrays.asList(
+ IndexDataTypeEnum.FLOAT.getIndexType(),
+ IndexDataTypeEnum.INT.getIndexType(),
+ IndexDataTypeEnum.LONG.getIndexType(),
+ INDEX_TYPE));
+
+ @Override
+ public IndexValue createIndexValue(BigDecimal value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.toString(), INDEX_TYPE);
+ }
+
+ @Override
+ public BigDecimal createObject(IndexValue value) {
+ return createObject(value.getType(),value.getValue(), value.getLanguage());
+ }
+ @Override
+ public BigDecimal createObject(IndexDataType type,Object value, String lang) {
+ if(value == null){
+ return null;
+ }
+ if(SUPPORTED.contains(type)){
+ try {
+ return new BigDecimal(value.toString());
+ } catch (NumberFormatException e) {
+ throw new UnsupportedValueException(this, type,value, e);
+ }
+ } else {
+ throw new UnsupportedIndexTypeException(type);
+ }
+ }
+
+ @Override
+ public Class<BigDecimal> getJavaType() {
+ return BigDecimal.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+ }
+ public static class TextConverter implements TypeConverter<Text> {
+
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.TXT.getIndexType();
+ private static final IndexDataType STRING_TYPE = IndexDataTypeEnum.STR.getIndexType();
+ protected final ValueFactory valueFactory;
+ public TextConverter(ValueFactory valueFactory) {
+ if(valueFactory == null){
+ throw new IllegalArgumentException("Parameter ValueFactory MUST NOT be NULL!");
+ }
+ this.valueFactory = valueFactory;
+ }
+ @Override
+ public IndexValue createIndexValue(Text value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.getText(), INDEX_TYPE,value.getLanguage());
+ }
+ @Override
+ public Text createObject(IndexValue value) throws UnsupportedIndexTypeException {
+ if(value == null){
+ return null;
+ }
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
+ }
+ @Override
+ public Class<Text> getJavaType() {
+ return Text.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+ @Override
+ public Text createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(type == null){
+ throw new UnsupportedIndexTypeException(this, type);
+ }
+ if(value == null){
+ return null;
+ }
+ if(type.equals(INDEX_TYPE) || type.equals(STRING_TYPE)){
+ return valueFactory.createText(value.toString(), lang);
+ } else {
+ throw new UnsupportedIndexTypeException(this, type);
+ }
+ }
+ }
+ public static class ReferenceConverter implements TypeConverter<Reference> {
+ public static final IndexDataType INDEX_TYPE = IndexDataTypeEnum.REF.getIndexType();
+ protected final ValueFactory valueFactory;
+ public ReferenceConverter(ValueFactory valueFactory) {
+ if(valueFactory == null){
+ throw new IllegalArgumentException("Parameter ValueFactory MUST NOT be NULL!");
+ }
+ this.valueFactory = valueFactory;
+ }
+ @Override
+ public IndexValue createIndexValue(Reference value) {
+ if(value == null){
+ return null;
+ }
+ return new IndexValue(value.getReference(), INDEX_TYPE);
+ }
+ @Override
+ public Reference createObject(IndexValue value) throws UnsupportedIndexTypeException {
+ if(value == null){
+ return null;
+ }
+ return createObject(value.getType(), value.getValue(), value.getLanguage());
+ }
+ @Override
+ public Class<Reference> getJavaType() {
+ return Reference.class;
+ }
+ @Override
+ public IndexDataType getIndexType() {
+ return INDEX_TYPE;
+ }
+ @Override
+ public Reference createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException, UnsupportedValueException {
+ if(value == null){
+ return null;
+ }
+ if(type != null && type.equals(INDEX_TYPE)){
+ return valueFactory.createReference(value.toString());
+ } else {
+ throw new UnsupportedIndexTypeException(this, type);
+ }
+ }
+ }
}
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/NoConverterException.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/NoConverterException.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/NoConverterException.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/NoConverterException.java Sun Dec 12 15:13:35 2010
@@ -11,18 +11,18 @@ import java.lang.reflect.Type;
*/
public class NoConverterException extends RuntimeException {
- /**
- * default serialVersionUID
- */
- private static final long serialVersionUID = 1L;
+ /**
+ * default serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
- /**
- * Create an instance of <code>NoAdapterException</code>
- * indicating that no adapter is available for the type.
- *
- * @param type the type for which no adapter is available
- */
- public NoConverterException(Type type) {
- super("No adapter available for type "+type);
- }
+ /**
+ * Create an instance of <code>NoAdapterException</code>
+ * indicating that no adapter is available for the type.
+ *
+ * @param type the type for which no adapter is available
+ */
+ public NoConverterException(Type type) {
+ super("No adapter available for type "+type);
+ }
}
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/TypeConverter.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/TypeConverter.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/TypeConverter.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/TypeConverter.java Sun Dec 12 15:13:35 2010
@@ -8,39 +8,39 @@ package eu.iksproject.rick.yard.solr.mod
* {@link IndexValue}s.
*/
public interface TypeConverter<T> {
- /**
- * Converts the parsed java instance to an index value
- * @param value the java instance
- * @return the index value representing the parsed java instance
- */
- IndexValue createIndexValue(T value);
- /**
- * Creates an java instance representing the parsed <code>IndexValue</code>
- * @param value the index value
- * @return the java instance representing the parsed index value
- * @throws if the <code>IndexType</code> of the parsed value is not compatible
- * with this converter.
- */
- T createObject(IndexValue value) throws UnsupportedIndexTypeException,UnsupportedValueException;
- /**
- * Creates an java instance representing the parsed value as returned by the
- * index.
- * @param type the index data type of the value. MUST NOT be <code>null</code>
- * @param value the value within the index. If <code>null</code> this method returns <code>null</code>.
- * @param lang the language
- * @return the java instance representing the parsed index value
- * @throws UnsupportedValueException if the value can not be processed by the
- * Converter
- */
- T createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,UnsupportedValueException;
- /**
- * Getter for the java type
- * @return the java class of the instances created by this converter
- */
- Class<T> getJavaType();
- /**
- * Getter for the index type
- * @return the index type of index values created by this converter
- */
- IndexDataType getIndexType();
-}
\ No newline at end of file
+ /**
+ * Converts the parsed java instance to an index value
+ * @param value the java instance
+ * @return the index value representing the parsed java instance
+ */
+ IndexValue createIndexValue(T value);
+ /**
+ * Creates an java instance representing the parsed <code>IndexValue</code>
+ * @param value the index value
+ * @return the java instance representing the parsed index value
+ * @throws if the <code>IndexType</code> of the parsed value is not compatible
+ * with this converter.
+ */
+ T createObject(IndexValue value) throws UnsupportedIndexTypeException,UnsupportedValueException;
+ /**
+ * Creates an java instance representing the parsed value as returned by the
+ * index.
+ * @param type the index data type of the value. MUST NOT be <code>null</code>
+ * @param value the value within the index. If <code>null</code> this method returns <code>null</code>.
+ * @param lang the language
+ * @return the java instance representing the parsed index value
+ * @throws UnsupportedValueException if the value can not be processed by the
+ * Converter
+ */
+ T createObject(IndexDataType type, Object value, String lang) throws UnsupportedIndexTypeException,UnsupportedValueException;
+ /**
+ * Getter for the java type
+ * @return the java class of the instances created by this converter
+ */
+ Class<T> getJavaType();
+ /**
+ * Getter for the index type
+ * @return the index type of index values created by this converter
+ */
+ IndexDataType getIndexType();
+}
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/UnsupportedIndexTypeException.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/UnsupportedIndexTypeException.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/UnsupportedIndexTypeException.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/UnsupportedIndexTypeException.java Sun Dec 12 15:13:35 2010
@@ -6,28 +6,28 @@ package eu.iksproject.rick.yard.solr.mod
* @author Rupert Westenthaler
*/
public class UnsupportedIndexTypeException extends RuntimeException {
-
- /**
- * default serial version UID
- */
- private static final long serialVersionUID = 1L;
- /**
- * Constructs the exception to be thrown when a an IndexType is not supported
- * by the current configuration of the {@link IndexValueFactory}
- *
- * @param indexType the unsupported <code>IndexType</code>
- */
- public UnsupportedIndexTypeException(IndexDataType indexType) {
- super(String.format("No Converter for IndexType %s registered!",indexType));
- }
- /**
- * Constructs the exception to be thrown if a converter does not support the
- * {@link IndexDataType} of the parsed {@link IndexValue}.
- * @param converter the converter (implement the {@link TypeConverter#toString()} method!)
- * @param type the unsupported {@link IndexDataType}
- */
- public UnsupportedIndexTypeException(TypeConverter<?> converter, IndexDataType type) {
- super(String.format("%s does not support the IndexType %s!",
- converter,type));
- }
+
+ /**
+ * default serial version UID
+ */
+ private static final long serialVersionUID = 1L;
+ /**
+ * Constructs the exception to be thrown when a an IndexType is not supported
+ * by the current configuration of the {@link IndexValueFactory}
+ *
+ * @param indexType the unsupported <code>IndexType</code>
+ */
+ public UnsupportedIndexTypeException(IndexDataType indexType) {
+ super(String.format("No Converter for IndexType %s registered!",indexType));
+ }
+ /**
+ * Constructs the exception to be thrown if a converter does not support the
+ * {@link IndexDataType} of the parsed {@link IndexValue}.
+ * @param converter the converter (implement the {@link TypeConverter#toString()} method!)
+ * @param type the unsupported {@link IndexDataType}
+ */
+ public UnsupportedIndexTypeException(TypeConverter<?> converter, IndexDataType type) {
+ super(String.format("%s does not support the IndexType %s!",
+ converter,type));
+ }
}
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/UnsupportedValueException.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/UnsupportedValueException.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/UnsupportedValueException.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/model/UnsupportedValueException.java Sun Dec 12 15:13:35 2010
@@ -6,31 +6,31 @@ package eu.iksproject.rick.yard.solr.mod
* @author Rupert Westenthaler
*/
public class UnsupportedValueException extends RuntimeException {
-
- /**
- * default serial version UID
- */
- private static final long serialVersionUID = 1L;
- /**
- * Constructs the exception to be thrown if a converter does not support the
- * the parsed value {@link IndexValue}.
- * @param converter the converter (implement the {@link TypeConverter#toString()} method!)
- * @param type the IndexDataType
- * @param value the value
- */
- public UnsupportedValueException(TypeConverter<?> converter, IndexDataType type, Object value) {
- this(converter, type, value,null);
- }
- /**
- * Constructs the exception to be thrown if a converter does not support the
- * the parsed value {@link IndexValue}.
- * @param converter the converter (implement the {@link TypeConverter#toString()} method!)
- * @param type the IndexDataType
- * @param value the value
- * @param cause the cause
- */
- public UnsupportedValueException(TypeConverter<?> converter, IndexDataType type, Object value,Throwable cause) {
- super(String.format("%s does not support the parsed value %s! Value is not compatible with the parsed IndexDataType %s",
- converter,value,type),cause);
- }
+
+ /**
+ * default serial version UID
+ */
+ private static final long serialVersionUID = 1L;
+ /**
+ * Constructs the exception to be thrown if a converter does not support the
+ * the parsed value {@link IndexValue}.
+ * @param converter the converter (implement the {@link TypeConverter#toString()} method!)
+ * @param type the IndexDataType
+ * @param value the value
+ */
+ public UnsupportedValueException(TypeConverter<?> converter, IndexDataType type, Object value) {
+ this(converter, type, value,null);
+ }
+ /**
+ * Constructs the exception to be thrown if a converter does not support the
+ * the parsed value {@link IndexValue}.
+ * @param converter the converter (implement the {@link TypeConverter#toString()} method!)
+ * @param type the IndexDataType
+ * @param value the value
+ * @param cause the cause
+ */
+ public UnsupportedValueException(TypeConverter<?> converter, IndexDataType type, Object value,Throwable cause) {
+ super(String.format("%s does not support the parsed value %s! Value is not compatible with the parsed IndexDataType %s",
+ converter,value,type),cause);
+ }
}
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/ConstraintTypePosition.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/ConstraintTypePosition.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/ConstraintTypePosition.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/ConstraintTypePosition.java Sun Dec 12 15:13:35 2010
@@ -1,5 +1,5 @@
/**
- *
+ *
*/
package eu.iksproject.rick.yard.solr.query;
@@ -17,52 +17,52 @@ package eu.iksproject.rick.yard.solr.que
*
*/
public class ConstraintTypePosition implements Comparable<ConstraintTypePosition>{
- /**
- * The possible positions of constraints within a Index Constraint.<p>
- * The ordinal number of the elements is used to sort the constraints in the
- * {@link EncodedConstraintParts}. So ensure, that the ordering in this
- * enumeration corresponds with the ordering in a constraint within the
- * index
- * @author Rupert Westenthaler
- *
- */
- public static enum PositionType {
- prefix,
- field,
- suffux,
- assignment,
- value;
- }
- private PositionType type;
- private int pos;
-
- public ConstraintTypePosition(PositionType type) {
- this(type,0);
- }
+ /**
+ * The possible positions of constraints within a Index Constraint.<p>
+ * The ordinal number of the elements is used to sort the constraints in the
+ * {@link EncodedConstraintParts}. So ensure, that the ordering in this
+ * enumeration corresponds with the ordering in a constraint within the
+ * index
+ * @author Rupert Westenthaler
+ *
+ */
+ public static enum PositionType {
+ prefix,
+ field,
+ suffux,
+ assignment,
+ value;
+ }
+ private PositionType type;
+ private int pos;
+
+ public ConstraintTypePosition(PositionType type) {
+ this(type,0);
+ }
- public ConstraintTypePosition(PositionType type,int pos) {
- if(type == null){
- throw new IllegalArgumentException("The ConstraintPosition MUST NOT be NULL!");
- }
- this.type = type;
- this.pos = pos;
- }
+ public ConstraintTypePosition(PositionType type,int pos) {
+ if(type == null){
+ throw new IllegalArgumentException("The ConstraintPosition MUST NOT be NULL!");
+ }
+ this.type = type;
+ this.pos = pos;
+ }
- @Override
- public int compareTo(ConstraintTypePosition other) {
- return type == other.type?pos-other.pos:type.ordinal()-other.type.ordinal();
- }
- @Override
- public int hashCode() {
- return type.hashCode()+pos;
- }
- @Override
- public boolean equals(Object obj) {
- return obj != null && obj instanceof ConstraintTypePosition
- && ((ConstraintTypePosition)obj).type == type && ((ConstraintTypePosition)obj).pos == pos;
- }
- @Override
- public String toString() {
- return String.format("constraintPosition %s,%d", type,pos);
- }
-}
\ No newline at end of file
+ @Override
+ public int compareTo(ConstraintTypePosition other) {
+ return type == other.type?pos-other.pos:type.ordinal()-other.type.ordinal();
+ }
+ @Override
+ public int hashCode() {
+ return type.hashCode()+pos;
+ }
+ @Override
+ public boolean equals(Object obj) {
+ return obj != null && obj instanceof ConstraintTypePosition
+ && ((ConstraintTypePosition)obj).type == type && ((ConstraintTypePosition)obj).pos == pos;
+ }
+ @Override
+ public String toString() {
+ return String.format("constraintPosition %s,%d", type,pos);
+ }
+}
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/EncodedConstraintParts.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/EncodedConstraintParts.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/EncodedConstraintParts.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/EncodedConstraintParts.java Sun Dec 12 15:13:35 2010
@@ -17,60 +17,60 @@ import java.util.Map.Entry;
* <code><per>
* <prefix>.field.<prefix><assignment><value>
* </pre></code>
- * The: <ul>
+ * The: <ul>
* <li> <code>prefix</code> is used for the data type and language constraints
* <li> <code>field</code> is predefined by by the field of the constraint
* <li> <code>suffix</code> is currently unused
* <li> <code>assignment</code> is used for checking static values or just adding
* ':' in the case that values of that field are filtered.
* <li> <code>value</code> is used to define filters like value ranges or
- * wildcard searches.
- * </ul>
+ * wildcard searches.
+ * </ul>
* The {@link ConstraintTypePosition} defines such position in ordinal numbers
* from left to right. This ordinal numbers are also used sort the elements
* of the {@link Iterable} interface implemented by this class.
- *
+ *
* @author Rupert Westenthaler
*
*/
public class EncodedConstraintParts implements Iterable<Entry<ConstraintTypePosition,Set<String>>>{
- /**
- * This maps contains all the encoded parts of the query.
- */
- private SortedMap<ConstraintTypePosition,Set<String>> constraintMap = new TreeMap<ConstraintTypePosition, Set<String>>();
- /**
- * Adds an constraint type
- * @param pos
- * @param values
- */
- public void addEncoded(ConstraintTypePosition pos,String...values){
- if(values == null || values.length<1){
- return;
- } else {
- Set<String> constraints = constraintMap.get(pos);
- if(constraints == null){
- constraints = new HashSet<String>();
- constraintMap.put(pos, constraints);
- }
- constraints.addAll(Arrays.asList(values));
- }
- }
-
- @Override
- public String toString() {
- return "Encoded Constraints: "+constraintMap.toString();
- }
+ /**
+ * This maps contains all the encoded parts of the query.
+ */
+ private SortedMap<ConstraintTypePosition,Set<String>> constraintMap = new TreeMap<ConstraintTypePosition, Set<String>>();
+ /**
+ * Adds an constraint type
+ * @param pos
+ * @param values
+ */
+ public void addEncoded(ConstraintTypePosition pos,String...values){
+ if(values == null || values.length<1){
+ return;
+ } else {
+ Set<String> constraints = constraintMap.get(pos);
+ if(constraints == null){
+ constraints = new HashSet<String>();
+ constraintMap.put(pos, constraints);
+ }
+ constraints.addAll(Arrays.asList(values));
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "Encoded Constraints: "+constraintMap.toString();
+ }
- @Override
- public Iterator<Entry<ConstraintTypePosition, Set<String>>> iterator() {
- return constraintMap.entrySet().iterator();
- }
- @Override
- public int hashCode() {
- return constraintMap.hashCode();
- }
- @Override
- public boolean equals(Object obj) {
- return obj != null && obj instanceof EncodedConstraintParts && ((EncodedConstraintParts)obj).constraintMap.equals(constraintMap);
- }
+ @Override
+ public Iterator<Entry<ConstraintTypePosition, Set<String>>> iterator() {
+ return constraintMap.entrySet().iterator();
+ }
+ @Override
+ public int hashCode() {
+ return constraintMap.hashCode();
+ }
+ @Override
+ public boolean equals(Object obj) {
+ return obj != null && obj instanceof EncodedConstraintParts && ((EncodedConstraintParts)obj).constraintMap.equals(constraintMap);
+ }
}
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/IndexConstraintTypeEncoder.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/IndexConstraintTypeEncoder.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/IndexConstraintTypeEncoder.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/IndexConstraintTypeEncoder.java Sun Dec 12 15:13:35 2010
@@ -13,7 +13,7 @@ import eu.iksproject.rick.yard.solr.mode
* constraints in the index. Do give some examples let's assume, that we are
* interested in documents that contains "life" in there English title.
* This constraint would be represented by the following constraints in the
- * index<ul>
+ * index<ul>
* <li> A {@link IndexConstraintTypeEnum#LANG} set to be English
* <li> A {@link IndexConstraintTypeEnum#FIELD} set to "dc:title" (dublin core)
* <li> A {@link IndexConstraintTypeEnum#WILDCARD} set to life* or alternatively
@@ -25,13 +25,13 @@ import eu.iksproject.rick.yard.solr.mode
* present. Because of that implementations of this interface can define there
* {@link #dependsOn()} other {@link IndexConstraintTypeEnum} to be present.
* Such types are than added with the default constraint <code>null</code> if
- * missing. Implementations can indicate with {@link #supportsDefault()} if
- * they are able to encode the constraint type when set to the default value
+ * missing. Implementations can indicate with {@link #supportsDefault()} if
+ * they are able to encode the constraint type when set to the default value
* <code>null</code>.<p>
* Finally different constraints need different types of values to be parsed.
* Therefore this interface uses a generic type and the {@link #acceptsValueType()}
* method can be used to check if the type of the parsed value is compatible
- * with the implementation registered for the current
+ * with the implementation registered for the current
* {@link IndexConstraintTypeEnum}.<p>
* Please note that implementations of this interface need to be thread save,
* because typically there will only be one instance that is shared for all
@@ -43,49 +43,49 @@ import eu.iksproject.rick.yard.solr.mode
* @param T the type of supported values!
*/
public interface IndexConstraintTypeEncoder<T> {
- /**
- * Encodes the parsed value and adds it to the IndexQueryConstraint. <p>
- * If the encoder supports default values (meaning that
- * {@link #supportsDefault()} returns <code>true</code>, than parsing
- * <code>null</code> as value MUST result in returning the
- * default value. Otherwise the encode method might throw an
- * {@link IllegalArgumentException} if <code>null</code> is parsed.<p>
- * Please note that <code>null</code> might also be a valid parameter even
- * if an Encoder does not support a default value!
- * @param value the value for the constraint
- * @throws IllegalArgumentException if the parsed value is not supported.
- * Especially if <code>null</code> is parsed and the implementation does not
- * {@link #supportsDefault()}!
- */
- void encode(EncodedConstraintParts constraint,T value) throws IllegalArgumentException;
- /**
- * Returns <code>true</code> if this Encoder supports a default value. This
- * would be e.g. an open ended upper or lower bound for range constraints or
- * any language for text constraints.
- * @return if the encoder supports a default encoding if no constraint of that
- * type is provided by the query.
- */
- boolean supportsDefault();
- /**
- * A set of other Constraints that need to be present, that the encoding provided
- * by this encoder results in a valid query constraint. e.g. A range constraint
- * always need a lower and an upper bound. So even if the query only defines
- * an upper bound, than there MUST BE also a open ended lower bound encoded to
- * result in a valid query constraint.
- * @return set of other index constraint types that must be present. If none
- * return {@link Collections#emptySet()}. This Method should return an
- * unmodifiable collection (e.g. {@link Arrays#asList(Object...)} or using
- * {@link Collections#unmodifiableCollection(Collection)})
- */
- Collection<IndexConstraintTypeEnum> dependsOn();
- /**
- * The type of the constraint this implementation encodes
- * @return the type of the constraints encoded by this implementation
- */
- IndexConstraintTypeEnum encodes();
- /**
- * Getter for the type of values this encoder accepts.
- * @return the generic type of the index constraint type encoder
- */
- Class<T> acceptsValueType();
+ /**
+ * Encodes the parsed value and adds it to the IndexQueryConstraint. <p>
+ * If the encoder supports default values (meaning that
+ * {@link #supportsDefault()} returns <code>true</code>, than parsing
+ * <code>null</code> as value MUST result in returning the
+ * default value. Otherwise the encode method might throw an
+ * {@link IllegalArgumentException} if <code>null</code> is parsed.<p>
+ * Please note that <code>null</code> might also be a valid parameter even
+ * if an Encoder does not support a default value!
+ * @param value the value for the constraint
+ * @throws IllegalArgumentException if the parsed value is not supported.
+ * Especially if <code>null</code> is parsed and the implementation does not
+ * {@link #supportsDefault()}!
+ */
+ void encode(EncodedConstraintParts constraint,T value) throws IllegalArgumentException;
+ /**
+ * Returns <code>true</code> if this Encoder supports a default value. This
+ * would be e.g. an open ended upper or lower bound for range constraints or
+ * any language for text constraints.
+ * @return if the encoder supports a default encoding if no constraint of that
+ * type is provided by the query.
+ */
+ boolean supportsDefault();
+ /**
+ * A set of other Constraints that need to be present, that the encoding provided
+ * by this encoder results in a valid query constraint. e.g. A range constraint
+ * always need a lower and an upper bound. So even if the query only defines
+ * an upper bound, than there MUST BE also a open ended lower bound encoded to
+ * result in a valid query constraint.
+ * @return set of other index constraint types that must be present. If none
+ * return {@link Collections#emptySet()}. This Method should return an
+ * unmodifiable collection (e.g. {@link Arrays#asList(Object...)} or using
+ * {@link Collections#unmodifiableCollection(Collection)})
+ */
+ Collection<IndexConstraintTypeEnum> dependsOn();
+ /**
+ * The type of the constraint this implementation encodes
+ * @return the type of the constraints encoded by this implementation
+ */
+ IndexConstraintTypeEnum encodes();
+ /**
+ * Getter for the type of values this encoder accepts.
+ * @return the generic type of the index constraint type encoder
+ */
+ Class<T> acceptsValueType();
}
Modified: incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/IndexConstraintTypeEnum.java
URL: http://svn.apache.org/viewvc/incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/IndexConstraintTypeEnum.java?rev=1044832&r1=1044831&r2=1044832&view=diff
==============================================================================
--- incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/IndexConstraintTypeEnum.java (original)
+++ incubator/stanbol/trunk/rick/yard/solr/src/main/java/eu/iksproject/rick/yard/solr/query/IndexConstraintTypeEnum.java Sun Dec 12 15:13:35 2010
@@ -1,5 +1,5 @@
/**
- *
+ *
*/
package eu.iksproject.rick.yard.solr.query;
@@ -8,50 +8,50 @@ import eu.iksproject.rick.yard.solr.mode
/**
* Constraint Types defined for IndexFields<p>
- * This could be replaced by a more flexible way to register supported
+ * This could be replaced by a more flexible way to register supported
* constraint types in future versions
* @author Rupert Westenthaler
*/
public enum IndexConstraintTypeEnum{
- /**
- * constraints the DataType of values
- * @see IndexDataType
- */
- DATATYPE,
- /**
- * Constraints the language of values
- */
- LANG,
- /**
- * Constraints the field
- */
- FIELD,
- /**
- * Constraints the Value
- */
- EQ,
- /**
- * REGEX based filter on values
- */
- REGEX,
- /**
- * Wildcard based filter on values
- */
- WILDCARD,
- /**
- * Greater than constraint
- */
- GT,
- /**
- * Lower than constraint
- */
- LT,
- /**
- * Greater else constraint
- */
- GE,
- /**
- * Lower else constraint
- */
- LE,
-}
\ No newline at end of file
+ /**
+ * constraints the DataType of values
+ * @see IndexDataType
+ */
+ DATATYPE,
+ /**
+ * Constraints the language of values
+ */
+ LANG,
+ /**
+ * Constraints the field
+ */
+ FIELD,
+ /**
+ * Constraints the Value
+ */
+ EQ,
+ /**
+ * REGEX based filter on values
+ */
+ REGEX,
+ /**
+ * Wildcard based filter on values
+ */
+ WILDCARD,
+ /**
+ * Greater than constraint
+ */
+ GT,
+ /**
+ * Lower than constraint
+ */
+ LT,
+ /**
+ * Greater else constraint
+ */
+ GE,
+ /**
+ * Lower else constraint
+ */
+ LE,
+}