/*
 * Copyright 2007 Kickmogu Co. Ltd. All rights reserved.
 *
 * 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.
 */



/*
 * 作成日: 2007/02/03
 *
 * TODO この生成されたファイルのテンプレートを変更するには次へジャンプ:
 * ウィンドウ - 設定 - Java - コード・スタイル - コード・テンプレート
 */
package com.kickmogu.rhythm.core.test;

import java.io.IOException;

import com.kickmogu.rhythm.core.*;

public class RoleXmlConvert {
	public static void main(String[] a) throws IOException {
		Role root = (Role) RhythmTreeManager.getRoot(Role.class);
		setAP(root);
		RhythmTreeManager.write(Role.class);
	}
	
	private static void setAP(Role root) {
		for (int i = 0; i < root.getAssisnPermissions().size(); i++) {
			AssignPermission ap = root.getAssisnPermissions().get(i);
			if (ap.getPermission() != null) {
				ap.setPermissionId(ap.getPermission().getId());
				//ap.setPermission(null);
			} else {
				ap.setPermissionId(-100);
			}
			if (ap.getTarget() != null) {
				ap.setTargetId(ap.getTarget().getId());
				//ap.setTarget(null);
			} else {
				ap.setTargetId(-100);
			}
		}
		for (int i = 0; i < root.getChildren().size(); i++) {
			setAP((Role) root.getChildren().get(i));
		}
	}
}
