001/* 002 * Copyright (C) 2014 konik.io 003 * 004 * This file is part of Konik library. 005 * 006 * Konik library is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Affero General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * Konik library is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU Affero General Public License for more details. 015 * 016 * You should have received a copy of the GNU Affero General Public License 017 * along with Konik library. If not, see <http://www.gnu.org/licenses/>. 018 */ 019package io.konik.zugferd.profile; 020 021import javax.validation.constraints.NotNull; 022import javax.xml.bind.annotation.XmlAccessType; 023import javax.xml.bind.annotation.XmlAccessorType; 024import javax.xml.bind.annotation.XmlElement; 025import javax.xml.bind.annotation.XmlType; 026import javax.xml.bind.annotation.adapters.CollapsedStringAdapter; 027import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; 028 029/** 030 * The ZUGFeRD full Profile Name 031 * 032 * Construction schema. namespace:version:[basic, comfort or extended] 033 * 034 * Example:: urn:ferd:invoice:rce:extended 035 * 036 */ 037@XmlAccessorType(XmlAccessType.FIELD) 038@XmlType(name = "DocumentContextParameterType", propOrder = { "id" }) 039public class Profile { 040 041 @NotNull 042 @XmlElement(name = "ID") 043 @XmlJavaTypeAdapter(CollapsedStringAdapter.class) 044 private final String id; 045 046 /** 047 * Instantiates a new profile. 048 */ 049 Profile() { 050 this.id = null; 051 } 052 053 /** 054 * Instantiates a new profile. 055 * 056 * @param fullName the full name 057 */ 058 public Profile(String fullName) { 059 this.id = fullName; 060 } 061 062 /** 063 * Instantiates a new profile. 064 * 065 * @param type the type 066 */ 067 public Profile(ProfileType type) { 068 this.id = type.fullName; 069 } 070 071 /** 072 * Gets the profile name. 073 074 * e.g. urn:ferd:invoice:rc:basic 075 * 076 * @return the full profile name 077 */ 078 public String getFullName() { 079 return id; 080 } 081 082 /** 083 * Gets the simple name of the profile 084 085 * e.g basic,comfort or extended. 086 * 087 * @return the simple name of the profile 088 */ 089 public String getSimpleName() { 090 return id.substring(id.lastIndexOf(':')); 091 } 092 093 /** 094 * Checks if profile is basic. 095 * 096 * @return true, if is basic 097 */ 098 public boolean isBasic() { 099 return ProfileType.isBasic(id); 100 } 101 102 /** 103 * Checks if profile is comfort. 104 * 105 * @return true, if is comfort 106 */ 107 public boolean isComfort() { 108 return ProfileType.isComfort(id); 109 } 110 111 /** 112 * Checks if profile is extended. 113 * 114 * @return true, if is extended 115 */ 116 public boolean isExtended() { 117 return ProfileType.isExtended(id); 118 } 119 120 /** 121 * Gets the version of the invoice. 122 * 123 * @return the version of the underlying invoice. 124 */ 125 public String getVersion() { 126 return ProfileType.extractVersion(id); 127 } 128 129}