001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 package org.apache.oozie.jms; 019 020 import java.util.Properties; 021 022 import org.apache.oozie.util.XLog; 023 024 public class JMSConnectionInfo { 025 026 private String jndiPropertiesString; 027 private Properties props; 028 029 /** 030 * Create a JMSConnectionInfo 031 * @param jndiPropertiesString JNDI properties with # as key value delimiter and ; as properties delimiter 032 */ 033 public JMSConnectionInfo(String jndiPropertiesString) { 034 this.jndiPropertiesString = jndiPropertiesString; 035 initializeProps(); 036 } 037 038 private void initializeProps() { 039 this.props = new Properties(); 040 String[] propArr = jndiPropertiesString.split(";"); 041 for (String pair : propArr) { 042 String[] kV = pair.split("#"); 043 if (kV.length > 1) { 044 props.put(kV[0].trim(), kV[1].trim()); 045 } 046 else { 047 XLog.getLog(getClass()).warn("Unformatted properties. Expected key#value : " + pair); 048 props = null; 049 } 050 } 051 if (props.isEmpty()) { 052 props = null; 053 } 054 } 055 056 /** 057 * Get JNDI properties to establish a JMS connection 058 * @return JNDI properties 059 */ 060 public Properties getJNDIProperties() { 061 return props; 062 } 063 064 /** 065 * Return JNDI properties string 066 * @return JNDI properties string 067 */ 068 public String getJNDIPropertiesString() { 069 return jndiPropertiesString; 070 } 071 072 @Override 073 public int hashCode() { 074 return 31 + ((jndiPropertiesString == null) ? 0 : jndiPropertiesString.hashCode()); 075 } 076 077 @Override 078 public boolean equals(Object obj) { 079 if (this == obj) 080 return true; 081 if (obj == null) 082 return false; 083 if (getClass() != obj.getClass()) 084 return false; 085 JMSConnectionInfo other = (JMSConnectionInfo) obj; 086 if (jndiPropertiesString == null) { 087 if (other.jndiPropertiesString != null) 088 return false; 089 } 090 else if (!jndiPropertiesString.equals(other.jndiPropertiesString)) 091 return false; 092 return true; 093 } 094 095 @Override 096 public String toString() { 097 return "JMSConnectionInfo [jndiProperties=" + jndiPropertiesString + "]"; 098 } 099 100 }