Java tutorial
/** * PureInfo Quake * @(#)ShowReseachCenterNames4User.java 1.0 2005-9-26 * * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. * All rights reserved, see the license file. * * www.pureinfo.com.cn */ package com.pureinfo.srm.view.function; import org.apache.commons.lang.StringUtils; import com.pureinfo.ark.content.ArkContentHelper; import com.pureinfo.dolphin.model.IObjects; import com.pureinfo.dolphin.script.function.handler.FunctionHandlerUtil; import com.pureinfo.dolphinview.context.model.IDVContext; import com.pureinfo.dolphinview.parser.function.FunctionHandlerDVImplBase; import com.pureinfo.force.exception.PureException; import com.pureinfo.force.lang.StrUtil; import com.pureinfo.srm.auth.domain.IUserOrgMapMgr; import com.pureinfo.srm.auth.model.UserOrgMap; import com.pureinfo.srm.org.domain.IOrganizationMgr; import com.pureinfo.srm.org.model.Organization; /** * <P> * Created on 2005-9-26 20:32:35<BR> * Last modified on 2005-9-26 * </P> * show all the research centers that an user belongs to * * @author elmar.chen * @version 1.0, 2005-9-26 * @since Quake 1.0 */ public class ShowReseachCenterNames4User extends FunctionHandlerDVImplBase { /** minimum number of arguments */ public final static int MIN_ARGS_NUM = 1; /** index of argument: name */ public final static int ARG_USER_ID = 0; /** index of argument: separator */ public final static int ARG_SEPARATOR = 1; /** * att * @see com.pureinfo.dolphinview.parser.function.FunctionHandlerDVImplBase#perform(java.lang.Object[], com.pureinfo.dolphinview.context.model.IDVContext) */ public Object perform(Object[] _args, IDVContext _context) throws PureException { FunctionHandlerUtil.validateArgsNum(_args, MIN_ARGS_NUM); String temp = _args[ARG_USER_ID].toString(); if (!StringUtils.isNumeric(temp)) { throw new PureException(PureException.INVALID_FORMAT, "user id must be numeric! >" + temp); } String sSep = _args[ARG_SEPARATOR].toString(); int nUserId = Integer.parseInt(temp); return doPerform(nUserId, sSep); } private Object doPerform(int _sUserId, String _sSep) throws PureException { IUserOrgMapMgr mgr = (IUserOrgMapMgr) ArkContentHelper.getContentMgrOf(UserOrgMap.class); IObjects objs = mgr.findAllByUserId(_sUserId); UserOrgMap uom; int[] orgIds = new int[objs.getSize()]; int i = 0; while ((uom = (UserOrgMap) objs.next()) != null) { orgIds[i++] = uom.getOrgId(); } String sOrgIds = StrUtil.join(orgIds, ','); IOrganizationMgr orgMgr = (IOrganizationMgr) ArkContentHelper.getContentMgrOf(Organization.class); IObjects orgs = orgMgr.lookupByIds(sOrgIds); boolean bFirst = true; while (((Organization) orgs.next()) != null) { if (bFirst) { } } return ""; } }