本文整理汇总了Java中javax.naming.CompositeName类的典型用法代码示例。如果您正苦于以下问题:Java CompositeName类的具体用法?Java CompositeName怎么用?Java CompositeName使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CompositeName类属于javax.naming包,在下文中一共展示了CompositeName类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doGet
import javax.naming.CompositeName; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain;UTF-8");
PrintWriter out = resp.getWriter();
try {
Context initCtx = new InitialContext();
Boolean b1 = (Boolean) initCtx.lookup(JNDI_NAME);
Boolean b2 = (Boolean) initCtx.lookup(
new CompositeName(JNDI_NAME));
out.print(b1);
out.print(b2);
} catch (NamingException ne) {
throw new ServletException(ne);
}
}
示例2: bind
import javax.naming.CompositeName; //导入依赖的package包/类
@Override
public void bind(Name name, Object obj) throws NamingException {
if (name.isEmpty()) {
throw new InvalidNameException("Cannot bind empty name");
}
Name nm = getMyComponents(name);
String atom = nm.get(0);
Object inter = iBindings.get(atom);
if (nm.size() == 1) {
if (inter != null)
throw new NameAlreadyBoundException("Use rebind to override");
obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv);
iBindings.put(atom, obj);
} else {
if (!(inter instanceof Context))
throw new NotContextException(atom + " does not name a context");
((Context) inter).bind(nm.getSuffix(1), obj);
}
}
示例3: rebind
import javax.naming.CompositeName; //导入依赖的package包/类
@Override
public void rebind(Name name, Object obj) throws NamingException {
if (name.isEmpty())
throw new InvalidNameException("Cannot bind empty name");
Name nm = getMyComponents(name);
String atom = nm.get(0);
if (nm.size() == 1) {
obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv);
iBindings.put(atom, obj);
} else {
Object inter = iBindings.get(atom);
if (!(inter instanceof Context))
throw new NotContextException(atom + " does not name a context");
((Context) inter).rebind(nm.getSuffix(1), obj);
}
}
示例4: testPropertyValue_Serializable
import javax.naming.CompositeName; //导入依赖的package包/类
@Test
public void testPropertyValue_Serializable() throws Exception
{
for (int i = 0; i < 100; i++)
{
// Choose a type that implements equals and hashCode but will not be recognised
runPropertyValueTest(new CompositeName("Name-"+i), false);
}
}
示例5: getDistinguishedName
import javax.naming.CompositeName; //导入依赖的package包/类
/**
* Returns the distinguished name of a search result.
*
* @param context Our DirContext
* @param base The base DN
* @param result The search result
* @return String containing the distinguished name
*/
protected String getDistinguishedName(DirContext context, String base, SearchResult result)
throws NamingException {
// Get the entry's distinguished name
NameParser parser = context.getNameParser("");
Name contextName = parser.parse(context.getNameInNamespace());
Name baseName = parser.parse(base);
// Bugzilla 32269
Name entryName = parser.parse(new CompositeName(result.getName()).get(0));
Name name = contextName.addAll(baseName);
name = name.addAll(entryName);
return name.toString();
}
示例6: getMyComponents
import javax.naming.CompositeName; //导入依赖的package包/类
protected Name getMyComponents(Name name) throws NamingException {
if (name instanceof CompositeName) {
if (name.size() > 1)
throw new InvalidNameException(name.toString() + " has more components than namespace can handle");
return parse(name.get(0));
} else {
return name;
}
}
示例7: lookup
import javax.naming.CompositeName; //导入依赖的package包/类
@Override
public Object lookup(Name name) throws NamingException {
if (name.isEmpty())
return cloneCtx();
Name nm = getMyComponents(name);
String atom = nm.get(0);
Object inter = iBindings.get(atom);
if (nm.size() == 1) {
if (inter == null)
throw new NameNotFoundException(name + " not found");
try {
return NamingManager.getObjectInstance(inter, new CompositeName().add(atom), this, iEnv);
} catch (Exception e) {
NamingException ne = new NamingException("getObjectInstance failed");
ne.setRootCause(e);
throw ne;
}
} else {
if (!(inter instanceof Context))
throw new NotContextException(atom + " does not name a context");
return ((Context) inter).lookup(nm.getSuffix(1));
}
}
示例8: next
import javax.naming.CompositeName; //导入依赖的package包/类
public Object next() throws NamingException {
String name = (String) iNames.nextElement();
Object obj = iBindings.get(name);
try {
obj = NamingManager.getObjectInstance(obj, new CompositeName().add(name), LocalContext.this, LocalContext.this.iEnv);
} catch (Exception e) {
NamingException ne = new NamingException("getObjectInstance failed");
ne.setRootCause(e);
throw ne;
}
return new Binding(name, obj);
}
示例9: getTargetContext
import javax.naming.CompositeName; //导入依赖的package包/类
protected DirContextNamePair getTargetContext(Name name)
throws NamingException {
if (cpe.getResolvedObj() == null)
throw (NamingException)cpe.fillInStackTrace();
Context ctx = NamingManager.getContext(cpe.getResolvedObj(),
cpe.getAltName(),
cpe.getAltNameCtx(),
env);
if (ctx == null)
throw (NamingException)cpe.fillInStackTrace();
if (ctx instanceof DirContext)
return new DirContextNamePair((DirContext)ctx, name);
if (ctx instanceof Resolver) {
Resolver res = (Resolver)ctx;
ResolveResult rr = res.resolveToClass(name, DirContext.class);
// Reached a DirContext; return result.
DirContext dctx = (DirContext)rr.getResolvedObj();
return (new DirContextNamePair(dctx, rr.getRemainingName()));
}
// Resolve all the way using lookup(). This may allow the operation
// to succeed if it doesn't require the penultimate context.
Object ultimate = ctx.lookup(name);
if (ultimate instanceof DirContext) {
return (new DirContextNamePair((DirContext)ultimate,
new CompositeName()));
}
throw (NamingException)cpe.fillInStackTrace();
}
示例10: ResolveResult
import javax.naming.CompositeName; //导入依赖的package包/类
/**
* Constructs a new instance of ResolveResult consisting of
* the resolved object and the remaining unresolved component.
*
* @param robj The non-null object resolved to.
* @param rcomp The single remaining name component that has yet to be
* resolved. Cannot be null (but can be empty).
*/
public ResolveResult(Object robj, String rcomp) {
resolvedObj = robj;
try {
remainingName = new CompositeName(rcomp);
// remainingName.appendComponent(rcomp);
} catch (InvalidNameException e) {
// ignore; shouldn't happen
}
}
示例11: appendRemainingComponent
import javax.naming.CompositeName; //导入依赖的package包/类
/**
* Adds a single component to the end of remaining name.
*
* @param name The component to add. Can be null.
* @see #getRemainingName
* @see #appendRemainingName
*/
public void appendRemainingComponent(String name) {
if (name != null) {
CompositeName rname = new CompositeName();
try {
rname.add(name);
} catch (InvalidNameException e) {
// ignore; shouldn't happen for empty composite name
}
appendRemainingName(rname);
}
}
示例12: testPropertySerializableValue
import javax.naming.CompositeName; //导入依赖的package包/类
@Test
public void testPropertySerializableValue() throws Exception
{
final Serializable serializableValue = new CompositeName("123");
RetryingTransactionCallback<Pair<Long, Serializable>> createValueCallback = new RetryingTransactionCallback<Pair<Long, Serializable>>()
{
public Pair<Long, Serializable> execute() throws Throwable
{
return propertyValueDAO.createPropertySerializableValue(serializableValue);
}
};
final Pair<Long, Serializable> entityPair = txnHelper.doInTransaction(createValueCallback, false);
assertNotNull(entityPair);
assertEquals(serializableValue, entityPair.getSecond());
RetryingTransactionCallback<Pair<Long, Serializable>> getValueCallback = new RetryingTransactionCallback<Pair<Long, Serializable>>()
{
public Pair<Long, Serializable> execute() throws Throwable
{
return propertyValueDAO.getPropertySerializableValueById(entityPair.getFirst());
}
};
final Pair<Long, Serializable> entityPairCheck = txnHelper.doInTransaction(getValueCallback, false);
assertNotNull(entityPairCheck);
assertEquals(entityPair.getFirst(), entityPairCheck.getFirst());
assertEquals(entityPair, entityPairCheck);
// Check that we can persist and retrieve byte[] as a Serializable
final Serializable bytes = (Serializable) new byte[] {1, 2, 3};
RetryingTransactionCallback<Pair<Long, Void>> testBytesCallback = new RetryingTransactionCallback<Pair<Long, Void>>()
{
public Pair<Long, Void> execute() throws Throwable
{
Long id = propertyValueDAO.createPropertySerializableValue(bytes).getFirst();
Serializable check = propertyValueDAO.getPropertySerializableValueById(id).getSecond();
assertNotNull(check);
assertTrue(check instanceof byte[]);
Arrays.equals((byte[])bytes, (byte[])check);
return null;
}
};
txnHelper.doInTransaction(testBytesCallback, false);
}
示例13: unbind
import javax.naming.CompositeName; //导入依赖的package包/类
@Override
public void unbind(String name) throws NamingException {
unbind(new CompositeName(name));
}
示例14: rename
import javax.naming.CompositeName; //导入依赖的package包/类
@Override
public void rename(String oldname, String newname) throws NamingException {
rename(new CompositeName(oldname), new CompositeName(newname));
}
示例15: list
import javax.naming.CompositeName; //导入依赖的package包/类
@Override
public NamingEnumeration list(String name) throws NamingException {
return list(new CompositeName(name));
}