use of javax.naming.CompositeName in project camel by apache.
the class JndiContext method composeName.
public String composeName(String name, String prefix) throws NamingException {
CompositeName result = new CompositeName(prefix);
result.addAll(new CompositeName(name));
return result.toString();
}
use of javax.naming.CompositeName in project camel by apache.
the class JndiContext method lookup.
public Object lookup(String name) throws NamingException {
if (name.length() == 0) {
return this;
}
Object result = treeBindings.get(name);
if (result == null) {
result = bindings.get(name);
}
if (result == null) {
int pos = name.indexOf(':');
if (pos > 0) {
String scheme = name.substring(0, pos);
Context ctx = NamingManager.getURLContext(scheme, environment);
if (ctx == null) {
throw new NamingException("scheme " + scheme + " not recognized");
}
return ctx.lookup(name);
} else {
// Split out the first name of the path
// and look for it in the bindings map.
CompositeName path = new CompositeName(name);
if (path.size() == 0) {
return this;
} else {
String first = path.get(0);
Object value = bindings.get(first);
if (value == null) {
throw new NameNotFoundException(name);
} else if (value instanceof Context && path.size() > 1) {
Context subContext = (Context) value;
value = subContext.lookup(path.getSuffix(1));
}
return value;
}
}
}
if (result instanceof Provider) {
Provider provider = (Provider) result;
result = provider.get();
}
if (result instanceof LinkRef) {
LinkRef ref = (LinkRef) result;
result = lookup(ref.getLinkName());
}
if (result instanceof Reference) {
try {
result = NamingManager.getObjectInstance(result, null, null, this.environment);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
}
}
if (result instanceof JndiContext) {
String prefix = getNameInNamespace();
if (prefix.length() > 0) {
prefix = prefix + SEPARATOR;
}
result = new JndiContext((JndiContext) result, environment, prefix + name);
}
return result;
}
use of javax.naming.CompositeName in project camel by apache.
the class JndiContext method composeName.
public String composeName(String name, String prefix) throws NamingException {
CompositeName result = new CompositeName(prefix);
result.addAll(new CompositeName(name));
return result.toString();
}
use of javax.naming.CompositeName in project camel by apache.
the class JndiContext method lookup.
public Object lookup(String name) throws NamingException {
if (name.length() == 0) {
return this;
}
Object result = treeBindings.get(name);
if (result == null) {
result = bindings.get(name);
}
if (result == null) {
int pos = name.indexOf(':');
if (pos > 0) {
String scheme = name.substring(0, pos);
Context ctx = NamingManager.getURLContext(scheme, environment);
if (ctx == null) {
throw new NamingException("scheme " + scheme + " not recognized");
}
return ctx.lookup(name);
} else {
// Split out the first name of the path
// and look for it in the bindings map.
CompositeName path = new CompositeName(name);
if (path.size() == 0) {
return this;
} else {
String first = path.get(0);
Object value = bindings.get(first);
if (value == null) {
throw new NameNotFoundException(name);
} else if (value instanceof Context && path.size() > 1) {
Context subContext = (Context) value;
value = subContext.lookup(path.getSuffix(1));
}
return value;
}
}
}
if (result instanceof LinkRef) {
LinkRef ref = (LinkRef) result;
result = lookup(ref.getLinkName());
}
if (result instanceof Reference) {
try {
result = NamingManager.getObjectInstance(result, null, null, this.environment);
} catch (NamingException e) {
throw e;
} catch (Exception e) {
throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
}
}
if (result instanceof JndiContext) {
String prefix = getNameInNamespace();
if (prefix.length() > 0) {
prefix = prefix + SEPARATOR;
}
result = new JndiContext((JndiContext) result, environment, prefix + name);
}
return result;
}
use of javax.naming.CompositeName in project uPortal by Jasig.
the class JpaBaseAggregationDaoTest method testUnclosedBaseAggregationRangeQuery.
@Test
public final void testUnclosedBaseAggregationRangeQuery() throws Exception {
final IEntityGroup entityGroupA = mock(IEntityGroup.class);
when(entityGroupA.getServiceName()).thenReturn(new CompositeName("local"));
when(entityGroupA.getName()).thenReturn("Group A");
when(compositeGroupService.findGroup("local.0")).thenReturn(entityGroupA);
final IEntityGroup entityGroupB = mock(IEntityGroup.class);
when(entityGroupB.getServiceName()).thenReturn(new CompositeName("local"));
when(entityGroupB.getName()).thenReturn("Group B");
when(compositeGroupService.findGroup("local.1")).thenReturn(entityGroupB);
final MutableInt aggrs = new MutableInt();
// Create 10 minutes of aggregations
final DateTime start = new DateTime(1326734644000l, DateTimeZone.UTC).minuteOfDay().roundFloorCopy();
final DateTime end = start.plusMinutes(10);
final AggregationInterval interval = AggregationInterval.FIVE_MINUTE;
final MutableObject startObj = new MutableObject();
final MutableObject endObj = new MutableObject();
this.executeInTransaction(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Random r = new Random(0);
final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0");
final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1");
populateDateTimeDimensions(start, end, new FunctionWithoutResult<Tuple<DateDimension, TimeDimension>>() {
@Override
protected void applyWithoutResult(Tuple<DateDimension, TimeDimension> input) {
final TimeDimension td = input.second;
final DateDimension dd = input.first;
final DateTime instant = td.getTime().toDateTime(dd.getDate());
if (startObj.getValue() == null) {
startObj.setValue(instant);
}
endObj.setValue(instant);
if (instant.equals(interval.determineStart(instant))) {
final AggregationIntervalInfo intervalInfo = aggregationIntervalHelper.getIntervalInfo(interval, instant);
final T baseAggregationA = getAggregationDao().createAggregation(createAggregationKey(intervalInfo, groupA));
final T baseAggregationB = getAggregationDao().createAggregation(createAggregationKey(intervalInfo, groupB));
for (int u = 0; u < r.nextInt(50); u++) {
updateAggregation(intervalInfo, baseAggregationA, r);
updateAggregation(intervalInfo, baseAggregationB, r);
}
if (aggrs.intValue() % 4 == 0) {
baseAggregationA.intervalComplete(5);
}
baseAggregationB.intervalComplete(5);
getAggregationDao().updateAggregation(baseAggregationA);
getAggregationDao().updateAggregation(baseAggregationB);
aggrs.add(2);
}
}
});
}
});
// Verify all aggrs created
assertEquals(4, aggrs.intValue());
// Find unclosed 1 aggr
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Collection<T> baseAggregations = getAggregationDao().getUnclosedAggregations(start.minusDays(1), end.plusDays(1), interval);
assertEquals(1, baseAggregations.size());
for (final T baseAggregationImpl : baseAggregations) {
baseAggregationImpl.intervalComplete(5);
getAggregationDao().updateAggregation(baseAggregationImpl);
}
}
});
// Find unclosed 0 aggr
this.execute(new CallableWithoutResult() {
@Override
protected void callWithoutResult() {
final Collection<T> baseAggregations = getAggregationDao().getUnclosedAggregations(start.minusDays(1), end.plusDays(1), interval);
assertEquals(0, baseAggregations.size());
}
});
}
Aggregations