/*
 * VpnService.java
 *
 * Created on July 7, 2006, 3:40 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package ossj.common.ex;

import com.infomodel.MplsVpnServiceKey;
import com.infomodel.MplsVpnServiceValue;
import java.rmi.RemoteException;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.ejb.Stateless;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.naming.InitialContext;
import ossj.common.AttributeAccessImpl;

/**
 *
 * @author vince
 */

@Stateless()
//@WebService(wsdlLocation="META-INF/wsdl/VpnServiceService.wsdl")
@WebService()
public class VpnService {
    
    @EJB(name="VpnServiceEJB",mappedName="System/System1/ApplicationType/Common/Application/1-5;1-5;ReferenceImplementation/Comp/VpnServiceBean")
    VpnServiceRemoteHome vpnHome;
    
    InitialContext initCtx = null;
    
    
    @WebMethod(operationName="createMplsVpnServiceByValue")
    public MplsVpnServiceKey  createMplsVpnServiceByValue(MplsVpnServiceValue mplsVpnServiceValue)
    throws javax.oss.OssIllegalArgumentException,
            java.rmi.RemoteException,
            javax.ejb.DuplicateKeyException,
            javax.ejb.CreateException{
        try {
            
            MplsVpnServiceKey retKey = null;
            try {
                retKey = getSession().createMplsVpnServiceByValue(mplsVpnServiceValue);
            } catch (java.rmi.RemoteException rex) {
                rex.printStackTrace();
                throw new EJBException("RemoteException" + rex.getMessage());
            }
            
            return retKey;
        } catch (Exception e) {
            String msg = "Unable to createMplsVpnServiceByValue... Exception :  ";
            throw new RemoteException(msg+e);
        }
    }
    
    @WebMethod(operationName="getMplsVpnServiceByKey")
    public MplsVpnServiceValue  getMplsVpnServiceByKey(MplsVpnServiceKey mplsVpnServiceKey, String[] attrNames)
    throws javax.oss.OssIllegalArgumentException,
            java.rmi.RemoteException,
            javax.ejb.ObjectNotFoundException{
        try {
            
            MplsVpnServiceValue retValue = null;
            try {
                retValue = getSession().getMplsVpnServiceByKey(mplsVpnServiceKey, attrNames);
            } catch (java.rmi.RemoteException rex) {
                rex.printStackTrace();
                throw new EJBException("RemoteException" + rex.getMessage());
            }
            //set all attribute populated for the XML encoding
            ((AttributeAccessImpl)retValue).setFullyPopulated();
            
            return retValue;
        } catch (Exception e) {
            String msg = "Unable to getMplsVpnServiceByKey... Exception :  ";
            throw new RemoteException(msg+e);
        }
    }
    
    @WebMethod(operationName="setMplsVpnServiceByValue")
    public void  setMplsVpnServiceByValue(MplsVpnServiceValue mplsVpnServiceValue, boolean resyncRequired)
    throws javax.oss.OssIllegalArgumentException, java.rmi.RemoteException,
            javax.ejb.ObjectNotFoundException, javax.oss.OssSetException,
            javax.oss.OssResyncRequiredException{
        try {
            
            try {
                getSession().setMplsVpnServiceByValue(mplsVpnServiceValue, resyncRequired);
            } catch (java.rmi.RemoteException rex) {
                rex.printStackTrace();
                throw new EJBException("RemoteException" + rex.getMessage());
            }            
        } catch (Exception e) {
            String msg = "Unable to setMplsVpnServiceByValue... Exception :  ";
            throw new RemoteException(msg+e);
        }
    }
    
    private VpnServiceRemote getSession() throws javax.ejb.CreateException, javax.naming.NamingException {
        
        if (initCtx == null) initCtx = new InitialContext();
        
        //vpnHome = (VpnServiceRemoteHome)initCtx.lookup("ejb/VpnServiceBean");
        vpnHome = (VpnServiceRemoteHome)initCtx.lookup("System/System1/ApplicationType/Common/Application/1-5;1-5;ReferenceImplementation/Comp/VpnServiceBean");
        if (vpnHome == null){
            throw new javax.ejb.CreateException("Lookup of VpnServiceRemoteHome failed");
        }
        
        try {
            return vpnHome.create();
        } catch (java.rmi.RemoteException rex) {
            rex.printStackTrace();
            throw new EJBException("RemoteException: " + rex.getMessage());
        }
    }
}
