| Adding Federation Support

## Naming System Boundaries

> The Federation lesson describes how a service provider determines which components of the composite name to process and which to pass on. The Essential Components lesson contains two examples of how a context implementation selects components from the input composite name to process. Both of these examples concern context implementations that support strong separation and therefore simply select the first component of the composite name.

> To support weak separation, you need to rewrite the utility method `getMyComponents()` and all of the context methods to eliminate the single component assumption. Following is a more general method that, given a composite or compound name, returns a two-element array. In that array, the first component contains the components to be processed by the current naming system and the second component contains the components to be processed by subsequent naming systems. This example handles strong separation.

> >     protected Name[] parseComponents(Name name) throws NamingException {
> >         Name head, tail;
> >         if (name instanceof CompositeName) {
> >             int separator;
> >             // If there is no name to parse, or
> >     	// if you're already at the boundary
> >             if (name.isEmpty() ||  name.get(0).equals("")) {
> >         	    separator = 0;
> >             } else {
> >     	    separator = 1;
> >             }

> >     	head = name.getPrefix(separator);
> >     	tail = name.getSuffix(separator);
> >         } else {
> >     	// Treat this like a compound name
> >     	head = new CompositeName().add(name.toString());
> >     	tail = null;
> >         }

> >         return new Name[]{head, tail};
> >     }

> Following the same method rewritten to support weak separation. For this particular context implementation, only leading components that contain the equals character ("=") are selected for the current naming system.

> >     protected Name[] parseComponents(Name name) throws NamingException {
> >         Name head, tail;
> >         if (name instanceof CompositeName) {
> >             int separator;
> >             // If there is no name to parse, or
> >     	// if you're already at the boundary
> >             if (name.isEmpty() ||  name.get(0).equals("")) {
> >     	    separator = 0;
> >             } else {
> >     	    // Find the leading components that have "="
> >     	    int total = name.size();
> >     	    int i;
> >     	    for (i = 0; i < total; i++) {
> >     	        if (name.get(i).indexOf('=') < 0) {
> >     		    break;
> >     	        }
> >     	    }
> >     	    separator = i;
> >             }

> >     	head = name.getPrefix(separator);
> >     	tail = name.getSuffix(separator);
> >         } else {
> >     	// Treat this like a compound name
> >     	head = new CompositeName().add(name.toString());
> >     	tail = null;
> >         }

> >         return new Name[]{head, tail};
> >     }

> If the context implementation supports dynamic weak separation (that is, determines the naming system boundary dynamically), then `parseComponents()` will return all components as belonging to the current naming system. Here is an example.

> >     protected Name[] parseComponents(Name name) throws NamingException {
> >         Name head, tail;
> >         if (name instanceof CompositeName) {
> >             int separator;
> >             // If there is no name to parse, or
> >     	// if you're already at the boundary
> >             if (name.isEmpty() ||  name.get(0).equals("")) {
> >     	    separator = 0;
> >             } else {
> >     	    // All components are eligible
> >     	    separator = name.size();
> >             }

> >     	head = name.getPrefix(separator);
> >     	tail = name.getSuffix(separator);
> >         } else {
> >     	// Treat this like a compound name
> >     	head = new CompositeName().add(name.toString());
> >     	tail = null;
> >         }

> >         return new Name[]{head, tail};
> >     }

> Once you have defined this method, your context methods can use it to extract the components. Here is an example.

> >     Name[] nm = parseComponents(name);
> >     Name mine = nm[0];
> >     Name rest = nm[1];

| Adding Federation Support