/* * @(#) Military_Organisation_Type 0_97_0 08/07/2009 * * see Annex C of the SOPES IEDM Specification * Military_Organisation_Type 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_Organisation_Type * @author ASMG * @version 0_97_0 08/07/2009 */ public class Military_Organisation_Type { public Military_Organisation_Type ( String identifier, Data data ) { m_data = data; Collection nextIdentifiers = new ArrayList(); nextIdentifiers.add(identifier); Collection col; Collection startPointCol = buildMilitaryOrganisationType( nextIdentifiers ); // Identifier always mandatory if ( startPointCol.isEmpty() ) { throw new IllegalArgumentException(); } m_step0.addAll( startPointCol ); includeTargetIdentifiers(nextIdentifiers); MilitaryOrganisationType militaryOrganisationType = (MilitaryOrganisationType)startPointCol.iterator().next(); if ( militaryOrganisationType.getAttributeValue("military-organisation-type-category-code").equalsIgnoreCase("UNIT") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), UnitType.getEntityIdentifier() ); col = buildUnit_Type( 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; } if ( militaryOrganisationType.getAttributeValue("military-organisation-type-category-code").equalsIgnoreCase("MILPST") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), MilitaryPostType.getEntityIdentifier() ); col = buildMilitary_Post_Type( 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; } if ( militaryOrganisationType.getAttributeValue("military-organisation-type-category-code").equalsIgnoreCase("EXCMIL") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), ExecutiveMilitaryOrganisationType.getEntityIdentifier() ); col = buildExecutive_Military_Organisation_Type( nextIdentifiers ); if ( col.size() < m_multiplicity3.getMin() || col.size() > m_multiplicity3.getMax() ) { throw new IllegalArgumentException(); } m_step3.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step3 = null; } if ( militaryOrganisationType.getAttributeValue("military-organisation-type-category-code").equalsIgnoreCase("TASK") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), TaskFormationType.getEntityIdentifier() ); col = buildTask_Formation_Type( nextIdentifiers ); if ( col.size() < m_multiplicity4.getMin() || col.size() > m_multiplicity4.getMax() ) { throw new IllegalArgumentException(); } m_step4.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step4 = null; } nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), GovernmentOrganisationType.getEntityIdentifier() ); col = buildGovernmentOrganisationType( nextIdentifiers ); if ( col.size() < m_multiplicity5.getMin() || col.size() > m_multiplicity5.getMax() ) { throw new IllegalArgumentException(); } m_step5.addAll( col ); includeTargetIdentifiers(nextIdentifiers); nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), OrganisationType.getEntityIdentifier() ); col = buildOrganisationType( 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(), ObjectType.getEntityIdentifier() ); col = buildObjectType( 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 buildMilitaryOrganisationType( 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( MilitaryOrganisationType.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new MilitaryOrganisationType(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildUnit_Type(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { Unit_Type unit_Type = new Unit_Type( identifier, m_data ); col.add(unit_Type); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildMilitary_Post_Type(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { Military_Post_Type military_Post_Type = new Military_Post_Type( identifier, m_data ); col.add(military_Post_Type); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildExecutive_Military_Organisation_Type(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { Executive_Military_Organisation_Type executive_Military_Organisation_Type = new Executive_Military_Organisation_Type( identifier, m_data ); col.add(executive_Military_Organisation_Type); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildTask_Formation_Type(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { Task_Formation_Type task_Formation_Type = new Task_Formation_Type( identifier, m_data ); col.add(task_Formation_Type); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildGovernmentOrganisationType( 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( GovernmentOrganisationType.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new GovernmentOrganisationType(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildOrganisationType( 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( OrganisationType.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new OrganisationType(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildObjectType( 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( ObjectType.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new ObjectType(it.next()) ); } return col; } private Collection getSourceIdentifiers(){ /* no implement see Annex C Military_Organisation_Type 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 = false; 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(1, 1); private Multiplicity m_multiplicity4 = new Multiplicity(1, 1); 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(); }