Search in sources :

Example 41 with CompositeName

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();
}
Also used : CompositeName(javax.naming.CompositeName)

Example 42 with CompositeName

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;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NotContextException(javax.naming.NotContextException) NamingException(javax.naming.NamingException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) NameNotFoundException(javax.naming.NameNotFoundException) Provider(com.google.inject.Provider) LinkRef(javax.naming.LinkRef)

Example 43 with CompositeName

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();
}
Also used : CompositeName(javax.naming.CompositeName)

Example 44 with CompositeName

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;
}
Also used : Context(javax.naming.Context) NameNotFoundException(javax.naming.NameNotFoundException) Reference(javax.naming.Reference) CompositeName(javax.naming.CompositeName) NamingException(javax.naming.NamingException) NamingException(javax.naming.NamingException) NameNotFoundException(javax.naming.NameNotFoundException) NotContextException(javax.naming.NotContextException) OperationNotSupportedException(javax.naming.OperationNotSupportedException) LinkRef(javax.naming.LinkRef)

Example 45 with CompositeName

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());
        }
    });
}
Also used : CompositeName(javax.naming.CompositeName) DateTime(org.joda.time.DateTime) CallableWithoutResult(org.apereo.portal.concurrency.CallableWithoutResult) IEntityGroup(org.apereo.portal.groups.IEntityGroup) FunctionWithoutResult(org.apereo.portal.concurrency.FunctionWithoutResult) AggregatedGroupMapping(org.apereo.portal.events.aggr.groups.AggregatedGroupMapping) Random(java.util.Random) MutableInt(org.apache.commons.lang.mutable.MutableInt) Collection(java.util.Collection) Tuple(org.apereo.portal.utils.Tuple) MutableObject(org.apache.commons.lang.mutable.MutableObject) Test(org.junit.Test) BaseAggrEventsJpaDaoTest(org.apereo.portal.test.BaseAggrEventsJpaDaoTest)

Aggregations

CompositeName (javax.naming.CompositeName)124 Test (org.junit.Test)69 Name (javax.naming.Name)43 NameNotFoundException (javax.naming.NameNotFoundException)27 NamingException (javax.naming.NamingException)25 Reference (javax.naming.Reference)19 Context (javax.naming.Context)18 InvalidNameException (javax.naming.InvalidNameException)13 NotContextException (javax.naming.NotContextException)12 ServiceName (org.jboss.msc.service.ServiceName)11 Test (org.junit.jupiter.api.Test)10 JndiPermission (org.wildfly.naming.java.permission.JndiPermission)10 Hashtable (java.util.Hashtable)9 Binding (javax.naming.Binding)8 LinkRef (javax.naming.LinkRef)8 OperationNotSupportedException (javax.naming.OperationNotSupportedException)8 CallableWithoutResult (org.apereo.portal.concurrency.CallableWithoutResult)7 IEntityGroup (org.apereo.portal.groups.IEntityGroup)7 BaseAggrEventsJpaDaoTest (org.apereo.portal.test.BaseAggrEventsJpaDaoTest)7 StringRefAddr (javax.naming.StringRefAddr)5