Author: reto
Date: Fri Jun 4 17:51:12 2010
New Revision: 951505
URL: http://svn.apache.org/viewvc?rev=951505&view=rev
Log:
made log-output more compact, shifted some from INFO to DEBUG
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/prefixmanager/TriaxrsPrefixManager.java
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java?rev=951505&r1=951504&r2=951505&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/JaxRsHandler.java
Fri Jun 4 17:51:12 2010
@@ -182,7 +182,7 @@ public class JaxRsHandler implements Han
}
protected void bindBundlePrefixManager(BundlePrefixManager
prefixManager) {
- logger.info("Binding bundle prefix manager");
+ logger.debug("Binding bundle prefix manager");
configLock.writeLock().lock();
try {
this.prefixManager = prefixManager;
@@ -193,7 +193,7 @@ public class JaxRsHandler implements Han
}
protected void unbindBundlePrefixManager(BundlePrefixManager
prefixManager) {
- logger.info("Unbinding bundle prefix manager");
+ logger.debug("Unbinding bundle prefix manager");
configLock.writeLock().lock();
try {
this.prefixManager = null;
@@ -209,7 +209,7 @@ public class JaxRsHandler implements Han
* The new JAX-RS component to bind.
*/
protected void bindComponent(ServiceReference serviceReference) {
- logger.info("Bind component of bundle {}", serviceReference
+ logger.debug("Bind component of bundle {}", serviceReference
.getBundle().getSymbolicName());
configLock.writeLock().lock();
try {
@@ -251,8 +251,8 @@ public class JaxRsHandler implements Han
component);
}
} else {
- logger.info("Register resource {} to path {}",
component.getClass().getName(), pathPrefix);
- logger.info("Path value {} ", path.value());
+ logger.info("Register resource {} to path {}{}",
+ new
Object[]{component.getClass().getName(), pathPrefix, path.value()});
collectHttpMethods(component.getClass());
final RootResourceDescriptor descriptor = new
RootResourceDescriptor(
clazz, component, pathPrefix +
path.value(), providers);
Modified:
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/prefixmanager/TriaxrsPrefixManager.java
URL:
http://svn.apache.org/viewvc/incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/prefixmanager/TriaxrsPrefixManager.java?rev=951505&r1=951504&r2=951505&view=diff
==============================================================================
---
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/prefixmanager/TriaxrsPrefixManager.java
(original)
+++
incubator/clerezza/trunk/org.apache.clerezza.parent/org.apache.clerezza.triaxrs/org.apache.clerezza.triaxrs/src/main/java/org/apache/clerezza/triaxrs/prefixmanager/TriaxrsPrefixManager.java
Fri Jun 4 17:51:12 2010
@@ -16,230 +16,230 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.clerezza.triaxrs.prefixmanager;
-
-import java.io.IOException;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import org.osgi.framework.Bundle;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.component.ComponentContext;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.apache.clerezza.jaxrs.extensions.prefixmanager.BundlePrefixManager;
-import org.apache.clerezza.triaxrs.Constants;
-
-/**
- * This class provides a function to get the appropriate path prefix for a
given
- * bundle.
- *
- * @author mir
- *
- * @scr.component
name="org.apache.clerezza.triaxrs.prefixmanager.TriaxrsPrefixManager"
immediate="true"
- * @scr.service
interface="org.apache.clerezza.jaxrs.extensions.prefixmanager.BundlePrefixManager"
- * @scr.reference name="configurationAdmin" cardinality="0..1" policy="dynamic"
- * interface="org.osgi.service.cm.ConfigurationAdmin"
- *
- */
-public class TriaxrsPrefixManager implements BundlePrefixManager {
-
- /**
- * Service property header, which contains the mappings between bundle
- * symbolic names and bundle prefixes.
- *
- * @scr.property name="mappings" values.name="key" values.value="foo"
- * values.name="path" values.value="bar"
- * description="Contains the mappings between bundle symbolic names and
custom prefixes"
- */
- public static final String TRIAXRS_MAPPINGS = "mappings";
-
- /**
- * Service property header which specifies, if the default path prefix
of
- * bundles is used. If the header is not set, the value "true" is
assumed.
- *
- * @scr.property type="Boolean" value="true"
- * description="Specifies if the default path prefix of bundles is
used."
- */
- public static final String TRIAXRS_USE_DEFAULT_PREFIXES =
"UseDefaultPrefix";
-
- /**
- * Service property header which specifies if the custom path prefix of
- * bundles is used. If the header is not set, the value "true" is
assumed.
- *
- * @scr.property type="Boolean" value="true"
- * description="Specifies if the custom path prefix of bundles is used."
- */
- public static final String TRIAXRS_USE_CUSTOM_PREFIXES =
"UseCustomPrefix";
-
- private Logger logger =
LoggerFactory.getLogger(TriaxrsPrefixManager.class);
-
- private ConfigurationAdmin configAdmin;
-
- private ComponentContext componentContext;
-
- /**
- * Return the appropriate path prefix for the given bundle
- *
- * @param bundle
- * @return
- */
- @Override
- public String getPrefix(Bundle bundle) {
- String prefix = "";
-
- String defaultPrefix = getDefaultPrefix(bundle);
- this.addDefaultMapping(bundle.getSymbolicName(), defaultPrefix);
- String customPrefix = getCustomPrefix(bundle);
-
- if (useDefaultPrefixes()) {
- prefix = defaultPrefix;
- }
-
- if (useCustomPrefixes()) {
- if (customPrefix != null) {
- prefix = customPrefix;
- } else {
- prefix = defaultPrefix;
- }
- }
-
- prefix = prefix.trim();
-
- if(prefix.endsWith("/")) {
- prefix = prefix.
- substring(0, prefix.length() - 1);
- }
- return prefix;
- }
-
- private Dictionary getProperties() {
- return componentContext.getProperties();
- }
-
- private Dictionary getMappings() {
- return parseMappings((String[])
getProperties().get(TRIAXRS_MAPPINGS));
- }
-
- /**
- * Adds the mapping to the configurations properties if there is no
mapping
- * already
- *
- * @param symbolicName
- * @param prefix
- */
- private void addDefaultMapping(String symbolicName, String prefix) {
- if (this.configAdmin != null) {
-
- try {
- Configuration configuration = configAdmin
-
.getConfiguration(TriaxrsPrefixManager.class.getName());
- Dictionary properties =
configuration.getProperties();
- if (properties == null) {
- properties = new Hashtable();
- }
- Dictionary mappings = parseMappings((String[])
properties
- .get(TRIAXRS_MAPPINGS));
- if (mappings.get(symbolicName) != null) {
- return;
- }
- mappings.put(symbolicName, prefix);
- String[] newMappings =
unparseMappings(mappings);
- properties.put(TRIAXRS_MAPPINGS, newMappings);
- configuration.update(properties);
- } catch (IOException e) {
- logger.warn("Unable to update configuration:
{}", e.toString());
- }
- } else {
- logger.warn("Cannot add prefix mapping. Configuration
Admin is missing");
- }
- }
-
- private String getDefaultPrefix(Bundle bundle) {
- Dictionary<String, String> headers = bundle.getHeaders();
- String defaultPrefix =
headers.get(Constants.TRIAXRS_PATH_PREFIX);
- if (defaultPrefix == null) {
- defaultPrefix = "";
- }
- return defaultPrefix;
- }
-
- private String getCustomPrefix(Bundle bundle) {
- return (String)
this.getMappings().get(bundle.getSymbolicName());
- }
-
- private boolean useCustomPrefixes() {
- Boolean boolUseCustom = ((Boolean) this.getProperties().get(
- TRIAXRS_USE_CUSTOM_PREFIXES));
- return boolUseCustom == null || boolUseCustom;
- }
-
- private boolean useDefaultPrefixes() {
- Boolean boolUseDefault = ((Boolean) this.getProperties().get(
- TRIAXRS_USE_DEFAULT_PREFIXES));
- return boolUseDefault == null || boolUseDefault;
- }
-
- public static Dictionary<String, String> parseMappings(String[]
mappings) {
- Dictionary<String, String> result = new Hashtable<String,
String>();
- if (mappings == null) {
- return result;
- }
- for (String mapping : mappings) {
- String[] parts = mapping.split("=");
- if (parts.length == 2) {
- result.put(parts[0], parts[1]);
- } else if (parts.length == 1) {
- result.put(parts[0], "");
- }
- }
- return result;
- }
-
- public static String[] unparseMappings(Dictionary mappings) {
- Enumeration keys = mappings.keys();
- String[] result = new String[mappings.size()];
- int index = 0;
-
- while (keys.hasMoreElements()) {
- String key = (String) keys.nextElement();
- result[index] = key + "="
- + formatPrefix((String)
mappings.get(key));
- index++;
- }
- return result;
- }
-
- private static String formatPrefix(String prefix) {
- prefix = prefix.trim();
- if (!prefix.startsWith("/")) {
- prefix = "/" + prefix;
- }
-
- if (!prefix.endsWith("/")) {
- prefix += "/";
- }
- return prefix;
- }
-
- protected void bindConfigurationAdmin(ConfigurationAdmin configAdmin) {
- logger.info("Binding configuration admin");
- this.configAdmin = configAdmin;
- }
-
- protected void unbindConfigurationAdmin(ConfigurationAdmin configAdmin)
{
- logger.info("Unbinding configuration admin");
- }
-
- /**
- * The activate method is called when SCR activates the component
- * configuration
- *
- * @param componentContext
- */
- protected void activate(ComponentContext componentContext) {
- this.componentContext = componentContext;
- }
-}
+package org.apache.clerezza.triaxrs.prefixmanager;
+
+import java.io.IOException;
+import java.util.Dictionary;
+import java.util.Enumeration;
+import java.util.Hashtable;
+
+import org.osgi.framework.Bundle;
+import org.osgi.service.cm.Configuration;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.osgi.service.component.ComponentContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.clerezza.jaxrs.extensions.prefixmanager.BundlePrefixManager;
+import org.apache.clerezza.triaxrs.Constants;
+
+/**
+ * This class provides a function to get the appropriate path prefix for a
given
+ * bundle.
+ *
+ * @author mir
+ *
+ * @scr.component
name="org.apache.clerezza.triaxrs.prefixmanager.TriaxrsPrefixManager"
immediate="true"
+ * @scr.service
interface="org.apache.clerezza.jaxrs.extensions.prefixmanager.BundlePrefixManager"
+ * @scr.reference name="configurationAdmin" cardinality="0..1" policy="dynamic"
+ * interface="org.osgi.service.cm.ConfigurationAdmin"
+ *
+ */
+public class TriaxrsPrefixManager implements BundlePrefixManager {
+
+ /**
+ * Service property header, which contains the mappings between bundle
+ * symbolic names and bundle prefixes.
+ *
+ * @scr.property name="mappings" values.name="key" values.value="foo"
+ * values.name="path" values.value="bar"
+ * description="Contains the mappings between bundle symbolic names and
custom prefixes"
+ */
+ public static final String TRIAXRS_MAPPINGS = "mappings";
+
+ /**
+ * Service property header which specifies, if the default path prefix
of
+ * bundles is used. If the header is not set, the value "true" is
assumed.
+ *
+ * @scr.property type="Boolean" value="true"
+ * description="Specifies if the default path prefix of bundles is
used."
+ */
+ public static final String TRIAXRS_USE_DEFAULT_PREFIXES =
"UseDefaultPrefix";
+
+ /**
+ * Service property header which specifies if the custom path prefix of
+ * bundles is used. If the header is not set, the value "true" is
assumed.
+ *
+ * @scr.property type="Boolean" value="true"
+ * description="Specifies if the custom path prefix of bundles is used."
+ */
+ public static final String TRIAXRS_USE_CUSTOM_PREFIXES =
"UseCustomPrefix";
+
+ private Logger logger =
LoggerFactory.getLogger(TriaxrsPrefixManager.class);
+
+ private ConfigurationAdmin configAdmin;
+
+ private ComponentContext componentContext;
+
+ /**
+ * Return the appropriate path prefix for the given bundle
+ *
+ * @param bundle
+ * @return
+ */
+ @Override
+ public String getPrefix(Bundle bundle) {
+ String prefix = "";
+
+ String defaultPrefix = getDefaultPrefix(bundle);
+ this.addDefaultMapping(bundle.getSymbolicName(), defaultPrefix);
+ String customPrefix = getCustomPrefix(bundle);
+
+ if (useDefaultPrefixes()) {
+ prefix = defaultPrefix;
+ }
+
+ if (useCustomPrefixes()) {
+ if (customPrefix != null) {
+ prefix = customPrefix;
+ } else {
+ prefix = defaultPrefix;
+ }
+ }
+
+ prefix = prefix.trim();
+
+ if(prefix.endsWith("/")) {
+ prefix = prefix.
+ substring(0, prefix.length() - 1);
+ }
+ return prefix;
+ }
+
+ private Dictionary getProperties() {
+ return componentContext.getProperties();
+ }
+
+ private Dictionary getMappings() {
+ return parseMappings((String[])
getProperties().get(TRIAXRS_MAPPINGS));
+ }
+
+ /**
+ * Adds the mapping to the configurations properties if there is no
mapping
+ * already
+ *
+ * @param symbolicName
+ * @param prefix
+ */
+ private void addDefaultMapping(String symbolicName, String prefix) {
+ if (this.configAdmin != null) {
+
+ try {
+ Configuration configuration = configAdmin
+
.getConfiguration(TriaxrsPrefixManager.class.getName());
+ Dictionary properties =
configuration.getProperties();
+ if (properties == null) {
+ properties = new Hashtable();
+ }
+ Dictionary mappings = parseMappings((String[])
properties
+ .get(TRIAXRS_MAPPINGS));
+ if (mappings.get(symbolicName) != null) {
+ return;
+ }
+ mappings.put(symbolicName, prefix);
+ String[] newMappings =
unparseMappings(mappings);
+ properties.put(TRIAXRS_MAPPINGS, newMappings);
+ configuration.update(properties);
+ } catch (IOException e) {
+ logger.warn("Unable to update configuration:
{}", e.toString());
+ }
+ } else {
+ logger.warn("Cannot add prefix mapping. Configuration
Admin is missing");
+ }
+ }
+
+ private String getDefaultPrefix(Bundle bundle) {
+ Dictionary<String, String> headers = bundle.getHeaders();
+ String defaultPrefix =
headers.get(Constants.TRIAXRS_PATH_PREFIX);
+ if (defaultPrefix == null) {
+ defaultPrefix = "";
+ }
+ return defaultPrefix;
+ }
+
+ private String getCustomPrefix(Bundle bundle) {
+ return (String)
this.getMappings().get(bundle.getSymbolicName());
+ }
+
+ private boolean useCustomPrefixes() {
+ Boolean boolUseCustom = ((Boolean) this.getProperties().get(
+ TRIAXRS_USE_CUSTOM_PREFIXES));
+ return boolUseCustom == null || boolUseCustom;
+ }
+
+ private boolean useDefaultPrefixes() {
+ Boolean boolUseDefault = ((Boolean) this.getProperties().get(
+ TRIAXRS_USE_DEFAULT_PREFIXES));
+ return boolUseDefault == null || boolUseDefault;
+ }
+
+ public static Dictionary<String, String> parseMappings(String[]
mappings) {
+ Dictionary<String, String> result = new Hashtable<String,
String>();
+ if (mappings == null) {
+ return result;
+ }
+ for (String mapping : mappings) {
+ String[] parts = mapping.split("=");
+ if (parts.length == 2) {
+ result.put(parts[0], parts[1]);
+ } else if (parts.length == 1) {
+ result.put(parts[0], "");
+ }
+ }
+ return result;
+ }
+
+ public static String[] unparseMappings(Dictionary mappings) {
+ Enumeration keys = mappings.keys();
+ String[] result = new String[mappings.size()];
+ int index = 0;
+
+ while (keys.hasMoreElements()) {
+ String key = (String) keys.nextElement();
+ result[index] = key + "="
+ + formatPrefix((String)
mappings.get(key));
+ index++;
+ }
+ return result;
+ }
+
+ private static String formatPrefix(String prefix) {
+ prefix = prefix.trim();
+ if (!prefix.startsWith("/")) {
+ prefix = "/" + prefix;
+ }
+
+ if (!prefix.endsWith("/")) {
+ prefix += "/";
+ }
+ return prefix;
+ }
+
+ protected void bindConfigurationAdmin(ConfigurationAdmin configAdmin) {
+ logger.debug("Binding configuration admin");
+ this.configAdmin = configAdmin;
+ }
+
+ protected void unbindConfigurationAdmin(ConfigurationAdmin configAdmin)
{
+ logger.debug("Unbinding configuration admin");
+ }
+
+ /**
+ * The activate method is called when SCR activates the component
+ * configuration
+ *
+ * @param componentContext
+ */
+ protected void activate(ComponentContext componentContext) {
+ this.componentContext = componentContext;
+ }
+}