Java Code Examples for org.yaml.snakeyaml.nodes.Node#setType()

The following examples show how to use org.yaml.snakeyaml.nodes.Node#setType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompactConstructor.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void construct2ndStep(Node node, Object object) {
    // Compact Object Notation may contain only one entry
    MappingNode mnode = (MappingNode) node;
    NodeTuple nodeTuple = mnode.getValue().iterator().next();

    Node valueNode = nodeTuple.getValueNode();

    if (valueNode instanceof MappingNode) {
        valueNode.setType(object.getClass());
        constructJavaBean2ndStep((MappingNode) valueNode, object);
    } else {
        // value is a list
        applySequence(object, constructSequence((SequenceNode) valueNode));
    }
}
 
Example 2
Source File: CompactConstructor.java    From snake-yaml with Apache License 2.0 6 votes vote down vote up
@Override
public void construct2ndStep(Node node, Object object) {
    // Compact Object Notation may contain only one entry
    MappingNode mnode = (MappingNode) node;
    NodeTuple nodeTuple = mnode.getValue().iterator().next();

    Node valueNode = nodeTuple.getValueNode();

    if (valueNode instanceof MappingNode) {
        valueNode.setType(object.getClass());
        constructJavaBean2ndStep((MappingNode) valueNode, object);
    } else {
        // value is a list
        applySequence(object, constructSequence((SequenceNode) valueNode));
    }
}
 
Example 3
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(EnvironmentElement.class);
	String path = getPath(node);
	EnvironmentElement be = new LazyEnvironmentElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	return be;
}
 
Example 4
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(ProjectSampleElement.class);
	String path = getPath(node);
	ProjectSampleElement be = new ProjectSampleElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	return be;
}
 
Example 5
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(ProjectTemplateElement.class);
	String path = getPath(node);
	ProjectTemplateElement be = new ProjectTemplateElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	return be;
}
 
Example 6
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(MenuElement.class);
	String path = getPath(node);
	MenuElement be = new MenuElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	forcePathsOfChildren(be.getChildren());
	return be;
}
 
Example 7
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(SmartTypingPairsElement.class);
	String path = getPath(node);
	SmartTypingPairsElement be = new SmartTypingPairsElement(path);
	MappingNode mapNode = (MappingNode) node;
	List<NodeTuple> tuples = mapNode.getValue();
	for (NodeTuple tuple : tuples)
	{
		ScalarNode keyNode = (ScalarNode) tuple.getKeyNode();
		String key = keyNode.getValue();
		// "pairs", "scope", "displayName" are required
		if ("pairs".equals(key)) //$NON-NLS-1$
		{
			SequenceNode pairsValueNode = (SequenceNode) tuple.getValueNode();
			List<Character> pairs = new ArrayList<Character>();
			List<Node> pairsValues = pairsValueNode.getValue();
			for (Node pairValue : pairsValues)
			{
				ScalarNode blah = (ScalarNode) pairValue;
				String pairCharacter = blah.getValue();
				pairs.add(Character.valueOf(pairCharacter.charAt(0)));
			}
			be.setPairs(pairs);
		}
		else if ("scope".equals(key)) //$NON-NLS-1$
		{
			ScalarNode scopeValueNode = (ScalarNode) tuple.getValueNode();
			be.setScope(scopeValueNode.getValue());
		}
		else if ("displayName".equals(key)) //$NON-NLS-1$
		{
			ScalarNode displayNameNode = (ScalarNode) tuple.getValueNode();
			be.setDisplayName(displayNameNode.getValue());
		}
	}
	return be;
}
 
Example 8
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(SnippetElement.class);
	String path = getPath(node);
	SnippetElement be = new SnippetElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	setPrefixTriggers(node, be);
	return be;
}
 
Example 9
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(CommandElement.class);
	String path = getPath(node);
	CommandElement be = new LazyCommandElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	setPrefixTriggers(node, be);
	return be;
}
 
Example 10
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(BundleElement.class);
	String path = getPath(node);
	BundleElement be = new BundleElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	return be;
}
 
Example 11
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(BuildPathElement.class);

	String path = getPath(node);
	String buildPath = getPath(node, "buildPath"); //$NON-NLS-1$
	BuildPathElement bpe = new BuildPathElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, bpe);
	bpe.setPath(path);
	bpe.setBuildPath(buildPath);
	return bpe;
}
 
Example 12
Source File: Serialization.java    From Diorite with MIT License 5 votes vote down vote up
/**
 * Serialize a Java object into a YAML Node.
 *
 * @param data
 *         Java object to be Serialized to YAML
 *
 * @return YAML Node
 */
public Node toYamlNode(@Nullable Object data)
{
    Node represent = this.yaml().represent(data);
    if (data != null)
    {
        if (! (data instanceof Map) && ! (data instanceof Collection))
        {
            represent.setType(data.getClass());
            represent.setTag(new Tag(data.getClass()));
        }
    }
    return represent;
}
 
Example 13
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(ContentAssistElement.class);
	String path = getPath(node);
	ContentAssistElement be = new LazyContentAssistElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	setPrefixTriggers(node, be);
	return be;
}
 
Example 14
Source File: BundleCacher.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public Object construct(Node node)
{
	node.setType(TemplateElement.class);
	String path = getPath(node);
	TemplateElement be = new LazyTemplateElement(path);
	Construct mappingConstruct = yamlClassConstructors.get(NodeId.mapping);
	mappingConstruct.construct2ndStep(node, be);
	be.setPath(path);
	setPrefixTriggers(node, be);
	return be;
}
 
Example 15
Source File: PerlTest.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
protected Construct getConstructor(Node node) {
    if (node.getTag().equals(new Tag("!de.oddb.org,2007/ODDB::Util::Code"))) {
        node.setUseClassConstructor(true);
        node.setType(CodeBean.class);
    }
    return super.getConstructor(node);
}
 
Example 16
Source File: Constructor.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
private Construct getConstructor(Node node) {
    Class<?> cl = getClassForNode(node);
    node.setType(cl);
    // call the constructor as if the runtime class is defined
    Construct constructor = yamlClassConstructors.get(node.getNodeId());
    return constructor;
}
 
Example 17
Source File: Constructor.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private Construct getConstructor(Node node) {
    Class<?> cl = getClassForNode(node);
    node.setType(cl);
    // call the constructor as if the runtime class is defined
    Construct constructor = yamlClassConstructors.get(node.getNodeId());
    return constructor;
}
 
Example 18
Source File: BaseConstructor.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
protected Object constructArrayStep2(SequenceNode node, Object array) {
    final Class<?> componentType = node.getType().getComponentType();

    int index = 0;
    for (Node child : node.getValue()) {
        // Handle multi-dimensional arrays...
        if (child.getType() == Object.class) {
            child.setType(componentType);
        }

        final Object value = constructObject(child);

        if (componentType.isPrimitive()) {
            // Null values are disallowed for primitives
            if (value == null) {
                throw new NullPointerException("Unable to construct element value for " + child);
            }

            // Primitive arrays require quite a lot of work.
            if (byte.class.equals(componentType)) {
                Array.setByte(array, index, ((Number) value).byteValue());

            } else if (short.class.equals(componentType)) {
                Array.setShort(array, index, ((Number) value).shortValue());

            } else if (int.class.equals(componentType)) {
                Array.setInt(array, index, ((Number) value).intValue());

            } else if (long.class.equals(componentType)) {
                Array.setLong(array, index, ((Number) value).longValue());

            } else if (float.class.equals(componentType)) {
                Array.setFloat(array, index, ((Number) value).floatValue());

            } else if (double.class.equals(componentType)) {
                Array.setDouble(array, index, ((Number) value).doubleValue());

            } else if (char.class.equals(componentType)) {
                Array.setChar(array, index, ((Character) value).charValue());

            } else if (boolean.class.equals(componentType)) {
                Array.setBoolean(array, index, ((Boolean) value).booleanValue());

            } else {
                throw new YAMLException("unexpected primitive type");
            }

        } else {
            // Non-primitive arrays can simply be assigned:
            Array.set(array, index, value);
        }

        ++index;
    }
    return array;
}
 
Example 19
Source File: BaseConstructor.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
protected Object constructArrayStep2(SequenceNode node, Object array) {
    final Class<?> componentType = node.getType().getComponentType();

    int index = 0;
    for (Node child : node.getValue()) {
        // Handle multi-dimensional arrays...
        if ( child.getType() == Object.class ) {
            child.setType(componentType);
        }
        
        final Object value = constructObject(child);

        if (componentType.isPrimitive()) {
            // Null values are disallowed for primitives
            if ( value == null ) {
                throw new NullPointerException ( "Unable to construct element value for " + child );
            }
            
            // Primitive arrays require quite a lot of work.
            if (byte.class.equals(componentType)) {
                Array.setByte(array, index, ((Number) value).byteValue());

            } else if (short.class.equals(componentType)) {
                Array.setShort(array, index, ((Number) value).shortValue());

            } else if (int.class.equals(componentType)) {
                Array.setInt(array, index, ((Number) value).intValue());

            } else if (long.class.equals(componentType)) {
                Array.setLong(array, index, ((Number) value).longValue());

            } else if (float.class.equals(componentType)) {
                Array.setFloat(array, index, ((Number) value).floatValue());

            } else if (double.class.equals(componentType)) {
                Array.setDouble(array, index, ((Number) value).doubleValue());

            } else if (char.class.equals(componentType)) {
                Array.setChar(array, index, ((Character) value).charValue());

            } else if (boolean.class.equals(componentType)) {
                Array.setBoolean(array, index, ((Boolean) value).booleanValue());

            } else {
                throw new YAMLException("unexpected primitive type");
            }

        } else {
            // Non-primitive arrays can simply be assigned:
            Array.set(array, index, value);
        }

        ++index;
    }
    return array;
}
 
Example 20
Source File: BaseConstructor.java    From onedev with MIT License 4 votes vote down vote up
protected Object constructArrayStep2(SequenceNode node, Object array) {
    final Class<?> componentType = node.getType().getComponentType();

    int index = 0;
    for (Node child : node.getValue()) {
        // Handle multi-dimensional arrays...
        if (child.getType() == Object.class) {
            child.setType(componentType);
        }

        final Object value = constructObject(child);

        if (componentType.isPrimitive()) {
            // Null values are disallowed for primitives
            if (value == null) {
                throw new NullPointerException(
                        "Unable to construct element value for " + child);
            }

            // Primitive arrays require quite a lot of work.
            if (byte.class.equals(componentType)) {
                Array.setByte(array, index, ((Number) value).byteValue());

            } else if (short.class.equals(componentType)) {
                Array.setShort(array, index, ((Number) value).shortValue());

            } else if (int.class.equals(componentType)) {
                Array.setInt(array, index, ((Number) value).intValue());

            } else if (long.class.equals(componentType)) {
                Array.setLong(array, index, ((Number) value).longValue());

            } else if (float.class.equals(componentType)) {
                Array.setFloat(array, index, ((Number) value).floatValue());

            } else if (double.class.equals(componentType)) {
                Array.setDouble(array, index, ((Number) value).doubleValue());

            } else if (char.class.equals(componentType)) {
                Array.setChar(array, index, ((Character) value).charValue());

            } else if (boolean.class.equals(componentType)) {
                Array.setBoolean(array, index, ((Boolean) value).booleanValue());

            } else {
                throw new YAMLException("unexpected primitive type");
            }

        } else {
            // Non-primitive arrays can simply be assigned:
            Array.set(array, index, value);
        }

        ++index;
    }
    return array;
}