
// Copyright (c) 2000 Oracle Corporation
package oracle.portal.provider.v1;

/**
 * A Class class.
 * <P>
 * @author Michael Freedman
 */
public class DeviceInfo extends Object
{

    private DeviceClass mDeviceClass;
    private DeviceOrientation mOrientation;
    private long mMaxDocSize;
    private boolean mClientConnectionSecure;

    /* Constructor */
    public DeviceInfo(
        DeviceClass deviceClass,
        DeviceOrientation orientation,
        long maxDocSize,
        boolean secure)
    {
        mDeviceClass = deviceClass;
        mOrientation = orientation;
        mMaxDocSize = maxDocSize;
        mClientConnectionSecure = secure;
    }

    /**
     *  @return the classification of the device.
     */
    public DeviceClass getDeviceClass()
    {
        return mDeviceClass;
    }

    /**
     *  @param the classification of the device.
     */
    public void setDeviceClass(DeviceClass deviceClass)
    {
        mDeviceClass = deviceClass;
    }

    /**
     *  @return the orientation of the device.
     */
    public DeviceOrientation getOrientation()
    {
        return mOrientation;
    }

    /**
     *  @param the orientation of the device.
     */
    public void setOrientation(DeviceOrientation orientation)
    {
        mOrientation = orientation;
    }

    /**
     *  @return the estimated maximum size in bytes the device supports.
     */
    public long getMaxDocSize()
    {
        return mMaxDocSize;
    }

    /**
     *  @param sets the estimated maximum size in bytes the device supports.
     */
    public void setMaxDocSize(long maxDocSize)
    {
        mMaxDocSize = maxDocSize;
    }

    /**
     *  @return whether the connection from the client device to the (gateway) is secure.
     */
    public boolean isClientConnectionSecure()
    {
        return mClientConnectionSecure;
    }

    /**
     *  @param sets hether the connection from the client device to the (gateway) is secure.
     */
    public void setClientConnectionSecure(boolean secure)
    {
        mClientConnectionSecure = secure;
    }

    // Top level nested class representing the enumerated types used to represent
    // data members of deviceInfos

    public static class DeviceClass extends Object
    {
        /* value indicates the device display is unknown */
        public static final int UNKNOWN = 0;
        /* value indicates the device display voice */
        public static final int VOICE = 1;
        /* value indicates the device display is small -- sms, pagers */
        public static final int MICROMESSENGER = 2;
        /* value indicates the device display is medium -- e-mail devices */
        public static final int MESSENGER = 3;
        /* value indicates the device display is small -- cell/wap phones */
        public static final int MICROBROWSER = 4;
        /* value indicates the device display is medium -- pdas */
        public static final int PDABROWSER = 5;
        /* value indicates the device display is large -- desktop */
        public static final int PCBROWSER = 6;
        private static final int LAST = PCBROWSER;

        /* constant object representing an unknown display */
        public static final DeviceClass DEVICE_UNKNOWN = new DeviceClass(null);
        /* constant object representing an voice display */
        public static final DeviceClass DEVICE_VOICE = new DeviceClass(DeviceClass.VOICE);
        /* constant object representing an small -- sms, pagers display */
        public static final DeviceClass DEVICE_MICROMESSENGER = new DeviceClass(DeviceClass.MICROMESSENGER);
        /* constant object representing a medium -- e-mail devices display */
        public static final DeviceClass DEVICE_MESSENGER = new DeviceClass(DeviceClass.MESSENGER);
        /* constant object representing a small -- cell/wap phones display */
        public static final DeviceClass DEVICE_MICROBROWSER = new DeviceClass(DeviceClass.MICROBROWSER);
        /* constant object representing a medium -- pdas display */
        public static final DeviceClass DEVICE_PDABROWSER = new DeviceClass(DeviceClass.PDABROWSER);
        /* constant object representing a large -- pc display */
        public static final DeviceClass DEVICE_PCBROWSER = new DeviceClass(DeviceClass.PCBROWSER);

        protected static final String DEVICE_CLASS_TYPE_VOICE = "voice";
        protected static final String DEVICE_CLASS_TYPE_MICROMESSENGER = "micromessenger";
        protected static final String DEVICE_CLASS_TYPE_MESSENGER = "messenger";
        protected static final String DEVICE_CLASS_TYPE_MICROBROWSER = "microbrowser";
        protected static final String DEVICE_CLASS_TYPE_PDABROWSER = "pdabrowser";
        protected static final String DEVICE_CLASS_TYPE_PCBROWSER = "pcbrowser";
        protected static final String DEVICE_CLASS_TYPE_UNKNOWN = "unknown";

        /**
         *  @return true if this is an voice device.
         */
        static public boolean isDeviceAudio(DeviceClass device)
        {
            if (device.getValue() == DeviceClass.VOICE)
                return true;
            else
                return false;
        }

        /**
         *  @return true if this device's display is small -- sms, pagers display.
         */
        static public boolean isDeviceMicroMessenger(DeviceClass device)
        {
            if (device.getValue() == DeviceClass.MICROMESSENGER)
                return true;
            else
                return false;
        }

        /**
         *  @return true if this device's display is medium -- e-mail devices display.
         */
        static public boolean isDeviceMessenger(DeviceClass device)
        {
            if (device.getValue() == DeviceClass.MESSENGER)
                return true;
            else
                return false;
        }

        /**
         *  @return true if this device's display ismall -- cell/wap phones display
         */
        static public boolean isDeviceMicrobrowser(DeviceClass device)
        {
            if (device.getValue() == DeviceClass.MICROBROWSER)
                return true;
            else
                return false;
        }

        /**
         *  @return true if this device's display medium -- pdas display
         */
        static public boolean isDevicePDABrowser(DeviceClass device)
        {
            if (device.getValue() == DeviceClass.PDABROWSER)
                return true;
            else
                return false;
        }

        /**
         *  @return true if this device's display large -- pc display
         */
        static public boolean isDevicePCBrowser(DeviceClass device)
        {
            if (device.getValue() == DeviceClass.PCBROWSER)
                return true;
            else
                return false;
        }

        /**
         *  @return false if this device's display size is unknown.
         */
        static public boolean isDeviceKnown(DeviceClass device)
        {
            if (device.getValue() != DeviceClass.UNKNOWN)
                return true;
            else
                return false;
        }

        /**
         *  @param deviceClass name of the type (size) of this device's display.
         *  @return a DeviceClass object representing the device's
         *  display size (class) based on the provided string value.
         *  If an invalid String value is passed the DeviceClass returned
         *  is one representing "unknown".
         */
        public static DeviceClass getDeviceClass(String deviceClass) {
            if (deviceClass == null)
                return DeviceClass.DEVICE_UNKNOWN;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_VOICE))
                return DeviceClass.DEVICE_VOICE;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_MICROMESSENGER))
                return DeviceClass.DEVICE_MICROMESSENGER;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_MESSENGER))
                return DeviceClass.DEVICE_MESSENGER;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_MICROBROWSER))
                return DeviceClass.DEVICE_MICROBROWSER;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_PDABROWSER))
                return DeviceClass.DEVICE_PDABROWSER;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_PCBROWSER))
                return DeviceClass.DEVICE_PCBROWSER;
            else
                return DeviceClass.DEVICE_UNKNOWN;
        }

        private int mValue;

        // constructor
        public DeviceClass(String deviceClass)
        {
            if (deviceClass == null)
                mValue = DeviceClass.UNKNOWN;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_VOICE))
                mValue = DeviceClass.VOICE;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_MICROMESSENGER))
                mValue = DeviceClass.MICROMESSENGER;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_MESSENGER))
                mValue = DeviceClass.MESSENGER;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_MICROBROWSER))
                mValue = DeviceClass.MICROBROWSER;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_PDABROWSER))
                mValue = DeviceClass.PDABROWSER;
            else if (deviceClass.equalsIgnoreCase(DeviceClass.DEVICE_CLASS_TYPE_PCBROWSER))
                mValue = DeviceClass.PCBROWSER;
            else
                mValue = DeviceClass.UNKNOWN;
        }

        // constructor
        public DeviceClass(int deviceClass)
        {
            if (deviceClass > DeviceClass.UNKNOWN && deviceClass <= DeviceClass.LAST)
                mValue = deviceClass;
            else
                mValue = DeviceClass.UNKNOWN;
        }

        /**
         *  @return the (enumerated) value of this device's class (display).
         */
        public int getValue()
        {
            return mValue;
        }

        /**
         *  @return the (String value of this device's class (display).
         */
        public String toString()
        {
            switch (mValue)
            {
            case DeviceClass.VOICE:
                return DeviceClass.DEVICE_CLASS_TYPE_VOICE;
            case DeviceClass.MICROMESSENGER:
                return DeviceClass.DEVICE_CLASS_TYPE_MICROMESSENGER;
            case DeviceClass.MESSENGER:
                return DeviceClass.DEVICE_CLASS_TYPE_MESSENGER;
            case DeviceClass.MICROBROWSER:
                return DeviceClass.DEVICE_CLASS_TYPE_MICROBROWSER;
            case DeviceClass.PDABROWSER:
                return DeviceClass.DEVICE_CLASS_TYPE_PDABROWSER;
            case DeviceClass.PCBROWSER:
                return DeviceClass.DEVICE_CLASS_TYPE_PCBROWSER;
            default:
                return DeviceClass.DEVICE_CLASS_TYPE_UNKNOWN;
            }
        }

    }

    /** To level nested class representing the enumerated types used to represent
     *  data members of deviceInfos.  This class represents the orientation of the
     *  device.
     */
    public static class DeviceOrientation extends Object
    {
        /* value indicates the device's orientation is unknown */
        public static final int UNKNOWN = 0;
        /* value indicates the device's orientation is landscape */
        public static final int LANDSCAPE = 1;
        /* value indicates the device's orientation is portrait */
        public static final int PORTRAIT = 2;
        private static final int LAST = PORTRAIT;

        /* constant object representing an unknown orientation */
        public static final DeviceOrientation ORIENTATION_UNKNOWN =
            new DeviceOrientation(DeviceOrientation.UNKNOWN);
        /* constant object representing an landscape orientation */
        public static final DeviceOrientation ORIENTATION_LANDSCAPE =
            new DeviceOrientation(DeviceOrientation.LANDSCAPE);
        /* constant object representing an portrait orientation */
        public static final DeviceOrientation ORIENTATION_PORTRAIT =
            new DeviceOrientation(DeviceOrientation.PORTRAIT);

        protected static final String DEVICE_ORIENTATION_LANDSCAPE = "landscape";
        protected static final String DEVICE_ORIENTATION_PORTRAIT = "portrait";
        protected static final String DEVICE_ORIENTATION_UNKNOWN = "unknown";

        /**
         *  @return true is this device's orientation is landscape.
         */
        static public boolean isLandscape(DeviceOrientation type)
        {
            if (type.getValue() == DeviceOrientation.LANDSCAPE)
                return true;
            else
                return false;
        }

        /**
         *  @return true is this device's orientation is portrait.
         */
        static public boolean isPortrait(DeviceOrientation type)
        {
            if (type.getValue() == DeviceOrientation.PORTRAIT)
                return true;
            else
                return false;
        }

        /**
         *  @return false is this device's orientation is unknown.
         */
        static public boolean isOrientationKnown(DeviceOrientation type)
        {
            if (type.getValue() != DeviceOrientation.UNKNOWN)
                return true;
            else
                return false;
        }

        /**
         *  @param orientation String representing the device's orientation.
         *  Value is either "landscape" or "portrait". Case doesn't matter.
         *  @return object representing device orientation based on String.
         */
        static public DeviceOrientation getDeviceOrientation(String orientation)
        {
            if (orientation == null)
                return DeviceOrientation.ORIENTATION_UNKNOWN;
            else if (orientation.equalsIgnoreCase(DeviceOrientation.DEVICE_ORIENTATION_LANDSCAPE))
                return DeviceOrientation.ORIENTATION_LANDSCAPE;
            else if (orientation.equalsIgnoreCase(DeviceOrientation.DEVICE_ORIENTATION_PORTRAIT))
                return DeviceOrientation.ORIENTATION_PORTRAIT;
            else
                return DeviceOrientation.ORIENTATION_UNKNOWN;
        }

        private int mValue;

        /**
         *  Constructor -- object representing device orientation based on String.
         *  @param orientation String representing the device's orientation.
         *  Value is either "landscape" or "portrait". Case doesn't matter.
         */
        public DeviceOrientation(String orientation)
        {
            if (orientation == null)
                mValue = DeviceOrientation.UNKNOWN;
            else if (orientation.equalsIgnoreCase(DeviceOrientation.DEVICE_ORIENTATION_LANDSCAPE))
                mValue = DeviceOrientation.LANDSCAPE;
            else if (orientation.equalsIgnoreCase(DeviceOrientation.DEVICE_ORIENTATION_PORTRAIT))
                mValue = DeviceOrientation.PORTRAIT;
            else
                mValue = DeviceOrientation.UNKNOWN;
        }

        /**
         *  Constructor.
         *  @param orientation the device's orientation.
         */
        public DeviceOrientation(int orientation)
        {
            if (orientation > DeviceOrientation.UNKNOWN && orientation <= DeviceOrientation.LAST)
                mValue = orientation;
            else
                mValue = DeviceOrientation.UNKNOWN;
        }

        /**
         *  @return Returns the device's orientation.
         */
        public int getValue()
        {
            return mValue;
        }

        /**
         *  @return Returns the device's orientation as a String.
         */
        public String toString()
        {
            switch (mValue)
            {
            case DeviceOrientation.LANDSCAPE:
                return DeviceOrientation.DEVICE_ORIENTATION_LANDSCAPE;
            case DeviceOrientation.PORTRAIT:
                return DeviceOrientation.DEVICE_ORIENTATION_PORTRAIT;
            default:
                return DeviceOrientation.DEVICE_ORIENTATION_UNKNOWN;
            }
        }
    }

}

