PSServicemoduleImpl.java :  » UML » MetaBoss » com » metaboss » sdlctools » domains » enterprisemodel » storage » xmlfileimpl » Java Open Source

Java Open Source » UML » MetaBoss 
MetaBoss » com » metaboss » sdlctools » domains » enterprisemodel » storage » xmlfileimpl » PSServicemoduleImpl.java
// THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
// OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Copyright 2000-2005  Softaris Pty.Ltd. All Rights Reserved.
package com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl;

import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;

import javax.xml.bind.JAXBException;

import com.metaboss.enterprise.ps.PSDataSourceOperationInvocationException;
import com.metaboss.enterprise.ps.PSException;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSServicemodule;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.STServicemodule;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.MessageDefListType;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ServiceDefListType;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ServicemoduleDefType;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.StructureDefListType;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.SystemDefType;

public class PSServicemoduleImpl implements PSServicemodule
{
    /** Returns  details entity corresponding to given reference or null struct if definition not found */
    public STServicemodule getServicemodule(String pServicemoduleRef) throws PSException
    {
        ServicemoduleDefType lServicemoduleDef = Storage.getServicemodule(pServicemoduleRef);
        if (lServicemoduleDef == null)
            return null;
        STServicemodule lStruct = new STServicemodule();
        lStruct.ServicemoduleRef = lServicemoduleDef.getServicemoduleRef();
        lStruct.Description = lServicemoduleDef.getDescription();
        return lStruct;
    }

    /* Returns list of all services comprising given service module */
    public String[]  getServicemoduleServiceRefs(String pServicemoduleRef) throws PSException
    {
        return Storage.getServicemoduleServiceRefs(pServicemoduleRef);
    }

    /* Returns list of all structures declared within given service module */
    public String[]  getServicemoduleStructureRefs(String pServicemoduleRef) throws PSException
    {
        return Storage.getServicemoduleStructureRefs(pServicemoduleRef);
    }

    /* Returns list of all messages declared within given service module */
    public String[]  getServicemoduleMessageRefs(String pServicemoduleRef) throws PSException
    {
        return Storage.getServicemoduleMessageRefs(pServicemoduleRef);
    }


    /** Inserts one or more new structure records into the database */
    public void insertServicemodule( STServicemodule pNewRecord) throws PSException
    {
      try
      {
            ServicemoduleDefType lServicemoduleDef = Util.getObjectFactory().createServicemoduleDef();
            lServicemoduleDef.setServicemoduleRef(pNewRecord.ServicemoduleRef);
            lServicemoduleDef.setDescription(pNewRecord.Description);
            StructureDefListType lStructureDefList = Util.getObjectFactory().createStructureDefList();
            lServicemoduleDef.setStructureDefList(lStructureDefList);
            ServiceDefListType lServiceDefList = Util.getObjectFactory().createServiceDefList();
            lServicemoduleDef.setServiceDefList(lServiceDefList);
            MessageDefListType lMessageDefList = Util.getObjectFactory().createMessageDefList();
            lServicemoduleDef.setMessageDefList(lMessageDefList);
            Storage.insertServicemodule(lServicemoduleDef);

            // Now find out the system this servicemodule belongs to and insert reference to this servicemodule
            // Servicemodule ref consists of three  parts - enterprise name . system name . servicemodule name
            StringTokenizer lTokenizer = new StringTokenizer(pNewRecord.ServicemoduleRef,".",false);
            SystemDefType lSystemDef = Storage.getSystem(lTokenizer.nextToken() + "." + lTokenizer.nextToken());
            lSystemDef.getServicemoduleRefList().getServicemoduleRef().add(pNewRecord.ServicemoduleRef);
            Storage.updateSystem(lSystemDef);
      }
    catch(JAXBException e)
    {
      throw new PSDataSourceOperationInvocationException(e);
    }
    }
    
  // Updates serviicemodule details in the database
  public void updateServicemodule( STServicemodule pUpdatedRecord) throws PSException
  {
    ServicemoduleDefType lServicemoduleDef = Storage.getServicemodule(pUpdatedRecord.ServicemoduleRef);
    if (lServicemoduleDef == null)
      throw new PSException("Servicemodule not found. ServicemoduleRef : " + pUpdatedRecord.ServicemoduleRef);
    lServicemoduleDef.setDescription(pUpdatedRecord.Description);
    Storage.updateServicemodule(lServicemoduleDef);
    // Now find out the system this servicemodule belongs to and update it
    // Servicemodule ref consists of three  parts - enterprise name . system name . servicemodule name
    StringTokenizer lTokenizer = new StringTokenizer(pUpdatedRecord.ServicemoduleRef,".",false);
    SystemDefType lSystemDef = Storage.getSystem(lTokenizer.nextToken() + "." + lTokenizer.nextToken());
    Storage.updateSystem(lSystemDef);
  }
    
    // Deletes existing servicemodule
    public void deleteServicemodule(String pServicemoduleRef) throws PSException
    {
        Storage.deleteServicemodule(pServicemoduleRef);
        // Now find out the system this servicemodule belongs to and delete reference to this servicemodule
        // Servicemodule ref consists of three  parts - enterprise name . system name . servicemodule name
        StringTokenizer lTokenizer = new StringTokenizer(pServicemoduleRef,".",false);
        SystemDefType lSystemDef = Storage.getSystem(lTokenizer.nextToken() + "." + lTokenizer.nextToken());
        List lServicemoduleRefList = lSystemDef.getServicemoduleRefList().getServicemoduleRef();
        Iterator lIter = lServicemoduleRefList.iterator();
        for (int  i = 0; lIter.hasNext(); i++)
        {
            String lServicemoduleRef = (String)lIter.next();
            if (lServicemoduleRef.equals(pServicemoduleRef))
            {
                lServicemoduleRefList.remove(i);
                Storage.updateSystem(lSystemDef);
                break;
            }
        }
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.