001package ca.uhn.fhir.rest.server; 002 003/* 004 * #%L 005 * HAPI FHIR - Core Library 006 * %% 007 * Copyright (C) 2014 - 2016 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.method.BaseMethodBinding; 027import ca.uhn.fhir.rest.method.RequestDetails; 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<?>> methods = new ArrayList<BaseMethodBinding<?>>(); 038 039 public ResourceBinding() { 040 } 041 042 public ResourceBinding(String resourceName, List<BaseMethodBinding<?>> methods) { 043 this.resourceName = resourceName; 044 this.methods = methods; 045 } 046 047 public BaseMethodBinding<?> getMethod(RequestDetails theRequest) { 048 if (null == methods) { 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 : methods) { 055 if (rm.incomingServerRequestMatchesMethod(theRequest)) { 056 ourLog.debug("Handler {} matches", rm); 057 return rm; 058 } else { 059 ourLog.trace("Handler {} does not match", rm); 060 } 061 } 062 return null; 063 } 064 065 public String getResourceName() { 066 return resourceName; 067 } 068 069 public void setResourceName(String resourceName) { 070 this.resourceName = resourceName; 071 } 072 073 public List<BaseMethodBinding<?>> getMethodBindings() { 074 return methods; 075 } 076 077 public void setMethods(List<BaseMethodBinding<?>> methods) { 078 this.methods = methods; 079 } 080 081 public void addMethod(BaseMethodBinding<?> method) { 082 this.methods.add(method); 083 } 084 085 @Override 086 public boolean equals(Object o) { 087 if (!(o instanceof ResourceBinding)) 088 return false; 089 return resourceName.equals(((ResourceBinding) o).getResourceName()); 090 } 091 092 @Override 093 public int hashCode() { 094 return 0; 095 } 096 097}