/* * @(#) Plan_Order_Item 0_97_0 08/07/2009 * * see Annex C of the SOPES IEDM Specification * Plan_Order_Item 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; /** * * Plan_Order_Item * @author ASMG * @version 0_97_0 08/07/2009 */ public class Plan_Order_Item { public Plan_Order_Item ( String identifier, Data data ) { m_data = data; Collection nextIdentifiers = new ArrayList(); nextIdentifiers.add(identifier); Collection col; Collection startPointCol = buildPlanOrder( nextIdentifiers ); // Identifier always mandatory if ( startPointCol.isEmpty() ) { throw new IllegalArgumentException(); } m_step0.addAll( startPointCol ); includeTargetIdentifiers(nextIdentifiers); PlanOrder planOrder = (PlanOrder)startPointCol.iterator().next(); nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), PlanOrderHeaderContent.getEntityIdentifier() ); col = buildPlan_Order_Header_Content( nextIdentifiers ); if ( col.size() < m_multiplicity1.getMin() || col.size() > m_multiplicity1.getMax() ) { throw new IllegalArgumentException(); } m_step1.addAll( col ); includeTargetIdentifiers(nextIdentifiers); if ( planOrder.getAttributeValue("plan-order-category-code").equalsIgnoreCase("PLAN") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), Plan.getEntityIdentifier() ); col = buildPlan( 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 ( planOrder.getAttributeValue("plan-order-category-code").equalsIgnoreCase("ORDER") ) { nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), Order.getEntityIdentifier() ); col = buildOrder( 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; } nextIdentifiers = m_data.getTargetIdentifiers( getSourceIdentifiers(), PlanOrderComponent.getEntityIdentifier() ); col = buildPlan_Order_Component( nextIdentifiers ); if ( col.size() < m_multiplicity4.getMin() || col.size() > m_multiplicity4.getMax() ) { throw new IllegalArgumentException(); } m_step4.addAll( col ); includeTargetIdentifiers(nextIdentifiers); } /* * Multiplicity min: 1 max : 1 */ private Collection buildPlanOrder( 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( PlanOrder.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new PlanOrder(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 2147483647 */ private Collection buildPlan_Order_Header_Content(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { Plan_Order_Header_Content plan_Order_Header_Content = new Plan_Order_Header_Content( identifier, m_data ); col.add(plan_Order_Header_Content); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildPlan( 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( Plan.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new Plan(it.next()) ); } return col; } /* * Multiplicity min: 1 max : 1 */ private Collection buildOrder( 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( Order.getEntityIdentifier(), identifier ) ); } Iterator it = rows.iterator(); while(it.hasNext()) { col.add(new Order(it.next()) ); } return col; } /* * Multiplicity min: 0 max : 2147483647 */ private Collection buildPlan_Order_Component(Collection identifiers ) { Collection col = new ArrayList(); Iterator sit = identifiers.iterator(); String identifier; Collection rows = new ArrayList(); while( sit.hasNext() ) { identifier = sit.next(); try { Plan_Order_Component plan_Order_Component = new Plan_Order_Component( identifier, m_data ); col.add(plan_Order_Component); } catch( IllegalArgumentException ie ) { /* implementation based response */ } } return col; } private Collection getSourceIdentifiers(){ /* no implement see Annex C Plan_Order_Item 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, 2147483647); private Multiplicity m_multiplicity2 = new Multiplicity(1, 1); private Multiplicity m_multiplicity3 = new Multiplicity(1, 1); private Multiplicity m_multiplicity4 = new Multiplicity(0, 2147483647); 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(); }