📄 mapcompositionimpl.java
字号:
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.personalization.data.IMapComposition#isNew()
*/
public boolean isNew () {
return m_isNew;
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.personalization.data.IMapComposition#getBookmarks()
*/
public List<IBookmark> getBookmarks () throws PersonalizationException {
if (m_daoProfile == null) {
LOG.error(ERROR_NULL_PROFILE_OBJECT);
throw new IllegalStateException (ERROR_NULL_PROFILE_OBJECT);
}
if (m_dataFactory == null) {
LOG.error(ERROR_NULL_DATA_FACTORY_OBJECT);
throw new IllegalStateException (ERROR_NULL_DATA_FACTORY_OBJECT);
}
List<BookmarkInfoRecord> bookmarkRecs = null;
IBookmarkDAO dao = null;
List<IBookmark> bookmarks = null;
Criteria criteria = null;
try {
if (!m_isNew) {
dao = m_daoProfile.getBookmarkDAO();
if (dao == null) {
LOG.error(ERROR_NULL_BOOKMARK_DAO_OBJECT);
throw new IllegalArgumentException (ERROR_NULL_BOOKMARK_DAO_OBJECT);
}
criteria = new Criteria();
criteria.setMapCompositionId(m_info.getId());
bookmarkRecs = dao.selectAll(criteria);
bookmarks = new ArrayList<IBookmark>();
if (bookmarkRecs != null) {
for (BookmarkInfoRecord rec : bookmarkRecs) {
IBookmark bookmark = m_dataFactory.createBookmark(rec);
bookmarks.add(bookmark);
}
}
return bookmarks;
} else {
return m_bookmarkSaveQueue;
}
} catch (PersonalizationDAOException e) {
throw new PersonalizationException (
PersonalizationException.Code.RETRIEVE_DATA_ERROR,
e);
}
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.personalization.data.IMapComposition#createBookmark()
*/
public IBookmark createBookmark() throws PersonalizationException {
if (m_dataFactory == null) {
LOG.error(ERROR_NULL_DATA_FACTORY_OBJECT);
throw new IllegalStateException (ERROR_NULL_DATA_FACTORY_OBJECT);
}
IBookmark bookmark = null;
bookmark = m_dataFactory.createBookmark(this);
return bookmark;
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.personalization.data.IMapComposition#getQueries()
*/
public List<IQuery> getQueries() throws PersonalizationException {
if (m_daoProfile == null) {
LOG.error(ERROR_NULL_PROFILE_OBJECT);
throw new IllegalStateException (ERROR_NULL_PROFILE_OBJECT);
}
if (m_dataFactory == null) {
LOG.error(ERROR_NULL_DATA_FACTORY_OBJECT);
throw new IllegalStateException (ERROR_NULL_DATA_FACTORY_OBJECT);
}
List<QueryInfoRecord> queryRecs = null;
IQueryDAO dao = null;
List<IQuery> queries = null;
Criteria criteria = null;
try {
if (!m_isNew) {
dao = m_daoProfile.getQueryDAO();
if (dao == null) {
LOG.error(ERROR_NULL_QUERY_DAO_OBJECT);
throw new IllegalArgumentException (ERROR_NULL_QUERY_DAO_OBJECT);
}
criteria = new Criteria();
criteria.setMapCompositionId(m_info.getId());
queryRecs = dao.selectAll(criteria);
queries = new ArrayList<IQuery>();
if (queryRecs != null) {
for (QueryInfoRecord rec : queryRecs) {
IQuery query = m_dataFactory.createQuery(rec);
queries.add(query);
}
}
return queries;
} else {
return m_querySaveQueue;
}
} catch (PersonalizationDAOException e) {
throw new PersonalizationException (
PersonalizationException.Code.RETRIEVE_DATA_ERROR,
e);
}
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.personalization.data.IMapComposition#createQuery()
*/
public IQuery createQuery(IQuery.Type type) throws PersonalizationException {
if (m_dataFactory == null) {
LOG.error(ERROR_NULL_DATA_FACTORY_OBJECT);
throw new IllegalStateException (ERROR_NULL_DATA_FACTORY_OBJECT);
}
IQuery query = null;
query = m_dataFactory.createQuery(this, type);
if (m_isNew) {
m_querySaveQueue.add(query);
}
return query;
}
/**
* Sets the record bean that contains basic information on a Map
* Composition.
*
* @param record Contains basic information on a Map Composition,
* cannot be <code>null</code>.
* @throws NullPointerException Thrown if the <code>record</code>
* argument is <code>null</code>.
*/
public void setMapCompositionInfoRecord (MapCompositionInfoRecord record) {
if (record == null) {
throw new NullPointerException();
}
m_info = record;
}
/**
* Sets the flag to indicate if this is a new Map Composition.
*
* @param isNew Flag indicating if the Map Composition is new.
*/
public void setNew (boolean isNew) {
m_isNew = isNew;
}
/**
* Sets the reference to the profile of DAO objects that will be used
* to retrieve and store personalization data.
*
* @param profile Contains references to all DAO objects, cannot
* be <code>null</code>.
*
* @throws NullPointerException Thrown if the <code>profile</code>
* argument is <code>null</code>
*/
public void setPersonalizationDAOProfile (IPersonalizationDAOProfile profile) {
if (profile == null) {
throw new NullPointerException ();
}
m_daoProfile = profile;
}
/**
* Sets the reference to the factory that will create
* {@link IMapComposition}, {@link IQuery}, and {@link IBookmark}
* objects.
*
* @param factory Factory for creating objects, cannot be <code>null</code>.
*
* @throws NullPointerException Thrown if the <code>factory</code>
* argument is <code>null</code>.
*/
public void setDataFactory (IDataFactory factory) {
if (factory == null) {
throw new NullPointerException ();
}
m_dataFactory = factory;
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof MapCompositionImpl)) {
return false;
}
MapCompositionImpl mc = (MapCompositionImpl) obj;
return mc.toString().equals(toString());
}
@Override
public int hashCode() {
return toString().hashCode();
}
/*
* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString () {
StringBuilder sb = new StringBuilder();
sb.append("ID:[");
sb.append(getId());
sb.append("],Name:[");
sb.append(getName());
sb.append("],Description:[");
sb.append(getDescription());
sb.append("]");
return sb.toString();
}
private MapCompositionRecord createRecord() throws JAXBException {
MapCompositionRecord record = new MapCompositionRecord();
record.setCreator(m_currentUser.getId().getUsername());
record.setId(m_bean.getId());
record.setDescription(m_bean.getDescription());
record.setName(m_bean.getName());
record.setTimeModified(new java.sql.Timestamp(System.currentTimeMillis()));
byte[] data = marshallBean();
record.setData(data);
return record;
}
private byte[] marshallBean() throws JAXBException {
JAXBContext ctx = null;
ctx = JAXBContext.newInstance(JAXB_BEAN_PACKAGE_NAME);
Marshaller marshaller = ctx.createMarshaller();
ByteArrayOutputStream out = new ByteArrayOutputStream();
marshaller.marshal(m_bean, out);
byte[] data = out.toByteArray();
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(DEBUG_MAP_COMPOSITION_DATA_AFTER_MARSHALLING, getId(), getName(), new String(data)));
}
return data;
}
private void unmarshallBean(byte[] data) throws JAXBException {
if (LOG.isDebugEnabled()) {
LOG.debug(MessageFormat.format(DEBUG_MAP_COMPOSITION_DATA_BEFORE_UNMARSHALLING, getId(), getName(), new String(data)));
}
JAXBContext ctx = null;
ctx = JAXBContext.newInstance(JAXB_BEAN_PACKAGE_NAME);
Unmarshaller unmarshaller = ctx.createUnmarshaller();
m_bean = (MapCompositionType) unmarshaller.unmarshal(new ByteArrayInputStream(data));
}
/**
* Protects the {@link MapCompositionType} bean from having its ID
* property modified. Don't want callers to be able to change the
* ID. The ID will be managed by this class.
*/
private class ProtectIDModification implements InvocationHandler {
/**
* Reference to the {@link MapCompositionType} bean
*/
private MapCompositionType m_comp;
/**
* Constructs a new <code>ProtectIDModification</code> object
* with a reference to a {@link MapCompositionType} bean.
*
* @param comp Reference to {@link MapCompositionType} bean.
*/
public ProtectIDModification (MapCompositionType comp) {
m_comp = comp;
}
/*
* (non-Javadoc)
* @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object, java.lang.reflect.Method, java.lang.Object[])
*/
public Object invoke(Object proxy, Method method, Object[] args)
throws Throwable {
if (!method.getName().equals("setId")) {
return method.invoke(m_comp, args);
} else {
LOG.info ("Attempting to setId on MapCompositionType, not allowed.");
}
return Void.TYPE;
}
}
List<IBookmark> getBookmarkSaveQueue() {
return m_bookmarkSaveQueue;
}
List<IQuery> getQuerySaveQueue() {
return m_querySaveQueue;
}
/*
* (non-Javadoc)
* @see com.esri.solutions.jitk.personalization.data.IMapComposition#getLastModifiedDate()
*/
public Date getLastModifiedDate() {
if (m_info != null) {
return m_info.getTimeModified();
}
return null;
}
public void setCurrentUser(IUser currentUser) {
m_currentUser = currentUser;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -