Package org.apache.slide.common

Source Code of org.apache.slide.common.NamespaceAccessTokenImpl

/*
* $Header: /home/cvspublic/jakarta-slide/src/share/org/apache/slide/common/NamespaceAccessTokenImpl.java,v 1.13 2001/02/26 12:51:58 juergen Exp $
* $Revision: 1.13 $
* $Date: 2001/02/26 12:51:58 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation.  All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
*    notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in
*    the documentation and/or other materials provided with the
*    distribution.
*
* 3. The end-user documentation included with the redistribution, if
*    any, must include the following acknowlegement:
*       "This product includes software developed by the
*        Apache Software Foundation (http://www.apache.org/)."
*    Alternately, this acknowlegement may appear in the software itself,
*    if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
*    Foundation" must not be used to endorse or promote products derived
*    from this software without prior written permission. For written
*    permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
*    nor may "Apache" appear in their names without prior written
*    permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``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 THE APACHE SOFTWARE FOUNDATION OR
* ITS 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 ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation.  For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* [Additional notices, if required by prior licensing conditions]
*
*/

package org.apache.slide.common;

import java.util.Hashtable;
import java.util.Vector;
import java.util.Enumeration;
import java.util.Stack;
import java.util.Date;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import javax.transaction.UserTransaction;
import javax.transaction.Status;
import javax.transaction.TransactionManager;
import javax.transaction.Transaction;
import javax.transaction.Synchronization;
import javax.transaction.HeuristicCommitException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.InvalidTransactionException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.apache.slide.structure.*;
import org.apache.slide.content.*;
import org.apache.slide.lock.*;
import org.apache.slide.security.Security;
import org.apache.slide.security.SecurityImpl;
import org.apache.slide.macro.*;
import org.apache.slide.authenticate.CredentialsToken;
import org.apache.slide.util.conf.Configuration;
import org.apache.slide.util.conf.ConfigurationElement;
import org.apache.slide.util.conf.Populate;
import org.apache.slide.util.conf.ConfigurationException;

/**
* Namespace access token implementation.
*
* @author <a href="mailto:remm@apache.org">Remy Maucherat</a>
* @version $Revision: 1.13 $
*/
public final class NamespaceAccessTokenImpl implements NamespaceAccessToken {
   
   
    // ------------------------------------------------------------ Constructor
   
   
    /**
     * Constructor.
     *
     * @param namespace Namespace which can be accessed through this token
     */
    NamespaceAccessTokenImpl(Namespace namespace) {
        this.namespace = namespace;
        securityHelper = new SecurityImpl(namespace, namespace.getConfig());
        lockHelper =
            new LockImpl(namespace, namespace.getConfig(), securityHelper);
        structureHelper =
            new StructureImpl(namespace, namespace.getConfig(),
                              securityHelper, lockHelper);
        contentHelper =
            new ContentImpl(namespace, namespace.getConfig(), securityHelper,
                            structureHelper, lockHelper);
        macroHelper =
            new MacroImpl(namespace, namespace.getConfig(), securityHelper,
                          contentHelper, structureHelper, lockHelper);
    }
    
   
    // ----------------------------------------------------- Instance Variables
   
   
    /**
     * Default namespace associated with this token.
     */
    Namespace namespace;
   
   
    /**
     * Structure helper functions.
     */
    private Structure structureHelper;
   
   
    /**
     * Content helper functions.
     */
    private Content contentHelper;
   
   
    /**
     * Lock helper functions.
     */
    private Lock lockHelper;
   
   
    /**
     * Security helper functions.
     */
    private Security securityHelper;
   
   
    /**
     * Macro helper functions.
     */
    private Macro macroHelper;
   
   
    // ------------------------------------------------------------- Properties
   
   
    /**
     * Get the structure helper.
     *
     * @return Structure helper
     */
    public Structure getStructureHelper() {
        return structureHelper;
    }
   
   
    /**
     * Get the content helper.
     *
     * @return Content helper
     */
    public Content getContentHelper() {
        return contentHelper;
    }
   
   
    /**
     * Get the lock helper.
     *
     * @return Lock Lock helper
     */
    public Lock getLockHelper() {
        return lockHelper;
    }
   
   
    /**
     * Get the security helper.
     *
     * @return Security Security helper
     */
    public Security getSecurityHelper() {
        return securityHelper;
    }
   
   
    /**
     * Get the macro helper.
     *
     * @return Macro Macro helper
     */
    public Macro getMacroHelper() {
        return macroHelper;
    }
   
   
    /**
     * Retrive the namespace configuration.
     *
     * @return NamespaceConfig Namespace configuration
     */
    public NamespaceConfig getNamespaceConfig() {
        return namespace.getConfig();
    }
   
   
    // ------------------------------------------- NamespaceAccessToken Methods
   
   
    /**
     * Import data from Avalon configuration object.
     *
     * @param token SlideToken, used for access to the namespace
     * @param dataConfiguration Configuration object
     * @exception ConfigurationException Something went wrong during the
     * reading of the XML
     * @exception UnknownObjectClassException Object class not found
     * @exception ServiceAccessException Error accessing service
     */
    public void importData(SlideToken token, Configuration dataConfiguration)
        throws ConfigurationException, UnknownObjectClassException,
        ServiceAccessException {
       
        XMLUnmarshaller.unmarshal(this, token, dataConfiguration);
       
    }
   
   
    /**
     * Import data from reader.
     *
     * @param token SlideToken, used for access to the namespace
     * @param reader Reader
     * @exception ConfigurationException Something went wrong during the
     * reading of the XML
     * @exception UnknownObjectClassException Object class not found
     * @exception ServiceAccessException Error accessing service
     */
    public void importData(SlideToken token, Reader reader)
        throws ConfigurationException, UnknownObjectClassException,
        ServiceAccessException, SAXException, IOException {

        try {
           
            SAXParserFactory factory = SAXParserFactory.newInstance();
            factory.setNamespaceAware(false);
            factory.setValidating(false);
            SAXParser parser = factory.newSAXParser();
           
            Populate pop = new Populate();
            Configuration configuration = new ConfigurationElement
                (pop.load(new InputSource(reader), parser.getParser()));
           
            importData(token, configuration);
           
        } catch (javax.xml.parsers.FactoryConfigurationError e) {
            throw new SlideRuntimeException(e.getMessage());
        } catch (javax.xml.parsers.ParserConfigurationException e) {
            throw new SlideRuntimeException(e.getMessage());
        }/* catch (Exception e) {
            throw new ConfigurationException(e.getMessage());
            }*/

    }


    /**
     * Saves Slide Data to XML.
     *
     * @param writer Writer
     * @exception SlideException
     */
    public void exportData(SlideToken token, Writer writer)
        throws SlideException {
        exportData(token, writer, "/");
    }
   
   
    /**
     * Saves Slide Data to XML.
     *
     * @param writer Writer
     * @param startNode Start generating XML from this node of the Slide tree
     * @exception SlideException
     */
    public void exportData(SlideToken token, Writer writer,
                           String startNode)
        throws SlideException {
       
        XMLMarshaller.marshal(this, token, writer, startNode);
       
    }
   
   
    /**
     * Disconnect.
     */
    public void disconnect() {
        try {
            namespace.disconnectServices();
        } catch(SlideException e) {
            e.printStackTrace();
        }
    }
   
   
    /**
     * Get namespace name.
     *
     * @return String namespace name.
     */
    public String getName() {
        return namespace.getName();
    }
   
   
    // ------------------------------------------------ UserTransaction Methods
   
   
    /**
     * Create a new transaction and associate it with the current thread.
     *
     * @exception NotSupportedException Thrown if the thread is already
     * associated with a transaction and the Transaction Manager
     * implementation does not support nested transactions.
     * @exception SystemException Thrown if the transaction manager encounters
     * an unexpected error condition.
     */
    public void begin()
        throws NotSupportedException, SystemException {
        namespace.getTransactionManager().begin();
    }
   
   
    /**
     * Complete the transaction associated with the current thread. When this
     * method completes, the thread becomes associated with no transaction.
     *
     * @exception RollbackException Thrown to indicate that the transaction
     * has been rolled back rather than committed.
     * @exception HeuristicMixedException Thrown to indicate that a heuristic
     * decision was made and that some relevant updates have been committed
     * while others have been rolled back.
     * @exception HeuristicRollbackException Thrown to indicate that a
     * heuristic decision was made and that some relevant updates have been
     * rolled back.
     * @exception SecurityException Thrown to indicate that the thread is not
     * allowed to commit the transaction.
     * @exception IllegalStateException Thrown if the current thread is not
     * associated with a transaction.
     * @exception SystemException Thrown if the transaction manager encounters
     * an unexpected error condition.
     */
    public void commit()
        throws RollbackException, HeuristicMixedException,
        HeuristicRollbackException, SecurityException, IllegalStateException,
        SystemException {
        namespace.getTransactionManager().commit();
    }
   
   
    /**
     * Roll back the transaction associated with the current thread. When
     * this method completes, the thread becomes associated with no
     * transaction.
     *
     * @exception SecurityException Thrown to indicate that the thread is not
     * allowed to commit the transaction.
     * @exception IllegalStateException Thrown if the current thread is not
     * associated with a transaction.
     * @exception SystemException Thrown if the transaction manager encounters
     * an unexpected error condition.
     */
    public void rollback()
        throws SecurityException, IllegalStateException, SystemException {
        namespace.getTransactionManager().rollback();
    }
   
   
    /**
     * Modify the transaction associated with the current thread such that
     * the only possible outcome of the transaction is to roll back the
     * transaction.
     *
     * @exception IllegalStateException Thrown if the current thread is not
     * associated with a transaction.
     * @exception SystemException Thrown if the transaction manager encounters
     * an unexpected error condition.
     */
    public void setRollbackOnly()
        throws IllegalStateException, SystemException {
        namespace.getTransactionManager().setRollbackOnly();
    }
   
   
    /**
     * Obtain the status of the transaction associated with the current thread.
     *
     * @exception SystemException Thrown if the transaction manager encounters
     * an unexpected error condition.
     * @return The transaction status. If no transaction is associated with
     * the current thread, this method returns the Status.NoTransaction value.
     */
    public int getStatus()
        throws SystemException {
        return namespace.getTransactionManager().getStatus();
    }
   
   
    /**
     * Modify the value of the timeout value that is associated with the
     * transactions started by the current thread with the begin method.
     * <p>
     * If an application has not called this method, the transaction service
     * uses some default value for the transaction timeout.
     *
     * @param seconds The value of the timeout in seconds. If the value is
     * zero, the transaction service restores the default value.
     * @exception SystemException Thrown if the transaction manager encounters
     * an unexpected error condition.
     */
    public void setTransactionTimeout(int seconds)
        throws SystemException {
        namespace.getTransactionManager().setTransactionTimeout(seconds);
    }
   
   
}

TOP

Related Classes of org.apache.slide.common.NamespaceAccessTokenImpl

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.