001/* 002 * Copyright 2010 Red Hat, Inc. 003 * Red Hat licenses this file to you under the Apache License, version 004 * 2.0 (the "License"); you may not use this file except in compliance 005 * with the License. You may obtain a copy of the License at 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * Unless required by applicable law or agreed to in writing, software 008 * distributed under the License is distributed on an "AS IS" BASIS, 009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 010 * implied. See the License for the specific language governing 011 * permissions and limitations under the License. 012 */ 013 014package org.hornetq.api.jms.management; 015 016import org.hornetq.utils.json.JSONArray; 017import org.hornetq.utils.json.JSONObject; 018 019/** 020 * A JMSConnectionInfo 021 * 022 * @author jmesnil 023 * 024 * 025 */ 026public class JMSConnectionInfo 027{ 028 029 // Constants ----------------------------------------------------- 030 031 // Attributes ---------------------------------------------------- 032 033 private final String connectionID; 034 035 private final String clientAddress; 036 037 private final long creationTime; 038 039 private final String clientID; 040 041 private final String username; 042 043 044 // Static -------------------------------------------------------- 045 046 public static JMSConnectionInfo[] from(final String jsonString) throws Exception 047 { 048 JSONArray array = new JSONArray(jsonString); 049 JMSConnectionInfo[] infos = new JMSConnectionInfo[array.length()]; 050 for (int i = 0; i < array.length(); i++) 051 { 052 JSONObject obj = array.getJSONObject(i); 053 String cid = obj.isNull("clientID") ? null : obj.getString("clientID"); 054 String uname = obj.isNull("principal") ? null : obj.getString("principal"); 055 056 JMSConnectionInfo info = new JMSConnectionInfo(obj.getString("connectionID"), 057 obj.getString("clientAddress"), 058 obj.getLong("creationTime"), 059 cid, 060 uname); 061 infos[i] = info; 062 } 063 return infos; 064 } 065 066 // Constructors -------------------------------------------------- 067 068 private JMSConnectionInfo(final String connectionID, 069 final String clientAddress, 070 final long creationTime, 071 final String clientID, 072 final String username) 073 { 074 this.connectionID = connectionID; 075 this.clientAddress = clientAddress; 076 this.creationTime = creationTime; 077 this.clientID = clientID; 078 this.username = username; 079 } 080 081 // Public -------------------------------------------------------- 082 083 public String getConnectionID() 084 { 085 return connectionID; 086 } 087 088 public String getClientAddress() 089 { 090 return clientAddress; 091 } 092 093 public long getCreationTime() 094 { 095 return creationTime; 096 } 097 098 public String getClientID() 099 { 100 return clientID; 101 } 102 103 public String getUsername() 104 { 105 return username; 106 } 107 108 // Package protected --------------------------------------------- 109 110 // Protected ----------------------------------------------------- 111 112 // Private ------------------------------------------------------- 113 114 // Inner classes ------------------------------------------------- 115 116}