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.visitors;
/*
* #%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 java.lang.reflect.Method;
import java.util.ArrayDeque;
import java.util.Deque;
import javax.inject.Inject;
import javax.inject.Provider;
import com.getperka.flatpack.FlatPackVisitor;
import com.getperka.flatpack.HasUuid;
import com.getperka.flatpack.codexes.EntityCodex;
import com.getperka.flatpack.ext.Codex;
import com.getperka.flatpack.ext.DeserializationContext;
import com.getperka.flatpack.ext.EntitySecurity;
import com.getperka.flatpack.ext.Property;
import com.getperka.flatpack.ext.PropertySecurity;
import com.getperka.flatpack.ext.TypeContext;
import com.getperka.flatpack.ext.VisitorContext;
import com.getperka.flatpack.inject.PackScoped;
import com.google.gson.JsonObject;
/**
* Populates the properties of individual entities.
*/
@PackScoped
public class PackReader extends FlatPackVisitor {
static class State {
HasUuid entity;
}
@Inject
private DeserializationContext context;
@Inject
private EntitySecurity entitySecurity;
@Inject
private Provider impliedPropertySetters;
private JsonObject payload;
@Inject
private PropertySecurity security;
private final Deque stack = new ArrayDeque();
@Inject
private TypeContext typeContext;
/**
* Requires injection.
*/
protected PackReader() {}
@Override
public void endVisit(Property prop, VisitorContext ctx) {
context.pushPath("." + prop.getName());
try {
// Ignore properties that cannot be set
if (prop.getSetter() == null) {
return;
}
String simplePropertyName = prop.getName();
context.pushPath("." + simplePropertyName);
try {
Object value;
if (prop.isEmbedded()) {
/*
* Embedded objects are never referred to by uuid in the payload, so an instance will need
* to be allocated before reading in the properties.
*/
@SuppressWarnings("unchecked")
EntityCodex codex = (EntityCodex) prop.getCodex();
HasUuid embedded = codex.allocateEmbedded(payload, context);
value = ctx.walkImmutable(codex).accept(this, embedded);
} else {
@SuppressWarnings("unchecked")
Codex