📄 syncmanager.java
字号:
/* * SyncManager.java * * Created on August 8, 2003, 10:24 AM */package gov.nist.examples.bps.presenceserver;import java.util.*;import javax.sip.message.*;import javax.sip.header.*;import javax.sip.address.*;import gov.nist.examples.bps.gateway.*;/** * * @author deruelle */public class SyncManager { //private GatewayGUI gatewayGUI; private PresenceServer presenceServer; /** Creates a new instance of SyncManager */ /*public SyncManager(GatewayGUI gatewayGUI,PresenceServer presenceServer) { this.presenceServer=presenceServer; this.gatewayGUI=gatewayGUI; }*/ /** Creates a new instance of SyncManager */ public SyncManager(PresenceServer presenceServer) { this.presenceServer=presenceServer; } /***********************************************************************************/ /************************* PUBLIC METHODS ******************************************/ /***********************************************************************************/ public synchronized void displayBadgesListTable() { // we remove all the badges from the GUI. GatewayDebug.println("SyncManager, we lock the manager, displayBadgesListTable(),"+ " we display all the badges created."); displayBadgesListTable(presenceServer.badgesList); } public synchronized Badge getBadgeFromBadgesListTable(String identifier) { return getBadgeFromIdentifier(identifier); } public synchronized void removeBadgeFromBadgeInfoFrameListener(Badge badge) { removeBadge(badge); write(); displayBadgesListTable(presenceServer.badgesList); } public synchronized void removeBadgesFromBadgesTable(String baseReaderIdentifier) { GatewayDebug.println("SyncManager, we lock the manager, removeBadgesTable(),"+ " we remove all badges from the base: "+baseReaderIdentifier); removeBadgesTableFromBase(baseReaderIdentifier); } public synchronized void updateBadgesFromBadgesTable(Vector badgesTempList,String baseReaderIdentifier) { Vector res=new Vector(); for (int i=0;i<badgesTempList.size();i++) { Badge badgeTemp=(Badge)badgesTempList.elementAt(i); for (int j=0;j<presenceServer.badgesList.size();j++) { Badge badge=(Badge)presenceServer.badgesList.elementAt(j); if (badge.getIdentifier().compareToIgnoreCase(badgeTemp.getIdentifier()) ==0 ) res.addElement(badge); } } removeBadgesTableFromBase(baseReaderIdentifier); Base base=getBase(baseReaderIdentifier); if (base!=null) addBadgesTable(res,base.getLocation(),baseReaderIdentifier); else { GatewayDebug.println("SyncManager, "+ " ERROR, the base for these BADGES is disconnected, cannot update the GUI"); } } public synchronized void writeBadgesToXMLFile(){ write(); } public synchronized void updateBases(Base base) { if (!hasBase(base)) addBase(base); } public synchronized boolean isSenderAllowed(Request request) { return hasSenderBadge(request); } public synchronized boolean isReceiverAllowed(Request request) { return hasReceiverBadge(request); } /*public synchronized void initBadgeInfoFrame(Badge badge,Vector peopleCheckBoxList, JPanel fourthCenterTabPanel) { fourthCenterTabPanel.setLayout( new GridLayout(presenceServer.badgesList.size(),1,2,4) ); for (int i=0;i<presenceServer.badgesList.size();i++) { Badge badgeOri=(Badge)presenceServer.badgesList.elementAt(i); JCheckBox peopleCheckBox=new JCheckBox(badgeOri.getOwner()); // Initialise the check box: if (badge!=null && badge.peopleConstraints!=null ) { for (int j=0;j<badge.peopleConstraints.size();j++) { PeopleConstraint peopleConstraint=(PeopleConstraint)badge. peopleConstraints.elementAt(j); if (peopleConstraint.name.compareToIgnoreCase(badgeOri.getOwner())==0 ) peopleCheckBox.setSelected(true); } } peopleCheckBoxList.addElement(peopleCheckBox); fourthCenterTabPanel.add(peopleCheckBox); } }*/ /*public synchronized void updateBadgesListTable(BadgeInfoFrame badgeInfoFrame,boolean toAdd) { if (toAdd) addBadge(badgeInfoFrame.badge); // Update the RANK constraints: badgeInfoFrame.badge.rankConstraints= new Vector(); for (int i=0;i<badgeInfoFrame.rankCheckBoxList.size();i++) { JCheckBox rankCheckBox=(JCheckBox)badgeInfoFrame.rankCheckBoxList.elementAt(i); if (rankCheckBox.isSelected()) { RankConstraint rankConstraint=new RankConstraint(rankCheckBox.getText()); badgeInfoFrame.badge.rankConstraints.addElement(rankConstraint); } } // Update the LOCATION constraints: badgeInfoFrame.badge.locationConstraints= new Vector(); for (int i=0;i<badgeInfoFrame.locationCheckBoxList.size();i++) { JCheckBox locationCheckBox=(JCheckBox)badgeInfoFrame.locationCheckBoxList.elementAt(i); if (locationCheckBox.isSelected()) { LocationConstraint locationConstraint=new LocationConstraint(locationCheckBox.getText()); badgeInfoFrame.badge.locationConstraints.addElement(locationConstraint); } } // Update the PEOPLE constraints: badgeInfoFrame.badge.peopleConstraints= new Vector(); for (int i=0;i<badgeInfoFrame.peopleCheckBoxList.size();i++) { JCheckBox peopleCheckBox=(JCheckBox)badgeInfoFrame.peopleCheckBoxList.elementAt(i); if (peopleCheckBox.isSelected()) { PeopleConstraint peopleConstraint=new PeopleConstraint(peopleCheckBox.getText()); badgeInfoFrame.badge.peopleConstraints.addElement(peopleConstraint); } } write(); displayBadgesListTable(presenceServer.badgesList); }*/ public synchronized int checkConstraints(Request request) { GatewayDebug.println("SyncManager, we lock the manager, cheking the constraints"); /********* the RANK constraints ************************/ // 1. Let's get the destination badge rank constraints. // 2. Check if the sender belongs to a rank constraint. // 3. if yes, Check if the sfor (int i=0;i<badgesList.size();i++) { FromHeader fromHeader=(FromHeader)request.getHeader(FromHeader.NAME); Address fromAddress=fromHeader.getAddress(); javax.sip.address.URI fromURI=fromAddress.getURI(); ToHeader toHeader=(ToHeader)request.getHeader(ToHeader.NAME); Address toAddress=toHeader.getAddress(); javax.sip.address.URI toURI=toAddress.getURI(); javax.sip.address.URI toURICleaned=GatewayUtilities.getCleanUri(toURI); Badge receiverBadge=getBadgeFromURI(toURICleaned.toString() ); if (receiverBadge==null) { GatewayDebug.println("SyncManager, we lock the manager, checkConstraints(),"+ " the receiver "+ "badge does not exist: STATUS FAILED_ON_PEOPLE_RANK"); return Constraint.FAILED_ON_PEOPLE_RANK; } // If the destination is not online it is success: if (!hasBadgeInBadgeTable(receiverBadge)) { GatewayDebug.println("SyncManager, we lock the manager, checkConstraints(),"+ " the destination "+ "badge is not online: STATUS SUCCESS"); return Constraint.SUCCESS; } // Let's get the location of the receiver: Location locationReceiver=getBadgeLocationInBadgeTable(receiverBadge); if (locationReceiver==null) { GatewayDebug.println("PresenceServer, checkConstraints(), the destination "+ "badge is nowhere: STATUS SUCCESS"); return Constraint.SUCCESS; } Vector rankConstraints=receiverBadge.rankConstraints; if (rankConstraints==null || rankConstraints.isEmpty() ) { GatewayDebug.println("SyncManager, we lock the manager, checkConstraints(),"+ " the destination "+ "badge does not have any RANK constraints."); } else { // We have to check for all constraints that the badges are online or not. for (int i=0;i<rankConstraints.size();i++) { RankConstraint rankConstraint=(RankConstraint)rankConstraints.elementAt(i); // Get all the badges in the same place as the receiver badge with the rank constraint boolean rankConstraintRes=checkRankConstraint(rankConstraint.rank, locationReceiver.name, receiverBadge.getIdentifier() ); if (rankConstraintRes) { GatewayDebug.println("SyncManager, we lock the manager, checkConstraints(), "+ "the receiver "+ "badge is present with some people who belongs to his constraints: "+ "STATUS FAILED_ON_PEOPLE_RANK"); return Constraint.FAILED_ON_PEOPLE_RANK; } } } /********* the PEOPLE constraints ************************/ // 1. Let's get the destination badge people constraints. // 2. Check if the sender belongs to a people constraint. // 3. if yes, Check if the sender is in the same place as the receiver. /* Badge senderBadge=getBadge(fromURI.toString() ); if (senderBadge==null) { GatewayDebug.println("PresenceServer, checkConstraints(), the sender "+ "badge does not exist: STATUS FAILED_ON_PEOPLE_RANK"); return Constraint.SUCCESS; } */ Vector peopleConstraints=receiverBadge.peopleConstraints; if (peopleConstraints==null || peopleConstraints.isEmpty() ) { GatewayDebug.println("SyncManager, we lock the manager, checkConstraints(),"+ " the destination "+ "badge does not have any PEOPLE PRESENCE constraints."); } else { // We have to check for all constraints that the badges are online or not. for (int i=0;i<peopleConstraints.size();i++) { PeopleConstraint peopleConstraint=(PeopleConstraint)peopleConstraints.elementAt(i); // Get all the badges in the same place as the receiver badge with the people constraint boolean peopleConstraintRes=checkPeopleConstraint(peopleConstraint.name, locationReceiver.name, receiverBadge.getIdentifier() ); if (peopleConstraintRes) { GatewayDebug.println("SyncManager, we lock the manager, checkConstraints(), "+ "the receiver "+ "badge is present with some people who belongs to his constraints: "+ "STATUS FAILED_ON_PEOPLE_PRESENCE"); return Constraint.FAILED_ON_PEOPLE_PRESENCE; } } } /********* the PEOPLE constraints ************************/ // 1. Check if the receiver position belongs to a location constraint. Vector locationConstraints=receiverBadge.locationConstraints; if (locationConstraints==null || locationConstraints.isEmpty() ) { GatewayDebug.println("SyncManager, we lock the manager, checkConstraints(),"+ " the destination "+ "badge does not have any LOCATION constraints."); } else { // We have to check for all constraints that the badge is there. for (int i=0;i<locationConstraints.size();i++) { LocationConstraint locationConstraint=(LocationConstraint)locationConstraints.elementAt(i);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -