Source code: com/obinary/cms/beans/SubscriberInfo.java
1 /**
2 *
3 * Magnolia and its source-code is licensed under the LGPL.
4 * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5 * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6 * you are required to provide proper attribution to obinary.
7 * If you reproduce or distribute the document without making any substantive modifications to its content,
8 * please use the following attribution line:
9 *
10 * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11 *
12 * */
13
14
15
16
17
18 package com.obinary.cms.beans;
19
20
21 import com.obinary.cms.core.HierarchyManager;
22 import com.obinary.cms.core.Content;
23 import com.obinary.cms.core.Container;
24
25 import javax.jcr.ElementNotFoundException;
26 import javax.jcr.RepositoryException;
27 import java.util.Iterator;
28 import java.util.Hashtable;
29 import java.util.Enumeration;
30
31
32 /**
33 * User: sameercharles
34 * Date: Apr 28, 2003
35 * Time: 11:20:59 AM
36 * @author Sameer Charles
37 * @version 1.0
38 */
39
40
41
42 public class SubscriberInfo {
43
44
45 private static final String START_PAGE = "/subscribers";
46
47 private static Iterator ipList;
48 private static Hashtable cachedContent;
49 private static String senderAddress;
50 private static String senderProtocol;
51
52 private String address;
53 private String protocol;
54
55
56 /**
57 * constructor
58 */
59 public SubscriberInfo() {
60
61 }
62
63
64
65 /**
66 * constructor Initializes and cache content
67 *
68 * @param init
69 * @throws javax.jcr.ElementNotFoundException
70 * @throws javax.jcr.RepositoryException
71 */
72 public SubscriberInfo(boolean init) throws ElementNotFoundException, RepositoryException {
73 SubscriberInfo.init();
74 }
75
76
77
78 /**
79 * <p>reads listener config from the config repository and caches its content
80 * in to the hash table</p>
81 *
82 * @throws javax.jcr.ElementNotFoundException
83 * @throws javax.jcr.RepositoryException
84 */
85 public static void init() throws ElementNotFoundException, RepositoryException {
86 HierarchyManager hm = new HierarchyManager();
87 hm.setStartPage(ConfigLoader.configRoot);
88 Content startPage = hm.getPage(START_PAGE);
89 try {
90 SubscriberInfo.ipList = startPage.getContainerList("SubscriberConfig").getChildren().iterator();
91 SubscriberInfo.cacheContent();
92 } catch (Exception e) {}
93 try {
94 Container container = startPage.getContainer("SenderConfig");
95 SubscriberInfo.senderAddress = container.getAtom("address").getString();
96 SubscriberInfo.senderProtocol = container.getAtom("protocol").getString();
97 } catch (RepositoryException re) {}
98 }
99
100
101
102 /**
103 * <p>Cache listener content from the config repository</p>
104 *
105 */
106 private static void cacheContent() {
107 SubscriberInfo.cachedContent = new Hashtable();
108 while (SubscriberInfo.ipList.hasNext()) {
109 Container c = (Container) SubscriberInfo.ipList.next();
110 SubscriberInfo si = new SubscriberInfo();
111 si.address = c.getAtom("address").getString();
112 si.protocol = c.getAtom("protocol").getString();
113 SubscriberInfo.cachedContent.put(c.getName(),si);
114 }
115 SubscriberInfo.ipList = null;
116 }
117
118
119
120 /**
121 * <p>get list of all configured ip
122 * </p>
123 * @return Enumeration
124 * @throws Exception
125 */
126 public static Enumeration getList() throws Exception {
127 return SubscriberInfo.cachedContent.elements();
128 }
129
130
131
132 /**
133 * @return String sender address as configured in SenderConfig
134 */
135 public static String getSenderAddress() {
136 return SubscriberInfo.senderAddress;
137 }
138
139
140
141 /**
142 * @return String sender protocol as configured in SenderConfig
143 */
144 public static String getSenderProtocol() {
145 return SubscriberInfo.senderProtocol;
146 }
147
148
149
150 /**
151 * @return address as string
152 * */
153 public String getAddress() {
154 return this.address;
155 }
156
157
158
159 /**
160 * @return protocol
161 * */
162 public String getProtocol() {
163 return this.protocol;
164 }
165
166
167
168
169 }