Package net.sf.freecol.common.io
Class FreeColXMLReader
- java.lang.Object
-
- javax.xml.stream.util.StreamReaderDelegate
-
- net.sf.freecol.common.io.FreeColXMLReader
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,javax.xml.stream.XMLStreamConstants,javax.xml.stream.XMLStreamReader
public class FreeColXMLReader extends javax.xml.stream.util.StreamReaderDelegate implements java.io.CloseableA wrapper forXMLStreamReaderand potentially an underlying stream. Adds on many useful utilities for reading XML and FreeCol values.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFreeColXMLReader.ReadScope
-
Field Summary
Fields Modifier and Type Field Description private java.io.InputStreaminputStreamThe stream to read from.private static java.util.logging.Loggerloggerprivate FreeColXMLReader.ReadScopereadScopeThe read scope to apply.private static java.util.Map<java.lang.Integer,java.lang.String>tagStringsMap for the XMLStreamConstants.private booleantracingTrace all reads?private java.util.Map<java.lang.String,FreeColObject>uninternedA cache of uninterned objects.
-
Constructor Summary
Constructors Constructor Description FreeColXMLReader(java.io.BufferedInputStream bis)Creates a newFreeColXMLReader.FreeColXMLReader(java.io.File file)Creates a newFreeColXMLReader.FreeColXMLReader(java.io.InputStream inputStream)Creates a newFreeColXMLReader.FreeColXMLReader(java.io.Reader reader)Creates a newFreeColXMLReader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanatTag(java.lang.String tag)Is the stream at the given tag?voidclose()Closes both theXMLStreamReaderand the underlying stream if any.voidcloseTag(java.lang.String tag)Close the current tag, checking that it did indeed close correctly.voidcloseTag(java.lang.String tag, java.lang.String... others)Close the current tag, but accept some alternative elements first.<T extends FreeColObject>
Tcopy(Game game, java.lang.Class<T> returnClass)Copy a FreeColObject by serializing it and reading back the result with a non-interning stream.java.lang.StringcurrentTag()Extract the current tag and its attributes from an input stream.voidexpectTag(java.lang.String tag)Expect a particular tag.<T extends AIObject>
TfindAIObject(AIMain aiMain, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue, boolean required)Find a FreeCol AI object from an attribute in a stream.<T extends FreeColGameObject>
TfindFreeColGameObject(Game game, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue, boolean required)Find aFreeColGameObjectof a given class from a stream attribute.java.util.Map<java.lang.String,java.lang.String>getAllAttributes()Get a map of all attributes present.java.util.Map<java.lang.String,java.lang.String>getArrayAttributeMap()Get a map of the array attributes.booleangetAttribute(java.lang.String attributeName, boolean defaultValue)Gets a boolean from an attribute in a stream.floatgetAttribute(java.lang.String attributeName, float defaultValue)Gets a float from an attribute in a stream.intgetAttribute(java.lang.String attributeName, int defaultValue)Gets an int from an attribute in a stream.longgetAttribute(java.lang.String attributeName, long defaultValue)Gets a long from an attribute in a stream.<T extends java.lang.Enum<T>>
TgetAttribute(java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)Gets an enum from an attribute in a stream.java.lang.StringgetAttribute(java.lang.String attributeName, java.lang.String defaultValue)Gets a string from an attribute in a stream.<T extends FreeColObject>
TgetAttribute(Game game, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)Gets a FreeCol object from an attribute in a stream.<T extends AIObject>
TgetAttribute(AIMain aiMain, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)Get a FreeCol AI object from an attribute in a stream.java.util.Map<java.lang.String,java.lang.String>getAttributeMap(java.lang.String... attributes)Get a map of attributes.LocationgetLocationAttribute(Game game, java.lang.String attributeName, boolean make)Find a new location from a stream attribute.FreeColXMLReader.ReadScopegetReadScope()Get the read scope.<T extends FreeColSpecObjectType>
TgetType(Specification spec, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)Get a FreeColSpecObjectType by identifier from a stream from a specification.booleanhasAttribute(java.lang.String attributeName)Is there an attribute present in the stream?private <T extends FreeColObject>
TinternedRead(Game game, java.lang.Class<T> returnClass)Do a normal interning read of aFreeColObject.private FreeColObjectlookup(Game game, java.lang.String id)Look up an identifier in an enclosing game.<T extends FreeColObject>
Tlookup(Game game, java.lang.String id, java.lang.Class<T> returnClass)Look up an identifier in an enclosing game.<T extends AIObject>
TmakeAIObject(AIMain aiMain, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue, boolean required)Either get an existingAIObjectfrom a stream attribute or create it if it does not exist.<T extends FreeColObject>
TmakeFreeColObject(Game game, java.lang.String attributeName, java.lang.Class<T> returnClass, boolean required)Either get an existingFreeColObjectfrom a stream attribute or create it if it does not exist.booleanmoreTags()Check if there are more tags in the current element.private static javax.xml.stream.XMLInputFactorynewXMLInputFactory()Create a new XMLInputFactory.intnextTag()intreadAttributeValues(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String attr)Fill in the identifier values supplied in a map.<T extends FreeColObject>
TreadFreeColObject(Game game)Read aFreeColObjectfrom a stream.<T extends FreeColObject>
TreadFreeColObject(Game game, java.lang.Class<T> returnClass)Reads aFreeColObjectfrom a stream.java.lang.StringreadId()Reads the identifier attribute.<T extends FreeColSpecObjectType>
java.util.List<T>readList(Specification spec, java.lang.String tag, java.lang.Class<T> type)Reads an XML-representation of a list ofFreeColSpecObjectTypes.FreeColXMLReader.ReadScopereplaceScope(FreeColXMLReader.ReadScope newReadScope)Replace a the scope.FreeColXMLReadersetReadScope(FreeColXMLReader.ReadScope readScope)Set the read scope.FreeColXMLReadersetTracing(boolean tracing)Set the tracing state.booleanshouldClearContainers()Should the game object type being read clear its containers before reading the child elements? Usually true, but not if the type is extending another one.booleanshouldIntern()Should reads from this stream intern their objects into the enclosing game?voidswallowTag(java.lang.String tag)Swallow a tag, ignoring anything read until the tag closes.voidunexpectedTag(java.lang.String context)Standardized way to throw a parsing exception with a bit of context.private <T extends FreeColObject>
TuninternedRead(Game game, java.lang.Class<T> returnClass)Do a special non-interning read of aFreeColObject.-
Methods inherited from class javax.xml.stream.util.StreamReaderDelegate
getAttributeCount, getAttributeLocalName, getAttributeName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getCharacterEncodingScheme, getElementText, getEncoding, getEventType, getLocalName, getLocation, getName, getNamespaceContext, getNamespaceCount, getNamespacePrefix, getNamespaceURI, getNamespaceURI, getNamespaceURI, getParent, getPIData, getPITarget, getPrefix, getProperty, getText, getTextCharacters, getTextCharacters, getTextLength, getTextStart, getVersion, hasName, hasNext, hasText, isAttributeSpecified, isCharacters, isEndElement, isStandalone, isStartElement, isWhiteSpace, next, require, setParent, standaloneSet
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
tagStrings
private static final java.util.Map<java.lang.Integer,java.lang.String> tagStrings
Map for the XMLStreamConstants.
-
tracing
private boolean tracing
Trace all reads?
-
inputStream
private java.io.InputStream inputStream
The stream to read from.
-
readScope
private FreeColXMLReader.ReadScope readScope
The read scope to apply.
-
uninterned
private java.util.Map<java.lang.String,FreeColObject> uninterned
A cache of uninterned objects. Uninterned reads add to this list so that they can refer to sub-objects correctly. However there is no obvious place to clear this cache, so we do that in replaceScope as you can not expect to reference the same object across scopes.
-
-
Constructor Detail
-
FreeColXMLReader
public FreeColXMLReader(java.io.BufferedInputStream bis) throws javax.xml.stream.XMLStreamExceptionCreates a newFreeColXMLReader.- Parameters:
bis- TheBufferedInputStreamto create anFreeColXMLReaderfor.- Throws:
javax.xml.stream.XMLStreamException- can be thrown while creating the reader.
-
FreeColXMLReader
public FreeColXMLReader(java.io.InputStream inputStream) throws javax.xml.stream.XMLStreamExceptionCreates a newFreeColXMLReader.- Parameters:
inputStream- TheInputStreamto create anFreeColXMLReaderfor.- Throws:
javax.xml.stream.XMLStreamException- can be thrown while creating the reader.
-
FreeColXMLReader
public FreeColXMLReader(java.io.File file) throws java.io.IOException, javax.xml.stream.XMLStreamExceptionCreates a newFreeColXMLReader.- Parameters:
file- TheFileto create anFreeColXMLReaderfor.- Throws:
java.io.IOException- if the file is missing.javax.xml.stream.XMLStreamException- can be thrown while creating the reader.
-
FreeColXMLReader
public FreeColXMLReader(java.io.Reader reader) throws javax.xml.stream.XMLStreamExceptionCreates a newFreeColXMLReader.- Parameters:
reader- AReaderto create anFreeColXMLReaderfor.- Throws:
javax.xml.stream.XMLStreamException- if thrown while creating the reader.
-
-
Method Detail
-
newXMLInputFactory
private static javax.xml.stream.XMLInputFactory newXMLInputFactory()
Create a new XMLInputFactory. Respond to CVE 2018-1000825.- Returns:
- A new
XMLInputFactory.
-
setTracing
public FreeColXMLReader setTracing(boolean tracing)
Set the tracing state.- Parameters:
tracing- The new tracing state.- Returns:
- This reader.
-
shouldIntern
public boolean shouldIntern()
Should reads from this stream intern their objects into the enclosing game?- Returns:
- True if this is an interning stream.
-
getReadScope
public FreeColXMLReader.ReadScope getReadScope()
Get the read scope.- Returns:
- The
ReadScope.
-
setReadScope
public FreeColXMLReader setReadScope(FreeColXMLReader.ReadScope readScope)
Set the read scope.- Parameters:
readScope- The newReadScope.- Returns:
- This reader.
-
replaceScope
public FreeColXMLReader.ReadScope replaceScope(FreeColXMLReader.ReadScope newReadScope)
Replace a the scope.- Parameters:
newReadScope- TheReadScopeto push.- Returns:
- The previous
ReadScope.
-
lookup
private FreeColObject lookup(Game game, java.lang.String id)
Look up an identifier in an enclosing game. If not interning prefer an non-interned result.- Parameters:
game- TheGameto consult.id- The object identifier.- Returns:
- The
FreeColObjectfound, or null if none.
-
lookup
public <T extends FreeColObject> T lookup(Game game, java.lang.String id, java.lang.Class<T> returnClass) throws javax.xml.stream.XMLStreamException
Look up an identifier in an enclosing game. This is public to allow the special fixup in Game.readChildren.- Type Parameters:
T- The expected object class type.- Parameters:
game- TheGameto consult.id- The object identifier.returnClass- The class of the return value.- Returns:
- The
FreeColObjectfound, or null if none. - Throws:
javax.xml.stream.XMLStreamException- if the return class does not match.
-
close
public void close()
Closes both theXMLStreamReaderand the underlying stream if any. Implements interface Closeable.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein interfacejavax.xml.stream.XMLStreamReader- Overrides:
closein classjavax.xml.stream.util.StreamReaderDelegate
-
readId
public java.lang.String readId()
Reads the identifier attribute. When all the compatibility code is obsolete, remove this routine and replace its uses with just: getAttribute(in, ID_ATTRIBUTE_TAG, (String)null) or equivalent.- Returns:
- The identifier found, or null if none present.
-
nextTag
public int nextTag() throws javax.xml.stream.XMLStreamException- Specified by:
nextTagin interfacejavax.xml.stream.XMLStreamReader- Overrides:
nextTagin classjavax.xml.stream.util.StreamReaderDelegate- Throws:
javax.xml.stream.XMLStreamException
-
atTag
public boolean atTag(java.lang.String tag)
Is the stream at the given tag?- Parameters:
tag- The tag to test.- Returns:
- True if at the given tag.
-
expectTag
public void expectTag(java.lang.String tag) throws javax.xml.stream.XMLStreamExceptionExpect a particular tag.- Parameters:
tag- The expected tag name.- Throws:
javax.xml.stream.XMLStreamException- if the expected tag is not found.
-
moreTags
public boolean moreTags() throws javax.xml.stream.XMLStreamExceptionCheck if there are more tags in the current element.- Returns:
- True if the stream has not reached the end of the current element.
- Throws:
javax.xml.stream.XMLStreamException- if there is an error with the stream.
-
closeTag
public void closeTag(java.lang.String tag) throws javax.xml.stream.XMLStreamExceptionClose the current tag, checking that it did indeed close correctly.- Parameters:
tag- The expected tag name.- Throws:
javax.xml.stream.XMLStreamException- if a closing tag is not found.
-
closeTag
public void closeTag(java.lang.String tag, java.lang.String... others) throws javax.xml.stream.XMLStreamExceptionClose the current tag, but accept some alternative elements first.- Parameters:
tag- The expected tag to close.others- Alternate elements to accept.- Throws:
javax.xml.stream.XMLStreamException- if a closing tag is not found.
-
swallowTag
public void swallowTag(java.lang.String tag) throws javax.xml.stream.XMLStreamExceptionSwallow a tag, ignoring anything read until the tag closes.- Parameters:
tag- The tag to swallow.- Throws:
javax.xml.stream.XMLStreamException- if a there is an error with the stream.
-
currentTag
public java.lang.String currentTag()
Extract the current tag and its attributes from an input stream. Useful for error messages.- Returns:
- A simple display of the stream state.
-
unexpectedTag
public void unexpectedTag(java.lang.String context) throws javax.xml.stream.XMLStreamExceptionStandardized way to throw a parsing exception with a bit of context.- Parameters:
context- A context string.- Throws:
javax.xml.stream.XMLStreamException- is always thrown.
-
hasAttribute
public boolean hasAttribute(java.lang.String attributeName)
Is there an attribute present in the stream?- Parameters:
attributeName- An attribute name- Returns:
- True if the attribute is present.
-
getAttribute
public boolean getAttribute(java.lang.String attributeName, boolean defaultValue)Gets a boolean from an attribute in a stream.- Parameters:
attributeName- The attribute name.defaultValue- The default value.- Returns:
- The boolean attribute value, or the default value if none found.
-
getAttribute
public float getAttribute(java.lang.String attributeName, float defaultValue)Gets a float from an attribute in a stream.- Parameters:
attributeName- The attribute name.defaultValue- The default value.- Returns:
- The float attribute value, or the default value if none found.
-
getAttribute
public int getAttribute(java.lang.String attributeName, int defaultValue)Gets an int from an attribute in a stream.- Parameters:
attributeName- The attribute name.defaultValue- The default value.- Returns:
- The int attribute value, or the default value if none found.
-
getAttribute
public long getAttribute(java.lang.String attributeName, long defaultValue)Gets a long from an attribute in a stream.- Parameters:
attributeName- The attribute name.defaultValue- The default value.- Returns:
- The long attribute value, or the default value if none found.
-
getAttribute
public java.lang.String getAttribute(java.lang.String attributeName, java.lang.String defaultValue)Gets a string from an attribute in a stream.- Parameters:
attributeName- The attribute name.defaultValue- The default value.- Returns:
- The string attribute value, or the default value if none found.
-
getAttribute
public <T extends java.lang.Enum<T>> T getAttribute(java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)Gets an enum from an attribute in a stream.- Type Parameters:
T- The expected enum type.- Parameters:
attributeName- The attribute name.returnClass- The class of the return value.defaultValue- The default value.- Returns:
- The enum attribute value, or the default value if none found.
-
getAttribute
public <T extends FreeColObject> T getAttribute(Game game, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue) throws javax.xml.stream.XMLStreamException
Gets a FreeCol object from an attribute in a stream.- Type Parameters:
T- The expected attribute type.- Parameters:
game- TheGameto look in.attributeName- The attribute name.returnClass- TheFreeColObjecttype to expect.defaultValue- The default value.- Returns:
- The
FreeColObjectfound, or the default value if not. - Throws:
javax.xml.stream.XMLStreamException- if the wrong class was passed.
-
getAttribute
public <T extends AIObject> T getAttribute(AIMain aiMain, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)
Get a FreeCol AI object from an attribute in a stream.- Type Parameters:
T- The expected attribute type.- Parameters:
aiMain- TheAIMainthat contains the object.attributeName- The attribute name.returnClass- TheAIObjecttype to expect.defaultValue- The default value.- Returns:
- The
AIObjectfound, or the default value if not.
-
getLocationAttribute
public Location getLocationAttribute(Game game, java.lang.String attributeName, boolean make) throws javax.xml.stream.XMLStreamException
Find a new location from a stream attribute. This is necessary becauseLocationis an interface.- Parameters:
game- TheGameto look in.attributeName- The attribute to check.make- If true, try to make the location if it is not found.- Returns:
- The
Locationfound. - Throws:
javax.xml.stream.XMLStreamException- if a problem was encountered during parsing.
-
getAttributeMap
public java.util.Map<java.lang.String,java.lang.String> getAttributeMap(java.lang.String... attributes)
Get a map of attributes.- Parameters:
attributes- The list of attributes to look up.- Returns:
- A map of attributes.
-
getArrayAttributeMap
public java.util.Map<java.lang.String,java.lang.String> getArrayAttributeMap()
Get a map of the array attributes.- Returns:
- A map of array attributes.
-
getAllAttributes
public java.util.Map<java.lang.String,java.lang.String> getAllAttributes()
Get a map of all attributes present.- Returns:
- A map of all the attributes.
-
readList
public <T extends FreeColSpecObjectType> java.util.List<T> readList(Specification spec, java.lang.String tag, java.lang.Class<T> type) throws javax.xml.stream.XMLStreamException
Reads an XML-representation of a list ofFreeColSpecObjectTypes.- Type Parameters:
T- The list member type.- Parameters:
tag- The tag for the list.spec- TheSpecificationto find items in.type- The type of the items to be added. The type must exist in the supplied specification.- Returns:
- The list.
- Throws:
javax.xml.stream.XMLStreamException- if a problem was encountered during parsing.
-
findFreeColGameObject
public <T extends FreeColGameObject> T findFreeColGameObject(Game game, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue, boolean required) throws javax.xml.stream.XMLStreamException
Find aFreeColGameObjectof a given class from a stream attribute. Use this routine when the object is optionally already be present in the game.- Type Parameters:
T- The actual return type.- Parameters:
game- TheGameto look in.attributeName- The attribute name.returnClass- The class to expect.defaultValue- A default value to return if not found.required- If true a null result should throw an exception.- Returns:
- The
FreeColGameObjectfound, or the default value if not found. - Throws:
javax.xml.stream.XMLStreamException- if the attribute is missing.
-
makeFreeColObject
public <T extends FreeColObject> T makeFreeColObject(Game game, java.lang.String attributeName, java.lang.Class<T> returnClass, boolean required) throws javax.xml.stream.XMLStreamException
Either get an existingFreeColObjectfrom a stream attribute or create it if it does not exist. Use this routine when the object may not necessarily already be present in the game, but is expected to be defined eventually.- Type Parameters:
T- The actual return type.- Parameters:
game- TheGameto look in.attributeName- The required attribute name.returnClass- The class of object.required- If true a null result should throw an exception.- Returns:
- The
FreeColObjectfound or made, or null if the attribute was not present. - Throws:
javax.xml.stream.XMLStreamException- if a problem was encountered during parsing.
-
internedRead
private <T extends FreeColObject> T internedRead(Game game, java.lang.Class<T> returnClass) throws javax.xml.stream.XMLStreamException
Do a normal interning read of aFreeColObject.- Type Parameters:
T- The actual return type.- Parameters:
game- TheGameto look in.returnClass- The class to expect.- Returns:
- The
FreeColObjectfound, or null there was no ID_ATTRIBUTE_TAG present. - Throws:
javax.xml.stream.XMLStreamException- if there is problem reading the stream.
-
uninternedRead
private <T extends FreeColObject> T uninternedRead(Game game, java.lang.Class<T> returnClass) throws javax.xml.stream.XMLStreamException
Do a special non-interning read of aFreeColObject.- Type Parameters:
T- The actual return type.- Parameters:
game- TheGameto look in.returnClass- The class to expect.- Returns:
- The
FreeColObjectfound, or null there was no ID_ATTRIBUTE_TAG present. - Throws:
javax.xml.stream.XMLStreamException- if there is problem reading the stream.
-
readFreeColObject
public <T extends FreeColObject> T readFreeColObject(Game game, java.lang.Class<T> returnClass) throws javax.xml.stream.XMLStreamException
Reads aFreeColObjectfrom a stream. Expects the object to be identified by the standard ID_ATTRIBUTE_TAG. Use this routine when the object may or may not have been referenced and created-by-id in this game, but this is the point where it is authoritatively defined.- Type Parameters:
T- The actual return type.- Parameters:
game- TheGameto look in.returnClass- The class to expect.- Returns:
- The
FreeColObjectfound, or null there was no ID_ATTRIBUTE_TAG present. - Throws:
javax.xml.stream.XMLStreamException- if there is problem reading the stream.
-
readFreeColObject
public <T extends FreeColObject> T readFreeColObject(Game game) throws javax.xml.stream.XMLStreamException
Read aFreeColObjectfrom a stream.- Type Parameters:
T- The actual return type.- Parameters:
game- TheGameto look in.- Returns:
- The
FreeColObjectfound. - Throws:
javax.xml.stream.XMLStreamException- if there is problem reading the stream.
-
findAIObject
public <T extends AIObject> T findAIObject(AIMain aiMain, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue, boolean required) throws javax.xml.stream.XMLStreamException
Find a FreeCol AI object from an attribute in a stream.- Type Parameters:
T- The actual return type.- Parameters:
aiMain- TheAIMainthat contains the object.attributeName- The attribute name.returnClass- TheAIObjecttype to expect.defaultValue- The default value.required- If true a null result should throw an exception.- Returns:
- The
AIObjectfound, or the default value if not. - Throws:
javax.xml.stream.XMLStreamException- if there is problem reading the stream.
-
makeAIObject
public <T extends AIObject> T makeAIObject(AIMain aiMain, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue, boolean required) throws javax.xml.stream.XMLStreamException
Either get an existingAIObjectfrom a stream attribute or create it if it does not exist. Use this routine when the object may not necessarily already be present in the game, but is expected to be defined eventually.- Type Parameters:
T- The actual return type.- Parameters:
aiMain- TheAIMainthat contains the object.attributeName- The attribute name.returnClass- TheAIObjecttype to expect.defaultValue- The default value.required- If true, throw exceptions on missing data.- Returns:
- The
AIObjectfound, or the default value if not. - Throws:
javax.xml.stream.XMLStreamException- if there is problem reading the stream.
-
shouldClearContainers
public boolean shouldClearContainers()
Should the game object type being read clear its containers before reading the child elements? Usually true, but not if the type is extending another one.- Returns:
- True if the containers should be cleared.
-
getType
public <T extends FreeColSpecObjectType> T getType(Specification spec, java.lang.String attributeName, java.lang.Class<T> returnClass, T defaultValue)
Get a FreeColSpecObjectType by identifier from a stream from a specification.- Type Parameters:
T- The actual return type.- Parameters:
spec- TheSpecificationto look in.attributeName- the name of the attribute identifying theFreeColSpecObjectType.returnClass- The expected class of the return value.defaultValue- A default value to return if the attributeName attribute is not present.- Returns:
- The
FreeColSpecObjectTypefound, or thedefaultValue.
-
copy
public <T extends FreeColObject> T copy(Game game, java.lang.Class<T> returnClass) throws javax.xml.stream.XMLStreamException
Copy a FreeColObject by serializing it and reading back the result with a non-interning stream.- Type Parameters:
T- The actual return type.- Parameters:
game- TheGameto look in.returnClass- The class to expect.- Returns:
- The copied
FreeColObjectfound, or null there was no ID_ATTRIBUTE_TAG present. - Throws:
javax.xml.stream.XMLStreamException- if there is problem reading the stream.
-
readAttributeValues
public int readAttributeValues(java.util.Map<java.lang.String,java.lang.String> map, java.lang.String attr) throws javax.xml.stream.XMLStreamExceptionFill in the identifier values supplied in a map. Special case for early reads of the client options.- Parameters:
map- A map containing identifiers to find as keys.attr- The attribute to get for each identifier found.- Returns:
- The number of identifiers found or negative on error.
- Throws:
javax.xml.stream.XMLStreamException- if a problem was encountered during parsing.
-
-