|
From: <fd...@us...> - 2010-05-16 16:50:14
|
Revision: 5751
http://jnode.svn.sourceforge.net/jnode/?rev=5751&view=rev
Author: fduminy
Date: 2010-05-16 16:50:07 +0000 (Sun, 16 May 2010)
Log Message:
-----------
- removed dependency cycle between org.jnode.naming and org.jnode.vm by moving DefaultNameSpace to org.jnode.vm
- BootLogInstance is now using InitialNaming to store the instance
Signed-off-by: Fabien DUMINY <fab...@we...>
Modified Paths:
--------------
trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java
trunk/core/src/core/org/jnode/bootlog/BootLogInstance.java
trunk/core/src/core/org/jnode/naming/InitialNaming.java
trunk/core/src/core/org/jnode/vm/BootLogImpl.java
trunk/core/src/core/org/jnode/vm/VmSystem.java
trunk/core/src/emu/org/jnode/emu/naming/BasicNameSpace.java
trunk/fs/src/test/org/jnode/test/fs/driver/stubs/StubNameSpace.java
Added Paths:
-----------
trunk/core/src/core/org/jnode/vm/DefaultNameSpace.java
Removed Paths:
-------------
trunk/core/src/core/org/jnode/naming/DefaultNameSpace.java
Modified: trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java
===================================================================
--- trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2010-05-16 16:48:59 UTC (rev 5750)
+++ trunk/builder/src/builder/org/jnode/build/AbstractBootImageBuilder.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -50,6 +50,8 @@
import org.jnode.assembler.x86.X86BinaryAssembler;
import org.jnode.bootlog.BootLog;
import org.jnode.bootlog.BootLogInstance;
+import org.jnode.emu.naming.BasicNameSpace;
+import org.jnode.naming.InitialNaming;
import org.jnode.plugin.PluginDescriptor;
import org.jnode.plugin.PluginException;
import org.jnode.plugin.PluginRegistry;
@@ -795,7 +797,8 @@
public final void execute() throws BuildException {
try {
- BootLogInstance.set(new BootLog() {
+ InitialNaming.setNameSpace(new BasicNameSpace());
+ BootLogInstance.set(new BootLog() {
@Override
public void warn(String msg) {
System.out.println(msg);
Modified: trunk/core/src/core/org/jnode/bootlog/BootLogInstance.java
===================================================================
--- trunk/core/src/core/org/jnode/bootlog/BootLogInstance.java 2010-05-16 16:48:59 UTC (rev 5750)
+++ trunk/core/src/core/org/jnode/bootlog/BootLogInstance.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -1,19 +1,19 @@
package org.jnode.bootlog;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import org.jnode.naming.InitialNaming;
+
+
/**
- * Class holding the {@link BootLog} instance used by the system.
- * <br/><h1>Implementation note :</h1> The reference to the actual instance of
- * the BootLog can't be stored in the InitialNaming that use VmType, which is
- * not fully initialized at build time (but BootLog is used). So, we are always
- * holding the reference in that class.
+ * Class holding the {@link BootLog} instance used by the system.
*
* @author Fabien DUMINY
*
*/
public final class BootLogInstance {
- private static BootLog BOOT_LOG_INSTANCE;
-
private BootLogInstance () {
}
@@ -22,14 +22,20 @@
* @return the system's {@link BootLog}.
*/
public static BootLog get() {
- return BOOT_LOG_INSTANCE;
+ try {
+ return InitialNaming.lookup(BootLog.class);
+ } catch (NameNotFoundException e) {
+ throw new Error("unable to find a BootLog instance", e);
+ }
}
/**
* Set the system's {@link BootLog}.
* @param bootLog the system's {@link BootLog}.
+ * @throws NamingException
+ * @throws NameAlreadyBoundException
*/
- public static void set(BootLog bootLog) {
- BOOT_LOG_INSTANCE = bootLog;
+ public static void set(BootLog bootLog) throws NameAlreadyBoundException, NamingException {
+ InitialNaming.bind(BootLog.class, bootLog);
}
}
Deleted: trunk/core/src/core/org/jnode/naming/DefaultNameSpace.java
===================================================================
--- trunk/core/src/core/org/jnode/naming/DefaultNameSpace.java 2010-05-16 16:48:59 UTC (rev 5750)
+++ trunk/core/src/core/org/jnode/naming/DefaultNameSpace.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -1,118 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2010 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.naming;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import javax.naming.NameAlreadyBoundException;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.jnode.annotation.PrivilegedActionPragma;
-import org.jnode.vm.classmgr.VmType;
-
-public class DefaultNameSpace extends AbstractNameSpace {
-
- /**
- * All bound names+services
- */
- protected final Map<VmType<?>, Object> namespace = new HashMap<VmType<?>, Object>();
-
- /**
- * Bind a given service in the namespace under a given name.
- *
- * @param name
- * @param service
- * @throws NameAlreadyBoundException if the name already exists within this namespace
- */
- @PrivilegedActionPragma
- public <T> void bind(Class<T> name, T service) throws NamingException,
- NameAlreadyBoundException {
- if (name == null) {
- throw new IllegalArgumentException("name == null");
- }
- synchronized (namespace) {
- if (namespace.containsKey(VmType.fromClass(name))) {
- throw new NameAlreadyBoundException(name.getName());
- }
- namespace.put(VmType.fromClass(name), service);
- }
-
- // notify listeners
- fireServiceBound(name, service);
- }
-
- /**
- * Unbind a service with a given name from the namespace. If the name does
- * not exist in this namespace, this method returns without an error.
- *
- * @param name
- */
- @PrivilegedActionPragma
- public void unbind(Class<?> name) {
- final Object service;
- synchronized (namespace) {
- service = namespace.remove(VmType.fromClass((Class<?>) name));
- }
-
- // notify listeners
- fireServiceUnbound(name, service);
- }
-
- /**
- * Lookup a service with a given name.
- *
- * @param name
- * @throws NameNotFoundException if the name was not found in this namespace
- */
- @PrivilegedActionPragma
- public <T> T lookup(Class<T> name) throws NameNotFoundException {
- final Object result = namespace.get(VmType.fromClass(name));
- if (result == null) {
-// if (!VmIsolate.isRoot()) {
-// System.out.println("Looking for " + name.getVmClass().hashCode());
-// for (VmType<?> type : namespace.keySet()) {
-// System.out.println(" found " + type.hashCode() + " " + (type == name.getVmClass()));
-// }
-// }
- throw new NameNotFoundException(name.getName());
- }
- return name.cast(result);
- }
-
- /**
- * Gets a set containing all names (Class) of the bound services.
- */
- public Set<Class<?>> nameSet() {
- final HashSet<VmType<?>> types;
- synchronized (namespace) {
- types = new HashSet<VmType<?>>(namespace.keySet());
- }
- final Set<Class<?>> result = new HashSet<Class<?>>(types.size());
- for (VmType<?> type : types) {
- result.add(type.asClass());
- }
- return result;
- }
-}
Modified: trunk/core/src/core/org/jnode/naming/InitialNaming.java
===================================================================
--- trunk/core/src/core/org/jnode/naming/InitialNaming.java 2010-05-16 16:48:59 UTC (rev 5750)
+++ trunk/core/src/core/org/jnode/naming/InitialNaming.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -45,7 +45,7 @@
/**
* All bound names+services
*/
- private static NameSpace namespace;
+ private static NameSpace NAME_SPACE;
/**
* Add a {@link NameSpaceListener} to the NameSpace
@@ -54,7 +54,7 @@
* @param l
*/
public static <T> void addNameSpaceListener(Class<T> name, NameSpaceListener<T> l) {
- getNameSpace().addNameSpaceListener(name, l);
+ NAME_SPACE.addNameSpaceListener(name, l);
}
/**
@@ -64,7 +64,7 @@
* @param l
*/
public static <T> void removeNameSpaceListener(Class<T> name, NameSpaceListener<T> l) {
- getNameSpace().removeNameSpaceListener(name, l);
+ NAME_SPACE.removeNameSpaceListener(name, l);
}
/**
@@ -73,11 +73,11 @@
* @param namespace
*/
public static void setNameSpace(NameSpace namespace) {
- if (InitialNaming.namespace != null) {
+ if (NAME_SPACE != null) {
throw new SecurityException(
"namespace can't be modified after first initialization");
}
- InitialNaming.namespace = namespace;
+ NAME_SPACE = namespace;
}
/**
@@ -89,7 +89,7 @@
*/
public static <T, E extends T> void bind(Class<T> name, E service) throws NamingException,
NameAlreadyBoundException {
- getNameSpace().bind(name, service);
+ NAME_SPACE.bind(name, service);
}
/**
@@ -99,7 +99,7 @@
* @param name
*/
public static void unbind(Class<?> name) {
- getNameSpace().unbind(name);
+ NAME_SPACE.unbind(name);
}
/**
@@ -109,25 +109,13 @@
* @throws NameNotFoundException if the name was not found in this namespace
*/
public static <T> T lookup(Class<T> name) throws NameNotFoundException {
- return getNameSpace().lookup(name);
+ return NAME_SPACE.lookup(name);
}
/**
* Gets a set containing all names (Class) of the bound services.
*/
public static Set<Class<?>> nameSet() {
- return getNameSpace().nameSet();
+ return NAME_SPACE.nameSet();
}
-
- /**
- * Get the actual {@link NameSpace} and use a default one
- * if none was yet defined.
- * @return
- */
- private static NameSpace getNameSpace() {
- if (namespace == null) {
- namespace = new DefaultNameSpace();
- }
- return namespace;
- }
}
Modified: trunk/core/src/core/org/jnode/vm/BootLogImpl.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/BootLogImpl.java 2010-05-16 16:48:59 UTC (rev 5750)
+++ trunk/core/src/core/org/jnode/vm/BootLogImpl.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -22,6 +22,9 @@
import java.io.PrintStream;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NamingException;
+
import org.jnode.bootlog.BootLog;
import org.jnode.bootlog.BootLogInstance;
@@ -148,6 +151,14 @@
static void initialize() {
Unsafe.debug("Initialize BootLog\n");
- BootLogInstance.set(new BootLogImpl());
+ try {
+ BootLogInstance.set(new BootLogImpl());
+ } catch (NameAlreadyBoundException e) {
+ Unsafe.debug(e.toString());
+ Unsafe.debug("\n");
+ } catch (NamingException e) {
+ Unsafe.debug(e.toString());
+ Unsafe.debug("\n");
+ }
}
}
Copied: trunk/core/src/core/org/jnode/vm/DefaultNameSpace.java (from rev 5750, trunk/core/src/core/org/jnode/naming/DefaultNameSpace.java)
===================================================================
--- trunk/core/src/core/org/jnode/vm/DefaultNameSpace.java (rev 0)
+++ trunk/core/src/core/org/jnode/vm/DefaultNameSpace.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -0,0 +1,119 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2010 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.vm;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jnode.annotation.PrivilegedActionPragma;
+import org.jnode.naming.AbstractNameSpace;
+import org.jnode.vm.classmgr.VmType;
+
+class DefaultNameSpace extends AbstractNameSpace {
+
+ /**
+ * All bound names+services
+ */
+ protected final Map<VmType<?>, Object> namespace = new HashMap<VmType<?>, Object>();
+
+ /**
+ * Bind a given service in the namespace under a given name.
+ *
+ * @param name
+ * @param service
+ * @throws NameAlreadyBoundException if the name already exists within this namespace
+ */
+ @PrivilegedActionPragma
+ public <T> void bind(Class<T> name, T service) throws NamingException,
+ NameAlreadyBoundException {
+ if (name == null) {
+ throw new IllegalArgumentException("name == null");
+ }
+ synchronized (namespace) {
+ if (namespace.containsKey(VmType.fromClass(name))) {
+ throw new NameAlreadyBoundException(name.getName());
+ }
+ namespace.put(VmType.fromClass(name), service);
+ }
+
+ // notify listeners
+ fireServiceBound(name, service);
+ }
+
+ /**
+ * Unbind a service with a given name from the namespace. If the name does
+ * not exist in this namespace, this method returns without an error.
+ *
+ * @param name
+ */
+ @PrivilegedActionPragma
+ public void unbind(Class<?> name) {
+ final Object service;
+ synchronized (namespace) {
+ service = namespace.remove(VmType.fromClass((Class<?>) name));
+ }
+
+ // notify listeners
+ fireServiceUnbound(name, service);
+ }
+
+ /**
+ * Lookup a service with a given name.
+ *
+ * @param name
+ * @throws NameNotFoundException if the name was not found in this namespace
+ */
+ @PrivilegedActionPragma
+ public <T> T lookup(Class<T> name) throws NameNotFoundException {
+ final Object result = namespace.get(VmType.fromClass(name));
+ if (result == null) {
+// if (!VmIsolate.isRoot()) {
+// System.out.println("Looking for " + name.getVmClass().hashCode());
+// for (VmType<?> type : namespace.keySet()) {
+// System.out.println(" found " + type.hashCode() + " " + (type == name.getVmClass()));
+// }
+// }
+ throw new NameNotFoundException(name.getName());
+ }
+ return name.cast(result);
+ }
+
+ /**
+ * Gets a set containing all names (Class) of the bound services.
+ */
+ public Set<Class<?>> nameSet() {
+ final HashSet<VmType<?>> types;
+ synchronized (namespace) {
+ types = new HashSet<VmType<?>>(namespace.keySet());
+ }
+ final Set<Class<?>> result = new HashSet<Class<?>>(types.size());
+ for (VmType<?> type : types) {
+ result.add(type.asClass());
+ }
+ return result;
+ }
+}
Modified: trunk/core/src/core/org/jnode/vm/VmSystem.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/VmSystem.java 2010-05-16 16:48:59 UTC (rev 5750)
+++ trunk/core/src/core/org/jnode/vm/VmSystem.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -119,7 +119,10 @@
*/
public static void initialize() {
if (!inited) {
- // Initialize BootLog
+ // Initialize Naming
+ InitialNaming.setNameSpace(new DefaultNameSpace());
+
+ // Initialize BootLog
BootLogImpl.initialize();
// Initialize resource manager
Modified: trunk/core/src/emu/org/jnode/emu/naming/BasicNameSpace.java
===================================================================
--- trunk/core/src/emu/org/jnode/emu/naming/BasicNameSpace.java 2010-05-16 16:48:59 UTC (rev 5750)
+++ trunk/core/src/emu/org/jnode/emu/naming/BasicNameSpace.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -36,7 +36,7 @@
*
* @author cr...@jn...
*/
-public final class BasicNameSpace extends AbstractNameSpace {
+public class BasicNameSpace extends AbstractNameSpace {
protected final Map<Class<?>, Object> namespace = new HashMap<Class<?>, Object>();
public <T> void bind(Class<T> name, T service)
Modified: trunk/fs/src/test/org/jnode/test/fs/driver/stubs/StubNameSpace.java
===================================================================
--- trunk/fs/src/test/org/jnode/test/fs/driver/stubs/StubNameSpace.java 2010-05-16 16:48:59 UTC (rev 5750)
+++ trunk/fs/src/test/org/jnode/test/fs/driver/stubs/StubNameSpace.java 2010-05-16 16:50:07 UTC (rev 5751)
@@ -24,10 +24,10 @@
import javax.naming.NameNotFoundException;
import javax.naming.NamingException;
import org.apache.log4j.Logger;
-import org.jnode.naming.DefaultNameSpace;
+import org.jnode.emu.naming.BasicNameSpace;
import org.jnode.test.support.MockUtils;
-public class StubNameSpace extends DefaultNameSpace {
+public class StubNameSpace extends BasicNameSpace {
private static final Logger log = Logger.getLogger(StubNameSpace.class);
public StubNameSpace() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|