List of usage examples for java.util Dictionary put
public abstract V put(K key, V value);
From source file:org.paxle.core.monitorable.observer.impl.MonitorableObserver.java
/** * @param filter an ldap filter expression that must be matched by monitorable variables * @throws InvalidSyntaxException /* w w w .ja v a 2 s.c o m*/ */ private void init(BundleContext bc, MonitorAdmin monitorAdmin, IObserverRule... observerRules) throws InvalidSyntaxException { if (bc == null) throw new NullPointerException("The bundle-context is null"); if (monitorAdmin == null) throw new NullPointerException("The monitor-admin service is null"); if (observerRules == null) throw new NullPointerException("The filter expression is null"); this.bc = bc; this.monitorAdmin = monitorAdmin; this.rules = new ArrayList<IObserverRule>(Arrays.asList(observerRules)); // extracting monitorable variables this.variableTree = extractMonitorables(observerRules); // registering this observer as event-handler: required to receive monitoring-events Dictionary<String, Object> properties = new Hashtable<String, Object>(); properties.put(EventConstants.EVENT_TOPIC, new String[] { "org/osgi/service/monitor" }); properties.put(EventConstants.EVENT_FILTER, String.format("(mon.listener.id=%s)", this.getObserverID())); this.bc.registerService(EventHandler.class.getName(), this, properties); // detecting already registered monitorables and // determine which of their variables we need to monitor final HashSet<String> variableNames = new HashSet<String>(); final ServiceReference[] services = bc.getServiceReferences(Monitorable.class.getName(), null); if (services != null) { for (ServiceReference reference : services) { this.addVariables4Monitor(reference, variableNames, true); } this.startScheduledJob(variableNames); } // registering this class as service-listener this.bc.addServiceListener(this, String.format("(%s=%s)", Constants.OBJECTCLASS, Monitorable.class.getName())); }
From source file:org.apache.tika.module.command.internal.Activator.java
private void configureLogging(BundleContext context) { ConfigurationAdmin configAdmin = getConfigurationAdmin(context); try {/*from w ww . j a v a 2 s. c o m*/ final Configuration configuration = configAdmin.getConfiguration("org.ops4j.pax.logging", null); String log4JConfigUri = System.getProperty("log4j.configuration"); if (log4JConfigUri != null) { Properties log4JProps = new Properties(); URL log4jUrl = Activator.class.getClassLoader().getResource(log4JConfigUri); InputStream log4jInputStream = null; if (log4jUrl == null) { log4jInputStream = new FileInputStream(new File(new URI(log4JConfigUri))); } else { log4jInputStream = log4jUrl.openStream(); } log4JProps.load(log4jInputStream); Dictionary<String, String> logProps = new Hashtable<>(); for (Entry currentProperty : log4JProps.entrySet()) { String key = (String) currentProperty.getKey(); String value = (String) currentProperty.getValue(); logProps.put(key, value); } configuration.update(logProps); } } catch (Exception e) { LOG.warn("Logging could not be properly configured", e); } }
From source file:org.openengsb.ports.jms.JMSPortTest.java
@Before public void setup() { System.setProperty("org.apache.activemq.default.directory.prefix", tempFolder.getRoot().getAbsolutePath() + "/"); setupKeys();//from www .ja v a 2 s. c o m String num = UUID.randomUUID().toString(); ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost" + num); jmsTemplate = new JmsTemplate(connectionFactory); jmsTemplateFactory = new JMSTemplateFactory() { @Override public SimpleMessageListenerContainer createMessageListenerContainer() { return simpleMessageListenerConainer; } @Override public JmsTemplate createJMSTemplate(DestinationUrl destinationUrl) { return jmsTemplate; } }; simpleMessageListenerConainer = new SimpleMessageListenerContainer(); incomingPort = new JMSIncomingPort(); incomingPort.setFactory(jmsTemplateFactory); incomingPort.setConnectionFactory(connectionFactory); RequestHandlerImpl requestHandlerImpl = new RequestHandlerImpl(); requestHandlerImpl.setUtilsService(new DefaultOsgiUtilsService(bundleContext)); handler = requestHandlerImpl; TestInterface mock2 = mock(TestInterface.class); registerServiceViaId(mock2, "test", TestInterface.class); when(mock2.method(anyString(), anyInt(), any(TestClass.class))).thenReturn(new TestClass("test")); Map<String, String> metaData = Maps.newHashMap(ImmutableMap.of("serviceId", "test")); MethodCall methodCall = new MethodCall("method", new Object[] { "123", 5, new TestClass("test"), }, metaData); call = new MethodCallMessage(methodCall, "123"); call.setDestination("host?receive"); MethodResult result = new MethodResult(new TestClass("test")); result.setMetaData(metaData); methodReturn = new MethodResultMessage(result, "123"); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(Constants.PROVIDED_CLASSES_KEY, Password.class.getName()); props.put(Constants.DELEGATION_CONTEXT_KEY, org.openengsb.core.api.Constants.DELEGATION_CONTEXT_CREDENTIALS); registerService(new ClassProviderImpl(bundle, Sets.newHashSet(Password.class.getName())), props, ClassProvider.class); DefaultSecurityManager securityManager = new DefaultSecurityManager(); securityManager.setAuthenticator(new Authenticator() { @Override public AuthenticationInfo authenticate(AuthenticationToken authenticationToken) throws org.apache.shiro.authc.AuthenticationException { return new SimpleAuthenticationInfo(authenticationToken.getPrincipal(), authenticationToken.getCredentials(), "openengsb"); } }); SecurityUtils.setSecurityManager(securityManager); }
From source file:org.openanzo.datasource.nodecentric.internal.NodeCentricDatasourceFactory.java
@SuppressWarnings("unchecked") public void updated(String pid, Dictionary configProperties) throws ConfigurationException { try {// w ww . j av a2s . c o m lock.lockInterruptibly(); if (!datasources.containsKey(pid)) { boolean enabled = ServicesDictionary.getEnabled(configProperties); if (enabled) { try { OsgiConfigurationUtils.validateConfiguration(instanceDef, configProperties); OsgiConfigurationUtils.updateConfigProperties(configProperties, context); String indexLocation = LuceneDictionary.getIndexLocation(configProperties); if (indexLocation == null) { File root = context.getDataFile(pid); if (!root.exists()) { root.mkdirs(); } File indexLocationFile = new File(root, "index"); if (!indexLocationFile.exists()) { indexLocationFile.mkdirs(); } LuceneDictionary.setIndexLocation(configProperties, indexLocationFile.getAbsolutePath()); } initializingDatasource.put(pid, configProperties); try { NodeCentricDatasource datasource = new NodeCentricDatasource(context, configProperties, getDependency(ICacheProvider.class), aclEventListeners, eventAdmin); Dictionary<String, String> properties = new Hashtable<String, String>(); properties.put(SerializationConstants.isPrimary, Boolean.toString(datasource.isPrimary())); properties.put(DatasourceDictionary.KEY_DATASOURCE_URI, datasource.getInstanceURI().toString()); serviceRegistrations.put(datasource, context.registerService(new String[] { NodeCentricDatasource.class.getName(), IDatasource.class.getName(), IStatisticsProvider.class.getName() }, datasource, properties)); IAuthorizationService auth = datasource.getAuthorizationService(); if (auth instanceof IAuthorizationEventListener) { serviceRegistrations.put(datasource, context .registerService(IAuthorizationEventListener.class.getName(), auth, null)); } datasources.put(pid, datasource); } finally { initializingDatasource.remove(pid); } } catch (AnzoException ae) { log.error(LogUtils.LIFECYCLE_MARKER, "Error creating new nodecentric datasource", ae); throw new AnzoRuntimeException(ae); } } } } catch (InterruptedException e) { throw new AnzoRuntimeException(ExceptionConstants.OSGI.INTERNAL_COMPONENT_ERROR, e); } finally { lock.unlock(); } }
From source file:org.paxle.gui.impl.servlets.UserView.java
private void updateUser(UserAdmin userAdmin, User user, HttpServletRequest request, Context context, Key k) throws InvalidSyntaxException, UnsupportedEncodingException { if (user == null) return;/*from w ww.ja v a2s . c om*/ // getting the http.login name String loginName = request.getParameter(HttpAuthManager.USER_HTTP_LOGIN); /* =========================================================== * USERNAME + PWD * =========================================================== */ // check if the login-name is not empty if (loginName == null || loginName.length() == 0) { String errorMsg = k.get("error.emptyLoginName").toString(); this.logger.warn("The http.login name was empty or null."); context.put(ERROR_MSG, errorMsg); return; } // check if the login name is unique Role[] roles = userAdmin.getRoles(String.format("(%s=%s)", HttpAuthManager.USER_HTTP_LOGIN, loginName)); if (roles != null && (roles.length > 2 || (roles.length == 1 && !roles[0].equals(user)))) { String errorMsg = k.get("error.usernameAlreadyKnown").insert(new String[] { loginName }).toString(); this.logger.warn( String.format("The given login name '%s' is already used by a different user.", loginName)); context.put(ERROR_MSG, errorMsg); return; } // check if the password is typed correctly String pwd1 = request.getParameter(HttpAuthManager.USER_HTTP_PASSWORD); String pwd2 = request.getParameter(HttpAuthManager.USER_HTTP_PASSWORD + "2"); if (pwd1 == null || pwd2 == null || !pwd1.equals(pwd2)) { String errorMsg = k.get("error.invalidPassword").insert(new String[] { loginName }).toString(); this.logger.warn(String.format("The password for login name '%s' was not typed correctly.", loginName)); context.put(ERROR_MSG, errorMsg); return; } // configure http-login data @SuppressWarnings("unchecked") Dictionary<String, Object> props = user.getProperties(); props.put(HttpAuthManager.USER_HTTP_LOGIN, loginName); @SuppressWarnings("unchecked") Dictionary<String, Object> credentials = user.getCredentials(); credentials.put(HttpAuthManager.USER_HTTP_PASSWORD, pwd1); /* =========================================================== * OPEN-ID * =========================================================== */ String openIdURL = request.getParameter("openid.url"); if (openIdURL != null && openIdURL.length() > 0) { // check if URL is unique roles = userAdmin.getRoles(String.format("(openid.url=%s)", openIdURL)); if (roles != null && (roles.length > 2 || (roles.length == 1 && !roles[0].equals(user)))) { String errorMsg = k.get("error.invalidOpenIDURL").insert(new String[] { openIdURL }).toString(); this.logger.warn( String.format("The given OpenID URL '%s' is already used by a different user.", openIdURL)); context.put(ERROR_MSG, errorMsg); return; } // configure the OpenID URL props.put("openid.url", openIdURL); } else { // delete old URL user.getProperties().remove("openid.url"); } /* =========================================================== * LANGUAGE * =========================================================== */ if (request.getParameter(USER_LANGUAGE) != null) { String lang = request.getParameter(USER_LANGUAGE); props.put(USER_LANGUAGE, lang); CookieTool cookies = (CookieTool) context.get("cookieTool"); cookies.add("l10n", lang); } /* =========================================================== * MEMBERSHIP * =========================================================== */ // process membership Authorization auth = userAdmin.getAuthorization(user); String[] currentMembership = auth.getRoles(); if (currentMembership == null) currentMembership = new String[0]; String[] newMembership = request.getParameterValues("membership"); if (newMembership == null) newMembership = new String[0]; // new memberships for (String groupName : newMembership) { if (!auth.hasRole(groupName)) { Role role = userAdmin.getRole(groupName); if (role != null && role.getType() == Role.GROUP) { ((Group) role).addMember(user); } } } // memberships to remove ArrayList<String> oldMemberships = new ArrayList<String>(Arrays.asList(currentMembership)); oldMemberships.removeAll(Arrays.asList(newMembership)); for (String roleName : oldMemberships) { if (auth.hasRole(roleName)) { Role role = userAdmin.getRole(roleName); if (role != null && role.getType() == Role.GROUP) { ((Group) role).removeMember(user); } } } }
From source file:com.oracle.osgi.jmx.compendium.ConfigAdminManager.java
@SuppressWarnings("unchecked") public void addProperty(String pid, String name, String value, String type) throws IOException { Configuration config = admin.getConfiguration(pid, null); Dictionary properties = config.getProperties(); if (properties == null) { properties = new Hashtable(); }//from w w w. j a v a2 s.c o m properties.put(name, parse(value, type)); config.update(properties); }
From source file:com.oracle.osgi.jmx.compendium.ConfigAdminManager.java
@SuppressWarnings("unchecked") public void addProperty(String pid, String location, String name, String value, String type) throws IOException { Configuration config = admin.getConfiguration(pid, location); Dictionary properties = config.getProperties(); if (properties == null) { properties = new Hashtable(); }// w w w.j a v a 2s . c o m properties.put(name, parse(value, type)); config.update(properties); }
From source file:com.whizzosoftware.hobson.bootstrap.api.hub.OSGIHubManager.java
@Override public void setHubLocation(String userId, String hubId, HubLocation location) { try {//from ww w. j av a 2s.c o m Configuration config = getConfiguration(); Dictionary d = getConfigurationProperties(config); if (location.getText() != null) { d.put(HubLocation.PROP_LOCATION_STRING, location.getText()); } if (location.hasLatitude()) { d.put(HubLocation.PROP_LATITUDE, location.getLatitude()); } if (location.hasLongitude()) { d.put(HubLocation.PROP_LONGITUDE, location.getLongitude()); } updateConfiguration(config, d); } catch (IOException e) { throw new HobsonRuntimeException("Error setting hub location", e); } }
From source file:it.greenvulcano.configuration.BaseConfigurationManager.java
private void setXMLConfigBasePath(String path) throws IOException, InvalidSyntaxException { @SuppressWarnings("unchecked") Dictionary<String, Object> gvesbCfg = Optional .of(configRepository.getConfigProperties(XMLConfig.CONFIG_PID)).orElse(new Hashtable<>()); gvesbCfg.put(XMLConfig.CONFIG_KEY_HOME, path); configRepository.update(XMLConfig.CONFIG_PID, gvesbCfg); XMLConfig.setBaseConfigPath(path);// w ww. j ava 2s. c o m }
From source file:com.basistech.yca.JsonNodeFlattener.java
private static void traverse(JsonNode node, String pathSoFar, Dictionary<String, Object> map) throws IOException { if (!node.isContainerNode()) { Object value;/*from ww w . j a v a 2s. com*/ if (node.isBigDecimal()) { value = node.decimalValue(); } else if (node.isBigInteger()) { value = node.bigIntegerValue(); } else if (node.isBinary()) { value = node.binaryValue(); } else if (node.isBoolean()) { value = node.booleanValue(); } else if (node.isDouble()) { value = node.doubleValue(); } else if (node.isFloat()) { value = node.floatValue(); } else if (node.isInt()) { value = node.intValue(); } else if (node.isLong()) { value = node.longValue(); } else if (node.isNull()) { // NOTE: stupid old Hashtable can't store null values. value = NULL; } else if (node.isShort()) { value = node.shortValue(); } else if (node.isTextual()) { value = node.textValue(); } else { throw new RuntimeException("Unanticipated node " + node); } map.put(pathSoFar, value); } else { if (node.isArray()) { traverseArray(node, pathSoFar, map); } else { traverseObject(node, pathSoFar, map); } } }