001 /*
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements. See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership. The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License. You may obtain a copy of the License at
010 *
011 * http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing,
014 * software distributed under the License is distributed on an
015 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
016 * KIND, either express or implied. See the License for the
017 * specific language governing permissions and limitations
018 * under the License.
019 *
020 */
021 package org.apache.qpid.management.configuration;
022
023 import java.util.UUID;
024
025 import org.apache.qpid.management.Messages;
026 import org.apache.qpid.transport.util.Logger;
027
028 /**
029 * Parser used for building broker connection data settings.
030 * The corresponding section on the configuration file is :
031 *
032 <broker>
033 <host>192.168.148.131</host>
034 <port>5672</port>
035 <virtual-host>test</virtual-host>
036 <user>guest</user>
037 <password>guest</password>
038 <max-pool-capacity>4</max-pool-capacity>
039 <initial-pool-capacity>4</initial-pool-capacity>
040 <max-wait-timeout>-1</max-wait-timeout>
041 </broker>
042 *
043 * @author Andrea Gazzarini
044 */
045 class BrokerConnectionDataParser implements IParser
046 {
047 private final static Logger LOGGER = Logger.get(Configuration.class);
048 private BrokerConnectionData _connectionData = new BrokerConnectionData();
049 private String _currentValue;
050
051 /**
052 * Callback : the given value is the text content of the current node.
053 */
054 public void setCurrrentAttributeValue (String value)
055 {
056 this._currentValue = value;
057 }
058
059 /**
060 * Callback: each time the end of an element is reached this method is called.
061 * It's here that the built mapping is injected into the configuration.
062 * <broker>
063 <host>192.168.61.130</host>
064 <port>5673</port>
065 <virtual-host>test</virtual-host>
066 <user>andrea</user>
067 <password>andrea</password>
068 </broker>
069 */
070 public void setCurrentAttributeName (String name)
071 {
072 switch (Tag.get(name))
073 {
074 case HOST:
075 {
076 _connectionData.setHost(_currentValue);
077 break;
078 }
079 case PORT :
080 {
081 _connectionData.setPort(_currentValue);
082 break;
083 }
084 case VIRTUAL_HOST:
085 {
086 _connectionData.setVirtualHost(_currentValue);
087 break;
088 }
089 case USER :
090 {
091 _connectionData.setUsername(_currentValue);
092 break;
093 }
094 case MAX_POOL_CAPACITY:
095 {
096 _connectionData.setMaxPoolCapacity (_currentValue);
097 break;
098 }
099 case INITIAL_POOL_CAPACITY:
100 {
101 _connectionData.setInitialPoolCapacity(_currentValue);
102 break;
103 }
104 case MAX_WAIT_TIMEOUT:
105 {
106 _connectionData.setMaxWaitTimeout(_currentValue);
107 break;
108 }
109 case PASSWORD:
110 {
111 _connectionData.setPassword(_currentValue);
112 break;
113 }
114 case BROKER:
115 {
116 try
117 {
118 Configuration.getInstance().addBrokerConnectionData(getUUId(),_connectionData);
119 } catch(Exception exception)
120 {
121 LOGGER.error(exception, Messages.QMAN_100007_UNABLE_TO_CONNECT_WITH_BROKER, _connectionData);
122 }
123 _connectionData = new BrokerConnectionData();
124 break;
125 }
126 }
127 }
128
129 /**
130 * Gets an uuid in order to associate current connection data with a broker.
131 * @return
132 */
133 UUID getUUId(){
134 return UUID.randomUUID();
135 }
136 }
|