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

📄 cppuserinvokerimpl.java

📁 打印管理程序,测试完全通过.windows开发环境.
💻 JAVA
字号:
package jp.co.ntl.swing.ext.cppuser;

import java.util.Vector;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.File;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;

import jp.co.ntl.Net;
import jp.co.ntl.Util;
import jp.co.ntl.NetworkException;
import jp.co.ntl.ServerException;
import jp.co.ntl.TimeOutException;
import jp.co.ntl.NoUSBException;
import jp.co.ntl.cppuser.CPPUserInfo;

public class CPPUserInvokerImpl extends CPPUserInvoker {
	private Net		net;
	
//	static {
//		System.loadLibrary("CPPUSB");
//	}
//	
	CPPUserInvokerImpl(Net net) {
		this.net = net;
	}
	
	public Vector getUserInfos() throws NetworkException, ServerException, TimeOutException {
		Vector				vcUserInfo = new Vector();
		ObjectInputStream	is = null;
		
		try {
			is = new ObjectInputStream(net.sendCommand(Net.cppUserServletName, "GetUserInfos"));
		} catch (IOException e) {
			throw new NetworkException(e.getMessage());
		} catch (KeyManagementException e) {
			throw new NetworkException(e.getMessage());
		} catch (NoSuchAlgorithmException e) {
			throw new NetworkException(e.getMessage());
		}
		
		try {
			boolean	b;
			try {
				b = is.readBoolean();
			} catch (IOException e) {
				throw new ServerException(e.getMessage());
			}

			if (b) {
				try {
					vcUserInfo = (Vector)is.readObject();
				} catch (IOException e) {
					throw new ServerException(e.getMessage());
				} catch (ClassNotFoundException e) {
					throw new ServerException(e.getMessage());
				}
			} else {
				try {
					String	message = is.readUTF();
					if (message.equals(Net.resultServerError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultTimeOut)) {
///						net.showLoginPage();
						throw new TimeOutException();
					} else {
						throw new ServerException(message);
					}
				} catch (IOException e) {
				}
			}
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				;
			}
		}
		
		return vcUserInfo;
	}
	
	public CPPUserInfo getUserInfo(CPPUserInfo userInfo) throws NetworkException, ServerException, TimeOutException {
		CPPUserInfo			retUserInfo = null;
		ObjectInputStream	is = null;
		
		try {
			is = new ObjectInputStream(net.sendCommand(Net.cppUserServletName, "GetUserInfo", userInfo));
		} catch (IOException e) {
			throw new NetworkException(e.getMessage());
		} catch (KeyManagementException e) {
			throw new NetworkException(e.getMessage());
		} catch (NoSuchAlgorithmException e) {
			throw new NetworkException(e.getMessage());
		}
		
		try {
			boolean	b;
			try {
				b = is.readBoolean();
			} catch (IOException e) {
				throw new ServerException(e.getMessage());
			}

			if (b) {
				try {
					retUserInfo = (CPPUserInfo)is.readObject();
				} catch (IOException e) {
					throw new ServerException(e.getMessage());
				} catch (ClassNotFoundException e) {
					throw new ServerException(e.getMessage());
				}
			} else {
				try {
					String	message = is.readUTF();
					if (message.equals(Net.resultServerError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultTimeOut)) {
///						net.showLoginPage();
						throw new TimeOutException();
					} else {
						throw new ServerException(message);
					}
				} catch (IOException e) {
				}
			}
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				;
			}
		}
		
		return retUserInfo;
	}
	
	public CPPUserInfo getUSBUserInfo() throws NetworkException, ServerException, TimeOutException, NoUSBException {
		CPPUserInfo		userInfo = null;
		try {
			userInfo = getUSBData(0);
		} catch (IOException e) {
			throw new NoUSBException(e.getMessage());
		}
		
		return userInfo;
	}
	
	public void setUserInfo(CPPUserInfo userInfo, boolean admin) throws NetworkException, ServerException, TimeOutException, NoUSBException {
		ObjectInputStream	is = null;
		
		try {
			is = new ObjectInputStream(
					net.sendCommand(Net.cppUserServletName, (admin ? "SetUserInfoForAdmin" : "SetUserInfoForUser"), userInfo));
		} catch (IOException e) {
			throw new NetworkException(e.getMessage());
		} catch (KeyManagementException e) {
			throw new NetworkException(e.getMessage());
		} catch (NoSuchAlgorithmException e) {
			throw new NetworkException(e.getMessage());
		}
		
		try {
			boolean	b;
			try {
				b = is.readBoolean();
			} catch (IOException e) {
				throw new ServerException(e.getMessage());
			}
			
			if (b) {
				setUSBData(userInfo);
			} else {
				try {
					String	message = is.readUTF();
					if (message.equals(Net.resultServerError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultSQLError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultTimeOut)) {
///						net.showLoginPage();
						throw new TimeOutException();
					} else {
						throw new ServerException(message);
					}
				} catch (IOException e) {
				}				
			}
		} finally {
			try {
				is.close();
			} catch (IOException e) {
			}
		}
	}

	public void addUser(CPPUserInfo userInfo) throws NetworkException, ServerException, TimeOutException, NoUSBException {
		try {
			getUSBData(Long.parseLong(userInfo.getSPSerial()));
		} catch (IOException e) {
			throw new NoUSBException(e.getMessage());
		}
		
		Vector	vcUserInfo = new Vector();
		vcUserInfo.addElement(userInfo);
		addUsers(vcUserInfo);
	}
	
	public void addUsers(Vector vcUserInfo) throws NetworkException, ServerException, TimeOutException {
		ObjectInputStream	is = null;
		
		try {
			is = new ObjectInputStream(net.sendCommand(Net.cppUserServletName, "AddUsers", vcUserInfo));
		} catch (IOException e) {
			throw new NetworkException(e.getMessage());
		} catch (KeyManagementException e) {
			throw new NetworkException(e.getMessage());
		} catch (NoSuchAlgorithmException e) {
			throw new NetworkException(e.getMessage());
		}
		
		try {
			boolean	b;
			try {
				b = is.readBoolean();
			} catch (IOException e) {
				throw new ServerException(e.getMessage());
			}
			
			if (b) {
			} else {
				try {
					String	message = is.readUTF();
					if (message.equals(Net.resultServerError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultSQLError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultTimeOut)) {
///						net.showLoginPage();
						throw new TimeOutException();
					} else {
						throw new ServerException(message);
					}
				} catch (IOException e) {
				}
			}
		} finally {
			try {
				is.close();
			} catch (IOException e) {
			}
		}
	}
	
	public void delUsers(Vector vcUserInfo) throws NetworkException, ServerException, TimeOutException {
		ObjectInputStream	is = null;
		
		try {
			is = new ObjectInputStream(net.sendCommand(Net.cppUserServletName, "DelUsers", vcUserInfo));
		} catch (IOException e) {
			throw new NetworkException(e.getMessage());
		} catch (KeyManagementException e) {
			throw new NetworkException(e.getMessage());
		} catch (NoSuchAlgorithmException e) {
			throw new NetworkException(e.getMessage());
		}
		
		try {
			boolean	b;
			try {
				b = is.readBoolean();
			} catch (IOException e) {
				throw new ServerException(e.getMessage());
			}
			
			if (b) {
			} else {
				try {
					String	message = is.readUTF();
					if (message.equals(Net.resultServerError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultSQLError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultTimeOut)) {
///						net.showLoginPage();
						throw new TimeOutException();
					} else {
						throw new ServerException(message);
					}
				} catch (IOException e) {
				}
			}
		} finally {
			try {
				is.close();
			} catch (IOException e) {
			}
		}
	}
	
	public int checkAdmin(CPPUserInfo userInfo) throws NetworkException, ServerException, TimeOutException, NoUSBException {
		CPPUserInfo		retUserInfo;
		int			ret = ERROR_OTHER;

		try {
			retUserInfo = getUSBData(0);
		} catch (IOException e) {
			throw new NoUSBException(e.getMessage());
        }
        
		userInfo.setSPSerial(retUserInfo.getSPSerial());
		userInfo.setUsername(retUserInfo.getUsername());
		userInfo.setPassword(retUserInfo.getPassword());
        
        boolean	bRegistered = isRegisteredUser(userInfo);
        if (!bRegistered) {
        	return ERROR_NOT_REGISTERED_USER;
        }
        
		ObjectInputStream	is = null;
		
		try {
			is = new ObjectInputStream(net.sendCommand(Net.cppUserServletName, "IsAdmin", userInfo));
		} catch (IOException e) {
			throw new NetworkException(e.getMessage());
		} catch (KeyManagementException e) {
			throw new NetworkException(e.getMessage());
		} catch (NoSuchAlgorithmException e) {
			throw new NetworkException(e.getMessage());
		}
		
		try {
			boolean	b;
			try {
				b = is.readBoolean();
			} catch (IOException e) {
				throw new ServerException(e.getMessage());
			}
			
			if (b) {
				try {
					String	userKind = is.readUTF();

					if (userKind.equals("AdminUser")) {
						ret = USER_ADMIN;
					} else if (userKind.equals("MaintenanceUser")) {
						ret = USER_MAINTENANCE;
					} else {
						ret = USER_GENERAL;
					}
				} catch (IOException e) {
					throw new ServerException(e.getMessage());
				}
			} else {
				try {
					String	message = is.readUTF();
					if (message.equals(Net.resultServerError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultTimeOut)) {
///						net.showLoginPage();
						throw new TimeOutException();
					} else {
						throw new ServerException(message);
					}
				} catch (IOException e) {
				}
			}
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				;
			}
		}
		
///		Util.debugPrint("USB serial = " + userInfo.getUSBSerial());
		Util.debugPrint("user name = " + userInfo.getUsername());
					        
		return ret;
	}
	
	public boolean isRegisteredUser(CPPUserInfo userInfo) throws NetworkException, ServerException, TimeOutException {
		ObjectInputStream	is = null;
		boolean			regUser = false;
		
		try {
			is = new ObjectInputStream(net.sendCommand(Net.cppUserServletName, "IsRegisteredUser", userInfo));
		} catch (IOException e) {
			throw new NetworkException(e.getMessage());
		} catch (KeyManagementException e) {
			throw new NetworkException(e.getMessage());
		} catch (NoSuchAlgorithmException e) {
			throw new NetworkException(e.getMessage());
		}
		
		try {
			boolean	b;
			try {
				b = is.readBoolean();
			} catch (IOException e) {
				throw new ServerException(e.getMessage());
			}
			
			if (b) {
				try {
					regUser = is.readBoolean();
				} catch (IOException e) {
					throw new ServerException(e.getMessage());
				}
			} else {
				try {
					String	message = is.readUTF();
					if (message.equals(Net.resultServerError)) {
						throw new ServerException("error");
					} else if (message.equals(Net.resultTimeOut)) {
///						net.showLoginPage();
						throw new TimeOutException();
					} else {
						throw new ServerException(message);
					}
				} catch (IOException e) {
				}
			}
		} finally {
			try {
				is.close();
			} catch (IOException e) {
				;
			}
		}
		return regUser;
	}
	
	public void searchUser(int kind, String pattern) throws NetworkException, ServerException, TimeOutException {
		
	}
	
	public Vector addUsersFromFile(File file) throws NetworkException, ServerException, TimeOutException {
		Vector	vcUserInfo = new Vector();
		
		return vcUserInfo;
	}
	
	public void downloadUserInfoList(File file) throws NetworkException, ServerException, TimeOutException {
		
	}
}

⌨️ 快捷键说明

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