📄 bookmarkdata.java
字号:
package com.esri.solutions.jitk.services.personalization.data;
import java.io.ByteArrayInputStream;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import com.esri.solutions.jitk.personalization.data.beans.v1.BookmarkType;
import com.esri.solutions.jitk.services.common.ServicesException;
/**
* Serializable Java Bean representation of a Bookmark.
*/
public class BookmarkData extends PersonalizationData implements java.io.Serializable {
private static final long serialVersionUID = 1L;
/**
* {@code byte[]} representation of the bookmark.
*/
private byte[] _data = null;
/**
* {@link String} containing the ID of the map composition against which the
* bookmark was created.
*/
private String _mapCompositionId = null;
/**
* {@link BookmarkType} representation of the bookmark information
*/
private BookmarkType _bookmark = null;
/**
* {@link Object} used by the {@link #equals(Object)} method to improve the
* performance of the calculations.
*/
private Object _equalsCalc = null;
/**
* {@code boolean} used by the {@link #hashCode()} method to improve the
* performance of the hash algorithm.
*/
private boolean _hashCodeCalc = false;
private static final String ERROR_DATA_DOES_NOT_REPRESENT_A_BOOKMARK = "The byte array provided does not unmarshall to a Bookmark Type.";
/**
* Default constructor
*/
public BookmarkData() {
}
/**
* Gets the id of the map composition with which this bookmark is associated
*
* @return {@link String} containing the associated map composition ID
*/
public String getMapCompositionId() {
return _mapCompositionId;
}
/**
* Sets the id of the map composition with which this bookmark is associated
*
* @param mapCompositionId {@link String} containing the associated map composition ID
*/
public void setMapCompositionId(String mapCompositionId) {
_mapCompositionId = mapCompositionId;
}
/**
* Gets the Bookmark information in the form of a XML String in {@code byte[]} format.
* @return The xml data for a bookmark as a byte array.
*/
public byte[] getData() {
return _data;
}
/**
* Sets the Bookmark information.
* <p>
* The {@code byte[]} parameter must unmarshall into a valid {@link BookmarkType}. If the parameter is {@code null},
* then the property in which {@code data} is stored, as well as the internal {@link BookmarkType} representation, will both
* be set to {@code null}, thus causing {@code null} to be returned from {@link #dataAsBookmark()}.
* </p>
* <p>
* If {@code data} is not {@code null}, this method will unmarshall the byte array into a {@link BookmarkType} that
* can be retrieved from {@link #dataAsBookmark()}.
* </p>
* @param data {@code byte[]} representation of a {@link BookmarkType}. The parameter can be {@code null}
* or of zero length, but if it is not, it must unmarshall to a {@link BookmarkType}.
* @throws ServicesException If {@code data} does not unmarshall to a valid {@link BookmarkType}.
*/
public void setData(byte[] data) throws ServicesException {
BookmarkType b = null;
if (data != null && data.length>0 ) {
try {
b = unmarshall(data);
/*
* t will be null if the unmarshall was successful but the data
* could not be converted to a MapCompositionType
*/
if (b == null) {
throw new ServicesException(
ERROR_DATA_DOES_NOT_REPRESENT_A_BOOKMARK);
}
_bookmark = b;
} catch (JAXBException e) {
throw new ServicesException(
ERROR_DATA_DOES_NOT_REPRESENT_A_BOOKMARK);
}
}
/*
* Set both the bookmark and the data array, that way if one is
* nulled out, the other will be as well.
*/
_bookmark = b;
_data = data;
}
/**
* Retrieves the bookmark information, set previously through a call to {@link #setData(byte[])}, as a {@link BookmarkType}
* @return {@link BookmarkType} version of the {@code byte[]} set in {@link #setData);
*/
public BookmarkType dataAsBookmark() {
return _bookmark;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
public synchronized boolean equals(Object obj) {
if (!(obj instanceof BookmarkData))
return false;
BookmarkData other = (BookmarkData) obj;
if (obj == null)
return false;
if (this == obj)
return true;
if (_equalsCalc != null) {
return (_equalsCalc == obj);
}
_equalsCalc = obj;
boolean _equals;
_equals = true
&& ((_creator == null && other.getCreator() == null) || (_creator != null && _creator
.equals(other.getCreator())))
&& ((_data == null && other.getData() == null) || (_data != null && _data
.equals(other.getData())))
&& ((_mapCompositionId == null && other.getMapCompositionId() == null) || (_mapCompositionId != null && _mapCompositionId
.equals(other.getMapCompositionId())));
_equalsCalc = null;
return _equals;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
public synchronized int hashCode() {
if (_hashCodeCalc) {
return 0;
}
_hashCodeCalc = true;
int _hashCode = 1;
if (getCreator() != null) {
_hashCode += getCreator().hashCode();
}
if (getData() != null) {
_hashCode += getData().hashCode();
}
if (getMapCompositionId() != null) {
_hashCode += getMapCompositionId().hashCode();
}
_hashCodeCalc = false;
return _hashCode;
}
/**
* Unmarshalls a {@code byte[]} into a {@link BookmarkType}
*
* @param data
* @throws JAXBException
*/
private BookmarkType unmarshall(byte[] data) throws JAXBException {
JAXBContext ctx = null;
ctx = JAXBContext.newInstance(JAXB_BEAN_PACKAGE_NAME);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
Object o = unmarshaller.unmarshal(new ByteArrayInputStream(data));
BookmarkType t = null;
if (o instanceof BookmarkType) {
t = (BookmarkType) o;
}
return t;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -