Package org.apache.ws.resource.properties

Source Code of org.apache.ws.resource.properties.SushiHome

/*=============================================================================*
*  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.apache.ws.resource.properties;

import org.apache.ws.resource.PropertiesResource;
import org.apache.ws.resource.Resource;
import org.apache.ws.resource.ResourceContext;
import org.apache.ws.resource.ResourceContextException;
import org.apache.ws.resource.ResourceException;
import org.apache.ws.resource.ResourceKey;
import org.apache.ws.resource.ResourceUnknownException;
import org.apache.ws.resource.impl.AbstractResourceHome;
import org.apache.ws.resource.impl.SimpleTypeResourceKey;
import org.apache.ws.resource.properties.impl.XmlBeansResourcePropertySet;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;

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

/**
* @author Sal Campana
*/
public class SushiHome
        extends AbstractResourceHome
        implements Serializable
{

    /**
     * DOCUMENT_ME
     */
    protected static String RESOURCE_PROPS_RESOURCE_PATH =
            "org/apache/ws/resource/properties/SushiProperties.xml";
    private boolean m_isOpenContent;

    public SushiHome( boolean isOpenContent )
    {
        m_isOpenContent = isOpenContent;
        setResourceKeyName( SimpleTypeResourceKey.class.getName() );
        setResourceClassName( SushiResource.class.getName() );
        try
        {
            init();
        }
        catch ( Exception e )
        {
            e.printStackTrace();
        }
    }

    /**
     * DOCUMENT_ME
     *
     * @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
    {

        Resource resource = null;
        ResourceKey key = resourceContext.getResourceKey();
        try
        {   //added because of AbstractPortType
            resource = null;
            try
            {
                resource = find( key );
            }
            catch ( ResourceException re )
            {
                ;
            }
            if ( resource == null )
            {
                InputStream in = getClass().getClassLoader().getResourceAsStream( RESOURCE_PROPS_RESOURCE_PATH );
                XmlOptions parseOpts = new XmlOptions().setLoadStripWhitespace();
                if ( ! m_isOpenContent ) {
                    parseOpts.setLoadReplaceDocumentElement( new QName( AbstractResourcePropertiesTestCase.NSURI_SUSHI, "ClosedSushiProperties", "sushi" ) );
                }
                XmlObject propsDocXBean = XmlObject.Factory.parse( in, parseOpts );
                in.close();
                ResourcePropertySet propSet = new XmlBeansResourcePropertySet( propsDocXBean );
                resource = createInstance( key);
                ( (PropertiesResource) resource ).setResourcePropertySet( propSet );
            }
        }
        catch ( Exception e )
        {
            throw new ResourceException( e );
        }

        add( key, resource );
        return resource;
    }

    public void setResourcePropsDocPath( String propsDoc )
    {
        SushiHome.RESOURCE_PROPS_RESOURCE_PATH = propsDoc;
    }
}
TOP

Related Classes of org.apache.ws.resource.properties.SushiHome

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.