⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 namenode.java

📁 OBPM是一个开源
💻 JAVA
字号:
/*
 * Created on 2005-3-31
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package cn.myapps.core.workflow.utility;

import cn.myapps.core.workflow.storage.runtime.ejb.Type;

/**
 * @author ZhouTY
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class NameNode {
	private String text;

	// private String name;

	public NameNode(String text) {
		this.text = text;
	}

	// 获取ID(角色或人员)
	public String getId() {
		if (text == null || text.trim().equals("")) {
			return null;
		}
		String[] tmp = CommonUtil.split(text, '|');
		if (tmp != null && tmp.length >= 1) {
			return tmp[0].substring(1);
		} else {
			return null;
		}
	}

	// 获取部门字串
	public String getDept() {
		if (text == null || text.trim().equals("")) {
			return null;
		}
		String[] tmp = CommonUtil.split(text, '|');
		if (tmp != null && tmp.length >= 2) {
			String part2 = tmp[1];
			int pos2 = part2.lastIndexOf("/");
			if (pos2 > 0) {
				return part2.substring(0, pos2);
			}
		}
		return null;
	}

	// 获取角色字串(角色或人员)
	public String getShortName() {
		if (text == null || text.trim().equals("")) {
			return null;
		}
		String[] tmp = CommonUtil.split(text, '|');
		if (tmp != null && tmp.length >= 2) {
			String part = tmp[1];
			int lastpos = part.lastIndexOf("/");
			if (lastpos > 0 && lastpos + 1 <= part.length()) {
				return part.substring(lastpos + 1, part.length());
			} else {
				return part;
			}
		}
		return null;
	}

	/**
	 * @return Returns the name.
	 */
	public String getText() {
		return text;
	}

	/**
	 * @param name
	 *            The name to set.
	 */
	public void setText(String text) {
		this.text = text;
	}

	public boolean equals(Object obj) {
		if (obj instanceof NameNode) {
			NameNode node = (NameNode) obj;
			String id1 = node.getId();
			String id2 = getId();
			boolean flag = id1 != null && id1.trim().length() > 0
					&& id2 != null && id2.trim().length() > 0
					&& id1.equals(id2);
			return flag;
		}
		return false;
	}

	public String toString(boolean onlyId) {
		if (text != null && text.trim().length() > 0) {
			if (onlyId) {
				return getId() + ";";
			} else {
				return text + ";";
			}
		}
		return "";
	}

	public String toString() {
		return toString(false);
	}

	public int getType() {
		if (text != null && text.length() > 1) {
			char t = text.charAt(0);
			switch (t) {
			case 'D':
				return Type.TYPE_DEPARTMENT;
			case 'U':
				return Type.TYPE_USER;
			case 'R':
				return Type.TYPE_ROLE;
			}
		}
		return -1;
	}

	public static void main(String[] args) {
		String s = "A001|a/b/c";
		NameNode n = new NameNode(s);
		System.out.println(n.toString(true));
		System.out.println(n.getId());
		System.out.println(n.getDept());
		System.out.println(n.getShortName());

	}

}

⌨️ 快捷键说明

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