/* * @(#) Military_Obstacle 0_97_0 08/07/2009 * * see Annex C of the SOPES IEDM Specification * Military_Obstacle oclConstructionSequence for the key mapping across steps * for this Transactional Artifact */ package org.omg.sopes0_97_0.PSM.Transactional; import org.omg.sopes0_97_0.PSM.Tuple; import org.omg.sopes0_97_0.PSM.Data; import org.omg.sopes0_97_0.PSM.Multiplicity; import org.omg.sopes0_97_0.PSM.Wrapper.*; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.Set; /** * * Military_Obstacle * @author ASMG * @version 0_97_0 08/07/2009 */ public class Military_Obstacle { public Military_Obstacle ( String identifier, Data data ) { m_data = data; Collection nextIdentifiers = new ArrayList(); nextIdentifiers.add(identifier); Collection col; Collection startPointCol = buildMilitaryObstacle( nextIdentifiers ); // Identifier always mandatory if ( startPointCol.isEmpty() ) { throw new IllegalArgumentException(); } m_step0.addAll( startPointCol ); includeTargetIdentifiers(nextIdentifiers); MilitaryObstacle militaryObstacle = (MilitaryObstacle)startPointCol.iterator().next(); if ( militaryObstacle.getAttributeValue("military-obstacle-category-code").equalsIgnoreCase("MNFLD") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), Minefield.getEntityIdentifier() ); col = buildMinefield( nextIdentifiers ); if ( col.size() < m_multiplicity1.getMin() || col.size() > m_multiplicity1.getMax() ) { throw new IllegalArgumentException(); } m_step1.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step1 = null; } Minefield minefield = (Minefield) m_step4.iterator().next(); if ( minefield.getAttributeValue("minefield-category-code").equalsIgnoreCase("MNFMRT") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), MinefieldMaritime.getEntityIdentifier() ); col = buildMinefieldMaritime( nextIdentifiers ); if ( col.size() < m_multiplicity2.getMin() || col.size() > m_multiplicity2.getMax() ) { throw new IllegalArgumentException(); } m_step2.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step2 = null; } nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), MinefieldMaritimeSustainedThreatMeasureOfEffectiveness.getEntityIdentifier() ); col = buildMinefield_Maritime_Sustained_Threat_Measure_Of_Effectiveness( nextIdentifiers ); if ( col.size() < m_multiplicity3.getMin() || col.size() > m_multiplicity3.getMax() ) { throw new IllegalArgumentException(); } m_step3.addAll( col ); includeTargetIdentifiers(nextIdentifiers); nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), MinefieldMaritimeCasualtyEstimate.getEntityIdentifier() ); col = buildMinefield_Maritime_Casualty_Estimate( nextIdentifiers ); if ( col.size() < m_multiplicity4.getMin() || col.size() > m_multiplicity4.getMax() ) { throw new IllegalArgumentException(); } m_step4.addAll( col ); includeTargetIdentifiers(nextIdentifiers); if ( minefield.getAttributeValue("minefield-category-code").equalsIgnoreCase("MNFLND") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), MinefieldLand.getEntityIdentifier() ); col = buildMinefieldLand( nextIdentifiers ); if ( col.size() < m_multiplicity5.getMin() || col.size() > m_multiplicity5.getMax() ) { throw new IllegalArgumentException(); } m_step5.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step5 = null; } nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), Facility.getEntityIdentifier() ); col = buildFacility( nextIdentifiers ); if ( col.size() < m_multiplicity6.getMin() || col.size() > m_multiplicity6.getMax() ) { throw new IllegalArgumentException(); } m_step6.addAll( col ); includeTargetIdentifiers(nextIdentifiers); nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), ObjectItem.getEntityIdentifier() ); col = buildObjectItem( nextIdentifiers ); if ( col.size() < m_multiplicity7.getMin() || col.size() > m_multiplicity7.getMax() ) { throw new IllegalArgumentException(); } m_step7.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } /* * Multiplicity min: 1 max : 1 */ private Collection buildMilitaryObstacle( Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); rows.addAll(m_data.extractRows( MilitaryObstacle.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new MilitaryObstacle(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildMinefield( Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); rows.addAll(m_data.extractRows( Minefield.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new Minefield(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildMinefieldMaritime( Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); rows.addAll(m_data.extractRows( MinefieldMaritime.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new MinefieldMaritime(it.next()) ); } return col; } /* * Multiplicity min: 0 max : 2147483647 */ private Collection buildMinefield_Maritime_Sustained_Threat_Measure_Of_Effectiveness(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { Minefield_Maritime_Sustained_Threat_Measure_Of_Effectiveness minefield_Maritime_Sustained_Threat_Measure_Of_Effectiveness = new Minefield_Maritime_Sustained_Threat_Measure_Of_Effectiveness( identifier, m_data ); col.add(minefield_Maritime_Sustained_Threat_Measure_Of_Effectiveness); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 0 max : 2147483647 */ private Collection buildMinefield_Maritime_Casualty_Estimate(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { Minefield_Maritime_Casualty_Estimate minefield_Maritime_Casualty_Estimate = new Minefield_Maritime_Casualty_Estimate( identifier, m_data ); col.add(minefield_Maritime_Casualty_Estimate); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildMinefieldLand( Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); rows.addAll(m_data.extractRows( MinefieldLand.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new MinefieldLand(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildFacility( Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); rows.addAll(m_data.extractRows( Facility.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new Facility(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildObjectItem( Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); rows.addAll(m_data.extractRows( ObjectItem.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new ObjectItem(it.next()) ); } return col; } private Collection getSourceIdentifiers(){ /* no implement see Annex C Military_Obstacle oclConstructionSequence for further information */ return null; } private void includeTargetIdentifiers(Collection nextIdentifiers){ /* no implement Record the variable for potential use by the method getSourceIdentifiers() */ } public boolean isWatchpoint(){ return m_isWatchpoint; } private Data m_data = null; private final boolean m_isWatchpoint = true; private Multiplicity m_multiplicity0 = new Multiplicity(1, 1); private Multiplicity m_multiplicity1 = new Multiplicity(1, 1); private Multiplicity m_multiplicity2 = new Multiplicity(1, 1); private Multiplicity m_multiplicity3 = new Multiplicity(0, 2147483647); private Multiplicity m_multiplicity4 = new Multiplicity(0, 2147483647); private Multiplicity m_multiplicity5 = new Multiplicity(1, 1); private Multiplicity m_multiplicity6 = new Multiplicity(1, 1); private Multiplicity m_multiplicity7 = new Multiplicity(1, 1); private Set m_step0 = new HashSet(); private Set m_step1 = new HashSet(); private Set m_step2 = new HashSet(); private Set m_step3 = new HashSet(); private Set m_step4 = new HashSet(); private Set m_step5 = new HashSet(); private Set m_step6 = new HashSet(); private Set m_step7 = new HashSet(); }