static String getAuthenticationCacheType(ModelNode node) { String type = null; if (node.hasDefined(CACHE_TYPE)) { type = node.get(CACHE_TYPE).asString(); } return type; } }
/** * Returns the attribute value of the specified operation * @param operation an operation * @return an attribute value */ public static ModelNode getAttributeValue(ModelNode operation) { return operation.hasDefined(ModelDescriptionConstants.VALUE) ? operation.get(ModelDescriptionConstants.VALUE) : new ModelNode(); }
/** * Indicates whether or not this operation expects to include default values. * @param operation an operation * @return true, if default values are expected, false otherwise. */ public static boolean isIncludeDefaults(ModelNode operation) { return operation.hasDefined(ModelDescriptionConstants.INCLUDE_DEFAULTS) ? operation.get(ModelDescriptionConstants.INCLUDE_DEFAULTS).asBoolean() : true; }
private Map<String, String> unwrap(final ModelNode model) { if (!model.hasDefined(PARAMETERS.getName())) { return Collections.emptyMap(); } ModelNode modelProps = model.get(PARAMETERS.getName()); Map<String, String> props = new HashMap<String, String>(); for (Property p : modelProps.asPropertyList()) { props.put(p.getName(), p.getValue().asString()); } return props; } }
@Override public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) { if (operation != null && !(operation.hasDefined(OPERATION_HEADERS) && operation.get(OPERATION_HEADERS, "push-to-servers").asBoolean(false)) ){ operation = operation.clone(); String statefulCache = operation.get(DEFAULT_SFSB_CACHE).asString(); String statefulPassivationDisabledCache = operation.get(DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE).asString(); operation.get(DEFAULT_SFSB_CACHE).set(statefulPassivationDisabledCache); operation.get(EJB3SubsystemModel.DEFAULT_CLUSTERED_SFSB_CACHE).set(statefulCache); operation.remove(DEFAULT_SFSB_PASSIVATION_DISABLED_CACHE); } return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT); } }
@Override public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) { ModelNode legacyOperation = this.transformer.transformOperation(operation); for (Attribute attribute: this.attributes) { String name = attribute.getName(); if (operation.hasDefined(name)) { legacyOperation.get(name).set(operation.get(name)); } } return new TransformedOperation(legacyOperation, OperationResultTransformer.ORIGINAL_RESULT); } }
private void writeBeanInstancePools(final XMLExtendedStreamWriter writer, final ModelNode beanInstancePoolModelNode) throws XMLStreamException { if (beanInstancePoolModelNode.hasDefined(EJB3SubsystemModel.STRICT_MAX_BEAN_INSTANCE_POOL)) { final List<Property> strictMaxPools = beanInstancePoolModelNode.get(EJB3SubsystemModel.STRICT_MAX_BEAN_INSTANCE_POOL).asPropertyList(); for (Property property : strictMaxPools) { // <strict-max-pool> writer.writeStartElement(EJB3SubsystemXMLElement.STRICT_MAX_POOL.getLocalName()); // contents of strict-max-pool this.writeStrictMaxPoolConfig(writer, property); // </strict-max-pool> writer.writeEndElement(); } } }
@Override protected Object[] getParameters(OperationContext context, ModelNode operation) { Object[] parameters = null; try { if (operation.hasDefined(USERNAME.getName()) || operation.hasDefined(PASSWORD.getName())) { parameters = new Object[2]; parameters[0] = USERNAME.resolveModelAttribute(context, operation).asString(); parameters[1] = PASSWORD.resolveModelAttribute(context, operation).asString(); } } catch (OperationFailedException ofe) { //just return null } return parameters; }
static Properties resolvePropertyValue(final OperationContext context, final ModelNode operation, final AttributeDefinition attribute) throws OperationFailedException { // Get the properties final Properties properties = new Properties(); if (operation.hasDefined(attribute.getName())) { for (Property p : resolveValue(context, operation, attribute).asPropertyList()) { properties.put(p.getName(), p.getValue().asString()); } } return properties; }
@Override public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode operation) { if (operation != null && !(operation.hasDefined(OPERATION_HEADERS) && operation.get(OPERATION_HEADERS, "push-to-servers").asBoolean(false)) ){ String originalAttribute = Operations.getAttributeName(operation); if (renames.containsKey(originalAttribute)){ operation = operation.clone(); operation.get(NAME).set(renames.get(originalAttribute)); } } return new TransformedOperation(operation, OperationResultTransformer.ORIGINAL_RESULT); }
@Override public void marshallAsAttribute(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { if (attribute.isMarshallable(resourceModel, marshallDefault)) { resourceModel = resourceModel.get(attribute.getName()); if (resourceModel.hasDefined(Constants.ALGORITHM)) { writer.writeAttribute(attribute.getName() + "-factory-" + Constants.ALGORITHM, resourceModel.get(Constants.ALGORITHM).asString()); } if (resourceModel.hasDefined(Constants.PROVIDER)) { writer.writeAttribute(attribute.getName() + "-factory-" + Constants.PROVIDER, resourceModel.get(Constants.PROVIDER).asString()); } } } }
private void validateStoreConfig(ModelNode operation, ModelNode model) throws OperationFailedException { if (operation.hasDefined(USE_JDBC_STORE) && operation.get(USE_JDBC_STORE).asBoolean() && operation.hasDefined(USE_JOURNAL_STORE) && operation.get(USE_JOURNAL_STORE).asBoolean()) { throw TransactionLogger.ROOT_LOGGER.onlyOneCanBeTrue(USE_JDBC_STORE, USE_JOURNAL_STORE); } if (operation.hasDefined(USE_JDBC_STORE) && operation.get(USE_JDBC_STORE).asBoolean() && !operation.hasDefined(JDBC_STORE_DATASOURCE)) { throw TransactionLogger.ROOT_LOGGER.mustBeDefinedIfTrue(JDBC_STORE_DATASOURCE, USE_JDBC_STORE); } }
@SuppressWarnings("deprecation") @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { // Handle recipe for version < 4.0 where stack was not required and the stack attribute would use default-stack for a default value if (!operation.hasDefined(Attribute.STACK.getName())) { ModelNode parentModel = context.readResourceFromRoot(context.getCurrentAddress().getParent(), false).getModel(); // If default-stack is not defined either, then recipe must be for version >= 4.0 and so this really is an invalid operation if (parentModel.hasDefined(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName())) { operation.get(Attribute.STACK.getName()).set(parentModel.get(JGroupsSubsystemResourceDefinition.Attribute.DEFAULT_STACK.getName())); } } handler.execute(context, operation); } };
/** {@inheritDoc} */ @Override public void writeContent(XMLExtendedStreamWriter writer, SubsystemMarshallingContext context) throws XMLStreamException { ModelNode node = context.getModelNode(); boolean hasChildren = node.hasDefined(RESOURCEADAPTER_NAME) && node.get(RESOURCEADAPTER_NAME).asPropertyList().size() > 0; context.startSubsystemElement(Namespace.CURRENT.getUriString(), !hasChildren); if (hasChildren) { writer.writeStartElement(Element.RESOURCE_ADAPTERS.getLocalName()); ModelNode ras = node.get(RESOURCEADAPTER_NAME); for (String name : ras.keys()) { final ModelNode ra = ras.get(name); writeRaElement(writer, ra, name); } writer.writeEndElement(); // Close the subsystem element writer.writeEndElement(); } }
private Object createSimpleBinding(OperationContext context, ModelNode model) throws OperationFailedException { final String value = NamingBindingResourceDefinition.VALUE.resolveModelAttribute(context, model).asString(); final String type; if (model.hasDefined(TYPE)) { type = NamingBindingResourceDefinition.TYPE.resolveModelAttribute(context, model).asString(); } else { type = null; } return coerceToType(value, type); }
@Override public void marshallAsElement(AttributeDefinition attribute, ModelNode model, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { if (model.hasDefined(attribute.getName())) { for (Property property : model.get(attribute.getName()).asPropertyList()) { writer.writeStartElement(Element.PROPERTY.getLocalName()); writer.writeAttribute(Element.NAME.getLocalName(), property.getName()); writer.writeCharacters(property.getValue().asString()); writer.writeEndElement(); } } } };
@Override protected boolean rejectAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) { if (attributeValue.isDefined()) { for (ModelNode node : attributeValue.asList()) { if (node.hasDefined(ANNOTATIONS)) { ModelNode annotations = node.get(ANNOTATIONS); if (EXPRESSION_PATTERN.matcher(annotations.asString()).matches() || annotations.asBoolean()) { return true; } } if (node.hasDefined(SERVICES)) { ModelNode services = node.get(SERVICES); if (EXPRESSION_PATTERN.matcher(services.asString()).matches() || !services.asBoolean()) { return true; } } if (node.hasDefined(META_INF)) { ModelNode metaInf = node.get(META_INF); if (EXPRESSION_PATTERN.matcher(metaInf.asString()).matches() || metaInf.asBoolean()) { return true; } } } } return false; }
@Override public void marshallAsElement(AttributeDefinition attribute, ModelNode resourceModel, boolean marshallDefault, XMLStreamWriter writer) throws XMLStreamException { if (resourceModel.hasDefined(attribute.getName())) { writer.writeStartElement(attribute.getXmlName()); String archive = resourceModel.get(attribute.getName()).asString(); writer.writeCharacters(archive); writer.writeEndElement(); } } })
@Override protected boolean applyUpdateToRuntime(OperationContext context, ModelNode operation, String attributeName, ModelNode resolvedValue, ModelNode currentValue, HandbackHolder<Void> voidHandback) { ModelNode submodel = context.readResource(PathAddress.EMPTY_ADDRESS).getModel(); //do the job return (submodel.hasDefined(Constants.ENABLED.getName()) && submodel.get(Constants.ENABLED.getName()).asBoolean()) || Constants.JNDI_NAME.getName().equals(attributeName); }
@Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { if (this.readHandler != null) { this.readHandler.execute(context, operation); } else { try { // If attribute has no read handler, simulate one ModelNode model = context.readResource(PathAddress.EMPTY_ADDRESS, false).getModel(); ModelNode result = context.getResult(); if (model.hasDefined(this.targetAttribute.getName())) { result.set(model.get(this.targetAttribute.getName())); } else if (Operations.isIncludeDefaults(operation)) { result.set(this.targetAttribute.getDefinition().getDefaultValue()); } } catch (Resource.NoSuchResourceException ignore) { // If the target resource does not exist return UNDEFINED return; } } ModelNode result = context.getResult(); result.set(this.translator.translate(context, result)); } }