Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2013 eBuddy B.V.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ebuddy.cassandra.property;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang3.ArrayUtils;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.DeserializerProvider;
import org.codehaus.jackson.map.JsonDeserializer;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.deser.StdDeserializer;
import org.codehaus.jackson.type.JavaType;
import org.codehaus.jackson.type.TypeReference;
import me.prettyprint.cassandra.serializers.StringSerializer;
/**
* Factory for creating instances of PropertyValue implementations.
* Currently supports String values, Maps, and Lists.
* TODO: Get rid of PropertyValues. Although the idea was to make it more strongly typed than "Object"
* TODO: to only allow certain types, in practice it complicates the API too much
*
* @deprecated just use Objects instead of PropertyValues
* @author Eric Zoerner [email protected]
*/
@SuppressWarnings({"UnusedDeclaration", "unchecked"})
@Deprecated
public class PropertyValueFactory extends StdDeserializer> {
/**
* The delimiter character for separating parts of a hierarchical property name.
*/
public static final char DELIMITER = '|';
/**
* The delimiter character in a String for separating parts of a hierarchical property name.
*/
public static final String DELIMITER_STRING = new String(new char[]{DELIMITER});
/** Reusable PropertyValue containing the empty string. */
public static final PropertyValue EMPTY_STRING = StringValue.fromString("");
/** Reusable PropertyValue containing a TRUE value as a string. */
public static final PropertyValue TRUE = StringValue.fromString("1");
/** Reusable PropertyValue containing a FALSE value as a string. */
public static final PropertyValue FALSE = StringValue.fromString("0");
private static final PropertyValueFactory INSTANCE = new PropertyValueFactory();
private ObjectMapper mapper = new ObjectMapper();
/**
* Construct an instance. Intended to be a private static final singleton only.
*/
private PropertyValueFactory() {
super(PropertyValueFactory.class);
}
public static PropertyValueFactory get() {
return INSTANCE;
}
/**
* @deprecated use PropertyValue#createPropertyValue(String) instead
*/
// !!ezoerner::20130503 This method is a bad idea.
// The whole point of PropertyValue is to make it stronger typing than Object.
// this method makes it possible to create property values from domain objects, for example,
// and having them converted with toString would be astonishing to the caller.
// I actually removed a method like this at one point and it was later recreated by someone else...
@Deprecated
public PropertyValue> createPropertyValue(Object value) {
if (value instanceof List) {
return createPropertyValue((List)value);
}
if (value instanceof Map) {
return createPropertyValue((Map>)value);
}
return value == null ? createPropertyValue("") : createPropertyValue(value.toString());
}
/**
* Create a PropertyValue given a String.
* @param value the String value
* @return the PropertyValue
*/
public PropertyValue createPropertyValue(String value) {
return StringValue.fromString(value);
}
/**
* Create a PropertyValue