权限组件所缺的文件

发表于:2007-07-04来源:作者:点击数: 标签:
原意是给大家看一下结构,没想大家都那么关心,我现在把所有的代码贴上来,谢谢大家关心. 唉,BLOG好烦啊,无法直接上传文件要一个一个贴 ================ResourceLib. java ============ package org.fswan; import java.util.ArrayList; import java.util.Prope
原意是给大家看一下结构,没想大家都那么关心,我现在把所有的代码贴上来,谢谢大家关心.

唉,BLOG好烦啊,无法直接上传文件要一个一个贴


================ResourceLib.java ============
package org.fswan;

import java.util.ArrayList;
import java.util.Properties;

/**
* 用来存储通用的XML配置文件位置和数据库连接属性.
* 作为org.fswan里所有的包中类的基础配置文件.
*/
public class ResourceLib
{
/**
* 驱动的字符串
*/
public static final String DRIVER = "Driver";
/**
* 数据库连接字符串
*/
public static final String URL = "URL";
/**
* 用户
*/
public static final String USER = "User";
/**
* 密码
*/
public static final String PASSWORD = "Password";
/**
* 所有的XML配置文件的存储位置,存储的对象为URL
*/
private static ArrayList resource = new ArrayList();
/**
* 存储所有的数据库配置.
* 所有的数据库存储位置格式为:
* 对象为Properties对象
* 而properties对象里包含:
* {@link #DRIVER DRIVER},{@link #URL URL},{@link #USER USER},{@link #PASSWORD PASSWORD},{@link #VIEW VIEW},{@link #TYPE TYPE}六个属性分别对应
* 数据库的驱动,边接字符串,用户名,密码,视图,类型
* 或者
* {@link #JNDI JNDI},{@link #VIEW VIEW},{@link #TYPE TYPE}
* JNDI名,视图,类型
* 类型是以下的一个
* {@link #WORKFLOW WORKFLOW}
* {@link #BRAND BRAND}
* {@link #STATUS STATUS}
* {@link #SWITCH SWITCHER}
* {@link #WORKUNIT WORKUNIT}
* {@link #USER USER}
*/
private static ArrayList prop = new ArrayList();
/**
* 获取所有的XML资源
* @return XML资源泉
*/
public static ArrayList getXmlResource()
{
return resource;
}
/**
* 获取所有的数据库连接属性
* @return 数据库链接属性
*/
public static ArrayList getConnection()
{
return prop;
}
/**
* 增加XML资源
* @param source XML资源
*/
public static void addResource(String source)
{
synchronized(resource)
{
resource.add(source);
}
}
/**
* 增加数据库链接属性
* @param pro 数据库链接属性
*/
public static void addDataProperty(Properties pro)
{
synchronized(prop)
{
prop.add(pro);
}
}
}

==============Input.java============
/*
* Created on 2003-11-20
*
* Create By 方志文
* email:fswan@yeah.net
*/
package org.fswan;

/**
* @author 方志文
*
* 输入数据的接口,作为主类的数据输入式,
* 现可以从xml,HttpServletRequest和JSPUpload获取数据
*
*/
public interface Input {
/**
* 获取参数的值,如果无该参数则返回null,如果该参数对应多个值则返回其第一个值
* @param parameter 参数
* @return 值
*/
public String getParameter(String parameter);
/**
* 获取参数的值列表
* @param parameter 参数
* @return 值
*/
public String[] getParameterValues(String parameter);
/**
* 获取参数名的列表
* @return 所有的参数的名
*/
public String[] getParameterNames();
/**
* 获取数据源
* @return 数据源
*/
public Object getSource();
/**
* 设置参数,如果已存在该参数,则原来的作废
* @param parameter 参数
* @param value 值
*/
public void setParameter(String parameter,String value);
/**
* 设置参数,如果已存在该参数,则把原来的作废
* @param parameter 参数
* @param values 值
*/
public void setParameter(String parameter,String[] values);
/**
* 添加参数,如果已存在该参数,则把该值添加到原值后成数组
* @param parameter 参数
* @param value 值
*/
public void addParameter(String parameter,String value);
/**
* 添加参数(多个值),如果已存在该参数,则把该值添加到原值后成数组
* @param parameter 参数
* @param values 值
*/
public void addParameter(String parameter,String[] values);
}
================ManualInput.java ==============
package org.fswan;

public class ManualInput extends AbstractInput
{
/* (non-Javadoc)
* @see org.fswan.Input#getSource()
*/
public Object getSource()
{
return null;
}

}
===================Identity.java==========
package org.fswan;

import org.fswan.workflow.exception.IdentityMappingError;

/**
* @author Administrator
* 这个接是一个标识,用来唯一标识所有的工作流,状态,切换开关,分枝操作
*/
public interface Identity
{
/**
* 工作流的标识
*/
public static final int WORKFLOW = 0;
/**
* 分枝操作的标识
*/
public static final int BRAND = 1;
/**
* 状态的标识
*/
public static final int STATUS =2;
/**
* 切换开关的标识
*/
public static final int SWITCH = 3;
/**
* 用户的标识
*/
public static final int USER = 4;
/**
* 工作单元
*/
public static final int WORKUNIT = 5;
/**
* 角色
*/
public static final int ROLE = 6;
/**
* 群组
*/
public static final int GROUP = 7;

public static final int VIEWCLASS = 255;

public static final String XMLWORKFLOW = "XMLWorkFlow";
public static final String XMLBRAND = "XMLBrand";
public static final String XMLSWITCHER = "XMLSwitcher";
public static final String XMLSTATUS = "XMLStatus";
public static final String XMLWORKUNIT = "XMLWorkUnit";
public static final String DBWORKFLOW = "DBWorkFlow";
public static final String DBBRAND = "DBBrand";
public static final String DBSWITCHER = "DBSwitcher";
public static final String DBSTATUS = "DBStatus";
public static final String DBWORKUNIT = "DBWorkUnit";
public static final String XMLUSER = "XMLUser";
public static final String XMLGROUP = "XMLGroup";
public static final String XMLROLE = "XMLRole";

/**
* 获取标识的类型
* 是以下常量中的一个
* {@link #WORKFLOW WORKFLOW}
* {@link #BRAND BRAND}
* {@link #STATUS STATUS}
* {@link #SWITCH SWITCH}
* {@link #USER USER}
* @return 标识的类型
*/
public int getIdType();
/**
* 获取标识的名称
* @return 标识的名称
*/
public String getIdName();
/**
* 返回该Identity的子类型,该子类型是给newInstance使用的
* @return 子类型
*/
public String getSubType();
/**
* 通过ID生成实例
* @return 实例
* @throws IdentityMappingError 找不到生器异常
*/
public Object newInstance() throws IdentityMappingError;
}
=============IdentityImpl.java===============
package org.fswan;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Hashtable;

import org.fswan.workflow.exception.IdentityMapHadExist;
import org.fswan.workflow.exception.IdentityMappingError;

/**
* 唯一标识符类.
* 由唯一标识符可以调用相应的类来生成相对应的接口生成相对应的实例
* 不同种类标识符生成相对应的实例的类在{@link map}中进行映射定义.
* 可调用静态方法register进行注册.
*/
public class IdentityImpl implements Identity
{
private String name;
private int type;
private String subType;
/**
* 从ID到类的映射表
*/
private static Hashtable map = new Hashtable();
public IdentityImpl(int type,String subType,String name)
{
this.type = type;
this.subType=subType;
this.name = name;
}
public IdentityImpl genIdentity(int type)
{
SimpleDateFormat f = new SimpleDateFormat("yyyyMMddHHmmssSSS");
String name = f.format(new Date());
return new IdentityImpl(type,"",name);
}
/* (non-Javadoc)
* @see org.fswan.Identity#getIdName()
*/
public String getIdName()
{
return name;
}

/* (non-Javadoc)
* @see org.fswan.Identity#getIdType()
*/
public int getIdType()
{
return type;
}
public String getSubType()
{
return subType;
}

public String toString()
{
return "["+type+":"+name+"]";
}
public boolean equals(Object obj)
{
if(obj instanceof Identity)
{
return this.getIdType()==((Identity)obj).getIdType()
&& getIdName().equals(((Identity)obj).getIdName());
}
return false;
}
/**
* 查找相应对的对象
* @return 实例化后的对象
* @throws IdentityMappingError 映射实现不了,
* 可能是因为注册的类不存在或者无法实例化该类,或该类不是ImplementIdentity
*/
public Object newInstance() throws IdentityMappingError
{
try
{
if(map.get(subType)==null)return null;
ImplementIdentity ids = (ImplementIdentity)Class.forName(map.get(subType).toString()).newInstance();
return ids.newInstance(this);
} catch (InstantiationException e)
{
e.printStackTrace();
} catch (IllegalAclearcase/" target="_blank" >ccessException e)
{
e.printStackTrace();
} catch (ClassNotFoundException e)
{
e.printStackTrace();
}
throw new IdentityMappingError();
}
/**
* 注册标识种类到生成实例类的映射
* @param type 类型
* @param obj 相对应的类名
* @throws IdentityMapHadExist 异常,(该类型已注册)
*/
public static void register(String subType,String obj) throws IdentityMapHadExist
{
if(map.containsKey(subType)) throw new IdentityMapHadExist(subType);
map.put(subType,obj);
}
static
{
try
{
IdentityImpl.register(Identity.DBBRAND,"org.fswan.workflow.DBWrokFlow");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.DBSTATUS,"org.fswan.workflow.DBStatus");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.DBSWITCHER,"org.fswan.workflow.DBSwitcher");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.DBWORKFLOW,"org.fswan.workflow.DBWrokFlow");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.DBWORKUNIT,"org.fswan.workflow.DBWorkUnit");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.XMLBRAND,"org.fswan.workflow.XMLBrand");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.XMLGROUP,"org.fswan.permission.XMLGroup");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.XMLROLE,"org.fswan.permission.XMLRole");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.XMLSTATUS,"org.fswan.workflow.XMLStatus");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.XMLSWITCHER,"org.fswan.workflow.XMLSwitcher");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.XMLUSER,"org.fswan.permission.XMLUser");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.XMLWORKFLOW,"org.fswan.workflow.XMLWorkFlow");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}
try
{
IdentityImpl.register(Identity.XMLWORKUNIT,"org.fswan.workflow.XMLWorkUnit");
} catch (IdentityMapHadExist e)
{
e.printStackTrace();
}

}
}
==================ImplementIdentity.java=============
package org.fswan;

/**
* @author swan
* 通过ID实例化相应的对象.
* 当用户自己实现User,Role,Group,Brand等对象时,通过ID来查找相对应的对象,
* 在类IdentityImpl对象中根据注册各种Identity类型对应的InstanceIdentity对象
* 来实例化对象.
* 注意:该接口的子类的构造方法一定是PUBLIC且不带任何参数.
*/
public interface ImplementIdentity
{
/**
* 实例化ID相对对应的对象.
* @param identity 要实例化的对象的ID
* @return 对象
*/
public Object newInstance(Identity identity);
}
===========CantFoundIDException.java-==============
package org.fswan.workflow.exception;

import org.fswan.Identity;

/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class CantFoundIDException extends Exception
{
public CantFoundIDException(Identity id)
{
super("Can''t Found ID:["+id.getIdType()+":"+id.getIdName()+"]");
}
}
==================IdentityMapHadExist.java============
package org.fswan.workflow.exception;

/**
* @author swan
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class IdentityMapHadExist extends Exception
{
public IdentityMapHadExist(String subType)
{
super("Mapping Had Exist:"+subType);
}
}
==================IdentityMappingError.java============
package org.fswan.workflow.exception;

/**
* @author swan
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class IdentityMappingError extends Exception
{
public IdentityMappingError()
{
super("The Mapping Class is not InstanceIdentity.");
}
}
=================TypeCastException.java ============
package org.fswan.workflow.exception;

import org.fswan.db.Field;

/**
* 类型转换异常,当从字符串转成特定类型出错时抛出
*/
public class TypeCastException extends Exception
{
/**
* 构造函数
* @param field 字段
* @param str 字符串值
*/
public TypeCastException(Field field,String str)
{
super(str+" cast to "+field + " Error");
}
}


原文转自:http://www.ltesting.net