use of javax.naming.Name in project wildfly by wildfly.
the class ContextManagedReferenceFactory method getReference.
@Override
public ManagedReference getReference() {
final NamingStore namingStore = namingStoreInjectedValue.getValue();
try {
final Name name = NameParser.INSTANCE.parse(this.name);
final NamingContext context = new NamingContext(name, namingStore, null);
return new ManagedReference() {
@Override
public void release() {
}
@Override
public Object getInstance() {
return context;
}
};
} catch (NamingException e) {
throw new RuntimeException(e);
}
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingContext method lookup.
public Object lookup(final Name name, boolean dereference) throws NamingException {
check(name, JndiPermission.ACTION_LOOKUP);
if (isEmpty(name)) {
return new NamingContext(prefix, namingStore, environment);
}
final Name absoluteName = getAbsoluteName(name);
Object result;
try {
result = namingStore.lookup(absoluteName, dereference);
} catch (CannotProceedException cpe) {
final Context continuationContext = NamingManager.getContinuationContext(cpe);
if (continuationContext instanceof NamingContext) {
result = ((NamingContext) continuationContext).lookup(cpe.getRemainingName(), dereference);
} else {
result = continuationContext.lookup(cpe.getRemainingName());
}
}
if (result instanceof ResolveResult) {
final ResolveResult resolveResult = (ResolveResult) result;
final Object resolvedObject = resolveResult.getResolvedObj();
Object context;
if (resolvedObject instanceof Context) {
context = resolvedObject;
} else if (resolvedObject instanceof LinkRef) {
context = resolveLink(resolvedObject, dereference);
} else {
context = getObjectInstance(resolvedObject, absoluteName, environment);
}
if (!(context instanceof Context)) {
throw notAContextException(absoluteName.getPrefix(absoluteName.size() - resolveResult.getRemainingName().size()));
}
final Context namingContext = (Context) context;
if (namingContext instanceof NamingContext) {
return ((NamingContext) namingContext).lookup(resolveResult.getRemainingName(), dereference);
} else {
return namingContext.lookup(resolveResult.getRemainingName());
}
} else if (result instanceof LinkRef) {
result = resolveLink(result, dereference);
} else if (result instanceof Reference) {
result = getObjectInstance(result, absoluteName, environment);
if (result instanceof LinkRef) {
result = resolveLink(result, dereference);
}
}
return result;
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingContext method getAbsoluteName.
private Name getAbsoluteName(final Name name) throws NamingException {
if (name.isEmpty()) {
return composeName(name, prefix);
}
final String firstComponent = name.get(0);
if (firstComponent.startsWith("java:")) {
final String cleaned = firstComponent.substring(5);
final Name suffix = name.getSuffix(1);
if (cleaned.isEmpty()) {
return suffix;
}
return suffix.add(0, cleaned);
} else if (firstComponent.isEmpty()) {
return name.getSuffix(1);
} else {
return composeName(name, prefix);
}
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingContext method composeName.
/** {@inheritDoc} */
public Name composeName(Name name, Name prefix) throws NamingException {
final Name result = (Name) prefix.clone();
if (name instanceof CompositeName) {
if (name.size() == 1) {
// name could be a nested name
final String firstComponent = name.get(0);
result.addAll(parseName(firstComponent));
} else {
result.addAll(name);
}
} else {
result.addAll(new CompositeName(name.toString()));
}
return result;
}
use of javax.naming.Name in project wildfly by wildfly.
the class NamingContext method check.
private void check(Name name, int actions) throws NamingException {
final SecurityManager sm = System.getSecurityManager();
if (sm != null && WildFlySecurityManager.isChecking()) {
// build absolute name (including store's base name)
Name absoluteName = (Name) namingStore.getBaseName().clone();
if (name.isEmpty()) {
absoluteName.addAll(prefix);
} else {
final String firstComponent = name.get(0);
if (firstComponent.startsWith("java:")) {
absoluteName = name;
} else if (firstComponent.isEmpty()) {
absoluteName.addAll(name.getSuffix(1));
} else {
absoluteName.addAll(prefix);
if (name instanceof CompositeName) {
if (name.size() == 1) {
// name could be a nested name
absoluteName.addAll(parseName(firstComponent));
} else {
absoluteName.addAll(name);
}
} else {
absoluteName.addAll(new CompositeName(name.toString()));
}
}
}
sm.checkPermission(new JndiPermission(absoluteName.toString(), actions));
}
}
Aggregations