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

📄 universityadmissionsservice.java~

📁 Java p2p程序设计2002年版
💻 JAVA~
字号:
package com.sams.jxta.groups.student;

import net.jxta.membership.MembershipService;
import net.jxta.membership.Authenticator;
import net.jxta.credential.Credential;
import net.jxta.credential.AuthenticationCredential;
import net.jxta.exception.PeerGroupException;
import net.jxta.exception.ProtocolNotSupportedException;
import net.jxta.document.Element;
import net.jxta.document.Advertisement;
import net.jxta.id.ID;
import net.jxta.peergroup.PeerGroup;
import net.jxta.protocol.ModuleImplAdvertisement;
import net.jxta.service.Service;
import net.jxta.document.StructuredDocument;

import java.util.Vector;

import java.util.Enumeration;

/*
 * A Membership Service designed to represent the Admission Process in a Univeristy.
 */

public class UniversityAdmissionsService extends MembershipService{

    private static final org.apache.log4j.Category LOG = 
        org.apache.log4j.Category.getInstance(UniversityAdmissionsService.class.getName());
    private PeerGroup peerGroup;
    private ModuleImplAdvertisement implAdv;
    private ID assignedID;
    private Vector    invitationLetters          = new Vector();
    private Vector    authenticationCredentials = new Vector();

    /*
     * This method is called during an apply process.
     */
        
    public Authenticator apply( AuthenticationCredential unsubscribedCredential )
         throws PeerGroupException, ProtocolNotSupportedException{
         
         String method = unsubscribedCredential.getMethod();
        
         if( (null != method) && !"PreApplication".equals( method ) )
            throw new ProtocolNotSupportedException(
            "Authentication method not recognized : Required \"PreApplication\" ");
        StructuredDocument preApForm = 
            (StructuredDocument)unsubscribedCredential.getIdentityInfo();
        Enumeration enum = preApForm.getChildren();
        Element element = (Element) enum.nextElement();
        String departmentAppliedFor =(String) element.getValue();
        // Vacancies exist only in the Computer Science Department
        if(!departmentAppliedFor.equals(PreApplicationForm.DEPARTMENT_COMPUTER_SCIENCE))
            throw new PeerGroupException("No Admissions to this Department(code:"+departmentAppliedFor+")");
        ApplicationForm applicationForm = new ApplicationForm(this,unsubscribedCredential);        
        return applicationForm;

    }         

    /*
     * This method is called when the peer is interested in joining the peer group.
     */
     
    public Credential join(Authenticator authenticated )throws PeerGroupException{

        ApplicationForm applicationForm   = (ApplicationForm)authenticated;
        // We double check that the Authentiction is indeed successful
        if(!applicationForm.isReadyForJoin())
            throw new PeerGroupException("Application Form rejected !!");            
        // this means that the person can be taken in 
        InvitationLetter invitationLetter = new InvitationLetter(this);
        invitationLetters.addElement(invitationLetter);
        authenticationCredentials.addElement(authenticated.getAuthenticationCredential());
        return invitationLetter;
    }

    /*
     * This method is called when the peer leaves the group.
     * Here we destroy all previous records of Authentication
     * Credentials and Credentials
     */
    public void resign() throws PeerGroupException{
        //Destory all records 
        invitationLetters          = new Vector();
        authenticationCredentials = new Vector();
   }

    /*
     * Returns all the Credentials for this peer 
     */
    public Enumeration getCurrentCredentials() throws PeerGroupException{
     return invitationLetters.elements();
    }

    /*
     * Returns all the Authentication Credentials for this peer 
     */
    public Enumeration getAuthCredentials()     throws PeerGroupException{
     return authenticationCredentials.elements();
     }

    /*
     * Returns the ModuleImplAdvertisement
     */
    public Advertisement getImplAdvertisement(){
     return implAdv;
    }

    /*
     * This method is called when the module is initialized.
     */
    public void init(PeerGroup peerGroup,
                     ID assignedID,
                     Advertisement implAdv)
        throws PeerGroupException{
        
            this.peerGroup = peerGroup;
            this.assignedID=assignedID;
            this.implAdv=(ModuleImplAdvertisement)implAdv;
    }

    /*
     * Getter method for the peer group
     */
    public PeerGroup getPeerGroup(){
        return peerGroup;
    }

    /*
     * Getter for the Interface.For the sake of simplicity ,
     * this object acts as it's own interface.
     */
    public Service getInterface() {
        return this;
    }
    
    /*
     * Methods to be implemented by virtue of being a module.
     * Not used in this example 
     */
    
    public int startApp(String[] args){return 0;}

    public void stopApp(){}

    /*
     * This method is currently not supported .//??? Is this OK ?
     */
    public Credential makeCredential( Element element )
            throws PeerGroupException, Exception{
        return null;
    }

}

⌨️ 快捷键说明

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