b3log的repositoriesMap里装了些什么

import org.b3log.latke.repository.jdbc.util.FieldDefinition;

import org.apache.commons.io.IOUtils;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class testRepositoriesMap {
	/**
	 * /** to json "nullable".
	 */
	private static final String NULLABLE = "nullable";

	/**
	 * /** to json "length".
	 */
	private static final String LENGTH = "length";

	/**
	 * ** to json "iskey".
	 */
	private static final String ISKEY = "iskey";

	/**
	 * the default keyname.
	 */
	public static final String OID = "oId";
	/**
	 * /** to json "keys".
	 */
	private static final String KEYS = "keys";
	/**
	 * /** to json "name".
	 */
	private static final String NAME = "name";
	/**
	 * /** to json "repositories".
	 */
	private static final String REPOSITORIES = "faka";
	/**
	 * /** to json "type".
	 */
	private static final String TYPE = "type";
	/**
	 * Stores all repository filed definition in a Map.
	 * 
	 * <p>
	 * key: the name of the repository value (or table name with prefix): list
	 * of all the FieldDefinition
	 * </p>
	 */
	private static Map<String, List<FieldDefinition>> repositoriesMap = null;
	/**
	 * Repositories description (repository.json).
	 */
	private static JSONObject jsonObject;

	/**
	 * @param args
	 * @throws JSONException
	 */
	public static void main(String[] args) throws JSONException {
		// TODO Auto-generated method stub
		final InputStream inputStream = testRepositoriesMap.class
				.getClassLoader().getResourceAsStream("liulixin.json");
		try {
			final String description = IOUtils.toString(inputStream);
			jsonObject = new JSONObject(description);
		} catch (final Exception e) {
		}

		repositoriesMap = new HashMap<String, List<FieldDefinition>>();
		final JSONArray repositoritArray = jsonObject
				.getJSONArray(REPOSITORIES);
		JSONObject repositoryObject;
		JSONObject fieldDefinitionObject;
		for (int i = 0; i < repositoritArray.length(); i++) {
			repositoryObject = repositoritArray.getJSONObject(i);
			final String repositoryName = repositoryObject.getString(NAME);
			System.out.println(repositoryName);
			final List<FieldDefinition> fieldDefinitions = new ArrayList<FieldDefinition>();

			repositoriesMap.put(repositoryName, fieldDefinitions);

			final JSONArray keysJsonArray = repositoryObject.getJSONArray(KEYS);

			FieldDefinition definition;

			for (int j = 0; j < keysJsonArray.length(); j++) {
				fieldDefinitionObject = keysJsonArray.getJSONObject(j);
				definition = fillFieldDefinitionData(fieldDefinitionObject);
				fieldDefinitions.add(definition);
				System.out.println(fieldDefinitionObject.getString(TYPE));
			}
		}

		about_repositoryMap();

	}

	static void about_repositoryMap() {
		System.out.println("inside about_repositoryMap()");
		System.out.println(repositoriesMap.get("comment").get(1).getName());
		System.out.println(repositoriesMap.get("comment").get(1).getType());
		System.out.println(repositoriesMap.get("comment").get(1).getLength());

	}

	/**
	 * fillFieldDefinitionData.
	 * 
	 * @param fieldDefinitionObject
	 *            josn model
	 * @return {@link FieldDefinition}
	 * @throws JSONException
	 *             JSONException
	 */
	private static FieldDefinition fillFieldDefinitionData(
			final JSONObject fieldDefinitionObject) throws JSONException {
		final FieldDefinition fieldDefinition = new FieldDefinition();

		fieldDefinition.setName(fieldDefinitionObject.getString(NAME));

		// final Integer type =
		// JSONTYPETOJDBCTYPEMAP
		// .get(fieldDefinitionObject.getString(TYPE));
		// if (type == null) {
		// LOGGER.severe("the type [" + fieldDefinitionObject.getString(TYPE)
		// + "] no mapping defined now!!!!");
		// throw new RuntimeException("the type ["
		// + fieldDefinitionObject.getString(TYPE)
		// + "] no mapping defined now!!!!");
		// }

		fieldDefinition.setType(fieldDefinitionObject.getString(TYPE));
		fieldDefinition.setNullable(fieldDefinitionObject.optBoolean(NULLABLE));
		fieldDefinition.setLength(fieldDefinitionObject.optInt(LENGTH));
		fieldDefinition.setIsKey(fieldDefinitionObject.optBoolean(ISKEY));

		/**
		 * the default key name is 'old'.
		 */
		if (OID.equals(fieldDefinition.getName())) {
			fieldDefinition.setIsKey(true);
		}

		return fieldDefinition;

	}

}

部分输出:

inside about_repositoryMap()
commentContent
String
2000

源代码:http://pan.baidu.com/share/link?shareid=842398635&uk=3878681452

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值