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

📄 rootws.java

📁 jxme的一些相关程序,主要是手机上程序开发以及手机和计算机通信的一些程序资料,程序编译需要Ant支持
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        // Finally the Satella Peer Group SERVICE advertisement is added to the 
        // Peer Group Advertisement.
        
        Hashtable satellaGroupAdvServiceHashtable,
                  grpAdvServicesHashtable=null;
        Enumeration keyEnumeration = null; 
        Object keyObject=null;
        Object membershipServiceKey=null;
        Object valueOject=null;
        Object dumbObject=null;
        ServiceAdvertisement satellaGroupMembershipServiceAdv=null;
        ServiceAdvertisement grpMembershipServiceAdv=null;
        Vector paramsLoginsAndPasswdsVector;
        Enumeration loginsEnumeration;
        String login, passwd, loginsandPasswdString="";
  
        satellaGroupAdvServiceHashtable=new Hashtable();
        grpAdvServicesHashtable=
                       parentPeerGroupAdvertisement.getServiceAdvertisements();
        keyEnumeration = grpAdvServicesHashtable.keys();
        
        // Parsing services inherited from NetPeerGroup
        // And copy all services except the membership service
        while (keyEnumeration.hasMoreElements()) {
            keyObject=keyEnumeration.nextElement();
            if (!(keyObject.toString().equals("jxta.service.membership"))) {
                dumbObject = satellaGroupAdvServiceHashtable.put
                           (keyObject, grpAdvServicesHashtable.get(keyObject)); 
            } else {
                membershipServiceKey=keyObject;
                grpMembershipServiceAdv=(ServiceAdvertisement) 
                                        grpAdvServicesHashtable.get(keyObject);
            }
        }

        // Done copying all the services from the parent Peer Group,
        // but the membership service
        
        // Create the Service Advertisement for the membership Advertisement 
        //that has to be build from scratch

        try {
            satellaGroupMembershipServiceAdv =(ServiceAdvertisement)
                          AdvertisementFactory.newAdvertisement(
                                  ServiceAdvertisement.getAdvertisementType());
        } catch (Exception e) {
            // Simplify exception scheme for caller: any sort of trbl is
            // a PeerGroupException.
              System.out.println("Can't create Satella Group Advertisement");
        }
          
        // Build the Params of the Membership service advertisement
        // In other words, create the Vector containing for only value
        // a string of the form "User1:Passwd1:User2:Passwd2:User3:Passwd3:"
        // That is what is expected by the 
        // net.jxta.impl.membership.PasswdMembership Class.
          
        paramsLoginsAndPasswdsVector=new Vector();
        loginsEnumeration=userPasswdHashtable.keys();
        while (loginsEnumeration.hasMoreElements()) {
            login=loginsEnumeration.nextElement().toString();
            passwd=userPasswdHashtable.get(login).toString();
            loginsandPasswdString=loginsandPasswdString+login+":"+passwd+":";
        }  
         paramsLoginsAndPasswdsVector.addElement (loginsandPasswdString); 
          
        // Creating the Membership service around the PasswdMembership Class
        satellaGroupMembershipServiceAdv.setName(
                                            grpMembershipServiceAdv.getName());

        satellaGroupMembershipServiceAdv.setCode(
                                  "net.jxta.impl.membership.PasswdMembership");
        // Important change performed Above 

        satellaGroupMembershipServiceAdv.setKeywords(
                                        grpMembershipServiceAdv.getKeywords());

        satellaGroupMembershipServiceAdv.setParams(
                                                 paramsLoginsAndPasswdsVector);
        // Important change performed Above 

        satellaGroupMembershipServiceAdv.setPipe( 
                                            grpMembershipServiceAdv.getPipeService());

        satellaGroupMembershipServiceAdv.setProvider (
                                        grpMembershipServiceAdv.getProvider());

        satellaGroupMembershipServiceAdv.setSecurity (
                                        grpMembershipServiceAdv.getSecurity());

        satellaGroupMembershipServiceAdv.setUri (
                                             grpMembershipServiceAdv.getUri());

        satellaGroupMembershipServiceAdv.setVersion(
                                         grpMembershipServiceAdv.getVersion());
          
        // Now Add the membership Service Advertisement to the 
        // satella Group Services
        dumbObject = satellaGroupAdvServiceHashtable.put(
                                             membershipServiceKey,
                                             satellaGroupMembershipServiceAdv);

        // Set the Satella Peer Group Services.
        satellaGroupAdv.setServiceAdvertisements(
                                              satellaGroupAdvServiceHashtable); 
        return satellaGroupAdv ; 
    }

    private void joinSatellaGroup (PeerGroup satellaGroup) {
        // Get the Heavy Weight Paper for the resume
        // Alias define the type of credential to be provided
        StructuredDocument creds = null;
        try {
            // Create the resume to apply for the Job
            // Alias generate the credentials for the Peer Group
            AuthenticationCredential authCred =
                     new AuthenticationCredential( satellaGroup, null, creds );

            // Create the resume to apply for the Job
            // Alias generate the credentials for the Peer Group
            MembershipService membership = 
                                (MembershipService) satellaGroup.getMembershipService();

            // Send the resume and get the  Job application form
            // Alias get the Authenticator from the Authentication creds
            Authenticator auth = membership.apply( authCred );

            // Fill in the Job Application Form
            // Alias complete the authentication
            completeAuth( auth );

            // Check if I got the Job
            // Alias Check if the authentication that was submitted was 
            //accepted.
            if( !auth.isReadyForJoin() ) {
                System.out.println( "Failure in authentication.");
                System.out.println( "Group was not joined. Does not know how to complete authenticator");
            }

            // I got the Job, Join the company
            // Alias I the authentication I completed was accepted, 
            // therefore join the Peer Group 
            // accepted.
            membership.join( auth );
            System.out.println ("Joined Satella Group");
        } catch (Exception e) {
            System.out.println("Failure in authentication.");
            System.out.println("Group was not joined. Login was incorrect.");
            e.printStackTrace();
        }    
    }

    private void completeAuth (Authenticator auth) throws Exception{
        
        Method [] methods = auth.getClass().getMethods();
        Vector authMethods = new Vector();
       
        // Find out with fields of the application needs to be filled
        // Alias Go through the methods of the Authenticator class and copy
        // them sorted by name into a vector.
        for( int eachMethod = 0; eachMethod < methods.length; eachMethod++ ) {
            if( methods[eachMethod].getName().startsWith("setAuth") ){
                if( Modifier.isPublic( methods[eachMethod].getModifiers())){

                    // sorted insertion.
                    for( int doInsert = 0; doInsert <= authMethods.size(); 
                                                                 doInsert++ ) {
                        int insertHere = -1;
                        if( doInsert == authMethods.size() )
                            insertHere = doInsert;
                       else {
                           if(methods[eachMethod].getName().compareTo(
 ((Method)authMethods.elementAt( doInsert )).getName()) <= 0 )
                                insertHere = doInsert;
                       } // end else

                        if(-1!= insertHere ) {
                            authMethods.insertElementAt(
                                       methods[eachMethod],insertHere);
                            break;
                       } // end if ( -1 != insertHere)
                   } // end for (int doInsert=0 
                } // end if (modifier.isPublic
            } // end if (methods[eachMethod] 
        } // end for (int eachMethod)
        
        Object [] AuthId = {"rootpeers"};
        Object [] AuthPasswd = {"JLXH"}; // encrypted RULE 
       
        for( int eachAuthMethod=0;eachAuthMethod<authMethods.size(); 
                                                           eachAuthMethod++ ) {
            Method doingMethod = (Method) authMethods.elementAt(eachAuthMethod);

            String authStepName = doingMethod.getName().substring(7); 
            if (doingMethod.getName().equals("setAuth1Identity")) {
                // Found identity Method, providing identity
                doingMethod.invoke( auth, AuthId);
            } else 
	    if (doingMethod.getName().equals("setAuth2Password")){
                // Found Passwd Method, providing passwd
                doingMethod.invoke( auth, AuthPasswd );
            }
        } 
    }
}

⌨️ 快捷键说明

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