ResourceType.java :  » Database-ORM » JPOX » org » jpox » Java Open Source

Java Open Source » Database ORM » JPOX 
JPOX » org » jpox » ResourceType.java
/**********************************************************************
Copyright (c) 2007 Erik Bengtson and others. All rights reserved.
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.

Contributors:
    ...
**********************************************************************/
package org.jpox;

import java.io.Serializable;

/**
 * Representation of a resource type. A Resource is a connection to the
 * datastore. There are two kinds of resources: JTA or RESOURCE_LOCAL
 * A transaction of a JTA resource is managed by a JTA TransactionManager,
 * while RESOURCE_LOCAL is managed by JPOX TransactionManager
 *
 * @since 1.1 
 * @version $Revision: 1.1 $
 */
public class ResourceType implements Serializable
{
    /** JTA transaction. */
    public static final ResourceType JTA = new ResourceType(1);

    /** Local transaction. */
    public static final ResourceType RESOURCE_LOCAL = new ResourceType(2);

    private final int typeId;
    private ResourceType(int i)
    {
        this.typeId = i;
    }

    /**
     * Indicates whether some other object is "equal to" this one.
     * @param o the reference object with which to compare. 
     * @return true if this object is the same as the obj argument; false otherwise.
     */
    public boolean equals(Object o)
    {
        if (o instanceof ResourceType)
        {
            return ((ResourceType)o).typeId == typeId;
        }
        return false;
    }

    /**
     * Returns a string representation of the object.
     * @return a string representation of the object.
     */
    public String toString()
    {
        switch (typeId)
        {
            case 1 :
                return "JTA";
            case 2 :
                return "RESOURCE_LOCAL";
        }
        return "";
    }

    /**
     * Accessor to the sequence strategy type
     * @return the type
     */    
    public int getType()
    {
        return typeId;
    }

    /**
     * Return Sequence strategy from String.
     * @param value sequence strategy
     * @return Instance of SequenceStrategy. If parse failed, return null.
     */
    public static ResourceType getValue(final String value)
    {
        if (value == null)
        {
            return null;
        }
        else if (ResourceType.JTA.toString().equalsIgnoreCase(value))
        {
            return ResourceType.JTA;
        }
        else if (ResourceType.RESOURCE_LOCAL.toString().equalsIgnoreCase(value))
        {
            return ResourceType.RESOURCE_LOCAL;
        }
        return null;
    }
}
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.