    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
    014    package org.hornetq.api.jms.management;
    015
    016    import org.hornetq.utils.json.JSONArray;
    017    import org.hornetq.utils.json.JSONException;
    018    import org.hornetq.utils.json.JSONObject;
    019
    020    /**
    021     * A JMSSessionInfo
    022     *
    023     * @author howard
    024     *
    025     *
    026     */
    027    public class JMSSessionInfo
    028    {
    029       private final String sessionID;
    030
    031       private final long creationTime;
    032
    033       public JMSSessionInfo(String sessionID, long creationTime)
    034       {
    035          this.sessionID = sessionID;
    036          this.creationTime = creationTime;
    037       }
    038
    039       public static JMSSessionInfo[] from(final String jsonString) throws JSONException
    040       {
    041          JSONArray array = new JSONArray(jsonString);
    042          JMSSessionInfo[] infos = new JMSSessionInfo[array.length()];
    043          for (int i = 0; i < array.length(); i++)
    044          {
    045             JSONObject obj = array.getJSONObject(i);
    046
    047             JMSSessionInfo info = new JMSSessionInfo(obj.getString("sessionID"),
    048                                                            obj.getLong("creationTime"));
    049             infos[i] = info;
    050          }
    051          return infos;
    052       }
    053
    054       public String getSessionID()
    055       {
    056          return sessionID;
    057       }
    058
    059       public long getCreationTime()
    060       {
    061          return creationTime;
    062       }
    063    }