001/** 002 * 003 * Copyright © 2014-2017 Florian Schmaus 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.jxmpp.jid.impl; 018 019import org.jxmpp.jid.BareJid; 020import org.jxmpp.jid.EntityBareJid; 021import org.jxmpp.jid.DomainBareJid; 022import org.jxmpp.jid.DomainFullJid; 023import org.jxmpp.jid.EntityFullJid; 024import org.jxmpp.jid.EntityJid; 025import org.jxmpp.jid.FullJid; 026import org.jxmpp.jid.parts.Domainpart; 027import org.jxmpp.jid.parts.Localpart; 028import org.jxmpp.jid.parts.Resourcepart; 029import org.jxmpp.stringprep.XmppStringprepException; 030 031public final class DomainpartJid extends AbstractJid implements DomainBareJid { 032 033 /** 034 * 035 */ 036 private static final long serialVersionUID = 1L; 037 038 protected final Domainpart domain; 039 040 DomainpartJid(String domain) throws XmppStringprepException { 041 this(Domainpart.from(domain)); 042 } 043 044 DomainpartJid(Domainpart domain) { 045 this.domain = requireNonNull(domain, "The Domainpart must not be null"); 046 } 047 048 @Override 049 public Domainpart getDomain() { 050 return domain; 051 } 052 053 @Override 054 public String toString() { 055 // Prefer the cached version over the domain.toString() one, since the cached version may 056 // also be the internalized representation of the String. Which, e.g. provides benefits when 057 // comparing JIDs. 058 if (cache != null) { 059 return cache; 060 } 061 cache = domain.toString(); 062 return cache; 063 } 064 065 @Override 066 public String asUnescapedString() { 067 // No un-escaping necessary for DomainpartJid 068 return toString(); 069 } 070 071 @Override 072 public DomainBareJid asDomainBareJid() { 073 return this; 074 } 075 076 @Override 077 public boolean hasNoResource() { 078 return true; 079 } 080 081 @Override 082 public EntityBareJid asEntityBareJidIfPossible() { 083 return null; 084 } 085 086 @Override 087 public EntityFullJid asEntityFullJidIfPossible() { 088 return null; 089 } 090 091 @Override 092 public DomainFullJid asDomainFullJidIfPossible() { 093 return null; 094 } 095 096 @Override 097 public boolean isParentOf(EntityBareJid bareJid) { 098 return domain.equals(bareJid.getDomain()); 099 } 100 101 @Override 102 public boolean isParentOf(EntityFullJid fullJid) { 103 return domain.equals(fullJid.getDomain()); 104 } 105 106 @Override 107 public boolean isParentOf(DomainBareJid domainBareJid) { 108 return domain.equals(domainBareJid.getDomain()); 109 } 110 111 @Override 112 public boolean isParentOf(DomainFullJid domainFullJid) { 113 return domain.equals(domainFullJid.getDomain()); 114 } 115 116 @Override 117 public BareJid asBareJid() { 118 return this; 119 } 120 121 @Override 122 public EntityJid asEntityJidIfPossible() { 123 return null; 124 } 125 126 @Override 127 public FullJid asFullJidIfPossible() { 128 return null; 129 } 130 131 @Override 132 public Resourcepart getResourceOrNull() { 133 return null; 134 } 135 136 @Override 137 public Localpart getLocalpartOrNull() { 138 return null; 139 } 140 141}