Android Open Source - msf-spaces-sdk-android C D M Data






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;
//ww w  .  j  av a 2  s.  com
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jdom2.Element;

import de.imc.mirror.sdk.cdm.CDMElement;
import de.imc.mirror.sdk.cdm.CDMVersion;
import de.imc.mirror.sdk.android.exceptions.InvalidBuildException;
import de.imc.mirror.sdk.android.utils.DatatypeConverter;

/**
 * Superclass for the Common Data Model. 
 */
public abstract class CDMData implements Serializable, de.imc.mirror.sdk.CDMData {
  private static final long serialVersionUID = 1L;

  private final CDMVersion cdmVersion;
  private final String id;
  private final Date timestamp;
  
  /**
   * Constructor for a new CDMData Object
   * @param element JDomElement with all CDMInformation.
   */
  public CDMData(Element element) {
    cdmVersion = CDMVersion.getVersionForString(element.getAttributeValue("cdmVersion"));
    id = element.getAttributeValue("id");
    String date = element.getAttributeValue("timestamp");
    Date parsedDate = null;
    if (date != null) {
      try {
        parsedDate = DatatypeConverter.parseDateTime(date).getTime(); 
      } catch (IllegalArgumentException e) {
        Logger logger = Logger.getAnonymousLogger();
        logger.log(Level.WARNING, "The timestamp seems to be in a false Format.", e);
      }
    }
    timestamp = (parsedDate != null) ? parsedDate : null;
  }
  
  /**
   * Creates a CDM data object based on the given attributes and elements.
   * @param attributes Map of attribute names and values.
   * @param elements Map of element names and XML element objects.
   * @throws InvalidBuildException Failed to create an CDMData object with the given arguments.
   */
  public CDMData(Map<String, String> attributes, Map<String, CDMElement> elements) throws InvalidBuildException {
    List<String> buildErrors = new ArrayList<String>();
    
    cdmVersion = CDMVersion.getVersionForString(attributes.get("cdmVersion"));
    id = attributes.get("id");
    Date parsedDate = null;
    if (attributes.containsKey("timestamp")) {
      try {
        parsedDate = DatatypeConverter.parseDateTime(attributes.get("timestamp")).getTime(); 
      } catch (IllegalArgumentException e) {
        buildErrors.add("The given timestamp cannot be parsed.");
        throw new InvalidBuildException("Failed to create CDM object.", buildErrors);
      }
    }
    timestamp = (parsedDate != null) ? parsedDate : null;
  }
  
  /**
   * Returns the version information of common data model implemented.
   * The CDM version information is only available in all objects with support for CDM version 1.0 or higher.  
   * @return Version information if a CDM version is set, otherwise <code>null</code>.
   */
  @Override
  public CDMVersion getCDMVersion() {
    return cdmVersion;
  }

  /**
   * Returns the ID of the data object.
   * The ID is unique within the domain and set by the server.
   * @return Data object identifier.
   */
  @Override
  public String getId() {
    return id;
  }

  /**
   * Returns the time the object was published.
   * The point in time is determined by the server.
   * @return Point in time the data object was published.
   */
  @Override
  public Date getTimeStamp() {
    return timestamp;
  }
  
  /**
   * Applies the data to the given XML element.
   * @param element XML element to add CDM information to.
   */
  public void applyToElement(Element element) {
    if (cdmVersion != null) element.setAttribute("cdmVersion", cdmVersion.getVersionString());
    if (id != null) element.setAttribute("id", id);
    if (timestamp != null) {
      Calendar calendar = Calendar.getInstance();
      calendar.setTime(timestamp);
      element.setAttribute("timestamp", DatatypeConverter.printDateTime(calendar));
    }
  }
}




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