
package com.codice.cm;

import java.lang.*;
import java.util.*;

class Info {

    class Common {
        @Serializable
        public class ObjectInfo {
            public long fIdOwner;
            public SEID owner;

            @Override
            public bool equals(object obj) {
                if (!(obj.getClass().equals(ObjectInfo.class)))
                    return false;

                if (Owner == null)
                    return true;

                return owner.equals(((ObjectInfo)obj).owner);
            }

            @Override
            public int hashCode() {
                return super.hashCode();
            }

        }

        @Serializable
        public class RepositoryServerInfo extends ObjectInfo {
            public string serverName;

            @Override
            public boolean equals(object obj) {
                if (!(obj.getClass().equals(RepositoryServerInfo.class))) {
                    return false;
                }

                RepositoryServerInfo repObj = (RepositoryServerInfo) obj;
                if (ServerLocator.get().areSameServer(serverName, repObj.serverName)) {
                    return false;
                }

                return super.equals(obj);
            }

            @Override
            public int hashCode()
            {
                return super.hashCode();
            }
        }

        @Serializable
        public class RepositoryInfo extends ObjectInfo
        {
            public long id = -1;
            public String Name;
            public Guid guid;
            private String mServer;

            public RepositoryInfo(long repId, String name, String server, Guid guid) {
                this(repId, name, server, guid, null);
            }

            public RepositoryInfo(
                long repId, string name, string server, Guid guid, SEID owner) {
                this.id = repId;
                this.name = name;
                this.guid = guid;
                if (!ServerLocator.get().isSameServer(server))
                    this.mServer = server;
                this.owner = owner;
            }
            
            public String getServer() {
                if((mServer != null) && (!"".equals(mServer))) {
                    return mServer;
                }
                
                return ServerLocator.get().getDefaultServer();
            }

            public void setExplicitServer(string serverName) {
                // Only set the value when the client calls directly to
                // the repository server, and it returns the mServer field to null.
                // Needs to set it manually.
                if (mServer == null || "".equals(mServer)) {
                    if (serverName == null) {
                        mServer = getServer();
                    } else
                        mServer = serverName;
                }
            }

            public String getInternalServerName() {
                return mServer;
            }

            @Override
            public boolean equals(object obj)
            {
                if (this == obj) return true;

                RepositoryInfo objInfo = (RepositoryInfo) obj;

                if (objInfo != null) {
                    return objInfo.guid == this.guid;
                } else {
                    return false;
                }
            }

            @Override
            public int hashCode() {
                return guid.hashCode();
            }

            @Override
            public String toString() {
                return this.name + " (" + this.getServer() + ")";
            }

            private RepositoryInfo()
            {
            }

            public RepositoryInfo createExplicitClone()
            {
                RepositoryInfo result = new RepositoryInfo();
                result.id = this.id;
                result.name = this.name;
                result.mServer = this.server;
                result.owner = this.owner;
                result.guid = this.guid;
                return result;
            }

            public RepositorySpec getRepSpec()
            {
                RepositorySpec result = new RepositorySpec();
                result.name = name;
                result.server = server;
                return result;
            }
        }
        
    }
    
    class InRep {
        @Serializable
        public class ObjectInRepInfo extends ObjectInfo {
            public long tepId = -1;
            public long id = -1;

            public ObjectInRepInfo() { }

            public ObjectInRepInfo(long id) {
                this.id = id;
            }

            @Override
            public boolean Equals(object obj) {
                if (!(obj.getClass().equals(ObjectInRepInfo.class))) {
                    return false;
                }

                ObjectInRepInfo repObj = (ObjectInRepInfo) obj;

                if (repId != repObj.repId) {
                    return false;
                }

                if (id != repObj.id) {
                    return false;
                }

                return super.equals(obj);
            }

            @Override
            public int hashCode()
            {
                return super.hashCode();
            }
        }
    }
}