public static void main(final String[] args) { final ParsedName name = new ParsedName("comp/env/jdbc/mydatabase"); while (name.next()) { System.out.println(name.getComponent()); } }
public int compareTo(final String other) { final int otherHash = other.hashCode(); return compareTo(otherHash); }
public NameNode(NameNode parent, ParsedName name, Object obj, NameNode parentTree) { atomicName = name.getComponent(); atomicHash = name.getComponentHashCode(); this.parent = parent; this.parentTree = parentTree; if (name.next()) subTree = new NameNode(this, name, obj, this); else myObject = obj; }
@Override public String toString() { return "ParsedName{" + "path=" + path() + ", component=" + getComponent() + '}'; }
public Object resolve(final ParsedName name) throws NameNotFoundException { final int compareResult = name.compareTo(atomicHash); NameNotFoundException n = null; final int pos = name.getPos(); if (compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)) { if (name.next()) { if (subTree != null) { try { name.reset(pos); final String nameInContext = name.remaining().path(); Federation f = null; for (final Context c : (Federation) myObject) { final NameNode node = new NameNode(null, new ParsedName(""), f, null); return new IvmContext(node);
public void bind(ParsedName name, Object obj) throws javax.naming.NameAlreadyBoundException { int compareResult = name.compareTo(atomicHash); if (compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)) { if (name.next()) { if (myObject != null) { throw new javax.naming.NameAlreadyBoundException(); } else { if (subTree != null) { throw new javax.naming.NameAlreadyBoundException(name.toString()); throw new javax.naming.NameAlreadyBoundException(name.toString());
final ParsedName name = new ParsedName(path); path = name.path(); return openejbURLContextFactory.getContext().lookup(path); } else if (prefix.equals("java")) { if (name.getComponent().equals("openejb")) { path = name.remaining().path(); return openejbURLContextFactory.getContext().lookup(path); } else { path = name.path(); return javaURLContextFactory.getContext().lookup(path); if (obj == null) { try { obj = mynode.resolve(new ParsedName(compoundName)); } catch (final NameNotFoundException nnfe) { obj = federate(compositName);
public void unbind(final ParsedName name) throws NameAlreadyBoundException { final int compareResult = name.compareTo(atomicHash); if (compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)) { if (name.next()) { if (subTree != null) { subTree.unbind(name); } } else { unbound = true; myObject = null; parentTree.unbind(this); } } else if (compareResult == ParsedName.IS_LESS) { if (lessTree != null) { lessTree.unbind(name); } } else {//ParsedName.IS_GREATER ... if (grtrTree != null) { grtrTree.unbind(name); } } }
public ParsedName remaining() { final ParsedName name = new ParsedName(""); final int next = pos + 1; if (next > components.length) { return name; } final String[] dest = new String[components.length - next]; System.arraycopy(components, next, dest, 0, dest.length); name.components = dest; return name; }
private String normalize(String pathname) { int n = pathname.length(); char prevChar = 0; for (int i = 0; i < n; i++) { char c = pathname.charAt(i); if ((prevChar == '/') && (c == '/')) return normalize(pathname, n, i - 1); prevChar = c; } if (prevChar == '/') return normalize(pathname, n, n - 1); return pathname; }
public IvmContext createSubcontext(ParsedName name) throws javax.naming.NameAlreadyBoundException { try { bind(name, null); name.reset(); return (IvmContext) resolve(name); } catch (javax.naming.NameNotFoundException exception) { exception.printStackTrace(); throw new RuntimeException(exception); } }
public Object resolve(final ParsedName name, boolean createReadOnlyContext) throws NameNotFoundException { final int compareResult = name.compareTo(atomicHash); NameNotFoundException n = null; final int pos = name.getPos(); if (compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)) { if (name.next()) { if (subTree != null) { try { name.reset(pos); final String nameInContext = compareResult != ParsedName.IS_EQUAL ? name.path() : name.remaining().path(); Federation f = null; for (final Context c : (Federation) myObject) { final NameNode node = new NameNode(null, new ParsedName(""), f, null); return new IvmContext(node, createReadOnlyContext);
public void bind(final ParsedName name, final Object obj) throws NameAlreadyBoundException { final int compareResult = name.compareTo(atomicHash); if (compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)) { if (name.next()) { if (myObject != null && !(myObject instanceof Federation)) { throw new NameAlreadyBoundException(); if (myObject != null) { if (!(myObject instanceof Federation)) { throw new NameAlreadyBoundException(name.toString()); } else { if (subTree != null) { throw new NameAlreadyBoundException(name.toString()); throw new NameAlreadyBoundException(name.toString());
final ParsedName name = new ParsedName(path); path = name.path(); return openejbURLContextFactory.getContext().lookup(path); } else if (prefix.equals("java")) { if (name.getComponent().equals("openejb")) { path = name.remaining().path(); return openejbURLContextFactory.getContext().lookup(path); } else { path = name.path(); return javaURLContextFactory.getContext().lookup(path); if (obj == null) { try { obj = mynode.resolve(new ParsedName(compoundName), readOnly); } catch (final NameNotFoundException nnfe) { obj = federate(compositName);
public void unbind(ParsedName name) throws javax.naming.NameAlreadyBoundException { int compareResult = name.compareTo(atomicHash); if (compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)) { if (name.next()) { if (subTree != null) { subTree.unbind(name); } } else { unbound = true; myObject = null; parentTree.unbind(this); } } else if (compareResult == ParsedName.IS_LESS) { if (lessTree != null) { lessTree.unbind(name); } } else {//ParsedName.IS_GREATER ... if (grtrTree != null) grtrTree.unbind(name); } }
public ParsedName remaining() { ParsedName name = new ParsedName(""); int next = pos +1; if (next > components.length) return name; String[] dest = new String[components.length - next]; System.arraycopy(components, next, dest, 0, dest.length); name.components = dest; return name; }
@Override public String toString() { return "ParsedName{" + "path=" + path() + ", component=" + getComponent() + '}'; }
private String normalize(final String pathname) { final int n = pathname.length(); char prevChar = 0; for (int i = 0; i < n; i++) { final char c = pathname.charAt(i); if (prevChar == '/' && c == '/') { return normalize(pathname, n, i - 1); } prevChar = c; } if (prevChar == '/') { return normalize(pathname, n, n - 1); } return pathname; }
public IvmContext createSubcontext(final ParsedName name) throws NameAlreadyBoundException { try { bind(name, null); name.reset(); return (IvmContext) resolve(name); } catch (final NameNotFoundException exception) { exception.printStackTrace(); throw new OpenEJBRuntimeException(exception); } }
public void bind(final ParsedName name, final Object obj) throws NameAlreadyBoundException { final int compareResult = name.compareTo(atomicHash); if (compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)) { if (name.next()) { if (myObject != null && !(myObject instanceof Federation)) { throw new NameAlreadyBoundException(); if (myObject != null) { if (!(myObject instanceof Federation)) { throw new NameAlreadyBoundException(name.toString()); } else { if (subTree != null) { throw new NameAlreadyBoundException(name.toString()); throw new NameAlreadyBoundException(name.toString());