You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by da...@apache.org on 2006/08/24 20:38:47 UTC
svn commit: r434463 - in
/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context:
AbstractContext.java AbstractFederatedContext.java ContextFederation.java
ImmutableContext.java
Author: dain
Date: Thu Aug 24 11:38:44 2006
New Revision: 434463
URL: http://svn.apache.org/viewvc?rev=434463&view=rev
Log:
Moved access control logic to AbstractContext which vastly simplifies ImmutableContext and AbstractFederatedContext
Changed ContextFederation to catch only OperationNotSupportedException instead of all NamingExceptions
Modified:
geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java
geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java
geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java?rev=434463&r1=434462&r2=434463&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java (original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractContext.java Thu Aug 24 11:38:44 2006
@@ -28,6 +28,7 @@
import javax.naming.LinkRef;
import javax.naming.NameNotFoundException;
import javax.naming.InitialContext;
+import javax.naming.OperationNotSupportedException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Hashtable;
@@ -37,21 +38,32 @@
private static final long serialVersionUID = 6481918425692261483L;
private final String nameInNamespace;
private final Name parsedNameInNamespace;
+ private final ContextAccess contextAccess;
+ private final boolean modifiable;
protected AbstractContext(String nameInNamespace) {
+ this(nameInNamespace, ContextAccess.MODIFIABLE);
+ }
+
+ public AbstractContext(String nameInNamespace, ContextAccess contextAccess) {
this.nameInNamespace = nameInNamespace;
try {
this.parsedNameInNamespace = getNameParser().parse(nameInNamespace);
} catch (NamingException e) {
throw new RuntimeException(e);
}
+ this.contextAccess = contextAccess;
+ this.modifiable = contextAccess.isModifiable(getParsedNameInNamespace());
}
-
public void close() throws NamingException {
//Ignore. Explicitly do not close the context
}
+ protected ContextAccess getContextAccess() {
+ return contextAccess;
+ }
+
//
// Lookup Binding
//
@@ -591,6 +603,7 @@
//
public void bind(String name, Object obj) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
if (name.length() == 0) {
throw new NameAlreadyBoundException("Cannot bind to an empty name (this context)");
@@ -599,6 +612,7 @@
}
public void bind(Name name, Object obj) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
if (name.isEmpty()) {
throw new NameAlreadyBoundException("Cannot bind to an empty name (this context)");
@@ -607,11 +621,13 @@
}
public void rebind(String name, Object obj) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
rebind(new CompositeName(name), obj);
}
public void rebind(Name name, Object obj) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
if (name.isEmpty()) {
throw new NameAlreadyBoundException("Cannot rebind an empty name (this context)");
@@ -620,12 +636,14 @@
}
public void rename(String oldName, String newName) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (oldName == null) throw new NullPointerException("oldName is null");
if (newName == null) throw new NullPointerException("newName is null");
rename(new CompositeName(oldName), new CompositeName(newName));
}
public void rename(Name oldName, Name newName) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (oldName == null || newName == null) {
throw new NullPointerException("name is null");
} else if (oldName.isEmpty() || newName.isEmpty()) {
@@ -636,11 +654,13 @@
}
public void unbind(String name) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
unbind(new CompositeName(name));
}
public void unbind(Name name) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
if (name.isEmpty()) {
throw new InvalidNameException("Cannot unbind empty name");
@@ -747,11 +767,13 @@
//
public Context createSubcontext(String name) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
return createSubcontext(new CompositeName(name));
}
public Context createSubcontext(Name name) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
if (name.isEmpty()) {
throw new InvalidNameException("Cannot create a subcontext if the name is empty");
@@ -762,11 +784,13 @@
}
public void destroySubcontext(String name) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
destroySubcontext(new CompositeName(name));
}
public void destroySubcontext(Name name) throws NamingException {
+ if (!modifiable) throw new OperationNotSupportedException("Context is read only");
if (name == null) throw new NullPointerException("name is null");
if (name.isEmpty()) {
throw new InvalidNameException("Cannot destroy subcontext with empty name");
Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java?rev=434463&r1=434462&r2=434463&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java (original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/AbstractFederatedContext.java Thu Aug 24 11:38:44 2006
@@ -20,7 +20,6 @@
import javax.naming.Name;
import javax.naming.NameAlreadyBoundException;
import javax.naming.NamingException;
-import javax.naming.OperationNotSupportedException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
@@ -30,8 +29,6 @@
*/
public abstract class AbstractFederatedContext extends AbstractContext {
private final ContextFederation contextFederation;
- private final ContextAccess contextAccess;
- private final boolean modifiable;
private final AbstractFederatedContext masterContext;
public AbstractFederatedContext() {
@@ -43,19 +40,15 @@
}
public AbstractFederatedContext(String nameInNamespace, ContextAccess contextAccess) {
- super(nameInNamespace);
+ super(nameInNamespace, contextAccess);
this.masterContext = this;
this.contextFederation = new ContextFederation(this);
- this.contextAccess = contextAccess;
- this.modifiable = contextAccess.isModifiable(getParsedNameInNamespace());
}
public AbstractFederatedContext(AbstractFederatedContext masterContext, String path) throws NamingException {
- super(masterContext.getNameInNamespace(path));
+ super(masterContext.getNameInNamespace(path), masterContext.getContextAccess());
this.masterContext = masterContext;
this.contextFederation = this.masterContext.contextFederation.createSubcontextFederation(path, this);
- this.contextAccess = masterContext.contextAccess;
- this.modifiable = masterContext.contextAccess.isModifiable(getParsedNameInNamespace());
}
protected Object faultLookup(String stringName, Name parsedName) {
@@ -135,89 +128,5 @@
protected AbstractFederatedContext getMasterContext() {
return masterContext;
- }
-
- public void bind(String name, Object obj) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.bind(name, obj);
- }
-
- public void bind(Name name, Object obj) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.bind(name, obj);
- }
-
- public void rebind(String name, Object obj) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.rebind(name, obj);
- }
-
- public void rebind(Name name, Object obj) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.rebind(name, obj);
- }
-
- public void rename(String oldName, String newName) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.rename(oldName, newName);
- }
-
- public void rename(Name oldName, Name newName) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.rename(oldName, newName);
- }
-
- public void unbind(String name) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.unbind(name);
- }
-
- public void unbind(Name name) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.unbind(name);
- }
-
- public Context createSubcontext(String name) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- return super.createSubcontext(name);
- }
-
- public Context createSubcontext(Name name) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- return super.createSubcontext(name);
- }
-
- public void destroySubcontext(String name) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.destroySubcontext(name);
- }
-
- public void destroySubcontext(Name name) throws NamingException {
- if (!modifiable) {
- throw new OperationNotSupportedException("Context is read only");
- }
- super.destroySubcontext(name);
}
}
Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java?rev=434463&r1=434462&r2=434463&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java (original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ContextFederation.java Thu Aug 24 11:38:44 2006
@@ -23,6 +23,7 @@
import javax.naming.NamingException;
import javax.naming.NamingEnumeration;
import javax.naming.Binding;
+import javax.naming.OperationNotSupportedException;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
@@ -95,7 +96,7 @@
context.bind(name, value);
}
return true;
- } catch (NamingException ignored) {
+ } catch (OperationNotSupportedException ignored) {
}
}
return false;
@@ -108,7 +109,7 @@
try {
context.unbind(name);
return true;
- } catch (NamingException ignored) {
+ } catch (OperationNotSupportedException ignored) {
}
}
return false;
Modified: geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java
URL: http://svn.apache.org/viewvc/geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java?rev=434463&r1=434462&r2=434463&view=diff
==============================================================================
--- geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java (original)
+++ geronimo/xbean/branches/colossus/xbean-naming/src/main/java/org/apache/xbean/naming/context/ImmutableContext.java Thu Aug 24 11:38:44 2006
@@ -44,7 +44,7 @@
}
public ImmutableContext(String nameInNamespace, Map bindings, boolean cacheReferences) throws NamingException {
- super(nameInNamespace);
+ super(nameInNamespace, ContextAccess.UNMODIFIABLE);
if (cacheReferences) {
bindings = CachingReference.wrapReferences(bindings);
@@ -113,58 +113,6 @@
return new NestedImmutableContext(path, bindings);
}
- public final void bind(Name name, Object obj) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void bind(String name, Object obj) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void close() throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final Context createSubcontext(Name name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final Context createSubcontext(String name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void destroySubcontext(Name name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void destroySubcontext(String name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void rebind(Name name, Object obj) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void rebind(String name, Object obj) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void rename(Name oldName, Name newName) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void rename(String oldName, String newName) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void unbind(Name name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void unbind(String name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
/**
* Nested context which shares the absolute index map in MapContext.
*/
@@ -173,7 +121,7 @@
private final String pathWithSlash;
public NestedImmutableContext(String path, Map bindings) {
- super(ImmutableContext.this.getNameInNamespace(path));
+ super(ImmutableContext.this.getNameInNamespace(path), ContextAccess.UNMODIFIABLE);
if (!path.endsWith("/")) path += "/";
this.pathWithSlash = path;
@@ -220,58 +168,6 @@
protected ImmutableContext getImmutableContext() {
return ImmutableContext.this;
- }
-
- public final void bind(Name name, Object obj) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void bind(String name, Object obj) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void close() throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final Context createSubcontext(Name name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final Context createSubcontext(String name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void destroySubcontext(Name name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void destroySubcontext(String name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void rebind(Name name, Object obj) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void rebind(String name, Object obj) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void rename(Name oldName, Name newName) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void rename(String oldName, String newName) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void unbind(Name name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
- }
-
- public final void unbind(String name) throws NamingException {
- throw new OperationNotSupportedException("Context is read only");
}
}
}