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 019package org.apache.oozie.jms; 020 021import java.util.Properties; 022 023import org.apache.oozie.util.XLog; 024 025public class JMSConnectionInfo { 026 027 private String jndiPropertiesString; 028 private Properties props; 029 030 /** 031 * Create a JMSConnectionInfo 032 * @param jndiPropertiesString JNDI properties with # as key value delimiter and ; as properties delimiter 033 */ 034 public JMSConnectionInfo(String jndiPropertiesString) { 035 this.jndiPropertiesString = jndiPropertiesString; 036 initializeProps(); 037 } 038 039 private void initializeProps() { 040 this.props = new Properties(); 041 String[] propArr = jndiPropertiesString.split(";"); 042 for (String pair : propArr) { 043 String[] kV = pair.split("#"); 044 if (kV.length > 1) { 045 props.put(kV[0].trim(), kV[1].trim()); 046 } 047 else { 048 XLog.getLog(getClass()).warn("Unformatted properties. Expected key#value : " + pair); 049 props = null; 050 } 051 } 052 if (props.isEmpty()) { 053 props = null; 054 } 055 } 056 057 /** 058 * Get JNDI properties to establish a JMS connection 059 * @return JNDI properties 060 */ 061 public Properties getJNDIProperties() { 062 return props; 063 } 064 065 /** 066 * Return JNDI properties string 067 * @return JNDI properties string 068 */ 069 public String getJNDIPropertiesString() { 070 return jndiPropertiesString; 071 } 072 073 @Override 074 public int hashCode() { 075 return 31 + ((jndiPropertiesString == null) ? 0 : jndiPropertiesString.hashCode()); 076 } 077 078 @Override 079 public boolean equals(Object obj) { 080 if (this == obj) 081 return true; 082 if (obj == null) 083 return false; 084 if (getClass() != obj.getClass()) 085 return false; 086 JMSConnectionInfo other = (JMSConnectionInfo) obj; 087 if (jndiPropertiesString == null) { 088 if (other.jndiPropertiesString != null) 089 return false; 090 } 091 else if (!jndiPropertiesString.equals(other.jndiPropertiesString)) 092 return false; 093 return true; 094 } 095 096 @Override 097 public String toString() { 098 return "JMSConnectionInfo [jndiProperties=" + jndiPropertiesString + "]"; 099 } 100 101}