Package org.oasisOpen.docs.wsrf.x2005.x01.wsrfInterop20Draft03Wsdl

Source Code of org.oasisOpen.docs.wsrf.x2005.x01.wsrfInterop20Draft03Wsdl.PrinterPortHome

/*=============================================================================*
*  Copyright 2004 The Apache Software Foundation
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*=============================================================================*/
package org.oasisOpen.docs.wsrf.x2005.x01.wsrfInterop20Draft03Wsdl;

import org.apache.ws.resource.*;
import org.apache.ws.resource.properties.faults.ResourceUnknownFaultException;
import org.apache.ws.resource.properties.v2004_11.impl.NamespaceVersionHolderImpl;
import org.apache.ws.resource.impl.AbstractResourceHome;
import org.apache.ws.resource.impl.SimpleTypeResourceKey;
import org.apache.ws.util.XmlBeanUtils;
import org.apache.xmlbeans.XmlObject;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.AttributedURI;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceDocument;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.EndpointReferenceType;
import org.xmlsoap.schemas.ws.x2004.x08.addressing.ReferencePropertiesType;

import javax.xml.namespace.QName;
import java.io.Serializable;

/**
* Home for PrinterPort WS-Resources.
*/
public class PrinterPortHome
   extends AbstractResourceHome
   implements Serializable
{
   private static final String SERVICE_NAME  = "PrinterPort";

   /** DOCUMENT_ME */
   public static final String  HOME_LOCATION =
      JndiConstants.CONTEXT_NAME_SERVICES + "/" + SERVICE_NAME + "/" + JndiConstants.ATOMIC_NAME_HOME;
  // private PrinterPortResource m_printer;
    private int m_printerId = 0;

    /**
    * @param resourceContext DOCUMENT_ME
    * @return DOCUMENT_ME
    * @throws ResourceException        DOCUMENT_ME
    * @throws ResourceContextException DOCUMENT_ME
    * @throws ResourceUnknownException DOCUMENT_ME
    */
   public Resource getInstance( ResourceContext resourceContext )
   throws ResourceException,
          ResourceContextException,
          ResourceUnknownException
   {
      ResourceKey key      = resourceContext.getResourceKey(  );
      Resource    resource = null;
      try
      {
         resource = find( key );
      }
      catch ( ResourceException re )
      {
         throw new ResourceUnknownFaultException( new NamespaceVersionHolderImpl(  ),
                                                  new ResourceUnknownException( null, "An error occurred" ) );
      }

      return resource;
   }


    public EndpointReferenceType getEprForResource( ResourceKey key,
                                                   String      serviceUrl )
   {
      EndpointReferenceDocument eprDoc  = EndpointReferenceDocument.Factory.newInstance(  );
      EndpointReferenceType     epr     = eprDoc.addNewEndpointReference(  );
      AttributedURI             address = epr.addNewAddress(  );
      address.setStringValue( serviceUrl + "/" +SERVICE_NAME );
      ReferencePropertiesType refProps = epr.addNewReferenceProperties(  );

      XmlObject               xmlObject = XmlBeanUtils.addChildElement( refProps,
                                                                        key.getName(  ) );
      XmlBeanUtils.setValue( xmlObject,
                             key.getValue(  ).toString(  ) );

      return epr;
   }

   /**
    * DOCUMENT_ME
    *
    * @param resourceContext DOCUMENT_ME
    *
    * @return DOCUMENT_ME
    *
    * @throws ResourceException DOCUMENT_ME
    * @throws ResourceContextException DOCUMENT_ME
    * @throws ResourceUnknownException DOCUMENT_ME
    */
   public Resource createPrinter( ResourceContext resourceContext )
   throws ResourceException,
          ResourceContextException,
          ResourceUnknownException
   {
       ++m_printerId;
       int printerId = m_printerId;
       SimpleTypeResourceKey key = createResourceKey(printerId);
       EndpointReferenceType printerEpr = getEprForResource( key,
                                                        resourceContext.getBaseURL(  ) );
         PrinterPortResource printer = new PrinterPortResource( "Printer" + printerId,
                                              getEprForResource( key, resourceContext.getBaseURL(  ) ) );
         printer.init(  );
         add(key, printer);
     
      return printer;
   }

     private SimpleTypeResourceKey createResourceKey(int printerId)
    {
        SimpleTypeResourceKey key    =
           new SimpleTypeResourceKey( QName.valueOf( "{http://docs.oasis-open.org/wsrf/2005/01/wsrf-Interop-2.0-draft-03.wsdl}ResourceID" ),
                                      "Printer" + Integer.toStringprinterId ) );
        return key;
    }

    public QName getServiceName()
    {
        return new QName(PrinterPortPropertyQNames.PRINTER_REFERENCE.getNamespaceURI(),"PrinterPort");
    }

    public QName getPortType()
    {
        return new QName(PrinterPortPropertyQNames.PRINTER_REFERENCE.getNamespaceURI(),"Printer");
    }

    public String getServicePortName()
    {
        return "PrinterPort";
    }

    public QName getResourceKeyNameQName()
    {
        return new QName("{http://docs.oasis-open.org/wsrf/2005/01/wsrf-Interop-2.0-draft-03.wsdl}ResourceID");
    }
}
TOP

Related Classes of org.oasisOpen.docs.wsrf.x2005.x01.wsrfInterop20Draft03Wsdl.PrinterPortHome

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.