001/* ***** BEGIN LICENSE BLOCK ***** 002 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 003 * 004 * The contents of this file are subject to the Mozilla Public License Version 005 * 1.1 (the "License"); you may not use this file except in compliance with 006 * the License. You may obtain a copy of the License at 007 * http://www.mozilla.org/MPL/ 008 * 009 * Software distributed under the License is distributed on an "AS IS" basis, 010 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 011 * for the specific language governing rights and limitations under the 012 * License. 013 * 014 * The Original Code is part of dcm4che, an implementation of DICOM(TM) in 015 * Java(TM), hosted at https://github.com/gunterze/dcm4che. 016 * 017 * The Initial Developer of the Original Code is 018 * Agfa Healthcare. 019 * Portions created by the Initial Developer are Copyright (C) 2011 020 * the Initial Developer. All Rights Reserved. 021 * 022 * Contributor(s): 023 * See @authors listed below 024 * 025 * Alternatively, the contents of this file may be used under the terms of 026 * either the GNU General Public License Version 2 or later (the "GPL"), or 027 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 028 * in which case the provisions of the GPL or the LGPL are applicable instead 029 * of those above. If you wish to allow use of your version of this file only 030 * under the terms of either the GPL or the LGPL, and not to allow others to 031 * use your version of this file under the terms of the MPL, indicate your 032 * decision by deleting the provisions above and replace them with the notice 033 * and other provisions required by the GPL or the LGPL. If you do not delete 034 * the provisions above, a recipient may use your version of this file under 035 * the terms of any one of the MPL, the GPL or the LGPL. 036 * 037 * ***** END LICENSE BLOCK ***** */ 038 039package org.dcm4che3.net; 040 041import java.io.Serializable; 042 043import org.dcm4che3.conf.core.api.ConfigurableClass; 044import org.dcm4che3.conf.core.api.ConfigurableProperty; 045import org.dcm4che3.conf.core.api.LDAP; 046import org.dcm4che3.net.pdu.ExtendedNegotiation; 047 048/** 049 * @author Gunter Zeilinger <gunterze@gmail.com> 050 * 051 */ 052@LDAP 053@ConfigurableClass 054public class StorageOptions implements Serializable { 055 056 private static final long serialVersionUID = 6911502883119290413L; 057 058 public enum LevelOfSupport { 059 LEVEL_0, LEVEL_1, LEVEL_2, UNSPECIFIED; 060 061 public static LevelOfSupport valueOf(int level) { 062 switch(level) { 063 case 0: 064 return LEVEL_0; 065 case 1: 066 return LEVEL_1; 067 case 2: 068 return LEVEL_2; 069 } 070 return UNSPECIFIED; 071 } 072 }; 073 074 public enum DigitalSignatureSupport { 075 UNSPECIFIED, LEVEL_1, LEVEL_2, LEVEL_3; 076 077 public static DigitalSignatureSupport valueOf(int level) { 078 switch(level) { 079 case 1: 080 return LEVEL_1; 081 case 2: 082 return LEVEL_2; 083 case 3: 084 return LEVEL_3; 085 } 086 return UNSPECIFIED; 087 } 088 }; 089 090 public enum ElementCoercion { 091 NO, YES, UNSPECIFIED; 092 093 public static ElementCoercion valueOf(int i) { 094 switch(i) { 095 case 0: 096 return NO; 097 case 1: 098 return YES; 099 } 100 return UNSPECIFIED; 101 } 102 }; 103 104 @ConfigurableProperty(name="dcmStorageConformance", 105 enumRepresentation = ConfigurableProperty.EnumRepresentation.ORDINAL, 106 defaultValue = "3" 107 ) 108 private LevelOfSupport levelOfSupport = LevelOfSupport.UNSPECIFIED; 109 110 @ConfigurableProperty(name="dcmDigitalSignatureSupport", 111 enumRepresentation = ConfigurableProperty.EnumRepresentation.ORDINAL, 112 defaultValue = "0" 113 ) 114 private DigitalSignatureSupport digitalSignatureSupport = DigitalSignatureSupport.UNSPECIFIED; 115 116 @ConfigurableProperty(name="dcmDataElementCoercion", 117 enumRepresentation = ConfigurableProperty.EnumRepresentation.ORDINAL, 118 defaultValue = "2" 119 ) 120 private ElementCoercion elementCoercion = ElementCoercion.UNSPECIFIED; 121 122 public StorageOptions() { 123 this(LevelOfSupport.UNSPECIFIED, 124 DigitalSignatureSupport.UNSPECIFIED, 125 ElementCoercion.UNSPECIFIED); 126 } 127 128 public StorageOptions(LevelOfSupport levelOfSupport, 129 DigitalSignatureSupport levelOfDigitalSignatureSupport, 130 ElementCoercion getElementCoercion) { 131 this.levelOfSupport = levelOfSupport; 132 this.digitalSignatureSupport = levelOfDigitalSignatureSupport; 133 this.elementCoercion = getElementCoercion; 134 } 135 136 public final LevelOfSupport getLevelOfSupport() { 137 return levelOfSupport; 138 } 139 140 public final void setLevelOfSupport(LevelOfSupport levelOfSupport) { 141 this.levelOfSupport = levelOfSupport; 142 } 143 144 public final DigitalSignatureSupport getDigitalSignatureSupport() { 145 return digitalSignatureSupport; 146 } 147 148 public final void setDigitalSignatureSupport( 149 DigitalSignatureSupport digitalSignatureSupport) { 150 this.digitalSignatureSupport = digitalSignatureSupport; 151 } 152 153 public final ElementCoercion getElementCoercion() { 154 return elementCoercion; 155 } 156 157 public final void setElementCoercion(ElementCoercion elementCoercion) { 158 this.elementCoercion = elementCoercion; 159 } 160 161 public byte[] toExtendedNegotiationInformation() { 162 return new byte[] { 163 (byte) levelOfSupport.ordinal(), 0, 164 (byte) digitalSignatureSupport.ordinal(), 0, 165 (byte) elementCoercion.ordinal(), 0 }; 166 } 167 168 public static StorageOptions valueOf(ExtendedNegotiation extNeg) { 169 return new StorageOptions( 170 LevelOfSupport.valueOf(extNeg.getField(0, (byte) 3)), 171 DigitalSignatureSupport.valueOf(extNeg.getField(2, (byte) 0)), 172 ElementCoercion.valueOf(extNeg.getField(4, (byte) 2))); 173 } 174 175 @Override 176 public int hashCode() { 177 return levelOfSupport.hashCode() 178 + digitalSignatureSupport.hashCode() 179 + elementCoercion.hashCode(); 180 } 181 182 @Override 183 public boolean equals(Object o) { 184 if (o == this) 185 return true; 186 187 if (!(o instanceof StorageOptions)) 188 return false; 189 190 StorageOptions other = (StorageOptions) o; 191 return levelOfSupport == other.levelOfSupport 192 && digitalSignatureSupport == other.digitalSignatureSupport 193 && elementCoercion == other.elementCoercion; 194 } 195 196 @Override 197 public String toString() { 198 return "StorageOptions[levelOfSupport=" + levelOfSupport.ordinal() 199 + ", digitalSignatureSupport=" + digitalSignatureSupport.ordinal() 200 + ", elementCoercion=" + elementCoercion.ordinal() + "]"; 201 } 202 203 public StorageOptions copy() { 204 return new StorageOptions(getLevelOfSupport(),getDigitalSignatureSupport(),getElementCoercion()); 205 } 206}