@Override public Object lookupLink(final Name name) throws NamingException { final Object result = lookup(name); if (result instanceof LinkRef) { final LinkRef ref = (LinkRef) result; final String link = ref.getLinkName(); if (link.startsWith("./")) { // relative link; assume currCtx is the immediate context in // which the link is bound return lookup(link.substring(2)); } else { // absolute link; resolve to the initial context return lookupLink(link); } } return result; }
public void testSerializable_Simple() throws ClassNotFoundException, IOException { String name = "www.apache.org/index.html"; LinkRef linkRef = new LinkRef(name); StringRefAddr addr = new StringRefAddr("StringRefAddr", "This is a String RefAddr."); linkRef.add(addr); // write to byte array ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(linkRef); byte[] buffer = baos.toByteArray(); oos.close(); baos.close(); // read from byte array ByteArrayInputStream bais = new ByteArrayInputStream(buffer); ObjectInputStream ois = new ObjectInputStream(bais); LinkRef linkRef2 = (LinkRef) ois.readObject(); ois.close(); bais.close(); assertEquals(linkRef, linkRef2); }
public void testSerializable_compatibility() throws ClassNotFoundException, IOException { ObjectInputStream ois = new ObjectInputStream(getClass() .getClassLoader().getResourceAsStream( "/serialization/javax/naming/LinkRef.ser")); LinkRef linkRef2 = (LinkRef) ois.readObject(); ois.close(); String name = "www.eclipse.org/org/index.html"; LinkRef linkRef = new LinkRef(name); StringRefAddr addr = new StringRefAddr("StringRefAddr", "This is a String RefAddr."); linkRef.add(addr); assertEquals(linkRef, linkRef2); }
public void testConstrcutor_ByNameNull() { Name name = null; try { new LinkRef(name); fail("It should throw NullPointerException."); } catch (NullPointerException e) { } }
public void testGetLinkName_NamingException() throws NamingException { String name = "www.apache.org/index.html"; LinkRef linkRef = new LinkRef(name); linkRef.clear(); try { linkRef.getLinkName(); fail("It should throw a MalformedLinkException"); } catch (MalformedLinkException e1) { } }
public void testEquals_Simple() { String name = "www.apache.org/index.html"; LinkRef linkRef0 = new LinkRef(name); LinkRef linkRef1 = new LinkRef(name); assertTrue(linkRef0.equals(linkRef1)); assertTrue(linkRef0.equals(linkRef0)); assertTrue(linkRef1.equals(linkRef0)); assertFalse(linkRef0.equals(null)); }
public void testHashcode_Simple() { String name = "www.apache.org/index.html"; StringRefAddr addr = new StringRefAddr("LinkAddress", name); String className = LinkRef.class.getName(); LinkRef linkRef = new LinkRef(name); assertEquals(className.hashCode() + addr.hashCode(), linkRef.hashCode()); }
public void testToString_Simple() { String name = "www.apache.org/index.html"; LinkRef linkRef = new LinkRef(name); StringRefAddr addr1 = new StringRefAddr("LinkAddress", "www.apache.org"); linkRef.add(addr1); /* * assertEquals( "Reference class name: " + LinkRef.class.getName() + * "\nReference addresses:\n\t" + addr0.toString() + "\n\t" + * addr1.toString() + "\n", linkRef.toString()); */ assertNotNull(linkRef.toString()); }
/** * LinkRef addresses need to be prefixed with java: or they won't resolve * * OpenEJB is fine with this, but Tomcat needs them * * @param value * @return */ private static Object normalize(final Object value) { try { if (!(value instanceof LinkRef)) { return value; } final LinkRef ref = (LinkRef) value; final RefAddr refAddr = ref.getAll().nextElement(); final String address = refAddr.getContent().toString(); if (address.startsWith("openejb:")) { return value; } if (!address.startsWith("java:")) { return new LinkRef("java:" + address); } } catch (final Exception e) { // no-op } return value; }
/** * Binds a name to an object. All intermediate contexts and the target * context (that named by all but terminal atomic component of the name) * must already exist. * * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @param rebind if true, then perform a rebind (ie, overwrite) * @exception NameAlreadyBoundException if name is already bound * @exception javax.naming.directory.InvalidAttributesException if object * did not supply all mandatory attributes * @exception NamingException if a naming exception is encountered */ protected void bind(Name name, Object obj, boolean rebind) throws NamingException { if (!checkWritable()) { return; } while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) throw new NamingException (sm.getString("namingContext.invalidName")); NamingEntry entry = bindings.get(name.get(0)); if (name.size() > 1) { if (entry == null) { throw new NameNotFoundException(sm.getString( "namingContext.nameNotBound", name, name.get(0))); } if (entry.type == NamingEntry.CONTEXT) { if (rebind) { ((Context) entry.value).rebind(name.getSuffix(1), obj); } else { ((Context) entry.value).bind(name.getSuffix(1), obj); } } else { throw new NamingException (sm.getString("namingContext.contextExpected")); } } else { if ((!rebind) && (entry != null)) { throw new NameAlreadyBoundException (sm.getString("namingContext.alreadyBound", name.get(0))); } else { // Getting the type of the object and wrapping it within a new // NamingEntry Object toBind = NamingManager.getStateToBind(obj, name, this, env); if (toBind instanceof Context) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT); } else if (toBind instanceof LinkRef) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF); } else if (toBind instanceof Reference) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else if (toBind instanceof Referenceable) { toBind = ((Referenceable) toBind).getReference(); entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else { entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY); } bindings.put(name.get(0), entry); } } }
/** * Binds a name to an object. All intermediate contexts and the target * context (that named by all but terminal atomic component of the name) * must already exist. * * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @param rebind if true, then perform a rebind (ie, overwrite) * @exception NameAlreadyBoundException if name is already bound * @exception InvalidAttributesException if object did not supply all * mandatory attributes * @exception NamingException if a naming exception is encountered */ protected void bind(Name name, Object obj, boolean rebind) throws NamingException { checkWritable(); while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) throw new NamingException (sm.getString("namingContext.invalidName")); NamingEntry entry = (NamingEntry) bindings.get(name.get(0)); if (name.size() > 1) { if (entry == null) { throw new NameNotFoundException (sm.getString("namingContext.nameNotBound", name.get(0))); } if (entry.type == NamingEntry.CONTEXT) { if (rebind) { ((Context) entry.value).rebind(name.getSuffix(1), obj); } else { ((Context) entry.value).bind(name.getSuffix(1), obj); } } else { throw new NamingException (sm.getString("namingContext.contextExpected")); } } else { if ((!rebind) && (entry != null)) { throw new NameAlreadyBoundException (sm.getString("namingContext.alreadyBound", name.get(0))); } else { // Getting the type of the object and wrapping it within a new // NamingEntry Object toBind = NamingManager.getStateToBind(obj, name, this, env); if (toBind instanceof Context) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT); } else if (toBind instanceof LinkRef) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF); } else if (toBind instanceof Reference) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else if (toBind instanceof Referenceable) { toBind = ((Referenceable) toBind).getReference(); entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else { entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY); } bindings.put(name.get(0), entry); } } }
/** * Binds a name to an object. All intermediate contexts and the target * context (that named by all but terminal atomic component of the name) * must already exist. * * @param name the name to bind; may not be empty * @param object the object to bind; possibly null * @param rebind if true, then perform a rebind (ie, overwrite) * @exception NameAlreadyBoundException if name is already bound * @exception InvalidAttributesException if object did not supply all * mandatory attributes * @exception NamingException if a naming exception is encountered */ protected void bind(Name name, Object obj, boolean rebind) throws NamingException { checkWritable(); while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) throw new NamingException (sm.getString("namingContext.invalidName")); NamingEntry entry = (NamingEntry) bindings.get(name.get(0)); if (name.size() > 1) { if (entry == null) { throw new NameNotFoundException (sm.getString("namingContext.nameNotBound", name.get(0))); } if (entry.type == NamingEntry.CONTEXT) { if (rebind) { ((Context) entry.value).rebind(name.getSuffix(1), obj); } else { ((Context) entry.value).bind(name.getSuffix(1), obj); } } else { throw new NamingException (sm.getString("namingContext.contextExpected")); } } else { if ((!rebind) && (entry != null)) { throw new NamingException (sm.getString("namingContext.alreadyBound", name.get(0))); } else { // Getting the type of the object and wrapping it within a new // NamingEntry Object toBind = NamingManager.getStateToBind(obj, name, this, env); if (toBind instanceof Context) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT); } else if (toBind instanceof LinkRef) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF); } else if (toBind instanceof Reference) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else if (toBind instanceof Referenceable) { toBind = ((Referenceable) toBind).getReference(); entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else { entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY); } bindings.put(name.get(0), entry); } } }
/** * Binds a name to an object. All intermediate contexts and the target * context (that named by all but terminal atomic component of the name) * must already exist. * * @param name * the name to bind; may not be empty * @param obj * the object to bind; possibly null * @param rebind * if true, then perform a rebind (ie, overwrite) * @exception NameAlreadyBoundException * if name is already bound * @exception javax.naming.directory.InvalidAttributesException * if object did not supply all mandatory attributes * @exception NamingException * if a naming exception is encountered */ protected void bind(Name name, Object obj, boolean rebind) throws NamingException { if (!checkWritable()) { return; } while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) throw new NamingException(sm.getString("namingContext.invalidName")); NamingEntry entry = bindings.get(name.get(0)); if (name.size() > 1) { if (entry == null) { throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name, name.get(0))); } if (entry.type == NamingEntry.CONTEXT) { if (rebind) { ((Context) entry.value).rebind(name.getSuffix(1), obj); } else { ((Context) entry.value).bind(name.getSuffix(1), obj); } } else { throw new NamingException(sm.getString("namingContext.contextExpected")); } } else { if ((!rebind) && (entry != null)) { throw new NameAlreadyBoundException(sm.getString("namingContext.alreadyBound", name.get(0))); } else { // Getting the type of the object and wrapping it within a new // NamingEntry Object toBind = NamingManager.getStateToBind(obj, name, this, env); if (toBind instanceof Context) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT); } else if (toBind instanceof LinkRef) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF); } else if (toBind instanceof Reference) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else if (toBind instanceof Referenceable) { toBind = ((Referenceable) toBind).getReference(); entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else { entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY); } bindings.put(name.get(0), entry); } } }
/** * Binds a name to an object. All intermediate contexts and the target * context (that named by all but terminal atomic component of the name) * must already exist. * * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @param rebind if true, then perform a rebind (ie, overwrite) * @throws NameAlreadyBoundException if name is already bound * @throws javax.naming.directory.InvalidAttributesException if object * did not supply all mandatory attributes * @throws NamingException if a jndi exception is encountered */ protected void bind(Name name, Object obj, boolean rebind) throws NamingException { while ((!name.isEmpty()) && (name.get(0).length() == 0)) { name = name.getSuffix(1); } if (name.isEmpty()) { throw new NamingException(SM.getString("namingContext.invalidName")); } NamingEntry entry = bindings.get(name.get(0)); if (name.size() > 1) { if (entry == null) { throw new NameNotFoundException(SM.getString("namingContext.nameNotBound", name, name.get(0))); } if (entry.type == NamingEntry.CONTEXT) { if (rebind) { ((Context) entry.value).rebind(name.getSuffix(1), obj); } else { ((Context) entry.value).bind(name.getSuffix(1), obj); } } else { throw new NamingException(SM.getString("namingContext.contextExpected")); } } else { if ((!rebind) && (entry != null)) { throw new NameAlreadyBoundException(SM.getString("namingContext.alreadyBound", name.get(0))); } else { // Getting the type of the object and wrapping it within a new // NamingEntry Object toBind = NamingManager.getStateToBind(obj, name, this, env); if (toBind instanceof Context) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.CONTEXT); } else if (toBind instanceof LinkRef) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.LINK_REF); } else if (toBind instanceof Reference) { entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else if (toBind instanceof Referenceable) { toBind = ((Referenceable) toBind).getReference(); entry = new NamingEntry(name.get(0), toBind, NamingEntry.REFERENCE); } else { entry = new NamingEntry(name.get(0), toBind, NamingEntry.ENTRY); } bindings.put(name.get(0), entry); } } }
public void testConstructor_ByName() throws NamingException { Name name = new CompositeName("www.apache.org/index.html"); LinkRef linkRef = new LinkRef(name); assertEquals(1, linkRef.size()); assertEquals(name.toString(), linkRef.getLinkName()); }
public void testConstructor_ByString() { String name = "www.apache.org/index.html"; LinkRef linkRef = new LinkRef(name); assertEquals(1, linkRef.size()); }
public void testConstrcutor_ByStringNull() { String name = null; LinkRef linkRef = new LinkRef(name); assertNull(linkRef.get("LinkAddress").getContent()); }
public void testGetLinkName_Simple() throws NamingException { String name = "www.apache.org/index.html"; LinkRef linkRef = new LinkRef(name); assertEquals(name, linkRef.getLinkName()); }
public void testGetClassName() { String name = "www.apache.org/index.html"; LinkRef linkRef = new LinkRef(name); assertEquals(LinkRef.class.getName(), linkRef.getClassName()); }
public void testGetFactoryClassName() { String name = "www.apache.org/index.html"; LinkRef linkRef = new LinkRef(name); assertNull(linkRef.getFactoryClassName()); }
public void testGetFactoryClassLocation() { String name = "www.apache.org/index.html"; LinkRef linkRef = new LinkRef(name); assertNull(linkRef.getFactoryClassLocation()); }