001package com.github.sarxos.webcam.ds.ipcam.impl;
002
003import java.net.MalformedURLException;
004import java.net.URL;
005
006import javax.xml.bind.annotation.XmlAccessType;
007import javax.xml.bind.annotation.XmlAccessorType;
008import javax.xml.bind.annotation.XmlAttribute;
009import javax.xml.bind.annotation.XmlElement;
010
011import com.github.sarxos.webcam.WebcamException;
012import com.github.sarxos.webcam.ds.ipcam.IpCamAuth;
013import com.github.sarxos.webcam.ds.ipcam.IpCamMode;
014
015
016@XmlAccessorType(XmlAccessType.FIELD)
017public class IpCamDescriptor {
018
019        @XmlAccessorType(XmlAccessType.FIELD)
020        protected static class AuthParams {
021
022                @XmlAttribute
023                private String user = null;
024
025                @XmlAttribute
026                private String password = null;
027
028                public String getUser() {
029                        return user;
030                }
031
032                public String getPassword() {
033                        return password;
034                }
035        }
036
037        @XmlAttribute
038        private String name = null;
039
040        @XmlAttribute(name = "url")
041        private String urlString = null;
042
043        private transient URL url = null;
044
045        @XmlAttribute
046        private IpCamMode mode = IpCamMode.PULL;
047
048        @XmlElement(name = "auth")
049        private AuthParams authParams = null;
050
051        private transient IpCamAuth auth = null;
052
053        public String getName() {
054                return name;
055        }
056
057        public URL getURL() {
058                if (urlString != null && url == null) {
059                        try {
060                                url = new URL(urlString);
061                        } catch (MalformedURLException e) {
062                                throw new WebcamException(e);
063                        }
064                }
065                return url;
066        }
067
068        public IpCamMode getMode() {
069                return mode;
070        }
071
072        public IpCamAuth getAuth() {
073                if (authParams != null && auth == null) {
074                        auth = new IpCamAuth(authParams.getUser(), authParams.getPassword());
075                }
076                return auth;
077        }
078}