Java Code Examples for org.jboss.dmr.ModelNode#isDefined()
The following examples show how to use
org.jboss.dmr.ModelNode#isDefined() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NamespaceRemoveHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final ModelNode model = context.readResourceForUpdate(PathAddress.EMPTY_ADDRESS).getModel(); ModelNode param = NAMESPACE.resolveModelAttribute(context, operation); ModelNode namespaces = model.get(NAMESPACES); Property toRemove = null; ModelNode newList = new ModelNode().setEmptyList(); String prefix = param.asString(); if (namespaces.isDefined()) { for (Property namespace : namespaces.asPropertyList()) { if (prefix.equals(namespace.getName())) { toRemove = namespace; } else { newList.add(namespace.getName(), namespace.getValue()); } } } if (toRemove != null) { namespaces.set(newList); } else { throw new OperationFailedException(ControllerLogger.ROOT_LOGGER.namespaceNotFound(prefix)); } }
Example 2
Source File: KeycloakSubsystemParser.java From keycloak with Apache License 2.0 | 6 votes |
void writeSps(final XMLExtendedStreamWriter writer, final ModelNode model) throws XMLStreamException { if (!model.isDefined()) { return; } for (Property sp : model.get(Constants.Model.SERVICE_PROVIDER).asPropertyList()) { writer.writeStartElement(Constants.XML.SERVICE_PROVIDER); writer.writeAttribute(Constants.XML.ENTITY_ID, sp.getName()); ModelNode spAttributes = sp.getValue(); for (SimpleAttributeDefinition attr : ServiceProviderDefinition.ATTRIBUTES) { attr.getAttributeMarshaller().marshallAsAttribute(attr, spAttributes, false, writer); } writeKeys(writer, spAttributes.get(Constants.Model.KEY)); writePrincipalNameMapping(writer, spAttributes); writeRoleIdentifiers(writer, spAttributes); writeRoleMappingsProvider(writer, spAttributes); writeIdentityProvider(writer, spAttributes.get(Constants.Model.IDENTITY_PROVIDER)); writer.writeEndElement(); } }
Example 3
Source File: ConfigurableElementFilter.java From revapi with Apache License 2.0 | 6 votes |
@Override public void initialize(@Nonnull AnalysisContext analysisContext) { ModelNode root = analysisContext.getConfiguration(); if (!root.isDefined()) { doNothing = true; return; } ModelNode elements = root.get("elements"); if (elements.isDefined()) { readFilter(elements, elementIncludes, elementExcludes); } ModelNode archives = root.get("archives"); if (archives.isDefined()) { readFilter(archives, archiveIncludes, archiveExcludes); } doNothing = elementIncludes.isEmpty() && elementExcludes.isEmpty() && archiveIncludes.isEmpty() && archiveExcludes.isEmpty(); }
Example 4
Source File: SchemaDrivenJSONToXmlConverter.java From revapi with Apache License 2.0 | 6 votes |
private static PlexusConfiguration convertArray(ModelNode configuration, ConversionContext ctx) { ModelNode itemsSchema = ctx.currentSchema.get("items"); if (!itemsSchema.isDefined()) { throw new IllegalArgumentException( "No schema found for items of a list. Cannot continue with XML-to-JSON conversion."); } PlexusConfiguration list = new XmlPlexusConfiguration(ctx.tagName); if (ctx.id != null) { list.setAttribute("id", ctx.id); } for (ModelNode childConfig : configuration.asList()) { ctx.tagName = "item"; ctx.currentSchema = itemsSchema; ctx.id = null; ctx.currentPath.push("[]"); PlexusConfiguration child = convert(childConfig, ctx); ctx.currentPath.pop(); list.addChild(child); } return list; }
Example 5
Source File: AddResourceMojo.java From wildfly-maven-plugin with GNU Lesser General Public License v2.1 | 6 votes |
/** * Checks the existence of a resource. If the resource exists, {@code true} is returned, otherwise {@code false}. * * @param address the address of the resource to check. * @param client the client used to execute the operation. * * @return {@code true} if the resources exists, otherwise {@code false}. * * @throws IOException if an error occurs executing the operation. * @throws RuntimeException if the operation fails. */ private boolean resourceExists(final ModelNode address, final ModelControllerClient client) throws IOException { final Property childAddress = ServerOperations.getChildAddress(address); final ModelNode parentAddress = ServerOperations.getParentAddress(address); final ModelNode r = client.execute(ServerOperations.createOperation(ServerOperations.READ_RESOURCE, parentAddress, false)); reportFailure(r); boolean found = false; final String name = childAddress.getName(); if (ServerOperations.isSuccessfulOutcome(r)) { final ModelNode resources = ServerOperations.readResult(r).get(name); if (resources.isDefined()) { for (ModelNode dataSource : resources.asList()) { if (dataSource.asProperty().getName().equals(childAddress.getValue().asString())) { found = true; } } } } return found; }
Example 6
Source File: FilterConversionTestCase.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
/** * Removes undefined attributes from the model. * * @param model the model to remove undefined attributes from * * @return the new model */ static ModelNode removeUndefined(final ModelNode model) { final ModelNode result = new ModelNode(); if (model.getType() == ModelType.OBJECT) { for (Property property : model.asPropertyList()) { final ModelNode value = property.getValue(); if (value.isDefined()) { if (value.getType() == ModelType.OBJECT) { final ModelNode m = removeUndefined(property.getValue()); if (m.isDefined()) { result.get(property.getName()).set(m); } } else { result.get(property.getName()).set(value); } } } } return result; }
Example 7
Source File: KeycloakSubsystemParser.java From keycloak with Apache License 2.0 | 5 votes |
void writeSingleSignOn(XMLExtendedStreamWriter writer, ModelNode model) throws XMLStreamException { if (!model.isDefined()) { return; } writer.writeStartElement(Constants.XML.SINGLE_SIGN_ON); for (SimpleAttributeDefinition attr : SingleSignOnDefinition.ATTRIBUTES) { attr.getAttributeMarshaller().marshallAsAttribute(attr, model, false, writer); } writer.writeEndElement(); }
Example 8
Source File: ValueTypeCompleter.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public ValueTypeCompleter(ModelNode propDescr, OperationRequestAddress address, CapabilityCompleterFactory factory) { if(propDescr == null || !propDescr.isDefined()) { throw new IllegalArgumentException("property description is null or undefined."); } this.propDescr = propDescr; this.address = address; this.factory = factory == null ? (a, p) -> { return new CapabilityReferenceCompleter(a, p); } : factory; }
Example 9
Source File: GlobalOperationHandlers.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
static boolean getRecursive(OperationContext context, ModelNode op) throws OperationFailedException { // -1 means UNDEFINED ModelNode recursiveNode = RECURSIVE.resolveModelAttribute(context, op); final int recursiveValue = recursiveNode.isDefined() ? (recursiveNode.asBoolean() ? 1 : 0) : -1; final int recursiveDepthValue = RECURSIVE_DEPTH.resolveModelAttribute(context, op).asInt(-1); // WFCORE-76: We are recursing in this round IFF: // Recursive is explicitly specified as TRUE and recursiveDepth is UNDEFINED // Recursive is either TRUE or UNDEFINED and recursiveDepth is >0 return recursiveValue > 0 && recursiveDepthValue == -1 || // recursiveValue != 0 && recursiveDepthValue > 0; }
Example 10
Source File: LogHandlerListAttributeDefinition.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public Set<String> resolvePropertyValue(final OperationContext context, final ModelNode model) throws OperationFailedException { Set<String> result = Collections.emptySet(); final ModelNode value = resolveModelAttribute(context, model); if (value.isDefined()) { result = resolver.resolveValue(context, value); } return result; }
Example 11
Source File: SizeValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.isDefined()) { parseSize(value); } }
Example 12
Source File: KeycloakSubsystemParser.java From keycloak with Apache License 2.0 | 5 votes |
void writeRoleMappingsProvider(final XMLExtendedStreamWriter writer, final ModelNode model) throws XMLStreamException { ModelNode providerId = model.get(Constants.Model.ROLE_MAPPINGS_PROVIDER_ID); if (!providerId.isDefined()) { return; } writer.writeStartElement(Constants.XML.ROLE_MAPPINGS_PROVIDER); writer.writeAttribute(Constants.XML.ID, providerId.asString()); ServiceProviderDefinition.ROLE_MAPPINGS_PROVIDER_CONFIG.marshallAsElement(model, false, writer); writer.writeEndElement(); }
Example 13
Source File: MigrateJsonOperation.java From keycloak with Apache License 2.0 | 5 votes |
private String readConfig(ModelNode operation) throws IOException { ModelNode file = operation.get(FILE_ATTRIBUTE.getName()); if (file.isDefined() && file.asBytes().length > 0) { return new String(file.asBytes()); } String localConfig = localConfig(); if (localConfig != null) return localConfig; throw new IOException("Can not find json file to migrate"); }
Example 14
Source File: CandidatesProviders.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
private static Collection<String> getChildrenNames(ModelControllerClient client, ModelNode address, String childType) { if(client == null) { return Collections.emptyList(); } final ModelNode request = new ModelNode(); request.get(Util.ADDRESS).set(address); request.get(Util.OPERATION).set(Util.READ_CHILDREN_NAMES); request.get(Util.CHILD_TYPE).set(childType); final ModelNode response; try { response = client.execute(request); } catch (IOException e) { return Collections.emptyList(); } final ModelNode result = response.get(Util.RESULT); if(!result.isDefined()) { return Collections.emptyList(); } final List<ModelNode> list = result.asList(); final List<String> names = new ArrayList<String>(list.size()); for(ModelNode node : list) { names.add(node.asString()); } return names; }
Example 15
Source File: RegexValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.isDefined()) { final String stringValue = value.asString(); if (!pattern.matcher(stringValue).matches()) { throw new OperationFailedException("Does not match pattern"); } } }
Example 16
Source File: InetAddressValidator.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
/** * {@inheritDoc} */ @Override public void validateParameter(String parameterName, ModelNode value) throws OperationFailedException { super.validateParameter(parameterName, value); if (value.isDefined() && value.getType() != ModelType.EXPRESSION) { String str = value.asString(); if (Inet.parseInetAddress(str) == null) { throw new OperationFailedException("Address is invalid: \"" + str + "\""); } } }
Example 17
Source File: LdapConnectionAddHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
@Override protected void performRuntime(final OperationContext context, final ModelNode operation, final ModelNode model) throws OperationFailedException { final PathAddress address = PathAddress.pathAddress(operation.get(OP_ADDR)); final String name = address.getLastElement().getValue(); final ServiceTarget serviceTarget = context.getServiceTarget(); final ServiceName ldapConMgrName = LdapConnectionManagerService.ServiceUtil.createServiceName(name); final ServiceBuilder<?> sb = serviceTarget.addService(ldapConMgrName); final Consumer<LdapConnectionManager> lcmConsumer = sb.provides(ldapConMgrName); final ModelNode securityRealm = SECURITY_REALM.resolveModelAttribute(context, model); Supplier<SSLContext> fullSSLContextSupplier = null; Supplier<SSLContext> trustSSLContextSupplier = null; if (securityRealm.isDefined()) { String realmName = securityRealm.asString(); fullSSLContextSupplier = SSLContextService.ServiceUtil.requires(sb, SecurityRealm.ServiceUtil.createServiceName(realmName), false); trustSSLContextSupplier = SSLContextService.ServiceUtil.requires(sb, SecurityRealm.ServiceUtil.createServiceName(realmName), true); } ExceptionSupplier<CredentialSource, Exception> credentialSourceSupplier = null; if (LdapConnectionResourceDefinition.SEARCH_CREDENTIAL_REFERENCE.resolveModelAttribute(context, model).isDefined()) { credentialSourceSupplier = CredentialReference.getCredentialSourceSupplier(context, LdapConnectionResourceDefinition.SEARCH_CREDENTIAL_REFERENCE, model, sb); } final LdapConnectionManagerService connectionManagerService = new LdapConnectionManagerService( lcmConsumer, fullSSLContextSupplier, trustSSLContextSupplier, credentialSourceSupplier, name, connectionManagerRegistry); updateRuntime(context, model, connectionManagerService); sb.setInstance(connectionManagerService); sb.install(); }
Example 18
Source File: StandaloneXml_4.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
private void setOrganization(final ModelNode address, final List<ModelNode> operationList, final ModelNode value) { if (value != null && value.isDefined() && value.asString().length() > 0) { final ModelNode update = Util.getWriteAttributeOperation(address, ORGANIZATION, value); operationList.add(update); } }
Example 19
Source File: AccessAuthorizationCombinationPolicyWriteAttributeHandler.java From wildfly-core with GNU Lesser General Public License v2.1 | 4 votes |
static void updateAuthorizer(final ModelNode value, final WritableAuthorizerConfiguration authorizerConfiguration) { ModelNode resolvedValue = value.isDefined() ? value : AccessAuthorizationResourceDefinition.PERMISSION_COMBINATION_POLICY.getDefaultValue(); String policyName = resolvedValue.asString().toUpperCase(Locale.ENGLISH); authorizerConfiguration.setPermissionCombinationPolicy(CombinationPolicy.valueOf(policyName)); }
Example 20
Source File: Revapi.java From revapi with Apache License 2.0 | 4 votes |
private <T extends Configurable> Map<ExtensionInstance<T>, AnalysisContext> splitByConfiguration(AnalysisContext fullConfig, Set<Class<? extends T>> configurables, List<String> extensionIdIncludes, List<String> extensionIdExcludes) { Map<ExtensionInstance<T>, AnalysisContext> map = new HashMap<>(); for (Class<? extends T> cc : configurables) { T c = instantiate(cc); String extensionId = c.getExtensionId(); if (extensionId == null) { extensionId = "$$%%(@#_)I#@)(*)(#$)(@#$__IMPROBABLE, right??!?!?!"; } // apply the filtering if (!extensionIdIncludes.isEmpty() && !extensionIdIncludes.contains(extensionId)) { continue; } if (extensionIdExcludes.contains(extensionId)) { continue; } T inst = null; boolean configured = false; for (ModelNode config : fullConfig.getConfiguration().asList()) { String configExtension = config.get("extension").asString(); if (!extensionId.equals(configExtension)) { continue; } if (inst == null) { inst = c; } else { inst = instantiate(cc); } ModelNode idNode = config.get("id"); String instanceId = idNode.isDefined() ? idNode.asString() : null; ExtensionInstance<T> key = new ExtensionInstance<>(inst, instanceId); map.put(key, fullConfig.copyWithConfiguration(config.get("configuration").clone())); configured = true; } if (!configured) { map.put(new ExtensionInstance<>(c, null), fullConfig.copyWithConfiguration(new ModelNode())); } } return map; }