/** * Creates or updates the text value of the element (or text or attribute) matched by * the supplied XPath expression. If the matched element (or text or attribute) does not exist, * it is created with the last segment of the XPath expression (but its parent must already exist). * * @param key an XPath expression. * @param value the value to set (may be null). * @return the previous value of the matched element (may be null). * @throws RuntimeException if the root element of this XMap is null, if the XPath expression is not valid, * or (creation case) if the parent node does not exist or is not an element instance. */ public String put(String key, String value) { return put(key, value, false); }
private void parseConfig(XMap config) { if (config != null) { gravityFactory = config.get("@factory", String.class, DEFAULT_GRAVITY_FACTORY); channelIdleTimeoutMillis = config.get("@channel-idle-timeout-millis", Long.TYPE, DEFAULT_CHANNEL_IDLE_TIMEOUT_MILLIS); longPollingTimeoutMillis = config.get("@long-polling-timeout-millis", Long.TYPE, DEFAULT_LONG_POLLING_TIMEOUT_MILLIS); retryOnError = config.get("@retry-on-error", Boolean.TYPE, DEFAULT_RETRY_ON_ERROR); maxMessagesQueuedPerChannel = config.get("@max-messages-queued-per-channel", Integer.TYPE, DEFAULT_MAX_MESSAGES_QUEUED_PER_CHANNEL); reconnectIntervalMillis = config.get("@reconnect-interval-millis", Long.TYPE, DEFAULT_RECONNECT_INTERVAL_MILLIS); reconnectMaxAttempts = config.get("@reconnect-max-attempts", Integer.TYPE, DEFAULT_RECONNECT_MAX_ATTEMPTS); encodeMessageBody = config.get("@encode-message-body", Boolean.TYPE, DEFAULT_ENCODE_MESSAGE_BODY); extra = config.getOne("configuration"); corePoolSize = config.get("thread-pool/@core-pool-size", Integer.TYPE, DEFAULT_CORE_POOL_SIZE); maximumPoolSize = config.get("thread-pool/@maximum-pool-size", Integer.TYPE, DEFAULT_MAXIMUM_POOL_SIZE); keepAliveTimeMillis = config.get("thread-pool/@keep-alive-time-millis", Long.TYPE, DEFAULT_KEEP_ALIVE_TIME_MILLIS); queueCapacity = config.get("thread-pool/@queue-capacity", Integer.TYPE, DEFAULT_QUEUE_CAPACITY); useUdp = config.containsKey("udp"); if (useUdp) { udpPort = config.get("udp/@port", Integer.TYPE, 0); udpNio = config.get("udp/@nio", Boolean.TYPE, true); udpConnected = config.get("udp/@connected", Boolean.TYPE, true); udpSendBufferSize = config.get("udp/@send-buffer-size", Integer.TYPE, DEFAULT_UDP_SEND_BUFFER_SIZE);
private void loadCustomMethodMatcher(XMap element, boolean custom) { XMap methodMatcher = element.getOne("method-matcher"); if (methodMatcher != null) { String type = methodMatcher.get("@type"); try { this.methodMatcher = (MethodMatcher)TypeUtil.newInstance(type); } catch (Exception e) { throw new GraniteConfigException("Could not construct method matcher: " + type, e); } } }
public static Destination forElement(XMap element, Adapter defaultAdapter, Map<String, Adapter> adaptersMap) { String id = element.get("@id"); List<String> channelRefs = new ArrayList<String>(); for (XMap channel : element.getAll("channels/channel[@ref]")) channelRefs.add(channel.get("@ref")); XMap properties = new XMap(element.getOne("properties")); List<String> rolesList = null; if (element.containsKey("security/security-constraint/roles/role")) { rolesList = new ArrayList<String>(); for (XMap role : element.getAll("security/security-constraint/roles/role")) rolesList.add(role.get(".")); } XMap adapter = element.getOne("adapter[@ref]"); Adapter adapterRef = adapter != null && adaptersMap != null ? adaptersMap.get(adapter.get("@ref")) : defaultAdapter; return new Destination(id, channelRefs, properties, rolesList, adapterRef, null); } }
private void loadCustomJMFDefaultStoredStrings(XMap element, boolean custom) { String jmfDefaultStoredStringsMode = element.get("jmf-default-stored-strings/@mode"); if (jmfDefaultStoredStringsMode != null) { try { this.jmfDefaultStoredStringsMode = JMF_EXTENSIONS_MODE.valueOf(jmfDefaultStoredStringsMode.toLowerCase()); } catch (Exception e) { throw new GraniteConfigException("Illegal JMF default stored strings mode: " + jmfDefaultStoredStringsMode, e); } } for (XMap codec : element.getAll("jmf-default-stored-strings/jmf-default-stored-string")) jmfDefaultStoredStrings.add(codec.get("@value")); }
@Override public void configure(XMap properties) throws ServiceException { String sServiceExceptionHandler = properties.get("service-exception-handler"); if (sServiceExceptionHandler == null) { XMap props = new XMap(properties); props.put("service-exception-handler", ExtendedServiceExceptionHandler.class.getName()); super.configure(props); } else super.configure(properties); GraniteConfig config = GraniteContext.getCurrentInstance().getGraniteConfig(); config.registerExceptionConverter(PersistenceExceptionConverter.class); config.registerExceptionConverter(EJBAccessExceptionConverter.class); this.lookup = properties.get("lookup"); }
protected Destination buildDestination(Adapter adapter) { List<String> channelIds = new ArrayList<String>(); channelIds.add("gravityamf"); Destination destination = new Destination(id, channelIds, new XMap(), roles, adapter, null); destination.getProperties().put("no-local", String.valueOf(noLocal)); destination.getProperties().put("session-selector", String.valueOf(sessionSelector)); if (getSecurizerClassName() != null) destination.getProperties().put("securizer", securizerClassName); if (getSecurizer() != null) destination.setSecurizer(getSecurizer()); return destination; } }
public void configure(XMap properties) { if (properties != null) { String dynamicclass = properties.get("dynamic-class"); if (Boolean.TRUE.toString().equalsIgnoreCase(dynamicclass)) dynamicClass = true; } }
@Override public ServiceInvoker<?> getServiceInstance(RemotingMessage request) throws ServiceException { String messageType = request.getClass().getName(); String destinationId = request.getDestination(); ServicesConfig servicesConfig = GraniteContext.getCurrentInstance().getServicesConfig(); Destination destination = servicesConfig.findDestinationById(messageType, destinationId); if (destination == null) throw new ServiceException("No matching destination: " + destinationId); if (!destination.getProperties().containsKey(TideServiceInvoker.VALIDATOR_CLASS_NAME)) destination.getProperties().put(TideServiceInvoker.VALIDATOR_CLASS_NAME, "org.granite.tide.validation.BeanValidation"); @SuppressWarnings("unchecked") Bean<PersistenceConfiguration> pcBean = (Bean<PersistenceConfiguration>)manager.getBeans(PersistenceConfiguration.class).iterator().next(); PersistenceConfiguration persistenceConfiguration = (PersistenceConfiguration)manager.getReference(pcBean, PersistenceConfiguration.class, manager.createCreationalContext(pcBean)); if (destination.getProperties().containsKey(ENTITY_MANAGER_FACTORY_JNDI_NAME)) persistenceConfiguration.setEntityManagerFactoryJndiName(destination.getProperties().get(ENTITY_MANAGER_FACTORY_JNDI_NAME)); else if (destination.getProperties().containsKey(ENTITY_MANAGER_JNDI_NAME)) persistenceConfiguration.setEntityManagerJndiName(destination.getProperties().get(ENTITY_MANAGER_JNDI_NAME)); // Create an instance of the component CDIServiceInvoker invoker = new CDIServiceInvoker(destination, this); return invoker; } }
public EjbServiceMetadata(XMap properties, Class<?> invokeeClass) { stateful = properties.containsKey("ejb-stateful"); if (stateful) { for (XMap removeMethod : properties.getAll("ejb-stateful/remove-method")) { String signature = removeMethod.get("signature"); if (signature == null) throw new ServiceException("Missing signature in remove-method declaration: " + properties); Boolean retainIfException = Boolean.valueOf(removeMethod.get("retain-if-exception")); try { removeMethods.put(TypeUtil.getMethod(invokeeClass, signature), retainIfException); } catch (NoSuchMethodException e) { throw new ServiceException("Could not find method: " + invokeeClass.getName() + "." + signature); } } } }
@Override public void configure(XMap adapterProperties, XMap destinationProperties) throws ServiceException { try { destinationName = destinationProperties.get("jms/destination-name"); if (Boolean.TRUE.toString().equals(destinationProperties.get("jms/transacted-sessions"))) transactedSessions = true; if ("AUTO_ACKNOWLEDGE".equals(destinationProperties.get("jms/acknowledge-mode"))) acknowledgeMode = Session.AUTO_ACKNOWLEDGE; else if ("CLIENT_ACKNOWLEDGE".equals(destinationProperties.get("jms/acknowledge-mode"))) acknowledgeMode = Session.CLIENT_ACKNOWLEDGE; else if ("DUPS_OK_ACKNOWLEDGE".equals(destinationProperties.get("jms/acknowledge-mode"))) acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE; if ("javax.jms.TextMessage".equals(destinationProperties.get("jms/message-type"))) textMessages = true; if (Boolean.TRUE.toString().equals(destinationProperties.get("jms/no-local"))) noLocal = true; if (Boolean.TRUE.toString().equals(destinationProperties.get("session-selector"))) sessionSelector = true; failoverRetryInterval = destinationProperties.get("jms/failover-retry-interval", Long.TYPE, DEFAULT_FAILOVER_RETRY_INTERVAL); if (failoverRetryInterval <= 0) { log.warn("Illegal failover retry interval: %d (using default %d)", failoverRetryInterval, DEFAULT_FAILOVER_RETRY_INTERVAL); failoverRetryCount = destinationProperties.get("jms/failover-retry-count", Integer.TYPE, DEFAULT_FAILOVER_RETRY_COUNT); if (failoverRetryCount <= 0) { log.warn("Illegal failover retry count: %s (using default %d)", failoverRetryCount, DEFAULT_FAILOVER_RETRY_COUNT); if (destinationProperties.get("server/broker-url") != null && !"".equals(destinationProperties.get("server/broker-url").trim())) {
@Override protected Adapter buildAdapter() { return new Adapter("jms-adapter", "org.granite.gravity.adapters.JMSServiceAdapter", new XMap()); }
/** * Constructs a new XMap instance from an XML input stream. * * @param input an XML input stream. */ public XMap(InputStream input, EntityResolver resolver) throws IOException, SAXException { this.root = getXMLUtil().loadDocument(input, resolver, null).getDocumentElement(); }
/** * Returns a list of XMap instances with all elements that match the * supplied XPath expression. Note that XPath result nodes that are not instance of * Element are ignored. Note also that returned XMaps contain original child elements of * the root element of this XMap so modifications made to child elements affect this XMap * instance as well. * * @param key an XPath expression. * @return an unmodifiable list of XMap instances. * @throws RuntimeException if the XPath expression isn't correct. */ public List<XMap> getAll(String key) { if (root == null) return new ArrayList<XMap>(0); try { List<Node> result = getXMLUtil().selectNodeSet(root, key); List<XMap> xMaps = new ArrayList<XMap>(result.size()); for (Node node : result) { if (node.getNodeType() == Node.ELEMENT_NODE) xMaps.add(new XMap(this.xmlUtil, (Element)node, false)); } return xMaps; } catch (Exception e) { throw new RuntimeException(e); } }
private void loadCustomClassGetter(XMap element, boolean custom) { XMap classGetter = element.getOne("class-getter"); if (classGetter != null) { String type = classGetter.get("@type"); try { this.classGetter = (ClassGetter)TypeUtil.newInstance(type); classGetterSet = true; } catch (Exception e) { throw new GraniteConfigException("Could not instantiate ClassGetter: " + type, e); } } }
public static Destination forElement(XMap element, Adapter defaultAdapter, Map<String, Adapter> adaptersMap) { String id = element.get("@id"); List<String> channelRefs = new ArrayList<String>(); for (XMap channel : element.getAll("channels/channel[@ref]")) channelRefs.add(channel.get("@ref")); XMap properties = new XMap(element.getOne("properties")); List<String> rolesList = null; if (element.containsKey("security/security-constraint/roles/role")) { rolesList = new ArrayList<String>(); for (XMap role : element.getAll("security/security-constraint/roles/role")) rolesList.add(role.get(".")); } XMap adapter = element.getOne("adapter[@ref]"); Adapter adapterRef = adapter != null && adaptersMap != null ? adaptersMap.get(adapter.get("@ref")) : defaultAdapter; return new Destination(id, channelRefs, properties, rolesList, adapterRef, null); } }
private void loadCustomJMFDefaultStoredStrings(XMap element, boolean custom) { String jmfDefaultStoredStringsMode = element.get("jmf-default-stored-strings/@mode"); if (jmfDefaultStoredStringsMode != null) { try { this.jmfDefaultStoredStringsMode = JMF_EXTENSIONS_MODE.valueOf(jmfDefaultStoredStringsMode.toLowerCase()); } catch (Exception e) { throw new GraniteConfigException("Illegal JMF default stored strings mode: " + jmfDefaultStoredStringsMode, e); } } for (XMap codec : element.getAll("jmf-default-stored-strings/jmf-default-stored-string")) jmfDefaultStoredStrings.add(codec.get("@value")); }