/* * @(#) Capability_Composite 0_97_0 08/07/2009 * * see Annex C of the SOPES IEDM Specification * Capability_Composite 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; /** * * Capability_Composite * @author ASMG * @version 0_97_0 08/07/2009 */ public class Capability_Composite { public Capability_Composite ( String identifier, Data data ) { m_data = data; Collection nextIdentifiers = new ArrayList(); nextIdentifiers.add(identifier); Collection col; Collection startPointCol = buildCapability( nextIdentifiers ); // Identifier always mandatory if ( startPointCol.isEmpty() ) { throw new IllegalArgumentException(); } m_step0.addAll( startPointCol ); includeTargetIdentifiers(nextIdentifiers); Capability capability = (Capability)startPointCol.iterator().next(); if ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("TRANSM") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), TransmissionCapability.getEntityIdentifier() ); col = buildTransmissionCapability_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 ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("FIRE") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), FireCapability.getEntityIdentifier() ); col = buildFireCapability_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 ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("ENGI") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), EngineeringCapability.getEntityIdentifier() ); col = buildEngineeringCapability_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 ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("STOR") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), StorageCapability.getEntityIdentifier() ); col = buildStorageCapability_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; } if ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("HNDLNG") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), HandlingCapability.getEntityIdentifier() ); col = buildHandlingCapability( 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; } if ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("SUPPRT") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), SupportCapability.getEntityIdentifier() ); col = buildSupportCapability( nextIdentifiers ); if ( col.size() < m_multiplicity6.getMin() || col.size() > m_multiplicity6.getMax() ) { throw new IllegalArgumentException(); } m_step6.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step6 = null; } if ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("OPERAT") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), OperationalCapability.getEntityIdentifier() ); col = buildOperationalCapability( nextIdentifiers ); if ( col.size() < m_multiplicity7.getMin() || col.size() > m_multiplicity7.getMax() ) { throw new IllegalArgumentException(); } m_step7.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step7 = null; } if ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("MOBL") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), MobilityCapability.getEntityIdentifier() ); col = buildMobilityCapability( nextIdentifiers ); if ( col.size() < m_multiplicity8.getMin() || col.size() > m_multiplicity8.getMax() ) { throw new IllegalArgumentException(); } m_step8.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step8 = null; } if ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("MAIN") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), MaintenanceCapability.getEntityIdentifier() ); col = buildMaintenanceCapability( nextIdentifiers ); if ( col.size() < m_multiplicity9.getMin() || col.size() > m_multiplicity9.getMax() ) { throw new IllegalArgumentException(); } m_step9.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step9 = null; } if ( capability.getAttributeValue("capability-category-code").equalsIgnoreCase("SURV") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), SurveillanceCapability.getEntityIdentifier() ); col = buildSurveillanceCapability( nextIdentifiers ); if ( col.size() < m_multiplicity10.getMin() || col.size() > m_multiplicity10.getMax() ) { throw new IllegalArgumentException(); } m_step10.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } else { m_step10 = null; } } /* * Multiplicity min: 1 max : 1 */ private Collection buildCapability( 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( Capability.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new Capability(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildTransmissionCapability_Type(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { TransmissionCapability_Type transmissionCapability_Type = new TransmissionCapability_Type( identifier, m_data ); col.add(transmissionCapability_Type); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildFireCapability_Type(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { FireCapability_Type fireCapability_Type = new FireCapability_Type( identifier, m_data ); col.add(fireCapability_Type); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildEngineeringCapability_Type(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { EngineeringCapability_Type engineeringCapability_Type = new EngineeringCapability_Type( identifier, m_data ); col.add(engineeringCapability_Type); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildStorageCapability_Type(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { StorageCapability_Type storageCapability_Type = new StorageCapability_Type( identifier, m_data ); col.add(storageCapability_Type); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildHandlingCapability( 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( HandlingCapability.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new HandlingCapability(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildSupportCapability( 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( SupportCapability.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new SupportCapability(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildOperationalCapability( 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( OperationalCapability.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new OperationalCapability(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildMobilityCapability( 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( MobilityCapability.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new MobilityCapability(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildMaintenanceCapability( 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( MaintenanceCapability.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new MaintenanceCapability(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildSurveillanceCapability( 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( SurveillanceCapability.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new SurveillanceCapability(it.next()) ); } return col; } private Collection getSourceIdentifiers(){ /* no implement see Annex C Capability_Composite 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 Multiplicity m_multiplicity8 = new Multiplicity(1, 1); private Multiplicity m_multiplicity9 = new Multiplicity(1, 1); private Multiplicity m_multiplicity10 = 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(); private Set m_step8 = new HashSet(); private Set m_step9 = new HashSet(); private Set m_step10 = new HashSet(); }