📄 qbpersistenceservice.java
字号:
featureQuery = (FeatureQueryType) queryType;
if (featureQuery == null) {
throw new NullPointerException("FeatureQuery is null");
}
// Set the spatial filter
if (featureQuery.getSpatialFilter() != null) {
setFeatureGeom(featureQuery, obj);
obj.setAttribute(QbPersistenceObject.QUERY_WHERE_CLAUSE_KEY,
featureQuery.getSpatialFilter().getWhereClause());
}
// else this is a queryfilter
else {
obj.setAttribute(QbPersistenceObject.QUERY_WHERE_CLAUSE_KEY,
featureQuery.getQueryFilter().getWhereClause());
}
// if (envelope != null){
// obj.setAttribute(QbPersistenceObject.QUERY_EXTENT_XMIN,
// String.valueOf(envelope.getXMin()));
// obj.setAttribute(QbPersistenceObject.QUERY_EXTENT_YMIN,
// String.valueOf(envelope.getYMin()));
// obj.setAttribute(QbPersistenceObject.QUERY_EXTENT_XMAX,
// String.valueOf(envelope.getXMax()));
// obj.setAttribute(QbPersistenceObject.QUERY_EXTENT_YMAX,
// String.valueOf(envelope.getYMax()));
// }
// get the first element in list, only one layer stored
layerType = (QueryLayerType) featureQuery.getQueryLayer().get(0);
obj.setAttribute(QbPersistenceObject.QUERY_LAYERNAME_KEY,
layerType.getName());
MapServiceList mapServices = featureQuery.getMapServices();
if (mapServices == null) {
throw new NullPointerException("Mapservices is Null");
}
obj.setMapServiceList(mapServices);
return obj;
}
private void setFeatureGeom(FeatureQueryType featureQuery,
QbPersistenceObject obj) {
PolygonN poly = (PolygonN) featureQuery.getSpatialFilter().getPolygonN();
PointN point = (PointN) featureQuery.getSpatialFilter().getPointN();
if (poly != null) {
poly = (PolygonN) featureQuery.getSpatialFilter().getPolygonN();
obj.setPolygonGeom(poly);
} else if (point != null) {
point = (PointN) featureQuery.getSpatialFilter().getPointN();
obj.setPointGeom(point);
}
}
public List<IQuery> getSavedQueries() throws PersonalizationException {
List<IQuery> queries = new ArrayList<IQuery>();
if (_personalizationContext == null) {
throw new IllegalStateException("personalization context not set");
}
for (IQuery q : _personalizationContext.getData().getQueries()) {
if (q.getType().equals(IQuery.Type.FEATURE)) {
queries.add(q);
}
}
return queries;
}
/*private String getExtendedAttributeValue(QueryType queryType, String key)
throws PersonalizationException {
String value = null;
Iterator iter = null;
AttributeType attr = null;
if (queryType == null) {
throw new NullPointerException("query cannot be null");
}
if (key == null) {
throw new NullPointerException("key cannot be null");
}
iter = queryType.getExtendedAttributes().getAttribute().iterator();
while (iter.hasNext()) {
attr = (AttributeType) iter.next();
if (attr.getName().equals(key)) {
value = attr.getValue();
break;
}
}
return value;
}*/
private IQuery getQuery(QbPersistenceObject obj)
throws PersonalizationException {
IQuery iquery = null;
List<IQuery> queries = null;
boolean newQuery = false;
if (obj == null) {
throw new NullPointerException("persistence object cannot be null");
}
if (_personalizationContext == null) {
throw new IllegalStateException("Personalization context not set");
}
queries = getSavedQueries();
for (IQuery q : queries) {
if (q.getName()
.equals(obj.getAttribute(
QbPersistenceObject.QUERY_NAME_KEY))) {
iquery = q;
_logger.debug("Updating query - ID: [" + q.getId() +
"] Name: [" + q.getName() + "]");
break;
}
}
// if the query was not found, create a new one
if (iquery == null) {
iquery = _personalizationContext.getData()
.createQuery(IQuery.Type.FEATURE);
newQuery = true;
}
this.setQueryProperties(iquery.getQuery(), obj, newQuery);
return iquery;
}
@SuppressWarnings("unchecked")
private QueryType setQueryProperties(QueryType queryType,
QbPersistenceObject obj, boolean isNew) {
FeatureQueryType featureQuery = null;
ObjectFactory factory = null;
QueryLayerType layerType = null;
SpatialFilter spatialFilter = null;
QueryFilter queryFilter = null;
if (queryType == null) {
throw new NullPointerException("QueryType cannot be null");
}
if (obj == null) {
throw new NullPointerException("QbPersistenceObject cannot be null");
}
featureQuery = (FeatureQueryType) queryType;
// set the query name and description
featureQuery.setName(obj.getAttribute(
QbPersistenceObject.QUERY_NAME_KEY));
featureQuery.setDescription(obj.getAttribute(
QbPersistenceObject.QUERY_DESCRIPTION_KEY));
try {
if (isNew) {
// create the object factory
factory = new ObjectFactory();
layerType = factory.createQueryLayerType();
// set the layer name
layerType.setName(obj.getAttribute(
QbPersistenceObject.QUERY_LAYERNAME_KEY));
// add QueryLayerType to featureQuery
featureQuery.getQueryLayer().add(layerType);
} else {
layerType = (QueryLayerType) featureQuery.getQueryLayer().get(0);
// set the layer name
layerType.setName(obj.getAttribute(
QbPersistenceObject.QUERY_LAYERNAME_KEY));
}
featureQuery.setSpatialFilter(null);
featureQuery.setQueryFilter(null);
if (isSpatialQuery(obj)) {
// set the query filter
spatialFilter = generateSpatialFilter(obj);
featureQuery.setSpatialFilter(spatialFilter);
} else {
queryFilter = generateQueryFilter(obj);
featureQuery.setQueryFilter(queryFilter);
}
// set the map services
if (obj.getMapServiceList() != null) {
featureQuery.setMapServices(obj.getMapServiceList());
}
} catch (JAXBException ex) {
_logger.warn("JAXBException occurred setting IQuery properties", ex);
queryType = null;
}
return queryType;
}
private QueryType unmarshallQuery(String xml)
throws PersonalizationException {
JAXBContext ctx = null;
Unmarshaller unmarshaller = null;
QueryType queryType = null;
if (xml == null) {
throw new NullPointerException();
}
if (_logger.isDebugEnabled()) {
_logger.debug(MessageFormat.format(
DEBUG_QUERY_DATA_BEFORE_UNMARSHALLING, xml));
}
try {
ctx = JAXBContext.newInstance(JAXB_BEAN_PACKAGE_NAME);
unmarshaller = ctx.createUnmarshaller();
queryType = (QueryType) unmarshaller.unmarshal(new ByteArrayInputStream(
xml.getBytes()));
return queryType;
} catch (JAXBException ex) {
_logger.warn("JAXBException occurred unmarshalling query xml", ex);
_logger.debug("JAXBException occurred unmarshalling query xml: " +
xml);
throw new PersonalizationException(PersonalizationException.Code.SERIALIZATION_ERROR);
}
}
private String marshallQuery(QueryType queryType)
throws PersonalizationException {
JAXBContext ctx = null;
Marshaller marshaller = null;
ByteArrayOutputStream out = null;
byte[] data = null;
if (queryType == null) {
throw new NullPointerException("QueryType cannot be null");
}
try {
ctx = JAXBContext.newInstance(JAXB_BEAN_PACKAGE_NAME);
marshaller = ctx.createMarshaller();
out = new ByteArrayOutputStream();
marshaller.marshal(queryType, out);
data = out.toByteArray();
if (_logger.isDebugEnabled()) {
_logger.debug(MessageFormat.format(
DEBUG_QUERY_DATA_AFTER_MARSHALLING, queryType.getId(),
queryType.getName(), new String(data)));
}
return new String(data);
} catch (JAXBException ex) {
_logger.warn("JAXBException occurred marshalling query to xml", ex);
throw new PersonalizationException(PersonalizationException.Code.SERIALIZATION_ERROR);
} catch (Exception ex) {
_logger.warn("Exception occurred marshalling query to xml", ex);
throw new PersonalizationException(PersonalizationException.Code.SERIALIZATION_ERROR);
}
}
private boolean isSpatialQuery(QbPersistenceObject obj) {
if (obj.getPolygonGeom() != null) {
return true;
} else if (obj.getPointGeom() != null) {
return true;
}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -