Android Open Source - msf-spaces-sdk-android Space Configuration






From Project

Back to project page msf-spaces-sdk-android.

License

The source code is released under:

Apache License

If you think the Android project msf-spaces-sdk-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package de.imc.mirror.sdk.android;
/*from www  .  ja v a 2s .  com*/
import java.util.HashSet;
import java.util.Set;

import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;

import de.imc.mirror.sdk.Space.PersistenceType;
import de.imc.mirror.sdk.Space.Type;
import de.imc.mirror.sdk.Space;
import de.imc.mirror.sdk.SpaceMember;
import de.imc.mirror.sdk.SpaceMember.Role;

/**
 * A space configuration container. 
 * @author nmach, simon.schwantzer(at)im-c.de
 */
public class SpaceConfiguration implements de.imc.mirror.sdk.SpaceConfiguration{
  
  private Space.Type type;
  private String name;
  private Set<SpaceMember> members = new HashSet<SpaceMember>();
  private PersistenceType persistenceType;
  private Duration persistenceDuration;
  
  /**
   * Creates an empty configuration.
   * Note: The empty configuration is not valid.  
   */
  public SpaceConfiguration() {
    this.members = new HashSet<SpaceMember>();
  }
  
  /**
   * Create a new configuration with the given properties.
   * @param type The type of the Space.
   * @param name The name of the Space.
   * @param ownerJID The bare-JID of the first member (moderator) of the space.
   * @param persistenceType Persistence settings for the space. See {@link PersistenceType} for details.
   * @param persistenceDuration Duration for the persistence if the persistence setting is {@link PersistenceType#DURATION}, otherwise <code>null</code>. 
   */
  public SpaceConfiguration(Space.Type type, String name, String ownerJID, PersistenceType persistenceType, Duration persistenceDuration) {
    this.type = type;
    this.name = name;
    this.members = new HashSet<SpaceMember>();
    SpaceMember owner = new de.imc.mirror.sdk.android.SpaceMember(ownerJID, Role.MODERATOR);
    members.add(owner);
    this.persistenceType = persistenceType;
    this.persistenceDuration = persistenceDuration;
  }
  
  /**
   * Create a new configuration with the given properties.
   * @param type The type of the Space.
   * @param name The name of the Space.
   * @param members Set of space members. Caution: This set may be modified.
   * @param persistenceType Persistence settings for the space. See {@link PersistenceType} for details.
   * @param persistenceDuration Duration for the persistence if the persistence setting is {@link PersistenceType#DURATION}, otherwise <code>null</code>. 
   */
  public SpaceConfiguration(Space.Type type, String name, Set<SpaceMember> members, PersistenceType persistenceType, Duration persistenceDuration) {
    this.type = type;
    this.name = name;
    this.members = members;
    this.persistenceType = persistenceType;
    this.persistenceDuration = persistenceDuration;
  }
  
  /**
   * Returns the space type.
   * @return Space type.
   */
  @Override
  public Space.Type getType() {
    return type;
  }

  /**
   * Returns the name set for the space.
   * @return Human-readable name for the space.
   */
  @Override
  public String getName() {
    return name;
  }

  /**
   * Sets the name of the space.
   * @param name Human-readable name for the space.
   */
  @Override
  public void setName(String name) {
    this.name = name;
  }

  /**
   * Returns the space members.
   * Member role are assigned in the space member models.
   * @return Set of space members.
   */
  @Override
  public Set<SpaceMember> getMembers() {
    return members;
  }

  /**
   * Sets the persistence type of the space.
   * A space can be configured to either do not persist published data objects ({@link PersistenceType#OFF}),
   * persist data objects ({@link PersistenceType#ON}), or persist data object for a specific duration 
   * ({@link PersistenceType#DURATION}).
   * @param persistenceType Persistence type to set.
   */
  public void setPersistenceType(PersistenceType persistenceType) {
    this.persistenceType = persistenceType;
  }
  
  /**
   * Returns the persistence configuration of the space.
   * @return Either {@link PersistenceType#OFF}, {@link PersistenceType#ON}, or {@link PersistenceType#DURATION}.
   */
  public PersistenceType getPersistenceType() {
    return persistenceType;
  }

  /**
   * Sets the duration for the data object persistence.
   * Only required when the persistence type is {@link PersistenceType#DURATION}.
   * @param duration Duration to set. See {@link DatatypeFactory} for details about instantiating a duration. 
   */
  public void setPersistenceDuration(Duration duration) {
    this.persistenceDuration = duration;
  }
  
  /**
   * Returns the duration for the data object persistence.
   * Only set when the persistence type is {@link PersistenceType#DURATION}.
   * @return Duration or <code>null</code>, if the space's persistence type is not {@link PersistenceType#DURATION}.
   */
  public Duration getPersistenceDuration() {
    return persistenceDuration;
  }

  /**
   * Sets the type for the space.
   * @param type Space type.
   */
  @Override
  public void setType(Type type){
    this.type = type;
  }

  /**
   * Sets the members for the space.
   * Member role are assigned in the space member models.
   * @param members Set of space members to set.
   */
  @Override
  public void setMembers(Set<SpaceMember> members){
    this.members = members;
  }

  /**
   * Revokes membership of a user.
   * If the user is not stored in the list of members, nothing will happen. 
   * @param userId Bare-JID of the user to revoke membership. 
   */
  @Override
  public boolean removeMember(String userId) {
    for (SpaceMember entry : members){
      if (entry.getJID().equalsIgnoreCase(userId)){
        return members.remove(entry);
      }
    }
    return false;
  }

  /**
   * Adds a member to the space.
   * If a given user is already member of the space, only the role will be updated.
   * @param member Space member model to set.
   */
  @Override
  public void addMember(SpaceMember member) {
    members.add(member);
  }
  
  @Override
  public String toString() {
    StringBuilder builder = new StringBuilder(200);
    builder.append("SpaceConfiguration(")
      .append("name = ").append(name)
      .append(", type = ").append(type)
      .append(", persistenceType = ").append(persistenceType)
      .append(", persistenceDuration = ").append(persistenceDuration);
    builder.append(", members = [");
    String delimiter = "";
    for (SpaceMember member : members) {
      builder.append(delimiter).append(member.toString());
      delimiter = ", ";
    }
    builder.append("])");
    return builder.toString();
  }
}




Java Source Code List

de.imc.mirror.sdk.android.CDMDataBuilder.java
de.imc.mirror.sdk.android.CDMData.java
de.imc.mirror.sdk.android.CommandType.java
de.imc.mirror.sdk.android.ConnectionConfigurationBuilder.java
de.imc.mirror.sdk.android.ConnectionConfiguration.java
de.imc.mirror.sdk.android.ConnectionHandler.java
de.imc.mirror.sdk.android.DataHandler.java
de.imc.mirror.sdk.android.DataModel.java
de.imc.mirror.sdk.android.DataObjectBuilder.java
de.imc.mirror.sdk.android.DataObject.java
de.imc.mirror.sdk.android.DataWrapper.java
de.imc.mirror.sdk.android.NetworkInformation.java
de.imc.mirror.sdk.android.OrgaSpace.java
de.imc.mirror.sdk.android.PrivateSpace.java
de.imc.mirror.sdk.android.ProviderInitializer.java
de.imc.mirror.sdk.android.RequestFuture.java
de.imc.mirror.sdk.android.SpaceChannel.java
de.imc.mirror.sdk.android.SpaceConfiguration.java
de.imc.mirror.sdk.android.SpaceHandler.java
de.imc.mirror.sdk.android.SpaceMember.java
de.imc.mirror.sdk.android.Space.java
de.imc.mirror.sdk.android.SpacesProvider.java
de.imc.mirror.sdk.android.TeamSpace.java
de.imc.mirror.sdk.android.UserInfo.java
de.imc.mirror.sdk.android.cdm.CDMData_0_1.java
de.imc.mirror.sdk.android.cdm.CDMData_0_2.java
de.imc.mirror.sdk.android.cdm.CDMData_1_0.java
de.imc.mirror.sdk.android.cdm.CDMData_2_0.java
de.imc.mirror.sdk.android.cdm.CreationInfo.java
de.imc.mirror.sdk.android.cdm.Reference.java
de.imc.mirror.sdk.android.cdm.References.java
de.imc.mirror.sdk.android.cdm.Summary.java
de.imc.mirror.sdk.android.data.ChannelsTable.java
de.imc.mirror.sdk.android.data.DataDB.java
de.imc.mirror.sdk.android.data.DataTable.java
de.imc.mirror.sdk.android.data.MembersTable.java
de.imc.mirror.sdk.android.data.SendTable.java
de.imc.mirror.sdk.android.data.SpacesTable.java
de.imc.mirror.sdk.android.exceptions.InvalidBuildException.java
de.imc.mirror.sdk.android.exceptions.RequestException.java
de.imc.mirror.sdk.android.filter.AndFilter.java
de.imc.mirror.sdk.android.filter.DataModelFilter.java
de.imc.mirror.sdk.android.filter.NamespaceFilter.java
de.imc.mirror.sdk.android.filter.OrFilter.java
de.imc.mirror.sdk.android.filter.PeriodFilter.java
de.imc.mirror.sdk.android.filter.PublisherFilter.java
de.imc.mirror.sdk.android.filter.ReferencesFilter.java
de.imc.mirror.sdk.android.packet.DeleteRequestIQ.java
de.imc.mirror.sdk.android.packet.DeleteResponseIQ.java
de.imc.mirror.sdk.android.packet.PersistenceServiceDeleteProvider.java
de.imc.mirror.sdk.android.packet.PersistenceServiceQueryProvider.java
de.imc.mirror.sdk.android.packet.QueryRequestIQ.java
de.imc.mirror.sdk.android.packet.QueryResponseIQ.java
de.imc.mirror.sdk.android.utils.DatatypeConverter.java
de.imc.mirror.sdk.android.utils.DateToXsdDatetimeFormatter.java
org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl.java
org.apache.xerces.jaxp.datatype.DurationImpl.java
org.apache.xerces.jaxp.datatype.SerializedDuration.java
org.apache.xerces.jaxp.datatype.SerializedXMLGregorianCalendar.java
org.apache.xerces.jaxp.datatype.XMLGregorianCalendarImpl.java
org.apache.xerces.util.DatatypeMessageFormatter.java