Merge "Issue #2361 remove StyleManager's use of SerializationUtil and ISerializableObject" into development

Former-commit-id: c2aacfc437 [formerly f4d52a5312ba3352c99eb6a51f9ebf71d4ff0356]
Former-commit-id: b4bcd14a85
This commit is contained in:
Nate Jensen 2013-11-14 16:34:28 -06:00 committed by Gerrit Code Review
commit 3b11ea8c5b
11 changed files with 140 additions and 45 deletions

View file

@ -72,4 +72,9 @@
<bean id="procedureXmlManagerInit" class="com.raytheon.uf.viz.core.procedures.ProcedureXmlManager" factory-method="inititializeAsync"/>
<bean id="vizSubClassLocator" class="com.raytheon.uf.viz.core.reflect.SubClassLocator"/>
<bean class="com.raytheon.uf.common.style.StyleManager" factory-method="getInstance">
<property name="subClassLocator" ref="vizSubClassLocator" />
</bean>
</beans>

View file

@ -55,7 +55,7 @@
<imageStyle>
<displayUnits>ft</displayUnits>
<defaultColormap>Grid/gridded data</defaultColormap>
<range scale="SURFACE">
<range scale="LINEAR">
<minValue>0</minValue>
<maxValue>4000</maxValue>
</range>
@ -4778,7 +4778,7 @@
<defaultColormap>Grid/warm to cold</defaultColormap>
<dataMapping>
<entry pixelValue="0.0" operator="&lt;" label="NONE" />
<entry pixelValue="30" operator="&gt;" displayValue='`100.0' label="100" />
<entry pixelValue="30" operator="&gt;" displayValue='100.0' label="100" />
<entry pixelValue="70" operator="&gt;" displayValue='200.0' label="200" />
<entry pixelValue="150" operator="&gt;" displayValue='5000.0' label="5000" />
<entry pixelValue="222" operator="&gt;" displayValue='11999.0' label="12k" />

View file

@ -56,6 +56,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* May 22, 2013 1917 rjpeter Added non-pretty print option to jaxb serialize methods.
* Aug 18, 2013 #2097 dhladky Allowed extension by OGCJAXBManager
* Sep 30, 2013 2361 njensen Refactored for cleanliness
* Nov 14, 2013 2361 njensen Added lazy init option, improved unmarshal error message
* </pre>
*
* @author chammack
@ -109,7 +110,9 @@ public class JAXBManager {
}
}
private final JAXBContext jaxbContext;
private volatile JAXBContext jaxbContext;
private Class<?>[] clazz;
protected final Queue<Unmarshaller> unmarshallers = new ConcurrentLinkedQueue<Unmarshaller>();
@ -127,10 +130,33 @@ public class JAXBManager {
* @throws JAXBException
*/
public JAXBManager(Class<?>... clazz) throws JAXBException {
long t0 = System.currentTimeMillis();
jaxbContext = JAXBContext.newInstance(clazz);
System.out.println("JAXB context with " + clazz.length
+ " classes inited in: " + (System.currentTimeMillis() - t0));
this(false, clazz);
}
/**
* Constructor. Clazz should include any classes that this JAXBManager needs
* to marshal to XML or unmarshal from XML. Does not need to include classes
* contained as fields or inner classes of other classes already passed to
* the constructor.
*
* If lazyInit is true, then the underlying JAXBContext (a potentially slow
* operation) will be constructed when first used, ie the first marshal or
* unmarshal operation.
*
* @param lazyInit
* whether or not to immediately initialize the underlying
* JAXBContext
* @param clazz
* classes that this instance must know about for
* marshalling/unmarshalling
* @throws JAXBException
*/
public JAXBManager(boolean lazyInit, Class<?>... clazz)
throws JAXBException {
this.clazz = clazz;
if (!lazyInit) {
getJaxbContext();
}
}
/**
@ -146,6 +172,18 @@ public class JAXBManager {
*/
@Deprecated
public JAXBContext getJaxbContext() throws JAXBException {
if (jaxbContext == null) {
synchronized (this) {
if (jaxbContext == null) {
long t0 = System.currentTimeMillis();
jaxbContext = JAXBContext.newInstance(clazz);
System.out.println("JAXB context with " + clazz.length
+ " classes inited in: "
+ (System.currentTimeMillis() - t0));
clazz = null;
}
}
}
return jaxbContext;
}
@ -507,7 +545,8 @@ public class JAXBManager {
Object obj = msh.unmarshal(reader);
return obj;
} catch (Exception e) {
throw new SerializationException(e.getLocalizedMessage(), e);
throw new SerializationException("Error reading " + file.getName()
+ "\n" + e.getLocalizedMessage(), e);
} finally {
if (msh != null) {
handleEvents(msh, file.getName());

View file

@ -34,6 +34,7 @@ import java.util.Collection;
* Date Ticket# Engineer Description
* ------------- -------- ----------- --------------------------
* Oct 23, 2013 2491 bsteffen Initial creation
* Nov 14, 2013 2361 njensen Promoted save() to interface
*
* </pre>
*
@ -50,4 +51,9 @@ public interface ISubClassLocator {
* @return all subclasses of base.
*/
public Collection<Class<?>> locateSubClasses(Class<?> base);
/**
* Store a cache of the located classes.
*/
public void save();
}

View file

@ -1,9 +0,0 @@
com.raytheon.uf.common.style.image.ImagePreferences
com.raytheon.uf.common.style.contour.ContourPreferences
com.raytheon.uf.common.style.arrow.ArrowPreferences
com.raytheon.uf.common.style.graph.GraphPreferences
com.raytheon.uf.common.style.level.SingleLevel
com.raytheon.uf.common.style.level.RangeLevel
com.raytheon.uf.common.style.StyleRule
com.raytheon.uf.common.style.StyleRuleset
com.raytheon.uf.common.style.ParamLevelMatchCriteria

View file

@ -36,8 +36,6 @@ import javax.xml.bind.annotation.XmlElementRef;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
import com.raytheon.uf.common.serialization.ISerializableObject;
/**
* Abstract style preferences
*
@ -46,13 +44,14 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 21, 2007 njensen Initial creation
* Nov 14, 2013 2361 njensen Remove ISerializableObject
*
* </pre>
*
* @author njensen
*/
@XmlAccessorType(XmlAccessType.NONE)
public abstract class AbstractStylePreferences implements ISerializableObject {
public abstract class AbstractStylePreferences {
@XmlRootElement(name = "displayUnits")
public static class DisplayUnit {

View file

@ -23,8 +23,6 @@ package com.raytheon.uf.common.style;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import com.raytheon.uf.common.serialization.ISerializableObject;
/**
* Abstract class of criteria to match against rules.
*
@ -33,13 +31,14 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 21, 2007 njensen Initial creation
* Nov 14, 2013 2361 njensen Remove ISerializableObject
*
* </pre>
*
* @author njensen
*/
@XmlAccessorType(XmlAccessType.NONE)
public abstract class MatchCriteria implements ISerializableObject {
public abstract class MatchCriteria {
/**
* Checks if the match criteria parameter is a match for this match
@ -53,6 +52,5 @@ public abstract class MatchCriteria implements ISerializableObject {
* @return the rating of the match, where a higher value is a stronger match
* than a lower value
*/
public abstract int matches(MatchCriteria aCriteria)
throws StyleException;
public abstract int matches(MatchCriteria aCriteria) throws StyleException;
}

View file

@ -20,19 +20,26 @@
package com.raytheon.uf.common.style;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXBException;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.LocalizationFile;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.serialization.JAXBManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.serialization.jaxb.JaxbDummyObject;
import com.raytheon.uf.common.serialization.reflect.ISubClassLocator;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.common.style.level.Level;
/**
* Manages the visualization styles
@ -41,10 +48,11 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 24, 2007 njensen Initial creation
* May 21, 2012 DR 14833 gzhang Adding a getter for StyleRuleset
* Sep 24, 2007 njensen Initial creation
* May 21, 2012 DR 14833 gzhang Adding a getter for StyleRuleset
* Sep 06, 2013 2251 mnash Add ability to plug in new style types
* Sep 24, 2013 2404 bclement changed to look in common for files
* Sep 24, 2013 2404 bclement changed to look in common for files
* Nov 13, 2013 2361 njensen Use ISubClassLocator instead of SerializationUtil
* </pre>
*
* @author njensen
@ -74,6 +82,10 @@ public class StyleManager {
// although HashMap allows null keys, would rather use this than Hashtable
private Map<IStyleType, StyleRuleset> rules = new HashMap<IStyleType, StyleRuleset>();
private JAXBManager jaxbMgr;
private ISubClassLocator subClassLocator;
private StyleManager() {
}
@ -112,10 +124,44 @@ public class StyleManager {
if (files == null) {
return;
}
synchronized (this) {
if (jaxbMgr == null) {
jaxbMgr = buildJaxbManager();
}
}
for (LocalizationFile lf : files) {
rules.addStyleRules((StyleRuleset) SerializationUtil
.jaxbUnmarshalFromXmlFile(StyleRuleset.class, lf.getFile()
.getPath()));
rules.addStyleRules(jaxbMgr.unmarshalFromXmlFile(
StyleRuleset.class, lf.getFile().getPath()));
}
}
/**
* Uses the subClassLocator to build a JAXBManager with classes related to
* unmarshalling style rules.
*
* @return a new JAXBManager for style rules
* @throws SerializationException
*/
private JAXBManager buildJaxbManager() throws SerializationException {
if (subClassLocator == null) {
throw new IllegalStateException(
"StyleManager must have an ISubClassLocator set on it, cannot detect and process style rules");
}
Collection<Class<?>> clz = new ArrayList<Class<?>>(20);
clz.add(JaxbDummyObject.class);
clz.add(StyleRuleset.class);
clz.addAll(subClassLocator
.locateSubClasses(AbstractStylePreferences.class));
clz.addAll(subClassLocator.locateSubClasses(MatchCriteria.class));
clz.addAll(subClassLocator.locateSubClasses(Level.class));
subClassLocator.save();
try {
return new JAXBManager(clz.toArray(new Class[0]));
} catch (JAXBException e) {
throw new SerializationException(
"Error initializing StyleManager's JAXB Context", e);
}
}
@ -194,4 +240,17 @@ public class StyleManager {
return rules.get(st);
}
/**
* Sets the sub class locator to detect style rules. Also clears out any
* rules already loaded, though this should really only be called at
* startup.
*
* @param locator
*/
public void setSubClassLocator(ISubClassLocator locator) {
this.subClassLocator = locator;
jaxbMgr = null;
rules.clear();
}
}

View file

@ -24,8 +24,6 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElementRef;
import com.raytheon.uf.common.serialization.ISerializableObject;
/**
* A rule for visualization style.
*
@ -34,6 +32,7 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* chammack Initial creation
* Nov 14, 2013 2361 njensen Remove ISerializableObject
*
* </pre>
*
@ -41,7 +40,7 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
*/
@XmlAccessorType(XmlAccessType.NONE)
public class StyleRule implements ISerializableObject {
public class StyleRule {
@XmlElementRef
private MatchCriteria matchCriteria;

View file

@ -21,14 +21,13 @@
package com.raytheon.uf.common.style;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import com.raytheon.uf.common.serialization.ISerializableObject;
/**
* Contains a set of style rules.
*
@ -37,6 +36,7 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 21, 2007 njensen Initial creation
* Nov 14, 2013 2361 njensen Remove ISerializableObject
*
* </pre>
*
@ -44,15 +44,15 @@ import com.raytheon.uf.common.serialization.ISerializableObject;
*/
@XmlRootElement(name = "styleRuleset")
@XmlAccessorType(XmlAccessType.NONE)
public class StyleRuleset implements ISerializableObject {
public class StyleRuleset {
@XmlElement(name = "styleRule")
private ArrayList<StyleRule> styleRules = new ArrayList<StyleRule>();
private List<StyleRule> styleRules = new ArrayList<StyleRule>();
/**
* @return the styleRules
*/
public ArrayList<StyleRule> getStyleRules() {
public List<StyleRule> getStyleRules() {
return styleRules;
}
@ -60,7 +60,7 @@ public class StyleRuleset implements ISerializableObject {
* @param styleRules
* the styleRules to set
*/
public void setStyleRules(ArrayList<StyleRule> styleRules) {
public void setStyleRules(List<StyleRule> styleRules) {
this.styleRules = styleRules;
}

View file

@ -27,23 +27,22 @@ import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import com.raytheon.uf.common.serialization.ISerializableObject;
/**
* Represents a level on the earth
* Represents a level on the earth for style rule purposes
*
* <pre>
* SOFTWARE HISTORY
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Sep 24, 2007 njensen Initial creation
* Nov 14, 2013 2361 njensen Remove ISerializableObject
*
* </pre>
*
* @author njensen
*/
@XmlAccessorType(XmlAccessType.NONE)
public abstract class Level implements ISerializableObject {
public abstract class Level {
public static enum LevelType {
THETA, HEIGHT_AGL, HEIGHT_MSL, PRESSURE, SURFACE, TILT, MB_AGL, MAXW, TW0, TEMP, FRZ, DEFAULT