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 2010 Google 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.
*/
package com.google.gwt.autobean.shared;
import com.google.gwt.autobean.shared.AutoBeanVisitor.ParameterizationVisitor;
import com.google.gwt.autobean.shared.impl.EnumMap;
import com.google.gwt.autobean.shared.impl.LazySplittable;
import com.google.gwt.autobean.shared.impl.StringQuoter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
/**
* Utility methods for encoding an AutoBean graph into a JSON-compatible string.
* This codex intentionally does not preserve object identity, nor does it
* encode cycles, but it will detect them.
*
*
AutoBeans has moved to
* com.google.web.bindery.autobeans. This package will be
* removed in a future version of GWT.
*/
@Deprecated
public class AutoBeanCodex {
/**
* Describes a means of encoding or decoding a particular type of data to or
* from a wire format representation.
*
*
AutoBeans has moved to
* com.google.web.bindery.autobeans. This package will be
* removed in a future version of GWT.
*/
@Deprecated
interface Coder {
Object decode(Splittable data);
void encode(StringBuilder sb, Object value);
}
/**
* Creates a Coder that is capable of operating on a particular
* parameterization of a datastructure (e.g. {@code Map>}
* ).
*/
class CoderCreator extends ParameterizationVisitor {
private Stack stack = new Stack();
@Override
public void endVisitType(Class> type) {
if (List.class.equals(type) || Set.class.equals(type)) {
stack.push(new CollectionCoder(type, stack.pop()));
} else if (Map.class.equals(type)) {
// Note that the parameters are passed in reverse order
stack.push(new MapCoder(stack.pop(), stack.pop()));
} else if (Splittable.class.equals(type)) {
stack.push(new SplittableDecoder());
} else if (type.getEnumConstants() != null) {
@SuppressWarnings(value = {"rawtypes", "unchecked"})
EnumCoder decoder = new EnumCoder(type);
stack.push(decoder);
} else if (ValueCodex.canDecode(type)) {
stack.push(new ValueCoder(type));
} else {
stack.push(new ObjectCoder(type));
}
}
public Coder getCoder() {
assert stack.size() == 1 : "Incorrect size: " + stack.size();
return stack.pop();
}
}
class CollectionCoder implements Coder {
private final Coder elementDecoder;
private final Class> type;
public CollectionCoder(Class> type, Coder elementDecoder) {
this.elementDecoder = elementDecoder;
this.type = type;
}
public Object decode(Splittable data) {
Collection