All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.as.console.client.widgets.forms.AddressBinding Maven / Gradle / Ivy

Go to download

Bundles the core AS7 console as a GWT module. Includes minor customizations to support extensions.

There is a newer version: 0.7.0.Final
Show newest version
package org.jboss.as.console.client.widgets.forms;

import org.jboss.dmr.client.ModelNode;

import java.util.LinkedList;
import java.util.List;

import static org.jboss.dmr.client.ModelDescriptionConstants.ADDRESS;
import static org.jboss.dmr.client.ModelDescriptionConstants.CHILD_TYPE;

/**
 * Represents entity address meta data, that declared using the {@link Address} annotation.
* Address declarations may contain wildcards. An AddressBinding supports replacement of * wildcards with proper address values when turned into {@link ModelNode} representations. * * @author Heiko Braun * @date 9/23/11 */ public class AddressBinding { private List address = new LinkedList(); private int countedWildcards = -1; public AddressBinding() { } public void add(String parent, String child) { address.add(new String[]{parent, child}); } public int getNumWildCards() { if(countedWildcards <0) { int counter = 0; for(String[] tuple : address) { if(tuple[0].startsWith("{")) counter++; if(tuple[1].startsWith("{")) counter++; } countedWildcards = counter; } return countedWildcards; } /** * Turns this address into a ModelNode with an address property. * * @param args parameters for address wildcards * @return a ModelNode with an address property */ public ModelNode asResource(String... args) { return asResource(new ModelNode(), args); } /** * Turns this address into a ModelNode with an address property.
* This method allows to specify a base address prefix (i.e server vs. domain addressing). * * @param baseAddress * @param args parameters for address wildcards * @return a ModelNode with an address property */ public ModelNode asResource(ModelNode baseAddress, String... args) { assert getNumWildCards() ==args.length : "Address arguments don't match number of wildcards: "+args.length+","+getNumWildCards(); ModelNode model = new ModelNode(); model.get(ADDRESS).set(baseAddress); int argsCounter = 0; for(String[] tuple : address) { String parent = tuple[0]; String child = tuple[1]; if(parent.startsWith("{")) { parent = args[argsCounter]; argsCounter++; } if(child.startsWith("{")) { child = args[argsCounter]; argsCounter++; } model.get(ADDRESS).add(parent, child); } return model; } /** * Turns this address into a subresource address, * including the address and child-type properties. * * @param args parameters for address wildcards * @return ModelNode including address and child-type property */ public ModelNode asSubresource(String... args) { return asSubresource(new ModelNode(), args); } /** * Turns this address into a subresource address, * including the address and child-type properties.
* The child-type is derived from the last address token qualifier. * * This method allows to specify a base address prefix (i.e server vs. domain addressing). * * @param baseAddress * @param args parameters for address wildcards * @return ModelNode including address and child-type property */ public ModelNode asSubresource(ModelNode baseAddress, String... args) { int numWildCards = getNumWildCards(); int wildcards = (numWildCards - 1) > 0 ? numWildCards-1 : 0; assert wildcards == args.length : "Address arguments don't match number of wildcards: "+args.length+","+wildcards; ModelNode model = new ModelNode(); model.get(ADDRESS).set(baseAddress); int argsCounter = 0; for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy