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 (c) 2008, http://www.snakeyaml.org
*
* 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 org.yaml.snakeyaml.constructor;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.error.YAMLException;
import org.yaml.snakeyaml.introspector.Property;
import org.yaml.snakeyaml.nodes.MappingNode;
import org.yaml.snakeyaml.nodes.Node;
import org.yaml.snakeyaml.nodes.NodeId;
import org.yaml.snakeyaml.nodes.NodeTuple;
import org.yaml.snakeyaml.nodes.ScalarNode;
import org.yaml.snakeyaml.nodes.SequenceNode;
import org.yaml.snakeyaml.nodes.Tag;
/**
* Construct a custom Java instance.
*/
public class Constructor extends SafeConstructor {
public Constructor() {
this(Object.class);
}
public Constructor(LoaderOptions loadingConfig) {
this(Object.class, loadingConfig);
}
/**
* Create Constructor for the specified class as the root.
*
* @param theRoot
* - the class (usually JavaBean) to be constructed
*/
public Constructor(Class extends Object> theRoot) {
this(new TypeDescription(checkRoot(theRoot)));
}
public Constructor(Class extends Object> theRoot, LoaderOptions loadingConfig) {
this(new TypeDescription(checkRoot(theRoot)), loadingConfig);
}
/**
* Ugly Java way to check the argument in the constructor
*/
private static Class extends Object> checkRoot(Class extends Object> theRoot) {
if (theRoot == null) {
throw new NullPointerException("Root class must be provided.");
} else
return theRoot;
}
public Constructor(TypeDescription theRoot) {
this(theRoot, null, new LoaderOptions());
}
public Constructor(TypeDescription theRoot, LoaderOptions loadingConfig) {
this(theRoot, null, loadingConfig);
}
public Constructor(TypeDescription theRoot, Collection moreTDs) {
this(theRoot, moreTDs, new LoaderOptions());
}
public Constructor(TypeDescription theRoot, Collection moreTDs, LoaderOptions loadingConfig) {
super(loadingConfig);
if (theRoot == null) {
throw new NullPointerException("Root type must be provided.");
}
this.yamlConstructors.put(null, new ConstructYamlObject());
if (!Object.class.equals(theRoot.getType())) {
rootTag = new Tag(theRoot.getType());
}
yamlClassConstructors.put(NodeId.scalar, new ConstructScalar());
yamlClassConstructors.put(NodeId.mapping, new ConstructMapping());
yamlClassConstructors.put(NodeId.sequence, new ConstructSequence());
addTypeDescription(theRoot);
if (moreTDs != null) {
for (TypeDescription td : moreTDs) {
addTypeDescription(td);
}
}
}
/**
* Create Constructor for a class which does not have to be in the classpath
* or for a definition from a Spring ApplicationContext.
*
* @param theRoot
* fully qualified class name of the root class (usually
* JavaBean)
* @throws ClassNotFoundException if cannot be loaded by the classloader
*/
public Constructor(String theRoot) throws ClassNotFoundException {
this(Class.forName(check(theRoot)));
}
public Constructor(String theRoot, LoaderOptions loadingConfig) throws ClassNotFoundException {
this(Class.forName(check(theRoot)), loadingConfig);
}
private static final String check(String s) {
if (s == null) {
throw new NullPointerException("Root type must be provided.");
}
if (s.trim().length() == 0) {
throw new YAMLException("Root type must be provided.");
}
return s;
}
/**
* Construct mapping instance (Map, JavaBean) when the runtime class is
* known.
*/
protected class ConstructMapping implements Construct {
/**
* Construct JavaBean. If type safe collections are used please look at
* TypeDescription.
*
* @param node
* node where the keys are property names (they can only be
* Strings) and values are objects to be created
* @return constructed JavaBean
*/
public Object construct(Node node) {
MappingNode mnode = (MappingNode) node;
if (Map.class.isAssignableFrom(node.getType())) {
if (node.isTwoStepsConstruction()) {
return newMap(mnode);
} else {
return constructMapping(mnode);
}
} else if (Collection.class.isAssignableFrom(node.getType())) {
if (node.isTwoStepsConstruction()) {
return newSet(mnode);
} else {
return constructSet(mnode);
}
} else {
Object obj = Constructor.this.newInstance(mnode);
if (node.isTwoStepsConstruction()) {
return obj;
} else {
return constructJavaBean2ndStep(mnode, obj);
}
}
}
@SuppressWarnings("unchecked")
public void construct2ndStep(Node node, Object object) {
if (Map.class.isAssignableFrom(node.getType())) {
constructMapping2ndStep((MappingNode) node, (Map