📄 xmlstreamparser.java
字号:
this.warning.append( "Found invalid isHit value: " ) .append( hit ) .append( ".\n" ); } // Is the location destroyed? boolean destFlag = false; try { if ( destroyed != null ) { destFlag = destroyed.equals( "true" ); } } catch ( Throwable excep ) { this.warning.append( "Found invalid isDestroyed value: " ) .append( destroyed ) .append( ".\n" ); } // Try to get the critical slot. CriticalSlot slot = this.entity.getCritical( this.loc, indexVal ); // Did we get it? if ( slot == null ) { if ( !type.equals( EMPTY ) ) { this.warning.append( "Could not find the " ) .append( type ) .append( " equipment that was expected at index " ) .append( indexVal ) .append( " of location " ) .append( this.loc ) .append( ".\n" ); } return; } // Is the slot for a critical system? if ( slot.getType() == CriticalSlot.TYPE_SYSTEM ) { // Does the XML file have some other kind of equipment? if ( !type.equals( SYSTEM ) ) { this.warning.append( "XML file expects to find " ) .append( type ) .append( " equipment at index " ) .append( indexVal ) .append( " of location " ) .append( this.loc ) .append( ", but Entity has a system.\n" ); } } else { // Nope, we've got equipment. Get this slot's mounted. Mounted mounted = this.entity.getEquipment ( slot.getIndex() ); // Reset transient values. mounted.restore(); // Hit and destroy the mounted, according to the flags. mounted.setDestroyed( hitFlag || destFlag ); // Is the mounted a type of ammo? if ( mounted.getType() instanceof AmmoType ) { // Get the saved ammo load. EquipmentType newLoad = EquipmentType.get( type ); if ( newLoad instanceof AmmoType ) { // Try to get a good shots value. int shotsVal = -1; try { shotsVal = Integer.parseInt( shots ); } catch ( NumberFormatException excep ) { // Handled by the next if test. } if ( shots.equals( NA ) ) { shotsVal = IArmorState.ARMOR_NA; this.warning.append( "Expected to find number of shots for " ) .append( type ) .append( ", but found " ) .append( shots ) .append( " instead.\n" ); } else if ( shotsVal < 0 || shotsVal > 200 ) { this.warning.append( "Found invalid shots value for slot: " ) .append( shots ) .append( ".\n" ); } else { // Change to the saved ammo type and shots. mounted.changeAmmoType((AmmoType) newLoad); mounted.setShotsLeft( shotsVal ); } // End have-good-shots-value } else { // Bad XML equipment. this.warning.append( "XML file expects " ) .append( type ) .append( " equipment at index " ) .append( indexVal ) .append( " of location " ) .append( this.loc ) .append( ", but Entity has " ) .append( mounted.getType().getInternalName() ) .append( "there .\n" ); } } // End slot-for-ammo // Not an ammo slot... does file agree with template? else if ( !mounted.getType().getInternalName() .equals( type ) ) { // Bad XML equipment. this.warning.append( "XML file expects " ) .append( type ) .append( " equipment at index " ) .append( indexVal ) .append( " of location " ) .append( this.loc ) .append( ", but Entity has " ) .append( mounted.getType().getInternalName() ) .append( "there .\n" ); } // Check for munition attribute. if (munition != null) { // Retrieve munition by name. EquipmentType munType = EquipmentType.get( munition ); // Make sure munition is a type of ammo. if ( munType instanceof AmmoType ) { // Change to the saved munition type. mounted.getLinked().changeAmmoType((AmmoType) munType); } else { // Bad XML equipment. this.warning.append( "XML file expects " ) .append( " ammo for munition argument of ") .append( " slot tag.\n" ); } } } // End have-equipment // Hit and destroy the slot, according to the flags. slot.setHit( hitFlag ); slot.setDestroyed( destFlag ); } // End have-required-fields } // End ready-for-slot } } // End public void recordElementStart( String, Hashtable ) public void recordElementEnd( String name ) throws ParseException { // TODO: handle template files. // What kind of element have we started? if ( name.equals( UNIT ) ) { // Are we in the middle of parsing an Entity? if ( this.entity != null ) { this.warning.append ( "End of unit while parsing an Entity.\n" ); // Are we in the middle of parsing an Entity's location? if ( this.loc != Entity.LOC_NONE ) { this.warning.append ( "Found end of unit while parsing a location.\n" ); // If the open location is marked destroyed, destroy it. if ( this.locDestroyed ) { this.destroyLocation( this.entity, this.loc ); } this.loc = Entity.LOC_NONE; } // Add the entity to the vector. this.entities.addElement( this.entity ); this.entity = null; } // Is this an empty unit? else if ( this.entities.isEmpty() ) { this.warning.append ( "Found an empty unit.\n" ); } } else if ( name.equals( TEMPLATE ) ) { // Do nothing. } else if ( name.equals( ENTITY ) ) { // We should be in the middle of parsing an Entity. if ( this.entity == null ) { this.warning.append ( "Found end of Entity, but not parsing an Entity.\n" ); } else { // Are we in the middle of parsing an Entity's location? if ( this.loc != Entity.LOC_NONE ) { this.warning.append ( "Found end of Entity while parsing a location.\n" ); // If the open location is marked destroyed, destroy it. if ( this.locDestroyed ) { this.destroyLocation( this.entity, this.loc ); } this.loc = Entity.LOC_NONE; } // Add the entity to the vector. this.entities.addElement( this.entity ); this.entity = null; } // End save-entity } else if ( name.equals( FLUFF ) ) { // Do nothing. } else if ( name.equals( PILOT ) ) { // Do nothing. } else if ( name.equals( LOCATION ) ) { // We should be in the middle of parsing an Entity. if ( this.entity == null ) { this.warning.append ( "Found end of location, but not parsing an Entity.\n" ); } // Are we in the middle of parsing an Entity's location? else if ( this.loc == Entity.LOC_NONE ) { this.warning.append ( "Found end of location, but not parsing a location.\n" ); } else { // If the location is marked destroyed, destroy the location. if ( this.locDestroyed ) { this.destroyLocation( this.entity, this.loc ); } // Reset the location. this.loc = Entity.LOC_NONE; } // End finish-location } else if ( name.equals( ARMOR ) ) { // Do nothing. } else if ( name.equals( SLOT ) ) { // Do nothing. } } public void recordPI( String name, String pValue ) { // Do nothing. } public void recordCharData( String charData ) { // Do nothing. } public void recordComment( String comment ) { // Do nothing. } public InputStream getDocumentStream() throws ParseException { if ( this.inStream == null ) { throw new ParseException( "Input document stream not defined." ); } return this.inStream; } public InputStream resolveExternalEntity( String name, String pubID, String sysID ) throws ParseException { // Return nothing. return null; } public InputStream resolveDTDEntity( String name, String pubID, String sysID ) throws ParseException { // Return nothing. return null; }} // End public class XMLStreamParser implements XMLResponder
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -