use of javax.naming.InvalidNameException in project Towny by ElgarL.
the class TownyDatabaseHandler method renameTown.
@Override
public void renameTown(Town town, String newName) throws AlreadyRegisteredException, NotRegisteredException {
lock.lock();
String oldName;
try {
String filteredName;
try {
filteredName = NameValidation.checkAndFilterName(newName);
} catch (InvalidNameException e) {
throw new NotRegisteredException(e.getMessage());
}
if (hasTown(filteredName))
throw new AlreadyRegisteredException("The town " + filteredName + " is already in use.");
// TODO: Delete/rename any invites.
List<Resident> toSave = new ArrayList<Resident>(town.getResidents());
Boolean isCapital = false;
Nation nation = null;
Double townBalance = 0.0;
oldName = town.getName();
// Clear accounts
if (TownySettings.isUsingEconomy())
try {
townBalance = town.getHoldingBalance();
town.removeAccount();
} catch (EconomyException e) {
}
// Store the nation in case we have to update the capitol
if (town.hasNation()) {
nation = town.getNation();
isCapital = town.isCapital();
}
/*
* Tidy up old files.
* Has to be done here else the town no longer exists
* and the file move command may fail.
*/
deleteTown(town);
/*
* Remove the old town from the townsMap
* and rename to the new name
*/
universe.getTownsMap().remove(town.getName().toLowerCase());
town.setName(filteredName);
universe.getTownsMap().put(filteredName.toLowerCase(), town);
// If this was a nation capitol
if (isCapital) {
nation.setCapital(town);
}
if (TownySettings.isUsingEconomy()) {
// TODO
try {
town.setBalance(townBalance, "Rename Town - Transfer to new account");
} catch (EconomyException e) {
e.printStackTrace();
}
}
for (Resident resident : toSave) {
saveResident(resident);
}
for (TownBlock townBlock : town.getTownBlocks()) {
// townBlock.setTown(town);
saveTownBlock(townBlock);
}
saveTown(town);
saveTownList();
saveWorld(town.getWorld());
if (nation != null) {
saveNation(nation);
}
} finally {
lock.unlock();
}
BukkitTools.getPluginManager().callEvent(new RenameTownEvent(oldName, town));
universe.setChangedNotify(RENAME_TOWN);
}
use of javax.naming.InvalidNameException in project Towny by ElgarL.
the class TownyFlatFileSource method saveResidentList.
@Override
public boolean saveResidentList() {
List<String> list = new ArrayList<String>();
for (Resident resident : getResidents()) {
try {
list.add(NameValidation.checkAndFilterPlayerName(resident.getName()));
} catch (InvalidNameException e) {
TownyMessaging.sendErrorMsg("Saving Error: Exception while saving town list file:" + resident.getName());
}
}
/*
* Make sure we only save in async
*/
this.queryQueue.add(new FlatFile_Task(list, rootFolder + dataFolder + FileMgmt.fileSeparator() + "residents.txt"));
return true;
}
use of javax.naming.InvalidNameException in project zm-mailbox by Zimbra.
the class CertUtil method getSubjectAttr.
private String getSubjectAttr(String needAttrName, String needAttrOid) {
String subjectDN = getSubjectDN();
try {
LdapName dn = new LdapName(subjectDN);
List<Rdn> rdns = dn.getRdns();
for (Rdn rdn : rdns) {
String type = rdn.getType();
boolean isOid = type.contains(".");
boolean matched = (isOid ? type.equals(needAttrOid) : type.equals(needAttrName));
if (matched) {
Object value = rdn.getValue();
if (value == null) {
continue;
}
if (isOid) {
byte[] bytes = (byte[]) value;
ASN1InputStream decoder = null;
try {
decoder = new ASN1InputStream(bytes);
ASN1Encodable encoded = decoder.readObject();
DERIA5String str = DERIA5String.getInstance(encoded);
return str.getString();
} catch (IOException e) {
ZimbraLog.account.warn(LOG_PREFIX + "unable to decode " + type, e);
} finally {
ByteUtil.closeStream(decoder);
}
} else {
return value.toString();
}
}
}
} catch (InvalidNameException e) {
ZimbraLog.account.warn(LOG_PREFIX + "Invalid subject dn value" + subjectDN, e);
}
return null;
}
use of javax.naming.InvalidNameException in project wildfly by wildfly.
the class ExceptionMapper method mapException.
public static NamingException mapException(Exception e, CNCtx ctx, NameComponent[] inputName) throws NamingException {
if (e instanceof NamingException) {
return (NamingException) e;
}
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
}
NamingException ne;
if (e instanceof NotFound) {
if (ctx.federation) {
return tryFed((NotFound) e, ctx, inputName);
} else {
ne = new NameNotFoundException();
}
} else if (e instanceof CannotProceed) {
ne = new CannotProceedException();
NamingContext nc = ((CannotProceed) e).cxt;
NameComponent[] rest = ((CannotProceed) e).rest_of_name;
// NotFound doesn't set rest as expected. -RL
if (inputName != null && (inputName.length > rest.length)) {
NameComponent[] resolvedName = new NameComponent[inputName.length - rest.length];
System.arraycopy(inputName, 0, resolvedName, 0, resolvedName.length);
// Wrap resolved NamingContext inside a CNCtx
// Guess that its name (which is relative to ctx)
// is the part of inputName minus rest_of_name
ne.setResolvedObj(new CNCtx(ctx._orb, nc, ctx._env, ctx.makeFullName(resolvedName)));
} else {
ne.setResolvedObj(ctx);
}
ne.setRemainingName(org.wildfly.iiop.openjdk.naming.jndi.CNNameParser.cosNameToName(rest));
} else if (e instanceof InvalidName) {
ne = new InvalidNameException();
} else if (e instanceof AlreadyBound) {
ne = new NameAlreadyBoundException();
} else if (e instanceof NotEmpty) {
ne = new ContextNotEmptyException();
} else {
ne = new NamingException();
}
ne.setRootCause(e);
return ne;
}
use of javax.naming.InvalidNameException in project wildfly by wildfly.
the class ServiceBasedNamingStore method suffix.
private Name suffix(ServiceName parent, ServiceName child) {
String[] p = parent.toArray();
String[] c = child.toArray();
CompositeName name = new CompositeName();
for (int i = p.length; i < c.length; i++) {
try {
name.add(c[i]);
} catch (InvalidNameException e) {
throw new IllegalStateException(e);
}
}
return name;
}
Aggregations