本文整理汇总了Java中javax.naming.LinkRef类的典型用法代码示例。如果您正苦于以下问题:Java LinkRef类的具体用法?Java LinkRef怎么用?Java LinkRef使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LinkRef类属于javax.naming包,在下文中一共展示了LinkRef类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: lookupLink
import javax.naming.LinkRef; //导入依赖的package包/类
@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;
}
示例2: testSerializable_Simple
import javax.naming.LinkRef; //导入依赖的package包/类
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);
}
示例3: testSerializable_compatibility
import javax.naming.LinkRef; //导入依赖的package包/类
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);
}
示例4: testConstrcutor_ByNameNull
import javax.naming.LinkRef; //导入依赖的package包/类
public void testConstrcutor_ByNameNull() {
Name name = null;
try {
new LinkRef(name);
fail("It should throw NullPointerException.");
} catch (NullPointerException e) {
}
}
示例5: testGetLinkName_NamingException
import javax.naming.LinkRef; //导入依赖的package包/类
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) {
}
}
示例6: testEquals_Simple
import javax.naming.LinkRef; //导入依赖的package包/类
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));
}
示例7: testHashcode_Simple
import javax.naming.LinkRef; //导入依赖的package包/类
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());
}
示例8: testToString_Simple
import javax.naming.LinkRef; //导入依赖的package包/类
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());
}
示例9: normalize
import javax.naming.LinkRef; //导入依赖的package包/类
/**
* 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;
}
示例10: bind
import javax.naming.LinkRef; //导入依赖的package包/类
/**
* 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);
}
}
}
示例11: bind
import javax.naming.LinkRef; //导入依赖的package包/类
/**
* 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);
}
}
}
示例12: bind
import javax.naming.LinkRef; //导入依赖的package包/类
/**
* 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);
}
}
}
示例13: bind
import javax.naming.LinkRef; //导入依赖的package包/类
/**
* 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);
}
}
}
示例14: bind
import javax.naming.LinkRef; //导入依赖的package包/类
/**
* 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);
}
}
}
示例15: testConstructor_ByName
import javax.naming.LinkRef; //导入依赖的package包/类
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());
}