parser.java

来自「有限状态机程序自动生成器可以自动生成C、C++和Java程序。自动生成的程序很容」· Java 代码 · 共 58 行

JAVA
58
字号
package org.abeesoft.fsmgenerator.parser.xml;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import org.abeesoft.fsmgenerator.configuration.Configuration;
import org.abeesoft.fsmgenerator.exception.Exception;
import org.abeesoft.fsmgenerator.specification.Specification;

public class Parser extends org.abeesoft.fsmgenerator.parser.Parser
{
	private static final String	FORMAT	= "xml";

	/**
	 * @param configuration
	 * @param specification
	 */
	public Parser( Configuration configuration )
	{
		super( configuration, FORMAT );
	}

	public Specification parse() throws Exception
	{
		if( configuration == null )
			throw new Exception();
		
		if( configuration.getSpecification().getFile() == null )
			throw new Exception();
			
		if( !configuration.getSpecification().getFormat().equals(getFormat()) )
			throw new Exception();
		
		Specification specification = null;
		try
		{
			JAXBContext jc = JAXBContext.newInstance("org.abeesoft.fsmgenerator.specification");
			Unmarshaller u = jc.createUnmarshaller();
			specification = (Specification)u.unmarshal(new FileInputStream(configuration.getSpecification().getFile()));
		}
		catch ( JAXBException e )
		{
			throw new Exception(e);
		}
		catch ( FileNotFoundException e )
		{
			throw new Exception(e);
		}
		
		return specification;
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?