001package ca.uhn.fhir.rest.server; 002 003/* 004 * #%L 005 * HAPI FHIR - Server Framework 006 * %% 007 * Copyright (C) 2014 - 2019 University Health Network 008 * %% 009 * Licensed under the Apache License, Version 2.0 (the "License"); 010 * you may not use this file except in compliance with the License. 011 * You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, software 016 * distributed under the License is distributed on an "AS IS" BASIS, 017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 018 * See the License for the specific language governing permissions and 019 * limitations under the License. 020 * #L% 021 */ 022 023import java.util.ArrayList; 024import java.util.List; 025 026import ca.uhn.fhir.rest.api.server.RequestDetails; 027import ca.uhn.fhir.rest.server.method.BaseMethodBinding; 028 029/** 030 * Created by dsotnikov on 2/25/2014. 031 */ 032public class ResourceBinding { 033 034 private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ResourceBinding.class); 035 036 private String resourceName; 037 private List<BaseMethodBinding<?>> myMethodBindings = new ArrayList<>(); 038 039 public ResourceBinding() { 040 } 041 042 public ResourceBinding(String resourceName, List<BaseMethodBinding<?>> methods) { 043 this.resourceName = resourceName; 044 this.myMethodBindings = methods; 045 } 046 047 public BaseMethodBinding<?> getMethod(RequestDetails theRequest) { 048 if (null == myMethodBindings) { 049 ourLog.warn("No methods exist for resource: {}", resourceName); 050 return null; 051 } 052 053 ourLog.debug("Looking for a handler for {}", theRequest); 054 for (BaseMethodBinding<?> rm : myMethodBindings) { 055 if (rm.incomingServerRequestMatchesMethod(theRequest)) { 056 ourLog.debug("Handler {} matches", rm); 057 return rm; 058 } 059 ourLog.trace("Handler {} does not match", rm); 060 } 061 return null; 062 } 063 064 public String getResourceName() { 065 return resourceName; 066 } 067 068 public void setResourceName(String resourceName) { 069 this.resourceName = resourceName; 070 } 071 072 public List<BaseMethodBinding<?>> getMethodBindings() { 073 return myMethodBindings; 074 } 075 076 public void setMethods(List<BaseMethodBinding<?>> methods) { 077 this.myMethodBindings = methods; 078 } 079 080 public void addMethod(BaseMethodBinding<?> method) { 081 this.myMethodBindings.add(method); 082 } 083 084 @Override 085 public boolean equals(Object o) { 086 if (!(o instanceof ResourceBinding)) 087 return false; 088 return resourceName.equals(((ResourceBinding) o).getResourceName()); 089 } 090 091 @Override 092 public int hashCode() { 093 return 0; 094 } 095 096}