KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > util > JmsLogAppender


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.util;
19
20 import java.net.URISyntaxException JavaDoc;
21
22 import org.apache.activemq.ActiveMQConnection;
23
24 import javax.jms.Connection JavaDoc;
25 import javax.jms.JMSException JavaDoc;
26
27 /**
28  * A JMS 1.1 log4j appender which uses ActiveMQ by default and does not require any JNDI
29  * configurations
30  *
31  * @version $Revision: 449919 $
32  */

33 public class JmsLogAppender extends JmsLogAppenderSupport {
34     private String JavaDoc uri = "tcp://localhost:61616";
35     private String JavaDoc userName;
36     private String JavaDoc password;
37
38     public JmsLogAppender() {
39     }
40
41     public String JavaDoc getUri() {
42         return uri;
43     }
44
45     public void setUri(String JavaDoc uri) {
46         this.uri = uri;
47     }
48
49     public String JavaDoc getUserName() {
50         return userName;
51     }
52
53     public void setUserName(String JavaDoc userName) {
54         this.userName = userName;
55     }
56
57     public String JavaDoc getPassword() {
58         return password;
59     }
60
61     public void setPassword(String JavaDoc password) {
62         this.password = password;
63     }
64
65     protected Connection createConnection() throws JMSException JavaDoc {
66         if (userName != null) {
67             try {
68                 return ActiveMQConnection.makeConnection(userName, password, uri);
69             } catch (URISyntaxException JavaDoc e) {
70                 throw new JMSException JavaDoc("Unable to connect to a broker using " +
71                         "userName: \'" + userName +
72                         "\' password \'" + password +
73                         "\' uri \'" + uri + "\' :: error - " +
74                         e.getMessage());
75             }
76         }
77         else {
78             try {
79                 return ActiveMQConnection.makeConnection(uri);
80             } catch (URISyntaxException JavaDoc e) {
81                 throw new JMSException JavaDoc("Unable to connect to a broker using " +
82                         "uri \'" + uri + "\' :: error - " +
83                         e.getMessage());
84             }
85         }
86     }
87 }
88
Popular Tags