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

📄 studentservice.java

📁 远程学生作业提交系统,所用技术JSP,Servelet,Ajax,Web Services,MySql
💻 JAVA
字号:
/*
 * StudentService.java
 *
 * Created on October 22, 2006, 2:58 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.sixtwenty.service;

import java.util.ArrayList;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;

import javax.xml.namespace.QName;
import javax.xml.rpc.ParameterMode;

import com.sixtwenty.Projects;

/**
 *
 * @author Balasubramaniam
 */
public class StudentService {
    
    String endpoint = "http://127.0.0.1:8080/axis/services/submit";
    
    public ArrayList getProjectListWithOpenStatus() {
       
       ArrayList listOfProject = new ArrayList();
       ArrayList listOfOpenProject = new ArrayList();
       
       try {
           Service service = new Service();
           Call call = (Call)service.createCall();

           call.setTargetEndpointAddress( new java.net.URL(endpoint) );
           call.setOperationName(new QName("http://soapinterop.org/", "getProjectList") );
           
           /** 
            * TODO - Not sure about setting the return type Projects[]
            */
           //Return type has to be object of type Projects
           call.setReturnType(XMLType.XSD_ANY);

           // This methos doesn't have an argument
           listOfProject = (ArrayList)call.invoke(new Object [] {});
           
           if(listOfProject.size() != 0) {
               System.out.println("List of Projects returned");
           
               for(int projCount = 0; projCount < listOfProject.size(); projCount++) {
                   
                   Projects proj = new Projects();
                   proj = (Projects)listOfProject.get(projCount);
                   String projectID = proj.getProj_id();
                   
                   //call the getProjectStatus 
                   String status = getProjectStatus(projectID);
                   if("open".equalsIgnoreCase(status)) {
                       listOfOpenProject.add(proj);
                   }
                   
               }
             
           }
           else {
              System.out.println("No Project found");
           }
       } catch (Exception e) {
           e.printStackTrace();
           System.out.println("StudentService -> getProjectListWithOpenStatus -> Exception :" +e.getMessage());
       }
       
       return listOfOpenProject;
    }
    
    
     /**
     * The method to get the status of a project. In other word if submissions can still be done
     * for this project or not.
     * "open" for yes
     * "close" for no
     * @param proj_id The project in question
     */
    private java.lang.String getProjectStatus(java.lang.String proj_id) throws java.rmi.RemoteException {
        
        String status = "";
        try{
           Service service = new Service();
           Call call = (Call)service.createCall();

           call.setTargetEndpointAddress( new java.net.URL(endpoint) );
           call.setOperationName(new QName("http://soapinterop.org/", "getProjectStatus") );

           call.addParameter("projID",
                             org.apache.axis.Constants.XSD_STRING,
                             javax.xml.rpc.ParameterMode.IN);
       
           call.setReturnType(XMLType.XSD_STRING);
           
           status = (String)call.invoke( new Object [] { proj_id });
           
           if((!status.equalsIgnoreCase("")) && status != null) {
              System.out.println("Got Project Status");
              
           }
           else {
              System.out.println("Get project status action failed");
           }

       } catch (Exception e) {
           e.printStackTrace();
           System.out.println("StudentService -> getProjectListWithOpenStatus -> Exception :" +e.getMessage());
       }
        
       return status;
    }
     
    
    
    public ArrayList getSubmissionList(String username) {
        ArrayList listOfSubmission = new ArrayList();
        try {
           Service service = new Service();
           Call call = (Call)service.createCall();

           call.setTargetEndpointAddress( new java.net.URL(endpoint) );
           call.setOperationName(new QName("http://soapinterop.org/", "getSubmissionList") );

           call.addParameter("username",
                             org.apache.axis.Constants.XSD_STRING,
                             javax.xml.rpc.ParameterMode.IN);
          
           //TODO- The return type has to be Submissions[] object(Changes has to be made accordingly)
           call.setReturnType(XMLType.XSD_ANY);
           
           listOfSubmission = (ArrayList)call.invoke( new Object [] { username });
           
           if(listOfSubmission.size() != 0) {
              System.out.println("Got list of Submissions");
           }
           else {
              System.out.println("Get Submission list failed");
           }
       } catch (Exception e) {
           System.out.println(e.toString());
       }
       return listOfSubmission; 
    }
    
    
    
}

⌨️ 快捷键说明

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