001/* 002 * **** BEGIN LICENSE BLOCK ***** 003 * Version: MPL 1.1/GPL 2.0/LGPL 2.1 004 * 005 * The contents of this file are subject to the Mozilla Public License Version 006 * 1.1 (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * http://www.mozilla.org/MPL/ 009 * 010 * Software distributed under the License is distributed on an "AS IS" basis, 011 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 012 * for the specific language governing rights and limitations under the 013 * License. 014 * 015 * The Original Code is part of dcm4che, an implementation of DICOM(TM) in 016 * Java(TM), hosted at https://github.com/gunterze/dcm4che. 017 * 018 * The Initial Developer of the Original Code is 019 * Agfa Healthcare. 020 * Portions created by the Initial Developer are Copyright (C) 2014 021 * the Initial Developer. All Rights Reserved. 022 * 023 * Contributor(s): 024 * See @authors listed below 025 * 026 * Alternatively, the contents of this file may be used under the terms of 027 * either the GNU General Public License Version 2 or later (the "GPL"), or 028 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 029 * in which case the provisions of the GPL or the LGPL are applicable instead 030 * of those above. If you wish to allow use of your version of this file only 031 * under the terms of either the GPL or the LGPL, and not to allow others to 032 * use your version of this file under the terms of the MPL, indicate your 033 * decision by deleting the provisions above and replace them with the notice 034 * and other provisions required by the GPL or the LGPL. If you do not delete 035 * the provisions above, a recipient may use your version of this file under 036 * the terms of any one of the MPL, the GPL or the LGPL. 037 * 038 * ***** END LICENSE BLOCK ***** 039 */ 040package org.dcm4che3.conf.dicom; 041 042import org.dcm4che3.conf.core.api.Path; 043import org.dcm4che3.conf.core.util.PathPattern; 044 045import java.util.HashMap; 046import java.util.Map; 047 048/** 049 * Single source for all the DicomConfiguration-related xpaths 050 * 051 * @author Roman K 052 */ 053public enum DicomPath { 054 055 DeviceNameByAEName, 056 DeviceNameByAENameAlias, 057 AllDeviceNames, 058 AllAETitles, 059 DeviceNameByHL7AppName, 060 AllHL7AppNames, 061 ConfigRoot, 062 TCGroups, 063 AllTCsOfAllAEsWithTCGroupExt, 064 DeviceNameByAEUUID, 065 DeviceNameByUUID, 066 DeviceUUIDByAnyUUID, 067 DeviceByNameForWrite, 068 DeviceByNameForRead, 069 AETransferCapabilities; 070 071 public static final Path TC_GROUPS_PATH = new Path("dicomConfigurationRoot","globalConfiguration","dcmTransferCapabilities"); 072 public static final Path CONFIG_ROOT_PATH = new Path("dicomConfigurationRoot"); 073 074 075 public static final Map<DicomPath, String> PATHS = new HashMap<DicomPath, String>(); 076 public static final Map<DicomPath, PathPattern> PATH_PATTERNS = new HashMap<DicomPath, PathPattern>(); 077 078 static { 079 // search 080 PATHS.put(/**************/AllAETitles, "/dicomConfigurationRoot/dicomDevicesRoot/*/dicomNetworkAE/*/dicomAETitle | /dicomConfigurationRoot/dicomDevicesRoot/*/dicomNetworkAE/*/dcmAETitleAliases"); 081 082 PATHS.put(/*******/DeviceNameByAEName, "/dicomConfigurationRoot/dicomDevicesRoot/*[dicomNetworkAE[@name='{aeName}']]/dicomDeviceName"); 083 PATHS.put(/**/DeviceNameByAENameAlias, "/dicomConfigurationRoot/dicomDevicesRoot/*[dicomNetworkAE[*/dcmAETitleAliases='{aeNameAlias}']]/dicomDeviceName"); 084 085 PATHS.put(/***********/AllDeviceNames, "/dicomConfigurationRoot/dicomDevicesRoot/*/dicomDeviceName"); 086 PATHS.put(/***********/AllHL7AppNames, "/dicomConfigurationRoot/dicomDevicesRoot/*/deviceExtensions/HL7DeviceExtension/hl7Apps/*/hl7ApplicationName"); 087 PATHS.put(/***/DeviceNameByHL7AppName, "/dicomConfigurationRoot/dicomDevicesRoot/*[deviceExtensions/HL7DeviceExtension/hl7Apps/*[hl7ApplicationName='{hl7AppName}']]/dicomDeviceName"); 088 PATHS.put(/*******/DeviceNameByAEUUID, "/dicomConfigurationRoot/dicomDevicesRoot/*[dicomNetworkAE/*[_.uuid='{aeUUID}']]/dicomDeviceName"); 089 PATHS.put(/*********/DeviceNameByUUID, "/dicomConfigurationRoot/dicomDevicesRoot/*[_.uuid='{deviceUUID}']/dicomDeviceName"); 090 091 // Get device UUID of a device that contains (or itself is) an object with the specified UUID 092 PATHS.put(/******/DeviceUUIDByAnyUUID, "/dicomConfigurationRoot/dicomDevicesRoot/*[.//_.uuid='{UUID}']/_.uuid"); 093 094 // single-result getNode (also can be used to store nodes) 095 PATHS.put(/***************/ConfigRoot, "/dicomConfigurationRoot"); 096 PATHS.put(/*****/DeviceByNameForWrite, "/dicomConfigurationRoot/dicomDevicesRoot[@name='{deviceName}']"); 097 098 PATHS.put(/******/DeviceByNameForRead, "/dicomConfigurationRoot/dicomDevicesRoot/{deviceName}"); 099 100 // Transfer capabilities 101 PATHS.put(/*****************/TCGroups, TC_GROUPS_PATH.toSimpleEscapedXPath()); 102 PATHS.put(AllTCsOfAllAEsWithTCGroupExt, "dicomNetworkAE/*[aeExtensions/TCGroupConfigAEExtension]/dcmTransferCapability"); 103 PATHS.put(/****/AETransferCapabilities, "/dcmTransferCapability"); 104 105 106 for (Map.Entry<DicomPath, String> entry : PATHS.entrySet()) { 107 PATH_PATTERNS.put(entry.getKey(), new PathPattern(entry.getValue())); 108 } 109 } 110 111 public static Path devicePath(String name) { 112 return new Path("dicomConfigurationRoot", "dicomDevicesRoot", name); 113 } 114 115 public static void validateDevicePath(Path path) { 116 if (path.getPathItems().size()>3 || 117 !path.getPathItems().get(0).equals("dicomConfigurationRoot") || 118 !path.getPathItems().get(1).equals("dicomDevicesRoot")) { 119 throw new IllegalArgumentException("Unexpected path:" + path); 120 } 121 } 122 123 /** 124 * Starts chaining 125 * 126 * @param paramName 127 * @param value 128 * @return 129 */ 130 public PathPattern.PathCreator set(String paramName, String value) { 131 return PATH_PATTERNS.get(this).set(paramName, value); 132 } 133 134 135 public PathPattern.PathParser parse(String path) { 136 return PATH_PATTERNS.get(this).parse(path); 137 } 138 139 public PathPattern.PathParser parseIfMatches(String path) { 140 return PATH_PATTERNS.get(this).parseIfMatches(path); 141 } 142 143 /** 144 * Gets path as is 145 * 146 * @return 147 */ 148 public String path() { 149 return PATHS.get(this); 150 } 151 152}