001: /*
002: * <copyright>
003: *
004: * Copyright 1997-2004 Mobile Intelligence Corp
005: * under sponsorship of the Defense Advanced Research Projects
006: * Agency (DARPA).
007: *
008: * You can redistribute this software and/or modify it under the
009: * terms of the Cougaar Open Source License as published on the
010: * Cougaar Open Source Website (www.cougaar.org).
011: *
012: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
013: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
014: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
015: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
016: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
017: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
018: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
019: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
020: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
021: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
022: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
023: *
024: * </copyright>
025: */
026:
027: package org.cougaar.community.requests;
028:
029: import javax.naming.directory.Attributes;
030:
031: import org.cougaar.core.service.community.CommunityService;
032: import org.cougaar.core.util.UID;
033:
034: /**
035: * Request to join (and optionally create) a community.
036: */
037: public class JoinCommunity extends CommunityRequest implements
038: java.io.Serializable {
039:
040: private String entityName;
041: private Attributes entityAttrs;
042: private int entityType;
043: private boolean createIfNotFound;
044: private Attributes communityAttrs;
045:
046: public JoinCommunity(String communityName, String entityName,
047: int entityType, Attributes entityAttrs, UID uid) {
048: this (communityName, entityName, entityType, entityAttrs, false,
049: null, uid, CommunityRequest.DEFAULT_TIMEOUT);
050: }
051:
052: public JoinCommunity(String communityName, String entityName,
053: int entityType, Attributes entityAttrs,
054: boolean createIfNotFound, Attributes communityAttrs, UID uid) {
055:
056: this (communityName, entityName, entityType, entityAttrs,
057: createIfNotFound, communityAttrs, uid,
058: CommunityRequest.DEFAULT_TIMEOUT);
059: }
060:
061: public JoinCommunity(String communityName, String entityName,
062: int entityType, Attributes entityAttrs,
063: boolean createIfNotFound, Attributes communityAttrs,
064: UID uid, long timeout) {
065: super (communityName, uid, timeout);
066: this .entityName = entityName;
067: this .entityType = entityType;
068: this .entityAttrs = entityAttrs;
069: this .createIfNotFound = createIfNotFound;
070: this .communityAttrs = communityAttrs;
071: }
072:
073: public String getEntityName() {
074: return entityName;
075: }
076:
077: public int getEntityType() {
078: return entityType;
079: }
080:
081: public Attributes getEntityAttributes() {
082: return entityAttrs;
083: }
084:
085: public boolean createIfNotFound() {
086: return createIfNotFound;
087: }
088:
089: public Attributes getCommunityAttributes() {
090: return communityAttrs;
091: }
092:
093: private String entityTypeAsString(int type) {
094: if (type == CommunityService.AGENT)
095: return "AGENT";
096: if (type == CommunityService.COMMUNITY)
097: return "COMMUNITY";
098: return "UNKNOWN_TYPE";
099: }
100:
101: public String toString() {
102: return "request=" + getRequestType() + " community="
103: + getCommunityName() + " entity=" + getEntityName()
104: + "(" + entityTypeAsString(getEntityType()) + ")"
105: + " createCommunityIfNotFound=" + createIfNotFound()
106: + " timeout=" + getTimeout() + " uid=" + getUID();
107: }
108:
109: }
|