001
014
015 package com.liferay.portal.osgi;
016
017 import com.liferay.portal.kernel.log.Log;
018 import com.liferay.portal.kernel.log.LogFactoryUtil;
019
020 import org.osgi.framework.FrameworkEvent;
021
022
025 public class FrameworkListener extends BaseListener
026 implements org.osgi.framework.FrameworkListener {
027
028 public void frameworkEvent(FrameworkEvent frameworkEvent) {
029 try {
030 int type = frameworkEvent.getType();
031
032 if (type == FrameworkEvent.ERROR) {
033 frameworkEventError(frameworkEvent);
034 }
035 else if (type == FrameworkEvent.INFO) {
036 frameworkEventInfo(frameworkEvent);
037 }
038 else if (type == FrameworkEvent.PACKAGES_REFRESHED) {
039 frameworkEventPackagesRefreshed(frameworkEvent);
040 }
041 else if (type == FrameworkEvent.STARTED) {
042 frameworkEventStarted(frameworkEvent);
043 }
044 else if (type == FrameworkEvent.STARTLEVEL_CHANGED) {
045 frameworkEventStartLevelChanged(frameworkEvent);
046 }
047 else if (type == FrameworkEvent.STOPPED) {
048 frameworkEventStopped(frameworkEvent);
049 }
050 else if (type == FrameworkEvent.STOPPED_BOOTCLASSPATH_MODIFIED) {
051 frameworkEventStoppedBootClasspathModified(frameworkEvent);
052 }
053 else if (type == FrameworkEvent.STOPPED_UPDATE) {
054 frameworkEventStoppedUpdate(frameworkEvent);
055 }
056 else if (type == FrameworkEvent.WAIT_TIMEDOUT) {
057 frameworkEventWaitTimedout(frameworkEvent);
058 }
059 else if (type == FrameworkEvent.WARNING) {
060 frameworkEventWarning(frameworkEvent);
061 }
062 }
063 catch (Exception e) {
064 _log.error(e, e);
065 }
066 }
067
068 protected void frameworkEventError(FrameworkEvent frameworkEvent)
069 throws Exception {
070
071 _log.error(
072 getLogMessage("[ERROR]", frameworkEvent.getSource()),
073 frameworkEvent.getThrowable());
074 }
075
076 protected void frameworkEventInfo(FrameworkEvent frameworkEvent)
077 throws Exception {
078
079 if (!_log.isInfoEnabled()) {
080 return;
081 }
082
083 _log.info(getLogMessage("[INFO]", frameworkEvent.getSource()));
084 }
085
086 protected void frameworkEventPackagesRefreshed(
087 FrameworkEvent frameworkEvent)
088 throws Exception {
089
090 if (!_log.isInfoEnabled()) {
091 return;
092 }
093
094 _log.info(
095 getLogMessage("[PACKAGES_REFRESHED]", frameworkEvent.getSource()));
096 }
097
098 protected void frameworkEventStarted(FrameworkEvent frameworkEvent)
099 throws Exception {
100
101 if (!_log.isInfoEnabled()) {
102 return;
103 }
104
105 _log.info(getLogMessage("[STARTED]", frameworkEvent.getSource()));
106 }
107
108 protected void frameworkEventStartLevelChanged(
109 FrameworkEvent frameworkEvent)
110 throws Exception {
111
112 if (!_log.isInfoEnabled()) {
113 return;
114 }
115
116 _log.info(
117 getLogMessage("[STARTLEVEL_CHANGED]", frameworkEvent.getSource()));
118 }
119
120 protected void frameworkEventStopped(FrameworkEvent frameworkEvent)
121 throws Exception {
122
123 if (!_log.isInfoEnabled()) {
124 return;
125 }
126
127 _log.info(getLogMessage("[STOPPED]", frameworkEvent.getSource()));
128 }
129
130 protected void frameworkEventStoppedBootClasspathModified(
131 FrameworkEvent frameworkEvent)
132 throws Exception {
133
134 if (!_log.isInfoEnabled()) {
135 return;
136 }
137
138 _log.info(
139 getLogMessage(
140 "[STOPPED_BOOTCLASSPATH_MODIFIED]",
141 frameworkEvent.getSource()));
142 }
143
144 protected void frameworkEventStoppedUpdate(FrameworkEvent frameworkEvent)
145 throws Exception {
146
147 if (!_log.isInfoEnabled()) {
148 return;
149 }
150
151 _log.info(
152 getLogMessage("[STOPPED_UPDATE]", frameworkEvent.getSource()));
153 }
154
155 protected void frameworkEventWaitTimedout(FrameworkEvent frameworkEvent)
156 throws Exception {
157
158 if (!_log.isInfoEnabled()) {
159 return;
160 }
161
162 _log.info(getLogMessage("[WAIT_TIMEDOUT]", frameworkEvent.getSource()));
163 }
164
165 protected void frameworkEventWarning(FrameworkEvent frameworkEvent)
166 throws Exception {
167
168 if (!_log.isInfoEnabled()) {
169 return;
170 }
171
172 _log.info(getLogMessage("[WARNING]", frameworkEvent.getSource()));
173 }
174
175 private static Log _log = LogFactoryUtil.getLog(FrameworkListener.class);
176
177 }