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.
package com.getperka.flatpack.codexes;
/*
* #%L
* FlatPack serialization code
* %%
* Copyright (C) 2012 - 2013 Perka Inc.
* %%
* 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.
* #L%
*/
import static com.getperka.flatpack.util.FlatPackCollections.listForAny;
import static com.getperka.flatpack.util.FlatPackCollections.sortedMapForIteration;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import javax.inject.Inject;
import org.slf4j.Logger;
import com.getperka.flatpack.ext.DeserializationContext;
import com.getperka.flatpack.ext.JsonKind;
import com.getperka.flatpack.ext.SerializationContext;
import com.getperka.flatpack.ext.Type;
import com.getperka.flatpack.ext.TypeContext;
import com.getperka.flatpack.ext.TypeHint;
import com.getperka.flatpack.inject.FlatPackLogger;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter;
/**
* Encodes Java annotations as simple datastructures. If an annotation being deserialized is not
* available in the classpath, it will be replaced with an {@link UnknownAnnotation}. The annotation
* instances produced by this codex will also implement the {@link AnnotationInfo} interface, which
* allows map-based access to annotation properties.
*/
public class AnnotationCodex extends ValueCodex {
static class Handler implements InvocationHandler, AnnotationInfo {
private final Class extends Annotation> annotationType;
private final String annotationTypeName;
private final Map values;
Handler(Class extends Annotation> annotationType, Map values) {
this.annotationType = annotationType;
this.annotationTypeName = annotationType.getName();
this.values = values;
}
Handler(String annotationTypeName, Map values) {
this.annotationType = UnknownAnnotation.class;
this.annotationTypeName = annotationTypeName;
this.values = values;
}
@Override
public String getAnnotationTypeName() {
return annotationTypeName;
}
@Override
public Map getAnnotationValues() {
return values;
}
@Override
public int hashCode() {
return values.hashCode();
}
@Override
public Object invoke(Object instance, Method m, Object[] args) throws Throwable {
if (Object.class.equals(m.getDeclaringClass())) {
if (m.getName().equals("equals")) {
return equals((Annotation) instance, args[0]);
}
return m.invoke(this, args);
}
if (AnnotationInfo.class.equals(m.getDeclaringClass())) {
return m.invoke(this, args);
}
if (m.getName().equals("annotationType")) {
return annotationType;
}
Object toReturn = values.get(m.getName());
if (toReturn == null) {
return m.getDefaultValue();
}
return toReturn;
}
@Override
public String toString() {
return values.toString();
}
private List> asList(Object array) {
List