001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (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 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.camel.component.properties; 018 019import org.apache.camel.util.ObjectHelper; 020 021public class PropertiesLocation { 022 private final String resolver; 023 private final String path; 024 private final boolean optional; 025 026 public PropertiesLocation(String location) { 027 // make sure to trim as people may use new lines when configuring using XML 028 // and do this in the setter as Spring/Blueprint resolves placeholders before 029 // Camel is being started 030 location = location.trim(); 031 032 int idx = location.indexOf(':'); 033 if (idx != -1) { 034 this.resolver = location.substring(0, idx); 035 location = location.substring(idx + 1); 036 } else { 037 this.resolver = "classpath"; 038 } 039 040 idx = location.lastIndexOf(';'); 041 if (idx != -1) { 042 this.optional = ObjectHelper.after(location.substring(idx + 1), "optional=", Boolean::valueOf).orElse(false); 043 location = location.substring(0, idx); 044 } else { 045 this.optional = false; 046 } 047 048 this.path = location; 049 } 050 051 public PropertiesLocation(String resolver, String path) { 052 this(resolver, path, false); 053 } 054 055 public PropertiesLocation(String resolver, String path, Boolean optional) { 056 this.resolver = resolver; 057 this.path = path; 058 this.optional = optional; 059 } 060 061 // ***************************** 062 // Getters 063 // ***************************** 064 065 public String getResolver() { 066 return resolver; 067 } 068 069 public String getPath() { 070 return path; 071 } 072 073 public boolean isOptional() { 074 return optional; 075 } 076 077 // ***************************** 078 // Equals/HashCode/ToString 079 // ***************************** 080 081 @Override 082 public boolean equals(Object o) { 083 if (this == o) { 084 return true; 085 } 086 if (o == null || getClass() != o.getClass()) { 087 return false; 088 } 089 090 PropertiesLocation location = (PropertiesLocation) o; 091 092 if (optional != location.optional) { 093 return false; 094 } 095 if (resolver != null ? !resolver.equals(location.resolver) : location.resolver != null) { 096 return false; 097 } 098 return path != null ? path.equals(location.path) : location.path == null; 099 } 100 101 @Override 102 public int hashCode() { 103 int result = resolver != null ? resolver.hashCode() : 0; 104 result = 31 * result + (path != null ? path.hashCode() : 0); 105 result = 31 * result + (optional ? 1 : 0); 106 return result; 107 } 108 109 @Override 110 public String toString() { 111 return "PropertiesLocation{" 112 + "resolver='" + resolver + '\'' 113 + ", path='" + path + '\'' 114 + ", optional=" + optional 115 + '}'; 116 } 117}