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

📄 softwarebean.java

📁 使用J2EE实现了软件园的下载和上传功能
💻 JAVA
字号:
package software;

import javax.ejb.EntityBean;
import javax.ejb.EntityContext;
import javax.ejb.CreateException;
import javax.ejb.RemoveException;
import java.text.DateFormat;
import java.util.*;
import javax.naming.*;
import javax.rmi.*;
public abstract class softwareBean implements EntityBean {
    EntityContext entityContext;
    public String ejbCreate(String softwareID, Integer softwareDownloadTime,
                            String softwareInfor, String softwarePath,
                            String softwareType, String softwareSize,
                            String softwareName) throws CreateException {

        setSoftwareID(softwareID);
        setSoftwareName(softwareName);

        setSoftwareSize(softwareSize);

        setSoftwareType(softwareType);

        setSoftwarePath(softwarePath);

        setSoftwareInfor(softwareInfor);

        setSoftwareDownloadTime(softwareDownloadTime);
        return "";
    }

    public void ejbPostCreate(String softwareID, Integer softwareDownloadTime,
                              String softwareInfor, String softwarePath,
                              String softwareType, String softwareSize,
                              String softwareName) throws CreateException {
    }

    public void ejbRemove() throws RemoveException {
    }

    public abstract void setSoftwareID(String softwareID);

    public abstract String getSoftwareID();

    public void ejbLoad() {
    }

    public void ejbStore() {
    }

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }

    public void unsetEntityContext() {
        this.entityContext = null;
    }

    public void setEntityContext(EntityContext entityContext) {
        this.entityContext = entityContext;
    }

    public abstract void setSoftwareDownloadTime(Integer softwareDownloadTime);

    public abstract void setSoftwareInfor(String softwareInfor);

    public abstract void setSoftwarePath(String softwarePath);

    public abstract void setSoftwareType(String softwareType);

    public abstract void setSoftwareSize(String softwareSize);

    public abstract void setSoftwareName(String softwareName);

    public abstract String getSoftwareName();

    public abstract String getSoftwareSize();

    public abstract String getSoftwareType();

    public abstract String getSoftwarePath();

    public abstract String getSoftwareInfor();

    public abstract Integer getSoftwareDownloadTime();

    public Collection ejbHomeGetTypes() {
        //返回所有的软件类型。
        //HashSet里面不能有重复值
        Collection types=new HashSet();
        try {
            javax.naming.Context ic = new javax.naming.InitialContext();
            Object obj = ic.lookup("softwareRemote");
            softwareRemoteHome home = (softwareRemoteHome) javax.rmi.
                                  PortableRemoteObject.narrow(obj,
                    softwareRemoteHome.class);
            Collection c1 =home.findAll();//取全部信息
            Object o1[]=c1.toArray();//转换为数组
            for(int i=0;i<o1.length;i++){
                softwareRemote s=(softwareRemote)o1[i];
                types.add(s.getSoftwareType());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return types;
    }

    public Collection  ejbHomeGetTypeSoftwares(String type) {
    //返回对应类型的所有软件。
     Collection softwares=new ArrayList();
  try {
      javax.naming.Context ic = new javax.naming.InitialContext();
      Object obj = ic.lookup("softwareRemote");
      softwareRemoteHome home = (softwareRemoteHome)PortableRemoteObject.narrow(obj,softwareRemoteHome.class);
      Collection c1 =home.findAll();//取全部信息
      Object o1[]=c1.toArray();//转换为数组
      for(int i=0;i<o1.length;i++){
          softwareRemote s=(softwareRemote)o1[i];
          if(s.getSoftwareType().equals(type)){
              softwares.add(s.getSoftwareName());
          }
      }
  } catch (Exception ex) {
      ex.printStackTrace();
  }
  return softwares;

    }

    public Collection ejbHomeGetTop5() {
        //HashSet里面不能有重复值
        Collection top5=new HashSet();
        //Collection top5=new ArrayList();
        try {

            Context ic = new InitialContext();
            Object obj = ic.lookup("softwareRemote");
            softwareRemoteHome home = (softwareRemoteHome)PortableRemoteObject.narrow(obj,
                    softwareRemoteHome.class);
            Collection c1 =home.findAll();//取全部信息
             int size=c1.size();
             int r[]=new int[size];
            Iterator i=c1.iterator();
             int j=0;
       while(i.hasNext()){
           softwareRemote s=(softwareRemote)i.next();
           r[j++]=s.getSoftwareDownloadTime().intValue();
           }
          Arrays.sort(r);
          //System.out.println(r[size-1]+"||"+r[size-2]+"||"+r[size-3]);
          if(size>=5){
          for(int k=size-1;k>=size-5;k--){
           Collection c=home.findByDownTime(r[k]);
           Iterator ii=c.iterator();
           while(ii.hasNext()){
               softwareRemote ss=(softwareRemote)ii.next();
               top5.add(ss);
               System.out.println("top5"+top5.size());
               }
              }
          }
          else{
              for(int k=size-1;k>=0;k--){
                  Collection c=home.findByDownTime(r[k]);
                  Iterator ii=c.iterator();
                  while(ii.hasNext()){
                    softwareRemote ss=(softwareRemote)ii.next();
                    top5.add(ss);}
                System.out.println("top5"+top5.size());
          }
          }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return top5;
}
}

⌨️ 快捷键说明

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