List of usage examples for javax.naming CompositeName CompositeName
public CompositeName(String n) throws InvalidNameException
From source file:org.apache.naming.NamingContext.java
/** * Retrieves the named object, following links except for the terminal * atomic component of the name.// w ww. j ava 2 s .c om * * @param name the name of the object to look up * @return the object bound to name, not following the terminal link * (if any). * @exception NamingException if a naming exception is encountered */ public Object lookupLink(String name) throws NamingException { return lookup(new CompositeName(name), false); }
From source file:org.apache.naming.NamingContext.java
/** * Retrieves the parser associated with the named context. * //from w ww.j a v a2 s . com * @param name the name of the context from which to get the parser * @return a name parser that can parse compound names into their atomic * components * @exception NamingException if a naming exception is encountered */ public NameParser getNameParser(String name) throws NamingException { return getNameParser(new CompositeName(name)); }
From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDaoTest.java
@Test public final void testBaseAggregationLifecycle() 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 DateTime instant = new DateTime(1326734644000l, DateTimeZone.UTC); //just a random time //Create required date and time dimensions populateDateTimeDimensions(instant.minusHours(2), instant.plusHours(2), null); //Create aggregations final Map<K, T> createdAggrs = this.executeInTransaction(new Callable<Map<K, T>>() { @Override/*from w w w. j ava2s .c o m*/ public Map<K, T> call() throws Exception { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant); final AggregationIntervalInfo hourInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.HOUR, instant); final Map<K, T> fiveMinGroupA = createAggregations(fiveMinuteInfo, groupA); final Map<K, T> fiveMinGroupB = createAggregations(fiveMinuteInfo, groupB); final Map<K, T> hourGroupA = createAggregations(hourInfo, groupA); final Map<K, T> aggrs = new HashMap<K, T>(fiveMinGroupA); aggrs.putAll(fiveMinGroupB); aggrs.putAll(hourGroupA); return aggrs; } }); //Verify aggregations were created this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant); final AggregationIntervalInfo hourInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.HOUR, instant); final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval( fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval()); final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval( hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval()); final Map<K, T> foundAggrs = new HashMap<K, T>(fiveMinGroup); foundAggrs.putAll(hourGroup); assertEquals("Aggregations not created as expected", createdAggrs, foundAggrs); } }); //Update Aggregations final Map<K, T> updatedAggrs = this.executeInTransaction(new Callable<Map<K, T>>() { @Override public Map<K, T> call() throws Exception { final Random r = new Random(0); final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant); final AggregationIntervalInfo hourInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.HOUR, instant); final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval( fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval()); final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval( hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval()); final Map<K, T> updatedAggrs = new HashMap<K, T>(); for (final Entry<K, T> aggrEntry : fiveMinGroup.entrySet()) { final T aggr = aggrEntry.getValue(); updateAggregation(fiveMinuteInfo, aggr, r); getAggregationDao().updateAggregation(aggr); updatedAggrs.put(aggrEntry.getKey(), aggr); } for (final Entry<K, T> aggrEntry : hourGroup.entrySet()) { final T aggr = aggrEntry.getValue(); updateAggregation(hourInfo, aggr, r); getAggregationDao().updateAggregation(aggr); updatedAggrs.put(aggrEntry.getKey(), aggr); } return updatedAggrs; } }); //Verify aggregations were updated this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant); final AggregationIntervalInfo hourInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.HOUR, instant); final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval( fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval()); final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval( hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval()); final Map<K, T> foundAggrs = new HashMap<K, T>(fiveMinGroup); foundAggrs.putAll(hourGroup); assertEquals("Aggregations not updated as expected", updatedAggrs, foundAggrs); } }); //Complete intervals final Map<K, T> completeAggrs = this.executeInTransaction(new Callable<Map<K, T>>() { @Override public Map<K, T> call() throws Exception { final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant); final AggregationIntervalInfo hourInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.HOUR, instant); final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval( fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval()); final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval( hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval()); final Map<K, T> completeAggrs = new HashMap<K, T>(); for (final Entry<K, T> aggrEntry : fiveMinGroup.entrySet()) { final T aggr = aggrEntry.getValue(); aggr.intervalComplete(5); getAggregationDao().updateAggregation(aggr); completeAggrs.put(aggrEntry.getKey(), aggr); } for (final Entry<K, T> aggrEntry : hourGroup.entrySet()) { final T aggr = aggrEntry.getValue(); aggr.intervalComplete(60); getAggregationDao().updateAggregation(aggr); completeAggrs.put(aggrEntry.getKey(), aggr); } return completeAggrs; } }); //Verify aggregations were completed this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregationIntervalInfo fiveMinuteInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.FIVE_MINUTE, instant); final AggregationIntervalInfo hourInfo = aggregationIntervalHelper .getIntervalInfo(AggregationInterval.HOUR, instant); final Map<K, T> fiveMinGroup = getAggregationDao().getAggregationsForInterval( fiveMinuteInfo.getDateDimension(), fiveMinuteInfo.getTimeDimension(), fiveMinuteInfo.getAggregationInterval()); final Map<K, T> hourGroup = getAggregationDao().getAggregationsForInterval( hourInfo.getDateDimension(), hourInfo.getTimeDimension(), hourInfo.getAggregationInterval()); final Map<K, T> foundAggrs = new HashMap<K, T>(fiveMinGroup); foundAggrs.putAll(hourGroup); assertEquals("Aggregations not completed as expected", completeAggrs, foundAggrs); } }); }
From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDaoTest.java
@Test public final void testBaseAggregationRangeQuery() 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 2 days of login aggregates ... every 5 minutes final DateTime start = new DateTime(1326734644000l, DateTimeZone.UTC).minuteOfDay().roundFloorCopy(); final DateTime end = start.plusDays(2); final AggregationInterval interval = AggregationInterval.FIVE_MINUTE; final MutableObject startObj = new MutableObject(); final MutableObject endObj = new MutableObject(); this.executeInTransaction(new CallableWithoutResult() { @Override//from w w w.j ava 2s. co m 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); } baseAggregationA.intervalComplete(5); baseAggregationB.intervalComplete(5); getAggregationDao().updateAggregation(baseAggregationA); getAggregationDao().updateAggregation(baseAggregationB); aggrs.add(2); } } }); } }); //Verify all aggrs created assertEquals(1152, aggrs.intValue()); //Find aggrs for one day this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final DateTime queryStart = start.toDateMidnight().toDateTime(); final DateTime queryEnd = queryStart.plusDays(1).minusSeconds(1); final List<T> baseAggregations = getAggregationDao().getAggregations(queryStart, queryEnd, createAggregationKey(interval, groupA), groupB); assertEquals(158, baseAggregations.size()); } }); //Find aggrs for second day this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final DateTime queryStart = start.toDateMidnight().minusDays(1).toDateTime(); final DateTime queryEnd = queryStart.plusDays(2).minusSeconds(1); final List<T> baseAggregations = getAggregationDao().getAggregations(queryStart, queryEnd, createAggregationKey(interval, groupA), groupB); assertEquals(158, baseAggregations.size()); } }); //Find all aggrs this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final List<T> baseAggregations = getAggregationDao().getAggregations(start, end.plusDays(1), createAggregationKey(interval, groupA), groupB); assertEquals(1152, baseAggregations.size()); } }); //Find first days worth this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final List<T> baseAggregations = getAggregationDao().getAggregations(start, end, createAggregationKey(interval, groupA), groupB); assertEquals(1152, baseAggregations.size()); } }); //Find second days worth this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final List<T> baseAggregations = getAggregationDao().getAggregations(start.plusDays(1), end.plusDays(1), createAggregationKey(interval, groupA), groupB); assertEquals(576, baseAggregations.size()); } }); //Find first 12 hours worth this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final List<T> baseAggregations = getAggregationDao().getAggregations(start, start.plusHours(12), createAggregationKey(interval, groupA), groupB); assertEquals(288, baseAggregations.size()); } }); //Find middle 24 hours worth this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final List<T> baseAggregations = getAggregationDao().getAggregations(start.plusHours(12), end.plusHours(12), createAggregationKey(interval, groupA), groupB); assertEquals(864, baseAggregations.size()); } }); //Find middle 24 hours worth for one group this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final List<T> baseAggregations = getAggregationDao().getAggregations(start.plusHours(12), end.plusHours(12), createAggregationKey(interval, groupA)); assertEquals(432, baseAggregations.size()); } }); //Find last 12 hours worth this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final AggregatedGroupMapping groupB = aggregatedGroupLookupDao.getGroupMapping("local.1"); final List<T> baseAggregations = getAggregationDao().getAggregations(start.plusHours(36), end.plusDays(1), createAggregationKey(interval, groupA), groupB); assertEquals(288, baseAggregations.size()); } }); //TODO Query for intervals that are stored this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final Set<AggregatedGroupMapping> aggregatedGroupMappings = getAggregationDao() .getAggregatedGroupMappings(); assertEquals(2, aggregatedGroupMappings.size()); final Set<AggregationInterval> aggregationIntervals = getAggregationDao().getAggregationIntervals(); assertEquals(1, aggregationIntervals.size()); } }); }
From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDaoTest.java
@Test public final void testModifyingClosedAggregationRangeQuery() 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 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// w ww. j a v a 2 s . com protected void callWithoutResult() { final Random r = new Random(0); final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); 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)); for (int u = 0; u < r.nextInt(50); u++) { updateAggregation(intervalInfo, baseAggregationA, r); } baseAggregationA.intervalComplete(5); getAggregationDao().updateAggregation(baseAggregationA); aggrs.add(1); } } }); } }); //Verify all aggrs created assertEquals(2, aggrs.intValue()); //Find unclosed 1 aggr this.execute(new CallableWithoutResult() { @Override protected void callWithoutResult() { final Random r = new Random(0); final AggregatedGroupMapping groupA = aggregatedGroupLookupDao.getGroupMapping("local.0"); final K key = createAggregationKey(interval, groupA); final List<T> aggregations = getAggregationDao().getAggregations(start.minusDays(1), end.plusDays(1), key); assertEquals(2, aggregations.size()); for (final T baseAggregationImpl : aggregations) { final DateTime instant = baseAggregationImpl.getDateTime(); final AggregationIntervalInfo intervalInfo = aggregationIntervalHelper.getIntervalInfo(interval, instant); updateAggregation(intervalInfo, baseAggregationImpl, r); //TODO verify unchanged } } }); }
From source file:org.apereo.portal.events.aggr.JpaBaseAggregationDaoTest.java
@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/*from ww w . jav a 2 s .c om*/ 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()); } }); }
From source file:org.beangle.security.ldap.connect.SimpleLdapUserStore.java
public Set<Attribute> getAttributes(String uid, String attrName) { Set<Attribute> values = CollectUtils.newHashSet(); DirContext ctx = getContext(); if (ctx == null) return values; try {/*from w ww .ja va 2 s.c o m*/ String dn = getUserDN(uid); if (dn == null) { logger.debug("User {} not found", uid); return values; } javax.naming.Name userID = new CompositeName(dn); Attributes attrs = null; if (null != attrName) { attrs = ctx.getAttributes(userID, new String[] { attrName }); } else { attrs = ctx.getAttributes(userID); } for (NamingEnumeration<? extends Attribute> ne = attrs.getAll(); ne.hasMoreElements();) { Attribute attr = ne.nextElement(); values.add(attr); } } catch (NamingException e) { e.printStackTrace(); } return values; }
From source file:org.eclim.util.file.FileUtils.java
/** * Translates a file name that does not conform to the standard url file * format./* w w w. j a v a2 s .c o m*/ * <p/> * Main purpose is to convert paths like:<br/> * <code>/opt/sun-jdk-1.5.0.05/src.zip/javax/swing/Spring.java</code><br/> * to<br/> * <code>zip:file:///opt/sun-jdk-1.5.0.05/src.zip!/javax/swing/Spring.java</code> * * @param file The file to translate. * @return The translated file. */ public static String toUrl(String file) { file = file.replace('\\', '/'); // if the path points to a real file, return it. if (new File(file).exists()) { return file; } // already an url. if (file.startsWith(JAR_PREFIX) || file.startsWith(ZIP_PREFIX)) { return file; } // otherwise do some conversion. StringBuffer buffer = new StringBuffer(); try { CompositeName fileName = new CompositeName(file); Enumeration<String> names = fileName.getAll(); while (names.hasMoreElements()) { String name = names.nextElement(); if (name.indexOf("$") != -1) { name = name.substring(0, name.indexOf("$")) + '.' + getExtension(name); } if (name.length() != 0) { buffer.append('/').append(name); if (!new File(buffer.toString()).exists()) { String path = getFullPath(buffer.toString()); if (path.endsWith("/") || path.endsWith("\\")) { path = path.substring(0, path.length() - 1); } if (path.endsWith(JAR_EXT)) { buffer = new StringBuffer(JAR_PREFIX).append(path).append('!').append('/').append(name); } else if (path.endsWith(ZIP_EXT)) { buffer = new StringBuffer(ZIP_PREFIX).append(path).append('!').append('/').append(name); } } } } } catch (Exception e) { throw new RuntimeException(e); } return buffer.toString(); }
From source file:org.eclipse.ecr.runtime.api.DataSourceHelper.java
/** * Look up a datasource given a partial name. * <p>//from w ww . ja v a2 s. co m * For a datasource {@code "jdbc/foo"}, then it's sufficient to pass {@code * "foo"} to this method. * * @param partialName the partial name * @return the datasource * @throws NamingException */ public static DataSource getDataSource(String partialName) throws NamingException { String jndiName = getDataSourceJNDIName(partialName); InitialContext context = new InitialContext(); Object resolved = context.lookup(jndiName); if (resolved instanceof Reference) { try { resolved = NamingManager.getObjectInstance(resolved, new CompositeName(jndiName), context, null); } catch (Exception e) { throw new Error("Cannot get access to " + jndiName, e); } } return (DataSource) resolved; }
From source file:org.eclipse.ecr.runtime.jtajca.NuxeoContainer.java
/** * Install transaction and connection management "by hand" if the container * didn't do it using file-based configuration. Binds the names in JNDI. * * @param txconfig the transaction manager configuration * @param cmconfig the connection manager configuration * * @since 5.4.2/*from www . j a v a2s . c o m*/ */ public static synchronized void install(TransactionManagerConfiguration txconfig, ConnectionManagerConfiguration cmconfig) throws NamingException { installNaming(); transactionManager = lookupTransactionManager(); if (transactionManager == null) { initTransactionManager(txconfig); addDeepBinding(rootContext, new CompositeName(JNDI_TRANSACTION_MANAGER), getTransactionManagerReference()); addDeepBinding(rootContext, new CompositeName(JNDI_USER_TRANSACTION), getUserTransactionReference()); } connectionManager = lookupConnectionManager(); if (connectionManager == null) { initConnectionManager(cmconfig); addDeepBinding(rootContext, new CompositeName(JNDI_NUXEO_CONNECTION_MANAGER), getConnectionManagerReference()); } }