You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/12/12 18:54:59 UTC
svn commit: r1550459 - in /karaf/trunk: ./
assemblies/features/enterprise/src/main/feature/ jndi/ jndi/command/
jndi/command/src/ jndi/command/src/main/ jndi/command/src/main/java/
jndi/command/src/main/java/org/ jndi/command/src/main/java/org/apache/ ...
Author: jbonofre
Date: Thu Dec 12 17:54:58 2013
New Revision: 1550459
URL: http://svn.apache.org/r1550459
Log:
[KARAF-2549] Add new enterprise JNDI service and commands
Added:
karaf/trunk/jndi/
karaf/trunk/jndi/command/
karaf/trunk/jndi/command/NOTICE
karaf/trunk/jndi/command/pom.xml
karaf/trunk/jndi/command/src/
karaf/trunk/jndi/command/src/main/
karaf/trunk/jndi/command/src/main/java/
karaf/trunk/jndi/command/src/main/java/org/
karaf/trunk/jndi/command/src/main/java/org/apache/
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/AliasCommand.java
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/BindCommand.java
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/CreateCommand.java
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/DeleteCommand.java
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/JndiCommandSupport.java
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/ListCommand.java
karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/UnbindCommand.java
karaf/trunk/jndi/command/src/main/resources/
karaf/trunk/jndi/command/src/main/resources/OSGI-INF/
karaf/trunk/jndi/command/src/main/resources/OSGI-INF/blueprint/
karaf/trunk/jndi/command/src/main/resources/OSGI-INF/blueprint/jndi-command.xml
karaf/trunk/jndi/command/src/main/resources/OSGI-INF/bundle.info
karaf/trunk/jndi/core/
karaf/trunk/jndi/core/NOTICE
karaf/trunk/jndi/core/pom.xml
karaf/trunk/jndi/core/src/
karaf/trunk/jndi/core/src/main/
karaf/trunk/jndi/core/src/main/java/
karaf/trunk/jndi/core/src/main/java/org/
karaf/trunk/jndi/core/src/main/java/org/apache/
karaf/trunk/jndi/core/src/main/java/org/apache/karaf/
karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/
karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiMBean.java
karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiService.java
karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/KarafInitialContextFactory.java
karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/
karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiMBeanImpl.java
karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiServiceImpl.java
karaf/trunk/jndi/core/src/main/resources/
karaf/trunk/jndi/core/src/main/resources/OSGI-INF/
karaf/trunk/jndi/core/src/main/resources/OSGI-INF/blueprint/
karaf/trunk/jndi/core/src/main/resources/OSGI-INF/blueprint/jndi-core.xml
karaf/trunk/jndi/core/src/main/resources/OSGI-INF/bundle.info
karaf/trunk/jndi/pom.xml
Modified:
karaf/trunk/assemblies/features/enterprise/src/main/feature/feature.xml
karaf/trunk/pom.xml
Modified: karaf/trunk/assemblies/features/enterprise/src/main/feature/feature.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/assemblies/features/enterprise/src/main/feature/feature.xml?rev=1550459&r1=1550458&r2=1550459&view=diff
==============================================================================
--- karaf/trunk/assemblies/features/enterprise/src/main/feature/feature.xml (original)
+++ karaf/trunk/assemblies/features/enterprise/src/main/feature/feature.xml Thu Dec 12 17:54:58 2013
@@ -47,13 +47,21 @@
<bundle start-level='30'>mvn:org.apache.aries.jpa/org.apache.aries.jpa.container.context/${aries.jpa.container.context.version}</bundle>
</feature>
- <feature name='jndi' description='OSGi Service Registry JNDI access' version='${aries.jndi.version}' resolver='(obr)'>
- <details>JNDI support provided by Apache Aries JNDI ${aries.jndi.version}</details>
+ <feature name='jms' description='Provide tooling about JMS' version='${project.version}' resolver='(obr)'>
+ <details>JMS support providing service, commands, and MBean.</details>
+
+ </feature>
+
+ <feature name='jndi' description='OSGi Service Registry JNDI access' version='${project.version}' resolver='(obr)'>
+ <details>JNDI support provided by Apache Aries JNDI ${aries.jndi.version}, including additional service, commands, and MBean.</details>
+ <bundle start-level='30'>mvn:org.apache.xbean/xbean-naming/${xbean.version}</bundle>
+ <bundle start-level='30'>mvn:org.apache.karaf.jndi/org.apache.karaf.jndi.core/${project.version}</bundle>
<bundle start-level='30'>mvn:org.apache.aries.jndi/org.apache.aries.jndi.api/${aries.jndi.api.version}</bundle>
<bundle start-level='30'>mvn:org.apache.aries.jndi/org.apache.aries.jndi.core/${aries.jndi.version}</bundle>
<bundle start-level='30'>mvn:org.apache.aries.jndi/org.apache.aries.jndi.rmi/${aries.jndi.version}</bundle>
<bundle start-level='30'>mvn:org.apache.aries.jndi/org.apache.aries.jndi.url/${aries.jndi.version}</bundle>
<bundle start-level='30'>mvn:org.apache.aries.jndi/org.apache.aries.jndi.legacy.support/${aries.jndi.version}</bundle>
+ <bundle>mvn:org.apache.karaf.jndi/org.apache.karaf.jndi.command/${project.version}</bundle>
</feature>
<feature name='application-without-isolation' description='Provide EBA archive support' version='${aries.application.version}'>
Added: karaf/trunk/jndi/command/NOTICE
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/NOTICE?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/NOTICE (added)
+++ karaf/trunk/jndi/command/NOTICE Thu Dec 12 17:54:58 2013
@@ -0,0 +1,71 @@
+Apache Karaf
+Copyright 2010-2013 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2010).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+OW2 (http://www.ow2.org/).
+Licensed under the BSD License.
+
+This product includes software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+Eclipse Foundation (http://www.eclipse.org/).
+Licensed under the EPL.
+
+This product includes software written by
+Antony Lesuisse.
+Licensed under Public Domain.
+
+
+II. Used Software
+
+This product uses software developed at
+FUSE Source (http://www.fusesource.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+AOP Alliance (http://aopalliance.sourceforge.net/).
+Licensed under the Public Domain.
+
+This product uses software developed at
+Tanuki Software (http://www.tanukisoftware.com/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+Jasypt (http://jasypt.sourceforge.net/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+JLine (http://jline.sourceforge.net).
+Licensed under the BSD License.
+
+This product uses software developed at
+SLF4J (http://www.slf4j.org/).
+Licensed under the MIT License.
+
+This product uses software developed at
+SpringSource (http://www.springsource.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+
+
+III. License Summary
+- Apache License 2.0
+- BSD License
+- EPL License
+- MIT License
Added: karaf/trunk/jndi/command/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/pom.xml?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/pom.xml (added)
+++ karaf/trunk/jndi/command/pom.xml Thu Dec 12 17:54:58 2013
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf.jndi</groupId>
+ <artifactId>jndi</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.karaf.jndi.command</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: JNDI :: Command</name>
+ <description>This bundle provides a set of commands to manipulate JNDI service.</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.karaf.jndi</groupId>
+ <artifactId>org.apache.karaf.jndi.core</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.console</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.shell</groupId>
+ <artifactId>org.apache.karaf.shell.table</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.info</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>!*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/AliasCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/AliasCommand.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/AliasCommand.java (added)
+++ karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/AliasCommand.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.command;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+
+@Command(scope = "jndi", name = "alias", description = "Create a JNDI alias on a given name.")
+public class AliasCommand extends JndiCommandSupport {
+
+ @Argument(index = 0, name = "name", description = "The JNDI name", required = true, multiValued = false)
+ String name;
+
+ @Argument(index = 1, name = "alias", description = "The JNDI alias", required = true, multiValued = false)
+ String alias;
+
+ public Object doExecute() throws Exception {
+ getJndiService().alias(name, alias);
+ return null;
+ }
+
+}
Added: karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/BindCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/BindCommand.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/BindCommand.java (added)
+++ karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/BindCommand.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.command;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+
+@Command(scope = "jndi", name = "bind", description = "Bind an OSGi service in the JNDI context")
+public class BindCommand extends JndiCommandSupport {
+
+ @Argument(index = 0, name = "service", description = "The ID of the OSGi service to bind", required = true, multiValued = false)
+ Long serviceId;
+
+ @Argument(index = 1, name = "name", description = "The JNDI name to bind the OSGi service", required = true, multiValued = false)
+ String name;
+
+ public Object doExecute() throws Exception {
+ this.getJndiService().bind(serviceId, name);
+ return null;
+ }
+
+}
Added: karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/CreateCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/CreateCommand.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/CreateCommand.java (added)
+++ karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/CreateCommand.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.command;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+
+@Command(scope = "jndi", name = "create", description = "Create a new JNDI sub-context.")
+public class CreateCommand extends JndiCommandSupport {
+
+ @Argument(index = 0, name = "context", description = "The JNDI sub-context name", required = true, multiValued = false)
+ String context;
+
+ public Object doExecute() throws Exception {
+ this.getJndiService().create(context);
+ return null;
+ }
+
+}
Added: karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/DeleteCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/DeleteCommand.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/DeleteCommand.java (added)
+++ karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/DeleteCommand.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.command;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+
+@Command(scope = "jndi", name = "delete", description = "Delete a JNDI sub-context.")
+public class DeleteCommand extends JndiCommandSupport {
+
+ @Argument(index = 0, name = "context", description = "The JNDI sub-context name", required = true, multiValued = false)
+ String context;
+
+ public Object doExecute() throws Exception {
+ this.getJndiService().delete(context);
+ return null;
+ }
+
+}
Added: karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/JndiCommandSupport.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/JndiCommandSupport.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/JndiCommandSupport.java (added)
+++ karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/JndiCommandSupport.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.command;
+
+import org.apache.karaf.jndi.JndiService;
+import org.apache.karaf.shell.console.OsgiCommandSupport;
+
+public abstract class JndiCommandSupport extends OsgiCommandSupport {
+
+ private JndiService jndiService;
+
+ public JndiService getJndiService() {
+ return jndiService;
+ }
+
+ public void setJndiService(JndiService jndiService) {
+ this.jndiService = jndiService;
+ }
+
+ public abstract Object doExecute() throws Exception;
+
+}
Added: karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/ListCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/ListCommand.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/ListCommand.java (added)
+++ karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/ListCommand.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.command;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+import org.apache.karaf.shell.table.ShellTable;
+
+import java.util.Map;
+
+@Command(scope = "jndi", name = "list", description = "List the JNDI names.")
+public class ListCommand extends JndiCommandSupport {
+
+ @Argument(index = 0, name = "context", description = "The JNDI context to display the names", required = false, multiValued = false)
+ String context;
+
+ public Object doExecute() throws Exception {
+ ShellTable table = new ShellTable();
+
+ table.column("JNDI Name");
+ table.column("Class Name");
+
+ Map<String, String> names;
+ if (context == null) {
+ names = this.getJndiService().list();
+ } else {
+ names = this.getJndiService().list(context);
+ }
+
+ for (String name : names.keySet()) {
+ table.addRow().addContent(name, names.get(name));
+ }
+
+ table.print(System.out);
+
+ return null;
+ }
+
+}
Added: karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/UnbindCommand.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/UnbindCommand.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/UnbindCommand.java (added)
+++ karaf/trunk/jndi/command/src/main/java/org/apache/karaf/jndi/command/UnbindCommand.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.command;
+
+import org.apache.karaf.shell.commands.Argument;
+import org.apache.karaf.shell.commands.Command;
+
+@Command(scope = "jndi", name = "unbind", description = "Unbind a JNDI name.")
+public class UnbindCommand extends JndiCommandSupport {
+
+ @Argument(index = 0, name = "name", description = "The JNDI name to unbind", required = true, multiValued = false)
+ String name;
+
+ public Object doExecute() throws Exception {
+ getJndiService().unbind(name);
+ return null;
+ }
+
+}
Added: karaf/trunk/jndi/command/src/main/resources/OSGI-INF/blueprint/jndi-command.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/resources/OSGI-INF/blueprint/jndi-command.xml?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/resources/OSGI-INF/blueprint/jndi-command.xml (added)
+++ karaf/trunk/jndi/command/src/main/resources/OSGI-INF/blueprint/jndi-command.xml Thu Dec 12 17:54:58 2013
@@ -0,0 +1,55 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version
+ 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the
+ License.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" default-activation="lazy">
+
+ <reference id="jndiService" interface="org.apache.karaf.jndi.JndiService" />
+
+ <command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.1.0">
+ <command>
+ <action class="org.apache.karaf.jndi.command.AliasCommand">
+ <property name="jndiService" ref="jndiService" />
+ </action>
+ </command>
+ <command>
+ <action class="org.apache.karaf.jndi.command.ListCommand">
+ <property name="jndiService" ref="jndiService" />
+ </action>
+ </command>
+ <command>
+ <action class="org.apache.karaf.jndi.command.CreateCommand">
+ <property name="jndiService" ref="jndiService"/>
+ </action>
+ </command>
+ <command>
+ <action class="org.apache.karaf.jndi.command.DeleteCommand">
+ <property name="jndiService" ref="jndiService"/>
+ </action>
+ </command>
+ <command>
+ <action class="org.apache.karaf.jndi.command.BindCommand">
+ <property name="jndiService" ref="jndiService"/>
+ </action>
+ </command>
+ <command>
+ <action class="org.apache.karaf.jndi.command.UnbindCommand">
+ <property name="jndiService" ref="jndiService" />
+ </action>
+ </command>
+ </command-bundle>
+
+</blueprint>
\ No newline at end of file
Added: karaf/trunk/jndi/command/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/command/src/main/resources/OSGI-INF/bundle.info?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/command/src/main/resources/OSGI-INF/bundle.info (added)
+++ karaf/trunk/jndi/command/src/main/resources/OSGI-INF/bundle.info Thu Dec 12 17:54:58 2013
@@ -0,0 +1,25 @@
+h1. Synopsis
+
+${project.name}
+
+${project.description}
+
+Maven URL:
+[mvn:${project.groupId}/${project.artifactId}/${project.version}]
+
+h1. Description
+
+This bundle provides the shell commands to manipulate the JNDI service.
+
+The following commands are available:
+
+* jndi:alias
+* jndi:bind
+* jndi:create
+* jndi:delete
+* jndi:list
+* jndi:unbind
+
+h1. See also
+
+JNDI - section of the Karaf User Guide
\ No newline at end of file
Added: karaf/trunk/jndi/core/NOTICE
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/NOTICE?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/NOTICE (added)
+++ karaf/trunk/jndi/core/NOTICE Thu Dec 12 17:54:58 2013
@@ -0,0 +1,71 @@
+Apache Karaf
+Copyright 2010-2013 The Apache Software Foundation
+
+
+I. Included Software
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+The OSGi Alliance (http://www.osgi.org/).
+Copyright (c) OSGi Alliance (2000, 2010).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+OW2 (http://www.ow2.org/).
+Licensed under the BSD License.
+
+This product includes software developed at
+OPS4J (http://www.ops4j.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software developed at
+Eclipse Foundation (http://www.eclipse.org/).
+Licensed under the EPL.
+
+This product includes software written by
+Antony Lesuisse.
+Licensed under Public Domain.
+
+
+II. Used Software
+
+This product uses software developed at
+FUSE Source (http://www.fusesource.org/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+AOP Alliance (http://aopalliance.sourceforge.net/).
+Licensed under the Public Domain.
+
+This product uses software developed at
+Tanuki Software (http://www.tanukisoftware.com/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+Jasypt (http://jasypt.sourceforge.net/).
+Licensed under the Apache License 2.0.
+
+This product uses software developed at
+JLine (http://jline.sourceforge.net).
+Licensed under the BSD License.
+
+This product uses software developed at
+SLF4J (http://www.slf4j.org/).
+Licensed under the MIT License.
+
+This product uses software developed at
+SpringSource (http://www.springsource.org/).
+Licensed under the Apache License 2.0.
+
+This product includes software from http://www.json.org.
+Copyright (c) 2002 JSON.org
+
+
+III. License Summary
+- Apache License 2.0
+- BSD License
+- EPL License
+- MIT License
Added: karaf/trunk/jndi/core/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/pom.xml?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/pom.xml (added)
+++ karaf/trunk/jndi/core/pom.xml Thu Dec 12 17:54:58 2013
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf.jndi</groupId>
+ <artifactId>jndi</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>org.apache.karaf.jndi.core</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Karaf :: JNDI :: Core</name>
+ <description>This bundle provides core implementation of the JNDI management service.</description>
+
+ <properties>
+ <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-naming</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.aries.proxy</groupId>
+ <artifactId>org.apache.aries.proxy.api</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>${project.basedir}/src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>**/*.info</include>
+ </includes>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <configuration>
+ <instructions>
+ <Export-Package>
+ org.apache.karaf.jndi
+ </Export-Package>
+ <Private-Package>
+ org.apache.karaf.jndi.internal
+ </Private-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiMBean.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiMBean.java (added)
+++ karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiMBean.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi;
+
+import javax.management.MBeanException;
+import java.util.Map;
+
+/**
+ * JNDI Service MBean
+ */
+public interface JndiMBean {
+
+ /**
+ * Get a map of JNDI names/class names (as attribute).
+ *
+ * @return the MBean attribute containing the map of names/class names.
+ * @throws MBeanException
+ */
+ public Map<String, String> getNames() throws MBeanException;
+
+ /**
+ * Get a map of JNDI names/class names children of a given base context.
+ *
+ * @param context the base context.
+ * @return the map of names/class names.
+ * @throws MBeanException
+ */
+ public Map<String, String> getNames(String context) throws MBeanException;
+
+ /**
+ * Create a JNDI sub-context.
+ *
+ * @param context the JNDI sub-context name.
+ * @throws MBeanException
+ */
+ public void create(String context) throws MBeanException;
+
+ /**
+ * Delete a JNDI sub-context.
+ *
+ * @param context the JNDI sub-context name.
+ * @throws MBeanException
+ */
+ public void delete(String context) throws MBeanException;
+
+ /**
+ * Create another JNDI name (alias) for a given one.
+ *
+ * @param name the "source" JNDI name.
+ * @param alias the JNDI alias name.
+ * @throws MBeanException
+ */
+ public void alias(String name, String alias) throws MBeanException;
+
+ /**
+ * Bind an OSGi service with a JNDI name.
+ *
+ * @param serviceId the OSGi service id (service.id property on the service, created by the framework).
+ * @param name the JNDI name.
+ * @throws MBeanException
+ */
+ public void bind(Long serviceId, String name) throws MBeanException;
+
+ /**
+ * Unbind a given JNDI name.
+ *
+ * @param name the JNDI name.
+ * @throws MBeanException
+ */
+ public void unbind(String name) throws MBeanException;
+
+}
Added: karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiService.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiService.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiService.java (added)
+++ karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/JndiService.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi;
+
+import java.util.Map;
+
+/**
+ * JNDI Service.
+ */
+public interface JndiService {
+
+ /**
+ * List the current JNDI names (with the bound class name).
+ *
+ * @return the JNDI names.
+ * @throws Exception
+ */
+ Map<String, String> list() throws Exception;
+
+ /**
+ * List the current JNDI name in the given context.
+ *
+ * @param context the JNDI context.
+ * @return the JNDI names in the context.
+ * @throws Exception
+ */
+ Map<String, String> list(String context) throws Exception;
+
+ /**
+ * Create a sub-context.
+ *
+ * @param context the new sub-context name to create.
+ * @throws Exception
+ */
+ void create(String context) throws Exception;
+
+ /**
+ * Delete a sub-context.
+ *
+ * @param context the sub-context name to delete.
+ * @throws Exception
+ */
+ void delete(String context) throws Exception;
+
+ /**
+ * Create an alias on a given JNDI name.
+ *
+ * @param name the JNDI name.
+ * @param alias the alias.
+ * @throws Exception
+ */
+ void alias(String name, String alias) throws Exception;
+
+ /**
+ * Bind a given OSGi service to a JNDI name.
+ *
+ * @param serviceId the OSGi service ID.
+ * @param name the JNDI name.
+ * @throws Exception
+ */
+ void bind(long serviceId, String name) throws Exception;
+
+ /**
+ * Unbind an existing name.
+ *
+ * @param name the JNDI name to unbind.
+ * @throws Exception
+ */
+ void unbind(String name) throws Exception;
+
+}
Added: karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/KarafInitialContextFactory.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/KarafInitialContextFactory.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/KarafInitialContextFactory.java (added)
+++ karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/KarafInitialContextFactory.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi;
+
+import org.apache.xbean.naming.context.WritableContext;
+import org.apache.xbean.naming.global.GlobalContextManager;
+
+/**
+ * A very simple writable initial context factory.
+ * @see org.apache.xbean.naming.context.WritableContext for details.
+ */
+public class KarafInitialContextFactory extends GlobalContextManager {
+
+ public KarafInitialContextFactory() throws Exception {
+ super();
+ setGlobalContext(new WritableContext());
+ }
+
+}
Added: karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiMBeanImpl.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiMBeanImpl.java (added)
+++ karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiMBeanImpl.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.internal;
+
+import org.apache.karaf.jndi.JndiService;
+import org.apache.karaf.jndi.JndiMBean;
+
+import javax.management.MBeanException;
+import java.util.Map;
+
+/**
+ * Implementation of the JndiMBean
+ */
+public class JndiMBeanImpl implements JndiMBean {
+
+ private JndiService jndiService;
+
+ @Override
+ public Map<String, String> getNames() throws MBeanException {
+ try {
+ return this.jndiService.list();
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public Map<String, String> getNames(String context) throws MBeanException {
+ try {
+ return this.jndiService.list(context);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void alias(String name, String alias) throws MBeanException {
+ try {
+ this.jndiService.alias(name, alias);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void bind(Long serviceId, String name) throws MBeanException {
+ try {
+ this.jndiService.bind(serviceId, name);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void unbind(String name) throws MBeanException {
+ try {
+ this.jndiService.unbind(name);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void create(String context) throws MBeanException {
+ try {
+ this.jndiService.create(context);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ @Override
+ public void delete(String context) throws MBeanException {
+ try {
+ this.jndiService.delete(context);
+ } catch (Throwable t) {
+ throw new MBeanException(null, t.getMessage());
+ }
+ }
+
+ public JndiService getJndiService() {
+ return jndiService;
+ }
+
+ public void setJndiService(JndiService jndiService) {
+ this.jndiService = jndiService;
+ }
+
+}
Added: karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiServiceImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiServiceImpl.java?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiServiceImpl.java (added)
+++ karaf/trunk/jndi/core/src/main/java/org/apache/karaf/jndi/internal/JndiServiceImpl.java Thu Dec 12 17:54:58 2013
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.jndi.internal;
+
+import org.apache.aries.proxy.ProxyManager;
+import org.apache.karaf.jndi.JndiService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+
+import javax.naming.*;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Implementation of the JNDI Service.
+ */
+public class JndiServiceImpl implements JndiService {
+
+ private BundleContext bundleContext;
+ private ProxyManager proxyManager;
+
+ private final static String OSGI_JNDI_CONTEXT_PREFIX = "osgi:service";
+ private final static String OSGI_JNDI_SERVICE_PROPERTY = "osgi.jndi.service.name";
+
+ @Override
+ public Map<String, String> list() throws Exception {
+ Map<String, String> result = list("/");
+ result.putAll(list(OSGI_JNDI_CONTEXT_PREFIX + "/"));
+ return result;
+ }
+
+ @Override
+ public Map<String, String> list(String name) throws Exception {
+ Map<String, String> map = new HashMap<String, String>();
+ if (name.startsWith(OSGI_JNDI_CONTEXT_PREFIX)) {
+ // OSGi service binding
+ // make a lookup using directly the OSGi service
+ Bundle[] bundles = bundleContext.getBundles();
+ for (Bundle bundle : bundles) {
+ ServiceReference<?>[] services = bundle.getRegisteredServices();
+ if (services != null) {
+ for (ServiceReference service : services) {
+ if (service.getProperty(OSGI_JNDI_SERVICE_PROPERTY) != null) {
+ Object actualService = bundleContext.getService(service);
+ if (proxyManager.isProxy(actualService)) {
+ actualService = proxyManager.unwrap(actualService).call();
+ }
+ map.put(OSGI_JNDI_CONTEXT_PREFIX + service.getProperty(OSGI_JNDI_SERVICE_PROPERTY), actualService.getClass().getName());
+ bundleContext.ungetService(service);
+ }
+ }
+ }
+ }
+ } else {
+ // "real" JNDI lookup
+ Context context = new InitialContext();
+ NamingEnumeration<NameClassPair> pairs = context.list(name);
+ while (pairs.hasMoreElements()) {
+ NameClassPair pair = pairs.nextElement();
+ Object o;
+ if (name != null) {
+ o = context.lookup(name + "/" + pair.getName());
+ } else {
+ o = context.lookup(pair.getName());
+ }
+ if (o instanceof Context) {
+ StringBuilder sb = new StringBuilder();
+ sb.append(pair.getName());
+ list((Context) o, sb, map);
+ } else {
+ map.put(pair.getName(), pair.getClassName());
+ }
+ }
+ }
+ return map;
+ }
+
+ /**
+ * Recursively list a context
+ *
+ * @param ctx the startup context.
+ * @param sb the string builder where to construct the full qualified name.
+ * @param map the final map containing name/class name pairs.
+ * @throws Exception
+ */
+ private static final void list(Context ctx, StringBuilder sb, Map<String, String> map) throws Exception {
+ NamingEnumeration list = ctx.listBindings("");
+ while (list.hasMore()) {
+ Binding item = (Binding) list.next();
+ String className = item.getClassName();
+ String name = item.getName();
+ sb.append("/");
+ sb.append(name);
+ Object o = item.getObject();
+ if (o instanceof Context) {
+ list((Context) o, sb, map);
+ } else {
+ map.put(sb.toString(), className);
+ }
+ }
+ }
+
+ @Override
+ public void create(String name) throws Exception {
+ Context context = new InitialContext();
+ String[] splitted = name.split("/");
+ if (splitted.length > 0) {
+ for (int i = 0; i < splitted.length; i++) {
+ context.createSubcontext(splitted[i]);
+ context = (Context) context.lookup(splitted[i]);
+ }
+ } else {
+ context.createSubcontext(name);
+ }
+ }
+
+ @Override
+ public void delete(String name) throws Exception {
+ Context context = new InitialContext();
+ context.destroySubcontext(name);
+ }
+
+ @Override
+ public void bind(long serviceId, String name) throws Exception {
+ Context context = new InitialContext();
+ Bundle[] bundles = bundleContext.getBundles();
+ for (Bundle bundle : bundles) {
+ ServiceReference<?>[] services = bundle.getRegisteredServices();
+ if (services != null) {
+ for (ServiceReference service : services) {
+ if (service.getProperty(Constants.SERVICE_ID) != null && ((Long) service.getProperty(Constants.SERVICE_ID)) == serviceId) {
+ Object actualService = bundleContext.getService(service);
+ if (proxyManager.isProxy(actualService)) {
+ actualService = proxyManager.unwrap(actualService).call();
+ }
+ try {
+ String[] splitted = name.split("/");
+ if (splitted.length > 0) {
+ for (int i = 0; i < splitted.length - 1; i++) {
+ context.createSubcontext(splitted[i]);
+ context = (Context) context.lookup(splitted[i]);
+ }
+ name = splitted[splitted.length - 1];
+ }
+ context.bind(name, actualService);
+ } finally {
+ bundleContext.ungetService(service);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ public void alias(String name, String alias) throws Exception {
+ Context context = new InitialContext();
+ if (name.startsWith(OSGI_JNDI_CONTEXT_PREFIX)) {
+ // get the object
+ Bundle[] bundles = bundleContext.getBundles();
+ for (Bundle bundle : bundles) {
+ ServiceReference<?>[] services = bundle.getRegisteredServices();
+ if (services != null) {
+ for (ServiceReference service : services) {
+ if (service.getProperty(OSGI_JNDI_SERVICE_PROPERTY) != null && ((String) service.getProperty(OSGI_JNDI_SERVICE_PROPERTY)).equals(name.substring(OSGI_JNDI_CONTEXT_PREFIX.length()))) {
+ Object actualService = bundleContext.getService(service);
+ try {
+ if (proxyManager.isProxy(actualService)) {
+ actualService = proxyManager.unwrap(actualService).call();
+ }
+ String[] splitted = alias.split("/");
+ if (splitted.length > 0) {
+ for (int i = 0; i < splitted.length - 1; i++) {
+ context.createSubcontext(splitted[i]);
+ context = (Context) context.lookup(splitted[i]);
+ }
+ alias = splitted[splitted.length -1];
+ }
+ context.bind(alias, actualService);
+ } finally {
+ bundleContext.ungetService(service);
+ }
+ }
+ }
+ }
+ }
+ } else {
+ Object object = context.lookup(name);
+ context.bind(alias, object);
+ }
+ }
+
+ @Override
+ public void unbind(String name) throws Exception {
+ InitialContext context = new InitialContext();
+ if (name.startsWith(OSGI_JNDI_CONTEXT_PREFIX)) {
+ throw new IllegalArgumentException("You can't unbind a name from the " + OSGI_JNDI_CONTEXT_PREFIX + " JNDI context.");
+ }
+ context.unbind(name);
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ this.bundleContext = bundleContext;
+ }
+
+ public ProxyManager getProxyManager() {
+ return proxyManager;
+ }
+
+ public void setProxyManager(ProxyManager proxyManager) {
+ this.proxyManager = proxyManager;
+ }
+
+}
Added: karaf/trunk/jndi/core/src/main/resources/OSGI-INF/blueprint/jndi-core.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/src/main/resources/OSGI-INF/blueprint/jndi-core.xml?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/src/main/resources/OSGI-INF/blueprint/jndi-core.xml (added)
+++ karaf/trunk/jndi/core/src/main/resources/OSGI-INF/blueprint/jndi-core.xml Thu Dec 12 17:54:58 2013
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version
+ 2.0 (the "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0 Unless required by
+ applicable law or agreed to in writing, software distributed under the
+ License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
+ CONDITIONS OF ANY KIND, either express or implied. See the License for
+ the specific language governing permissions and limitations under the
+ License.
+ -->
+<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
+ xmlns:ext="http://aries.apache.org/blueprint/xmlns/blueprint-ext/v1.0.0"
+ default-activation="lazy">
+
+ <ext:property-placeholder placeholder-prefix="$[" placeholder-suffix="]"/>
+
+ <bean id="karafInitialContextFactory" class="org.apache.karaf.jndi.KarafInitialContextFactory"/>
+
+ <reference id="proxyManager" interface="org.apache.aries.proxy.ProxyManager"/>
+
+ <service ref="karafInitialContextFactory" interface="javax.naming.spi.InitialContextFactory"/>
+
+ <bean id="jndiService" class="org.apache.karaf.jndi.internal.JndiServiceImpl">
+ <property name="bundleContext" ref="blueprintBundleContext"/>
+ <property name="proxyManager" ref="proxyManager"/>
+ </bean>
+
+ <service ref="jndiService" interface="org.apache.karaf.jndi.JndiService">
+ <service-properties>
+ <!-- bind the JNDI service itself in the JNDI context -->
+ <entry key="osgi.jndi.service.name" value="/jndi"/>
+ </service-properties>
+ </service>
+
+ <!-- Management -->
+ <bean id="jndiMBeanImpl" class="org.apache.karaf.jndi.internal.JndiMBeanImpl">
+ <property name="jndiService" ref="jndiService"/>
+ </bean>
+
+ <service ref="jndiMBeanImpl" auto-export="interfaces">
+ <service-properties>
+ <entry key="jmx.objectname" value="org.apache.karaf:type=jndi,name=$[karaf.name]"/>
+ </service-properties>
+ </service>
+
+</blueprint>
\ No newline at end of file
Added: karaf/trunk/jndi/core/src/main/resources/OSGI-INF/bundle.info
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/core/src/main/resources/OSGI-INF/bundle.info?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/core/src/main/resources/OSGI-INF/bundle.info (added)
+++ karaf/trunk/jndi/core/src/main/resources/OSGI-INF/bundle.info Thu Dec 12 17:54:58 2013
@@ -0,0 +1,19 @@
+h1. Synopsis
+
+${project.name}
+
+${project.description}
+
+Maven URL:
+[mvn:${project.groupId}/${project.artifactId}/${project.version}]
+
+h1. Description
+
+This bundle is the core implementation of the JNDI service support.
+
+JNDI allows to expose any OSGi services as JNDI names. Karaf JNDI also provides a set of commands and a MBean to list
+the current JNDI names, create JNDI aliases, ...
+
+h1. See also
+
+JNDI - section of the Karaf User Guide
Added: karaf/trunk/jndi/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/jndi/pom.xml?rev=1550459&view=auto
==============================================================================
--- karaf/trunk/jndi/pom.xml (added)
+++ karaf/trunk/jndi/pom.xml Thu Dec 12 17:54:58 2013
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.karaf</groupId>
+ <artifactId>karaf</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <groupId>org.apache.karaf.jndi</groupId>
+ <artifactId>jndi</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Karaf :: JNDI</name>
+
+ <modules>
+ <module>core</module>
+ <module>command</module>
+ </modules>
+
+</project>
\ No newline at end of file
Modified: karaf/trunk/pom.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/pom.xml?rev=1550459&r1=1550458&r2=1550459&view=diff
==============================================================================
--- karaf/trunk/pom.xml (original)
+++ karaf/trunk/pom.xml Thu Dec 12 17:54:58 2013
@@ -62,6 +62,7 @@
<module>scr</module>
<module>diagnostic</module>
<module>obr</module>
+ <module>jndi</module>
<module>tooling</module>
<module>assemblies</module>
<module>demos</module>
@@ -389,6 +390,17 @@
</dependency>
<dependency>
+ <groupId>org.apache.karaf.jndi</groupId>
+ <artifactId>org.apache.karaf.jndi.core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.karaf.jndi</groupId>
+ <artifactId>org.apache.karaf.jndi.command</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.karaf.service</groupId>
<artifactId>org.apache.karaf.service.core</artifactId>
<version>${project.version}</version>
@@ -1708,6 +1720,11 @@
<version>${xbean.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-naming</artifactId>
+ <version>${xbean.version}</version>
+ </dependency>
+ <dependency>
<groupId>tanukisoft</groupId>
<artifactId>wrapper</artifactId>
<version>${jsw.version}</version>