001    /*
002     * file StpLocation.java
003     *
004     * Licensed Materials - Property of IBM
005     * Restricted Materials of IBM 
006     *
007     * com.ibm.rational.wvcm.stp.StpLocation
008     *
009     * (C) Copyright IBM Corporation 2004, 2009.  All Rights Reserved.
010     * Note to U.S. Government Users Restricted Rights:  Use, duplication or 
011     * disclosure restricted by GSA ADP  Schedule Contract with IBM Corp.
012     */
013    
014    package com.ibm.rational.wvcm.stp;
015    
016    import java.io.File;
017    import java.io.Serializable;
018    import java.net.MalformedURLException;
019    import java.util.EnumSet;
020    import java.util.Hashtable;
021    import java.util.Map;
022    
023    import javax.wvcm.Location;
024    import javax.wvcm.Resource;
025    import javax.wvcm.WvcmException;
026    
027    import com.ibm.rational.wvcm.stpex.StpExEnumeration;
028    import com.ibm.rational.wvcm.stpex.annotation.RpcEnum;
029    
030    /**
031     * An extension of the javax.wvcm Location interface that provides a
032     * programmatic representation for the location of a resource.
033     * 
034     * <p>
035     * An StpLocation instance represents a location specification that has been
036     * parsed into its various component fields. A number of different formats or
037     * <i>schemes</i> are used to express the location of various resources as a
038     * string. These schemes consist of one or more of the following fields:
039     * <i>domain</i>, <i>repository name</i>, <i>namespace</i>, and <i>object
040     * name</i>. It is the namespace field that determines the scheme being used.
041     * <p>
042     * Locations are hierarchical, with the domain field specifying the top level of
043     * the hierarchy. Within a domain, resources are partitioned into repositories.
044     * Within a repository, resources are first partitioned into namespaces, and
045     * then uniquely identified by segmented pathnames within that namespace.
046     * <p>
047     * Each scheme requires certain of the above fields to be specified. If required
048     * fields are not present, the StpLocation object will have a non-OK Status.
049     * Individual field values can be queried to determine which fields aren't
050     * present.
051     * <p>
052     * To use this StpLocation to construct a proxy, its Status must be OK.
053     * <p>
054     * When a proxy is constructed, a new StpLocation may need to be constructed, so
055     * clients must not assume that the object returned by Resource.location()
056     * or any of the StpLocation factory methods defined in StpProvider is
057     * the same object passed to the proxy factory that created the proxy.
058     * <p>
059     * The preferred scheme for specifying an object is the <i>object selector
060     * scheme</i>, which has the following structure
061     * <p> [[<i>&lt;domain></i>.][<i>&lt;namespace></i>]:] [<i>&lt;object-name></i>][&#64;[<i>&lt;repository-name></i>]]
062     * <p>
063     * The <i>&lt;object-name></i>, and <i>&lt;repository-name></i> fields are
064     * segmented names where the segments are separated by '/'s or '\'s. The
065     * permitted <i>&lt;namespace></i>s are defined by
066     * {@link StpLocation.Namespace} and the permitted <i>&lt;domain></i>s are
067     * defined by {@link StpProvider.Domain}.
068     * <p>
069     * The character '&#64;' is reserved for use as the repository field delimiter
070     * as defined above. If it is to be part of the name field, it must be escaped
071     * by preceding it with a percent sign '%'. Similarly, the characters '/' and
072     * '\' are reserved in both the name and repository fields to be used as
073     * pathname segment separators. To use them as part of a segment they, too, must
074     * be escaped using a percent sign. Use two percent signs, '%%', to include a
075     * percent sign in the name or repository field. Note that escaped characters
076     * within a field are <i>not</i> unescaped when parsed into a StpLocation.
077     * Utility methods are provided by the StpProvider class for unescaping the
078     * fields, should a client need the unadulterated image.
079     * <p>
080     * Some resources can also be referenced directly or indirectly by an absolute or
081     * relative file system pathname. As an StpLocation image, such
082     * representations are called <i>path-scheme</i> locations, which have the
083     * following structure
084     * <p> [[<i>&lt;domain></i>.][<i>&lt;namespace></i>]:] [<i>&lt;path-name></i>]
085     * <p>
086     * The path-scheme locations are further categorized by their namespace as
087     * indicated in this enumeration...
088     * <ul>
089     * <li>{@linkplain #isOk() <i>invalid</i>} namespaces: NONE, DEFAULT, INVALID,
090     * <li>{@linkplain #isFilePathScheme() <i>file path scheme</i>} namespaces:
091     * PNAME, PNAME_IMPLIED, FILE,
092     * <li>{@linkplain #isRepositoryPathScheme() <i>repository path scheme</i>}
093     * namespaces: VOB, VIEW_UUID, REPLICA_UUID, PROJ_DB, USER_DB, DB_SET, SERVER,
094     * <li>WORKSPACE,
095     * <li>{@linkplain #isUrlPathScheme() <i>URL path scheme</i>} namespaces: FILE,
096     * HTTP, HTTPS,
097     * </ul>
098     * This interface defines a predicate for each of these categories. The reader
099     * is referred to the documentation for those predicates for more information on
100     * the formation and meaning of each type of path-scheme location. Note that if
101     * a namespace is <i>not</i> one of the above path-scheme namespaces, it is an
102     * {@linkplain #isObjectSelectorScheme() <i>object selector scheme</i>}
103     * namespace.
104     * <p>
105     * %-escaping is not used in path-scheme locations.
106     */
107    public interface StpLocation extends javax.wvcm.Location
108    {
109        /**
110         * Returns the StpProvider object that created this StpLocation object
111         * 
112         * @return The StpProvider object that instantiated this instance of
113         *         StpLocation
114         */
115        StpProvider stpProvider();
116    
117        /**
118         * This class enumerates the namespaces that may appear in a location
119         * specification. Instances of the class are used to represent the namespace
120         * of the location represented by an StpLocation object.
121         * 
122         * The Namespace maps directly to the word token used in a location
123         * specification to denote the namespace of the resource named by the
124         * location. Each resource may appear in multiple namespaces.
125         */
126        public static enum Namespace implements StpExEnumeration, Serializable
127        {
128            /**
129             * A special path-scheme Namespace indicating that the namespace field
130             * of a location is unknown.
131             */
132            @RpcEnum(id=23, simpleName="INVALID")
133            INVALID("INVALID" /* NOI18N */),
134    
135            /**
136             * A special path-scheme Namespace indicating that no namespace was
137             * specified in the location specification.
138             */
139            @RpcEnum(id=26, simpleName="NONE")
140            NONE("NONE" /* NOI18N */),
141    
142            /**
143             * A special path-scheme Namespace indicating that the namespace field
144             * in the location specification was empty, which is the convention for
145             * specifying the default namespace of a repository.
146             */
147            @RpcEnum(id=8, simpleName="DEFAULT")
148            DEFAULT("DEFAULT" /* NOI18N */),
149    
150            /**
151             * The special, compound namespace used in stable selector schemes. To
152             * fully specify the stable selector scheme namespace, a resource-type
153             * string must follow the REPO word token in the location specification.
154             */
155            @RpcEnum(id=38, simpleName="repo")
156            REPO("repo" /* NOI18N */),
157    
158            /**
159             * The special, compound namespace used in the selector scheme for
160             * specification of efficiently-accessed locations. To fully specify the
161             * efficient selector scheme namespace, a resource-type string must
162             * follow the FAST word token in the location specification.
163             */
164            @RpcEnum(id=12, simpleName="fast")
165            FAST("fast" /* NOI18N */),
166    
167            /**
168             * A special file-path-scheme namespace that forces the rest of the
169             * location to be interpreted as a ClearCase P-name, a file system
170             * pathname with an optional history-mode extension.
171             */
172            @RpcEnum(id=28, simpleName="pname")
173            PNAME("pname" /* NOI18N */),
174    
175            /**
176             * A special file-path-scheme Namespace indicating a pname without an
177             * explicit PNAME prefix. Locations in the PNAME_IMPLIED namespace
178             * display simply as P-names.
179             */
180            @RpcEnum(id=29, simpleName="implicit")
181            PNAME_IMPLIED("implicit" /* NOI18N */),
182    
183            /**
184             * A repository-path-scheme Namespace for a ClearCase VOB specified
185             * directly by tag or indirectly by an entity within the VOB.
186             */
187            @RpcEnum(id=46, simpleName="vob")
188            VOB("vob" /* NOI18N */),
189    
190            /**
191             * A repository-path-scheme Namespace for a ClearCase VOB specified by
192             * its replica UUID
193             */
194            @RpcEnum(id=37, simpleName="replicauuid")
195            REPLICA_UUID("replicauuid" /* NOI18N */),
196    
197            /**
198             * A repository-path-scheme Namespace for a ClearCase VOB specified by
199             * its VOB family UUID.
200             */
201            @RpcEnum(id=51, simpleName="vobuuid")
202            VOB_UUID("vobuuid" /* NOI18N */),
203    
204            /**
205             * A repository-path-scheme Namespace for a ClearCase view specified by
206             * its UUID
207             */
208            @RpcEnum(id=45, simpleName="viewuuid")
209            VIEW_UUID("viewuuid" /* NOI18N */),
210    
211            /**
212             * A stable-selector-scheme Namespace for a ClearCase resource specified
213             * by its DBID
214             */
215            @RpcEnum(id=6, simpleName="dbid")
216            DBID("dbid" /* NOI18N */),
217    
218            /** A repository-path-scheme Namespace for a ClearQuest user database */
219            @RpcEnum(id=43, simpleName="userdb")
220            USER_DB("userdb" /* NOI18N */),
221    
222            /**
223             * A repository-path-scheme Namespace for a ClearQuest database known
224             * variously as a profile, connection, database-set, master database, or
225             * schema repository
226             */
227            @RpcEnum(id=7, simpleName="dbset")
228            DB_SET("dbset" /* NOI18N */),
229    
230            /**
231             * The user-friendly-selector-scheme Namespace for an action
232             */
233            @RpcEnum(id=0, simpleName="action")
234            ACTION("action" /* NOI18N */),
235    
236            /**
237             * The user-friendly-selector-scheme Namespace for an activity
238             */
239            @RpcEnum(id=1, simpleName="activity")
240            ACTIVITY("activity" /* NOI18N */),
241    
242            /**
243             * The user-friendly-selector-scheme Namespace for an attribute type
244             */
245            @RpcEnum(id=2, simpleName="attype")
246            ATTYPE("attype" /* NOI18N */),
247    
248            /** The user-friendly-selector-scheme Namespace for a baseline */
249            @RpcEnum(id=3, simpleName="baseline")
250            BASELINE("baseline" /* NOI18N */),
251    
252            /** The user-friendly-selector-scheme Namespace for a branch */
253            @RpcEnum(id=50, simpleName="branch")
254            BRANCH("branch" /* NOI18N */),
255    
256            /** The user-friendly-selector-scheme Namespace for a branch type */
257            @RpcEnum(id=4, simpleName="brtype")
258            BRTYPE("brtype" /* NOI18N */),
259    
260            /** The user-friendly-selector-scheme Namespace for a component */
261            @RpcEnum(id=5, simpleName="component")
262            COMPONENT("component" /* NOI18N */),
263    
264            /**
265             * The user-friendly-selector-scheme Namespace for a dynamic choice
266             * list.
267             */
268            @RpcEnum(id=10, simpleName="choicelist")
269            DYNAMIC_CHOICE_LIST("choicelist" /* NOI18N */),
270    
271            /** The user-friendly-selector-scheme Namespace for an element type */
272            @RpcEnum(id=11, simpleName="eltype")
273            ELTYPE("eltype" /* NOI18N */),
274    
275            /** The user-friendly-selector-scheme Namespace for a field definition */
276            @RpcEnum(id=13, simpleName="field")
277            FIELD_DEFINITION("field" /* NOI18N */),
278    
279            /** The URL-path-scheme and file-path-scheme Namespace for a file URL */
280            @RpcEnum(id=14, simpleName="file")
281            FILE("file" /* NOI18N */),
282    
283            /** The user-friendly-selector-scheme Namespace for a folder */
284            @RpcEnum(id=15, simpleName="folder")
285            FOLDER("folder" /* NOI18N */),
286    
287            /** The user-friendly-selector-scheme Namespace for a form */
288            @RpcEnum(id=16, simpleName="form")
289            FORM("form" /* NOI18N */),
290    
291            /** The user-friendly-selector-scheme Namespace for a group */
292            @RpcEnum(id=17, simpleName="group")
293            GROUP("group" /* NOI18N */),
294    
295            /** The user-friendly-selector-scheme Namespace for a hyperlink */
296            @RpcEnum(id=18, simpleName="hlink")
297            HLINK("hlink" /* NOI18N */),
298    
299            /** The user-friendly-selector-scheme Namespace for a hyperlink type */
300            @RpcEnum(id=19, simpleName="hltype")
301            HLTYPE("hltype" /* NOI18N */),
302    
303            /** The user-friendly-selector-scheme Namespace for a hook */
304            @RpcEnum(id=20, simpleName="hook")
305            HOOK("hook" /* NOI18N */),
306    
307            /** The user-friendly-selector-scheme Namespace for a label type */
308            @RpcEnum(id=24, simpleName="lbtype")
309            LBTYPE("lbtype" /* NOI18N */),
310    
311            /**
312             * A stable-selector-scheme Namespace for a ClearCase resource specified
313             * by its OID
314             */
315            @RpcEnum(id=27, simpleName="oid")
316            OID("oid" /* NOI18N */),
317    
318            /** The user-friendly-selector-scheme Namespace for a pool */
319            @RpcEnum(id=30, simpleName="pool")
320            POOL("pool" /* NOI18N */),
321    
322            /** The user-friendly-selector-scheme Namespace for a project. */
323            @RpcEnum(id=31, simpleName="project")
324            PROJECT("project" /* NOI18N */),
325    
326            /**
327             * The user-friendly-selector-scheme Namespace for a project
328             * configuration
329             */
330            @RpcEnum(id=32, simpleName="projconfig")
331            PROJECT_CONFIGURATION("projconfig" /* NOI18N */),
332    
333            /**
334             * The user-friendly-selector-scheme Namespace for a query, chart,
335             * report, report format, or query folder.
336             */
337            @RpcEnum(id=33, simpleName="query")
338            QUERY("query" /* NOI18N */),
339    
340            /**
341             * The user-friendly-selector-scheme Namespace for a record, record
342             * type, attachment folder, or attachment
343             */
344            @RpcEnum(id=34, simpleName="record")
345            RECORD("record" /* NOI18N */),
346    
347            /**
348             * The user-friendly, efficient, and stable-scheme Namespace for a
349             * ClearCase registry region.
350             */
351            @RpcEnum(id=35, simpleName="registryregion")
352            REGISTRY_REGION("registryregion" /* NOI18N */),
353    
354            /** The user-friendly-selector-scheme Namespace for a replica */
355            @RpcEnum(id=36, simpleName="replica")
356            REPLICA("replica" /* NOI18N */),
357    
358            /** The user-friendly-selector-scheme Namespace for an rptype */
359            @RpcEnum(id=39, simpleName="rptype")
360            RPTYPE("rptype" /* NOI18N */),
361    
362            /** The user-friendly-selector-scheme Namespace for a stream */
363            @RpcEnum(id=40, simpleName="stream")
364            STREAM("stream" /* NOI18N */),
365    
366            /** The user-friendly-selector-scheme Namespace for a trigger type */
367            @RpcEnum(id=41, simpleName="trtype")
368            TRTYPE("trtype" /* NOI18N */),
369    
370            /**
371             * The URL-path-scheme Namespace denoting a location presented in the
372             * form of an HTTP URI or URL
373             */
374            @RpcEnum(id=21, simpleName="http")
375            HTTP("http" /* NOI18N */),
376    
377            /**
378             * The URL-path-scheme Namespace denoting a location presented in the
379             * form of an HTTPS URI or URL
380             */
381            @RpcEnum(id=22, simpleName="https")
382            HTTPS("https" /* NOI18N */),
383    
384            /** The user-friendly-selector-scheme Namespace for a user */
385            @RpcEnum(id=42, simpleName="user")
386            USER("user" /* NOI18N */),
387    
388            /**
389             * The user-friendly, efficient, and stable-scheme Namespace for a view
390             * tag.
391             */
392            @RpcEnum(id=44, simpleName="viewtag")
393            VIEWTAG("viewtag" /* NOI18N */),
394    
395            /**
396             * The user-friendly, efficient, and stable-scheme Namespace for a VOB
397             * tag.
398             */
399            @RpcEnum(id=47, simpleName="vobtag")
400            VOBTAG("vobtag" /* NOI18N */),
401    
402            /**
403             * The path-scheme Namespace for a ClearCase VOB tag, treated in some
404             * senses as a directory.
405             * 
406             * Note: This namespace is an implementation detail of the server, which
407             * unfortunately must be exposed to clients.
408             * 
409             * It is not intended that clients should attempt to create resources
410             * within this namespace.  Undefined behavior is guaranteed if clients
411             * attempt this.
412             * 
413             * It is not expected that the server will return resources within this
414             * namespace.
415             */
416            @RpcEnum(id=48, simpleName="vobtagasdirectory")
417            VOB_TAG_AS_DIRECTORY("vobtagasdirectory" /* NOI18N */),
418            
419            /** The path-scheme Namespace for a workspace */
420            @RpcEnum(id=49, simpleName="workspace")
421            WORKSPACE("workspace" /* NOI18N */),
422    
423            /**
424             * The user-friendly-selector-scheme Namespace for a domain server;
425             * e.g. ClearCase or ClearQuest
426             */
427            @RpcEnum(id=9, simpleName="domainserver")
428            DOMAINSERVER("domainserver" /* NOI18N */),
429            
430            /** The path-scheme for a CCRC (aka, "legacy") server */
431            @RpcEnum(id=25, simpleName="legacyserver")
432            LEGACYSERVER("legacyserver" /* NOI18N */);
433    
434            /**
435             * Returns the word token for this Namespace in the namespace field of a
436             * location specification.
437             * 
438             * @return A String containing the namespace field value that denotes
439             *         this Namespace.
440             */
441            public String toNamespaceField()
442            {
443                return m_namespaceField;
444            }
445    
446            /**
447             * Finds the Namespace enumerator from the identifier used in the
448             * namespace field of a location specification.
449             * 
450             * @param field The word token as it appears in a location namespace
451             *            field.
452             * 
453             * @return The Namespace that the namespace field identifier denotes.
454             *         Namespace.INVALID is returned if no Namespace enumerator
455             *         matches the symbol exactly.
456             */
457            public static final Namespace fromNamespaceField(String field)
458            {
459                // Force to lower case before consulting symbol map
460                String symbol = field.toLowerCase();
461    
462                Namespace namespace = g_symbolToNamespaceMap.get(symbol);
463    
464                return namespace == null? Namespace.INVALID : namespace;
465            }
466    
467            /**
468             * EnumSet definitions for the various classifications of Namespaces
469             */
470            private static EnumSet<Namespace> invalid = EnumSet.of(INVALID, NONE);
471            private static EnumSet<Namespace> valid = EnumSet.complementOf(invalid);
472            private static EnumSet<Namespace> filePathSchemes =
473                EnumSet.of(PNAME,
474                           PNAME_IMPLIED,
475                           FILE);
476            private static EnumSet<Namespace> repositoryPathSchemes =
477                EnumSet.of(VOB,
478                           VIEW_UUID,
479                           REPLICA_UUID,
480                           USER_DB,
481                           DB_SET,
482                           LEGACYSERVER);
483            private static EnumSet<Namespace> urlPathSchemes = EnumSet.of(FILE,
484                                                                          HTTP,
485                                                                          HTTPS);
486            private static EnumSet<Namespace> pathSchemes =
487                union(EnumSet.of(WORKSPACE, NONE, DEFAULT, INVALID),
488                      filePathSchemes,
489                      urlPathSchemes,
490                      repositoryPathSchemes);
491            private static EnumSet<Namespace> escapeEncoded =
492                union(EnumSet.complementOf(union(pathSchemes, invalid)),
493                      EnumSet.of(USER_DB, DB_SET));
494            private static EnumSet<Namespace> extendedNamespaces =
495                EnumSet.of(REPO, FAST);
496    
497            /**
498             * Computes the union of a set of EnumSets
499             * 
500             * @param set Two or more EnumSet<Namespace> objects to be combined
501             *            into one.
502             * @return The logical union of the given EnumSets.
503             */
504            private static EnumSet<Namespace> union(EnumSet... set)
505            {
506                EnumSet<Namespace> result = EnumSet.noneOf(Namespace.class);
507    
508                for (EnumSet s : set)
509                    result.addAll(StpException.<EnumSet<Namespace>>unchecked_cast(s));
510    
511                return result;
512            }
513            
514            /**
515             * Determines whether this namespace is valid (not NONE or INVALID).
516             * 
517             * @return <b>true</b> if this Namespace represents a valid namespace;
518             * <b>false</b> otherwise.
519             */
520            public boolean isValid()
521            {
522                return valid.contains(this);
523            }
524    
525            /**
526             * @return <b>true</b> iff this namespace prefixes a path scheme
527             */
528            public boolean isPathScheme()
529            {
530                return pathSchemes.contains(this);
531            }
532    
533            /**
534             * @return <b>true</b> iff this namespace prefixes a file path scheme.
535             */
536            public boolean isFilePathScheme()
537            {
538                return filePathSchemes.contains(this);
539            }
540    
541    
542            /**
543             * @return <b>true</b> iff this namespace prefixes a path scheme
544             *         selector for the name of a repository (or repository-like
545             *         entity not in a repository). Said path is the value of the
546             *         Repo field rather than the Name field of an StpLocation.
547             */
548            public boolean isRepositoryPathScheme()
549            {
550                return repositoryPathSchemes.contains(this);
551            }
552    
553    
554            /**
555             * @return <b>true</b> iff this namespace prefixes a path scheme
556             *         selector expressed as a URL or URI. The complete URI,
557             *         including this prefix is contained wholly within the Name
558             *         field of the StpLocation
559             */
560            public boolean isUrlPathScheme()
561            {
562                return urlPathSchemes.contains(this);
563            }
564    
565            /**
566             * @return <b>true</b> iff this namespace requires additional segments
567             *         to complete its specification.
568             */
569            public boolean isExtendedNamespace()
570            {
571                return extendedNamespaces.contains(this);
572            }
573    
574            /**
575             * @return Whether or not the name field of a location specification
576             *         prefixed by this namespace should be %-escaped encoded.
577             */
578            public boolean isEscapeEncoded()
579            {
580                return escapeEncoded.contains(this);
581            }
582    
583            /**
584             * Creates a new Namespace object given its namespace field image.
585             * 
586             * @param symbol The identifier used in the namespace field to denote
587             *            this namespace.
588             */
589            private Namespace(String symbol)
590            {
591                m_namespaceField = symbol;
592            }
593    
594            /** A map from namespace Symbol to Namespace */
595            private static Map<String, Namespace> g_symbolToNamespaceMap =
596                new Hashtable<String, Namespace>();
597    
598            static {
599                for (Namespace n : Namespace.values())
600                    if (null != g_symbolToNamespaceMap.put(n.m_namespaceField,
601                                                           n)) {
602                        throw new IllegalArgumentException
603                        ("Duplicate Selector.Namespace symbol" /* NOI18N */);
604                    }
605            }
606    
607            /** The symbol used in a selector to denote this Namespace */
608            private String m_namespaceField;
609    
610            /** Serialization version UID */
611            private static final long serialVersionUID = -3736971155548723312L;
612        }
613    
614        /**
615         * The characters within a location specification that syntactically delimit
616         * the fields of the selector.
617         */
618        static final String FIELD_DELIMITERS = "@" /* NOI18N */;
619    
620        /**
621         * The characters within a selector field that syntactically delimit the
622         * segments of a field.
623         */
624        static final String SEGMENT_DELIMITERS = "/\\" /* NOI18N */;
625    
626        /**
627         * The characters within a selector that syntactically delimit the fields
628         * and segments embedded within the selector.
629         */
630        static final String DELIMITERS = FIELD_DELIMITERS + SEGMENT_DELIMITERS;
631    
632        /**
633         * If one of the characters of DELIMITERS is to be part of a name segment it
634         * must be protected from its syntactic interpretation by preceding it with
635         * this escape character. The escape character must also be escaped if it is
636         * to be part of a name segment.
637         */
638        static final String ESCAPE_CHAR = "%" /* NOI18N */;
639    
640        /**
641         * Overall status of this StpLocation
642         * 
643         * @return <b>true</b> if all required fields were found in the given
644         *         location specification.
645         */
646        boolean isOk();
647    
648        /**
649         * Generates an StpException object that reports the state of this
650         * StpLocation.
651         * 
652         * @return An StpException whose message reports the state of this
653         *         StpLocation. Will be <b>null</b> if this StpLocation is valid.
654         */
655        StpException status();
656    
657        /**
658         * Throws an INVALID_OBJECT_SELECTOR StpException if this StpLocation does
659         * not reflect a syntactically complete and correct location specification.
660         * 
661         * @throws StpException if any required fields are missing from the
662         *             StpLocation specification.
663         */
664        void throwIfNotOk() throws StpException;
665    
666        /**
667         * Returns whether or not this location is specified using a pathname
668         * format. Such locations specify a location as a segmented pathname
669         * following an explicit scheme prefix:
670         * <p>[<i>domain</i> .] <i>namespace</i> : <i>segmented-path</i>.
671         * <p>
672         * The segmented-path is the value of either the name field or the repo
673         * field of this StpLocation and the other field is not used and empty. The
674         * segmented path is stored in the name field unless the predicate
675         * {@link #isRepositoryPathScheme} is also <b>true</b>.
676         * <p>
677         * Included in this scheme classification are the location specifications
678         * that are not complete enough to classify more precisely; i.e. it includes
679         * the locations with the following special Namespace values.
680         * <ul>
681         * <li>NONE: The location specification did not include a scheme delimiter
682         * (":") (at least, not before the first occurrence of a character not
683         * allowed in a scheme prefix). The original input is in the name field of
684         * this StpLocation.
685         * <li>INVALID: The location specification began with a syntactically valid
686         * scheme prefix, but the spelling of the namespace subfield did not match
687         * any known namespace. The location was parsed as a path-scheme location
688         * with all text following the first ':' stored in the name field. The
689         * apparently misspelled namespace field is available from the
690         * ExtendedNamespace field of this StpLocation.
691         * <li>DEFAULT: The location specification began with a syntactically valid
692         * scheme prefix, but the namespace field was empty. The location was parsed
693         * as a path-scheme location, with all text following the first ':' stored
694         * in the name field.
695         * </ul>
696         * 
697         * @return <b>true</b> if this is a path-scheme location; <b>false</b> otherwise
698         */
699        boolean isPathScheme();
700    
701        /**
702         * Returns whether or not this location is specified using the URL path-
703         * scheme format. Such locations are formatted as standards-conforming URLs
704         * (URL-encoded). The entire URL, including the scheme-prefix of the URL,
705         * such as "http:" or "file:" is included in the name field of the
706         * StpLocation object. An optional domain field is permitted before the
707         * scheme-prefix, but it is not included in the name field. A URL path
708         * scheme is a specialized form of path scheme. The URL could designate a
709         * server, a repository, or a resource inside or outside of a repository.
710         * The URL is stored in the repo field if {@link #isRepositoryPathScheme} is
711         * <b>true</b>; otherwise it is stored in the name field.
712         * 
713         * @return <b>true</b> if this is a URL path-location; <b>false</b>
714         *         otherwise
715         */
716        boolean isUrlPathScheme();
717    
718        /**
719         * Returns whether or not this location specifies a repository using a path-
720         * scheme format. Such locations have a repository field specified as a
721         * segmented pathname (un-encoded). A repository path-scheme is a
722         * specialized form of path-scheme in which the path is found in the repo
723         * field of the StpLocation object. For all other forms of path-location the
724         * path is found in the name field of the StpLocation object.
725         * 
726         * @return <b>true</b> if this is a repository path-location; <b>false</b>
727         *         otherwise
728         */
729        boolean isRepositoryPathScheme();
730    
731        /**
732         * Returns whether or not this location is specified using the file path-
733         * scheme format. In this format, the resource location is specified in the
734         * name field of this StpLocation as a segmented pathname (using native file
735         * system encoding conventions) to a file system object, perhaps extended by
736         * a ClearCase history-mode selector. The variant of the file path location
737         * format used in the specification of this StpLocation is indicated by the
738         * value of getNamespace().
739         * <ul>
740         * <li>FILE: The "file:" URL scheme prefix was used to specify this
741         * StpLocation. Since this is also a URL path-scheme, the file-scheme prefix
742         * is included in the name field of this object. Conversion of this location
743         * to a File via {@link #getFile()} or canonical path via
744         * {@link #getCanonicalPath()} will first use the java.net.URI class to
745         * parse the file URL.
746         * <li>PNAME: This location was specified with an explicit "pname:" prefix.
747         * The "pname:" prefix is <i>not</i> included in the name field of this
748         * object; it contains only the characters following "pname:"
749         * <li>PNAME_IMPLIED: This location was not specified with an explicit
750         * "pname:" prefix but is being treated as if it were a pname. The implied
751         * "pname:" prefix is <i>not</i> included in the name field of this object
752         * nor does it appear in the string image of this StpLocation.
753         * </ul>
754         * <p>
755         * Note that this and the other predicates are purely syntactic. The user
756         * may have intended to name a file, but if it so happens that its name
757         * looks exactly like a valid object selector, it will be parsed and
758         * classified as an object selector. {@link #isObjectSelectorScheme()} will
759         * be <b>true</b> not {@link #isFilePathScheme()}. Clients wishing to
760         * interpret a location as a file path location, may always use the
761         * {@link #getFile()} or {@link #getCanonicalPath()} methods to investigate
762         * that option further. If this StpLocation isn't in the FILE or PNAME
763         * namespace, these methods will use the original input in its entirety as
764         * the intended pathname.
765         * <p>
766         * Similarly, {@link #recomposeWithNamespace(StpLocation.Namespace) 
767         * recomposeWithNamespace(Namespace.PNAME)} will "do the right thing" and
768         * force the original input into an explicit file path selector. Note,
769         * however, that in this case, the image of that StpLocation will include
770         * the "pname:" prefix.
771         * 
772         * @return <code><b>true</b></code> if this selector is most likely a
773         *         pathname to a file system object, <code><b>false</b></code> if
774         *         there is a more likely interpretation.
775         */
776        boolean isFilePathScheme();
777    
778        /**
779         * Returns whether or not this file-path scheme location uses the optional
780         * ClearCase history-mode naming syntax.
781         * 
782         * @return <b>true</b> if the name segment of this location contains
783         *         history-mode naming syntax.
784         */
785        boolean isHistoryModeScheme();
786    
787        /**
788         * Returns whether or not this location uses either a stable, fast
789         * (efficient), or user-friendly object selector scheme. Locations using the
790         * object selector format have a pre-defined namespace and separate name and
791         * repository fields.
792         * 
793         * @return <b>true</b> if this location uses the object selector format;
794         *         <b>false</b> otherwise, in which case it uses either a path
795         *         scheme.
796         */
797        boolean isObjectSelectorScheme();
798    
799        /**
800         * Returns whether or not this location uses an object selector scheme with
801         * user-friendly namespace, name, and repository fields.
802         * 
803         * @return <b>true</b> if this is an object name selector; <b>false</b>
804         *         otherwise.
805         * 
806         */
807        boolean isUserFriendlySelectorScheme();
808    
809        /**
810         * Returns whether or not this location uses an object selector scheme with
811         * a compound REPO namespace. Its name and repository fields are densely
812         * encoded for greater stability and more efficient retrieval.
813         * 
814         * @return <b>true</b> if the location uses the REPO namespace; <b> false</b>
815         *         otherwise.
816         */
817        boolean isRepoSelectorScheme();
818    
819        /**
820         * Returns whether or not this location uses an object selector scheme with
821         * a compound FAST namespace. Its name and repository fields are densely
822         * encoded for greater stability and more efficient retrieval.
823         * 
824         * @return <b>true</b> if the location uses the FAST namespace; <b> false</b>
825         *         otherwise.
826         */
827        boolean isFastSelectorScheme();
828    
829        /**
830         * Returns whether or not this location uses an object selector scheme with
831         * a compound OID namespace. Its name and repository fields are densely
832         * encoded for greater stability and more efficient retrieval.
833         * 
834         * @return <b>true</b> if the location uses the OID namespace; <b> false</b>
835         *         otherwise.
836         */
837        boolean isOidSelectorScheme();
838    
839        /**
840         * Returns the StpLocation.Namespace of this selector.
841         * <p>
842         * The special Namespace.INVALID indicates that the namespace field was
843         * present but spelled different from any namespace known to the library.
844         * <p>
845         * The special Namespace.DEFAULT indicates that the namespace field was
846         * present but empty, indicating that the default namespace ought to be
847         * used.
848         * <p>
849         * The special Namespace.NONE indicates that the namespace field was not
850         * present (i.e. there was no ':' in the specification before the first
851         * occurrence of a character not allowed in a scheme prefix), making it
852         * quite likely that this is a file selector.
853         * <p>
854         * Namespace.HTTP, Namespace.HTTPS, and Namespace.FILE indicate that the
855         * selector used the URI/URL syntax, the entirety of which is present in the
856         * name property.
857         * <p>
858         * Namespace.PNAME indicates that the selector used the PNAME namespace
859         * prefix. The file pathname following the PNAME prefix is the value of the
860         * name field.
861         * <p>
862         * See the complete list of possible namespaces in the Namespace enum
863         * specification.
864         * 
865         * @return The namespace used in this location specification as a Namespace
866         *         object. This will never be <b>null</b>.
867         */
868        Namespace getNamespace();
869    
870        /**
871         * Returns the resource type field of a location specification if it used a
872         * compound namespace.
873         * 
874         * @return The resource type segment of this StpLocation. This field is
875         *         defined only for compound namespace locations (i.e. those that
876         *         use Namespace.REPO, Namespace.FAST, or Namespace.OID). It will be
877         *         an empty string otherwise.
878         */
879        String getResourceType();
880    
881        /**
882         * An object containing additional information associated with certain
883         * Namespace enumerators.
884         */
885        interface ExtendedNamespace
886        {
887    
888            /**
889             * @return Returns the namespace.
890             */
891            Namespace getNamespace();
892    
893            /**
894             * @return Returns the resource type portion of the compound REPO
895             *         namespace field. Returns the empty string if the namespace is
896             *         not REPO, FAST, or OID.
897             */
898            String getResourceType();
899    
900            /**
901             * The image of the extended namespace field. For Namespace.REPO, FAST,
902             * or OID, this includes the resource type subfield; for
903             * Namespace.INVALID, this is the (misspelled) namespace field as
904             * entered.
905             * 
906             * @return A String containing the image of the namespace field for this
907             *         extended namespace (without the delimiting ':'). Will be
908             *         empty if the namespace is DEFAULT and <b>null</b> if the
909             *         location specification has no namespace field separate from
910             *         the name field, i.e. if the namespace is NONE, PNAME_IMPLIED,
911             *         HTTP, HTTPS, or FILE.
912             */
913            String toNamespaceField();
914    
915            /**
916             * Generates a debug image for this ExtendedNamespace object
917             * 
918             * @return Returns the value of {@link #toNamespaceField()},
919             *         substituting "&lt;null>" for <b>null</b>.
920             */
921            public String toString();
922        }
923    
924        /**
925         * Returns an ExtendedNamespace object that, for some namespaces, contains
926         * additional information about the namespace field beyond its Namespace
927         * value.
928         * 
929         * @return For a REPO, FAST, or OID namespace, the ExtendedNamespace
930         *         specifies the resource type segment that is associated with it;
931         *         for an INVALID namespace, the ExtendedNamespace object specifies
932         *         the misspelled namespace field; for other namespaces, no
933         *         additional information is available. Will not be <b>null</b>.
934         */
935        ExtendedNamespace getExtendedNamespace();
936    
937        /**
938         * Returns the object name field specified for this location. This field is
939         * relevant and meaningful in all schemes <i>except</i> the repository-path
940         * scheme. In a repository-path scheme, it will be an empty Sting. The
941         * encoding of the returned String is unchanged from the original input.
942         * 
943         * @return An empty string for a repository-path-scheme location; otherwise
944         *         the object name field of an object selector or the pathname of a
945         *         path-scheme location. Will be never be <b> null</b>, but may be
946         *         empty.
947         */
948        String getName();
949    
950        /**
951         * The number of segments in the object name.
952         * 
953         * @return The length of the Sting array returned by
954         *         {@link #getNameSegments(int) getNameSegments(Integer.MAX_VALUE)}.
955         */
956        int getNameSegmentCount();
957    
958        /**
959         * Returns the first N segments of the name field of this location
960         * specification. If the requested number of segments is greater than the
961         * number in the name field, the entire name is returned; if zero or less,
962         * an empty array is returned.
963         * <p>
964         * Constructs a String array containing the segments of the given field. The
965         * elements of the array are the character sequences that preceded each
966         * segment delimiter plus the character sequence at the end of the field not
967         * followed by a delimiter as long as it is not empty. Thus, the array is
968         * empty if the field is empty; otherwise, the array has N+1 segments, where
969         * N is the number of segment delimiters in the field not counting the last
970         * delimiter if it appears at the end of the field.
971         * <p>
972         * The following examples illustrate the way a field is segmented.
973         * 
974         * <pre>
975         *  "" ==> {}
976         *  "fob/bar" ==> {"fob", "bar"}
977         *  "fob/" ==> {"fob"}
978         *  "fob" ==> {"fob"}
979         *  "/fob" ==> {"", "fob"}
980         *  "/" ==> {""}
981         *  "//" ==> {"", ""}
982         *  "fob//bar" ==> {"fob", "", "bar"}
983         *  "http://server" ==> {"http:", "", "server"}
984         *  "http://" ==> {"http:", ""}
985         *  "file:///" ==> {"file", "", ""}
986         * </pre>
987         * 
988         * Note that a trailing segment delimiter is "lost" only if it follows a
989         * non-empty segment. Consequently, when reconstructing the field from the
990         * array, segment delimiters should be inserted between each array element
991         * and a trailing delimiter should be added only if the last segment is
992         * empty.
993         * 
994         * <p>
995         * Note: The returned segments are encoded just as they were on input to the
996         * constructor. Any escape characters present in the field on input remain
997         * in each returned segment. Only the unescaped segment delimiters have been
998         * removed from the input field.
999         * 
1000         * @param nSegs the number of segments to return
1001         * 
1002         * @return a String array containing the first nSegs segments of the name
1003         *         field of this StpLocation.
1004         */
1005        String[] getNameSegments(int nSegs);
1006    
1007        /**
1008         * Returns contiguous segments of the name field of this selector. Segments
1009         * returned are in the intersection of the specified range and the actual
1010         * range of name segments. The first segment is at index zero.
1011         * 
1012         * <p>
1013         * Note: The returned segments are encoded just as they were on input to the
1014         * constructor. Any escape characters present in the field on input remain
1015         * in each returned segment. Only the unescaped segment delimiters have been
1016         * removed from the input field.
1017         * 
1018         * @param firstSeg the first segment to include
1019         * @param lastSeg the last segment to include
1020         * 
1021         * @return the requested segments of the object name. Will never be null,
1022         *         but may be empty if the specified range includes none of the
1023         *         segments of the name field.
1024         */
1025        String[] getNameSegments(int firstSeg,
1026                                 int lastSeg);
1027    
1028        /**
1029         * Returns the repository field of this location specification. This field
1030         * is irrelevant and empty in any path scheme location that does not have a
1031         * repository field. Conversely, if this location specification specified a
1032         * repository, it will be in this field.
1033         * 
1034         * @return An empty string if there was no repository field found in the
1035         *         location specification; otherwise the image of the repository
1036         *         field (without a repository field delimiter).
1037         */
1038        String getRepo();
1039    
1040        /**
1041         * The number of segments in the repository name.
1042         * 
1043         * @return The length of the String array returned by
1044         *         {@link #getRepoSegments(int) getRepoSegments(Integer.MAX_VALUE)}.
1045         */
1046        int getRepoSegmentCount();
1047    
1048        /**
1049         * Returns the first N segments of the repository field of this location. If
1050         * the requested number of segments is greater than the number in the
1051         * repository name, the entire repository name is returned; if zero or less,
1052         * an empty array is returned.
1053         * 
1054         * <p>
1055         * Note: The returned segments are encoded just as they were on input to the
1056         * constructor. Any escape characters present in the field on input remain
1057         * in each returned segment. Only the unescaped segment delimiters have been
1058         * removed from the input field.
1059         * 
1060         * @param nSegs the number of segments to return
1061         * 
1062         * @return a String containing the first nSegs segments of the repository
1063         *         name.
1064         * 
1065         * @see #getNameSegments(int) for a description of how segments are parsed
1066         *      and counted.
1067         */
1068        String[] getRepoSegments(int nSegs);
1069    
1070        /**
1071         * Returns contiguous segments of the repository name of this location.
1072         * Segments returned are in the intersection of the specified range and the
1073         * actual range of name segments. The first segment is at index zero.
1074         * 
1075         * <p>
1076         * Note: The returned segments are encoded just as they were on input to the
1077         * constructor. Any escape characters present in the field on input remain
1078         * in each returned segment. Only the unescaped segment delimiters have been
1079         * removed from the input field.
1080         * 
1081         * @param firstSeg the first segment to include
1082         * @param lastSeg the last segment to include
1083         * 
1084         * @return the requested segments of the repository name. Will never be
1085         *         null, but may be empty if the specified range includes none of
1086         *         the segments of the name.
1087         */
1088        String[] getRepoSegments(int firstSeg,
1089                                 int lastSeg);
1090    
1091        /**
1092         * Returns the domain specified or implied by the selector. In
1093         * URL-path-scheme locations this field is optional and will be NONE if no
1094         * domain information is available. In the other formats, the value NONE
1095         * denotes the default domain.
1096         * 
1097         * @return Returns the StpProvider.Domain. Will never be <b>null</b>, but
1098         *         may be {@link StpProvider.Domain#NONE NONE} or {@link
1099         *         StpProvider.Domain#INVALID INVALID}.
1100         */
1101        StpProvider.Domain getDomain();
1102    
1103        /**
1104         * Reconstitutes the location specification from its component fields.
1105         * 
1106         * @return For a valid StpLocation, a syntactically correct location
1107         *         specification string composed from the current values for the
1108         *         namespace, name, domain, and repo fields; otherwise the location
1109         *         specification as passed to the constructor.
1110         * 
1111         * @see java.lang.Object#toString()
1112         */
1113        String toString();
1114    
1115        /**
1116         * As above, but returns a location string <i>without</i> the domain
1117         * prefix.
1118         */
1119        String toStringWithoutDomain();
1120    
1121        /**
1122         * @see java.lang.Object#equals(java.lang.Object)
1123         */
1124        boolean equals(Object arg0);
1125    
1126        /**
1127         * Uses the hash code of the composed String image
1128         * 
1129         * @see java.lang.Object#hashCode()
1130         */
1131        int hashCode();
1132    
1133        /**
1134         * Constructs an StpLocation object based on the fields of this StpLocation
1135         * with optional replacements for some of the fields. A <b>null</b>
1136         * argument generally means to use the corresponding field of this
1137         * StpLocation in the new StpLocation.
1138         * <p>
1139         * NOTE: This method does not change the host StpLocation object. But
1140         * constructs and returns a new instance of StpLocation.
1141         * 
1142         * @param namespace The namespace for the new location expressed either as
1143         *            an ExtendedNamespace object, a Namespace enumeration or as a
1144         *            String containing the resource type of a REPO namespace. If
1145         *            namespace is Namespace.NONE no namespace prefix is generated
1146         *            for the selector. If namespace is <b>null</b>, the current
1147         *            value of getExtendedNamespace() is used.
1148         * @param name The name field of the new selector. If <b>null</b>, the
1149         *            current value of getName() is used.
1150         * @param domain The StpProvider.Domain for the new selector. If null, the
1151         *            current value of getDomain() is used.
1152         * @param repo The repository field for the new selector. If <b>null</b>,
1153         *            the current value of getRepo() is used. Must be <b>null</b>
1154         *            for path-path scheme locations that are not
1155         *            repository-path-schemes. If empty, no repository field will be
1156         *            generated for the selector.
1157         * 
1158         * @return A new StpLocation composed from the current namespace, name, type
1159         *         and repo fields, optionally overwritten by the given arguments.
1160         * 
1161         * @throws StpException Thrown if the given selector String is not in the
1162         *             correct form. StpReasonCode=INVALID_OBJECT_SELECTOR
1163         */
1164        StpLocation recomposeWithMods(Object namespace,
1165                                      String name,
1166                                      StpProvider.Domain domain,
1167                                      String repo) throws StpException;
1168    
1169        /**
1170         * Constructs new location based on this location but with a replacement for
1171         * its namespace field.
1172         * 
1173         * @param namespace The namespace for the new StpLocation. If namespace is
1174         *            Namespace.NONE, no namespace prefix is generated for the
1175         *            selector. If namespace is <b>null</b>, the current value of
1176         *            Namespace is used, effectively cloning this StpLocation
1177         *            object.
1178         * 
1179         * @return An StpLocation composed from the current name, domain and repo
1180         *         fields and the specified namespace argument.
1181         * 
1182         * @throws StpException if the given selector String is not in the
1183         *             correct form. StpReasonCode=INVALID_OBJECT_SELECTOR
1184         */
1185        StpLocation recomposeWithNamespace(StpLocation.Namespace namespace)
1186            throws StpException;
1187    
1188        /**
1189         * Constructs a new location based on this location with a replacement for
1190         * its name field.
1191         * 
1192         * @param name The new selector name field. If null, the current value of
1193         *            name() is used.
1194         * 
1195         * @return The selector composed from the current namespace, domain and repo
1196         *         fields and the specified name argument.
1197         * 
1198         * @throws StpException Thrown if the given selector String is not in the
1199         *             correct form. StpReasonCode=INVALID_OBJECT_SELECTOR
1200         */
1201        StpLocation recomposeWithName(String name) throws StpException;
1202    
1203        /**
1204         * Constructs a new location based on this location with a replacement for
1205         * its repository field.
1206         * 
1207         * @param repo The new repository field for the location. If <b>null</b>,
1208         *            the current value of getRepo() is used. If empty, no
1209         *            repository field will be generated for the location.
1210         * 
1211         * @return An StpLocation composed from the current namespace, name, and
1212         *         domain fields and the specified repo argument.
1213         * 
1214         * @throws StpException Thrown if the given selector String is not in the
1215         *             correct form. StpReasonCode=INVALID_OBJECT_SELECTOR
1216         */
1217        StpLocation recomposeWithRepo(String repo) throws StpException;
1218    
1219        /**
1220         * Constructs a new location based on this location with a replacement for
1221         * its domain field.
1222         * 
1223         * @param domain The new domain for the selector. If <b>null</b>, the
1224         *            current value of getDomain() is used.
1225         * 
1226         * @return An StpLocation composed from the current namespace, name, and
1227         *         repo fields and the specified domain argument.
1228         * 
1229         * @throws StpException Thrown if the given selector String is not in the
1230         *             correct form. StpReasonCode=INVALID_OBJECT_SELECTOR
1231         */
1232        StpLocation recomposeWithDomain(StpProvider.Domain domain)
1233            throws StpException;
1234    
1235        /**
1236         * Constructs an object selector with a replacement for its resource type
1237         * field, forcing the namespace to REPO.
1238         * 
1239         * @param rType The resource type for the new location. If <b>null</b>, the
1240         *            current value of getResourceType() is used.
1241         * 
1242         * @return A stable-selector scheme StpLocation composed from the current
1243         *         name, repo and domain fields and the specified resource type.
1244         * 
1245         * @throws StpException Thrown if the given selector String is not in the
1246         *             correct form. StpReasonCode=INVALID_OBJECT_SELECTOR
1247         */
1248        StpLocation recomposeWithResourceType(String rType) throws StpException;
1249    
1250        /**
1251         * Constructs an StpLocation for a pname based on the image of this
1252         * StpLocation. The StpLocation can be constructed with or without a pname
1253         * prefix and can be assigned a StpProvider.Domain.
1254         * <p>
1255         * In most cases, the entire image of this StpLocation (as returned by
1256         * toString()) becomes the value of the name field of the returned
1257         * StpLocation even if that image includes a namespace and/or a domain
1258         * prefix. The domain prefix can be elided from the name field of the new
1259         * location by using <b>null</b> for the domain argument to this method.
1260         * <p>
1261         * To convert any ill-formed selector to an implied pname, the following
1262         * logic might be used <code><pre>
1263         * if (!myLoc.isOk()) {
1264         *      // Convert to an implied pname so that it prints as it was
1265         *      // entered, but is treated internally as an OK file path selector
1266         *      myLoc = myLoc.recomposeAsPname(false, MY_DOMAIN);
1267         * }
1268         * </pre></code>
1269         * <p>
1270         * To convert any input not already formatted as a file-path-scheme location
1271         * to an explicit pname, the following logic might be used <code><pre>
1272         * if (!(myLoc.isFilePathScheme() && myLoc.isOk())) {
1273         *      myLoc = myLoc.recomposeAsPname(true, MY_DOMAIN);
1274         * }
1275         * </pre></code>
1276         * <p>
1277         * To convert all input to an implied pname, the following logic might be
1278         * used <code><pre>
1279         *  if (myLoc.getNamespace() == Namespace.PNAME) {
1280         *      // Keep the original "pname:" prefix out of the implied pname
1281         *      // Preserve any domain data from the input. 
1282         *      myLoc = myLoc.recomposeWithNamespace(Namespace.PNAME_IMPLIED);
1283         *  } else if (myLoc.getNamespace() == Namespace.FILE) {
1284         *      // Remove any domain info from the "file:" prefix, but push the
1285         *      // rest of the "file:" prefix into the pname.
1286         *      myLoc = myLoc.recomposeAsPname(false, null);
1287         *  } else {
1288         *      // All other input not using an explicit pname: or file: prefix is
1289         *      // treated as a raw pname.
1290         *      myLoc = myLoc.recomposeAsPname(false, MY_DOMAIN);
1291         *  }
1292         *  
1293         *  // Set the domain type if not already specified.
1294         *  if (myLoc.getDomain() == Domain.NONE)
1295         *      myLoc = recomposeWithType(MY_DOMAIN);
1296         * </pre></code>
1297         * 
1298         * @param withPrefix if <b>true</b>, the namespace of the returned
1299         *            StpLocation will be Namespace.PNAME; if <b>false</b>, the
1300         *            namespace will be Namespace.PNAME_IMPLIED.
1301         * @param domain The StpProvider.Domain of the returned StpLocation. If
1302         *            <b>null</b> the StpProvider.Domain of the current StpLocation
1303         *            will be used <i>and the image of that domain will be elided
1304         *            from the pname.</i>
1305         * @return An StpLocation reconfigured as a Pname instance, explicit or
1306         *         implied as requested
1307         */
1308        StpLocation recomposeAsPname(boolean withPrefix,
1309                                     StpProvider.Domain domain) throws StpException;
1310    
1311        /**
1312         * Constructs a location suitable for addressing resources of the type
1313         * indicated by the supplied proxy class by filling in unspecified fields of
1314         * this location using provider-defined or resource-type-dependent defaults.
1315         * <p>
1316         * Note, when an StpLocation object is passed to a Provider proxy factory
1317         * method this forClass is implicitly invoked using the Class of the proxy
1318         * returned by the proxy factory method. Similarly, when an StpLocation is
1319         * passed to a method of a proxy, that method implicitly invokes forClass
1320         * using a proxy class deduced from the host proxy and the operation.
1321         * <p>
1322         * Clients need to use this method only if they want to complete/verify a
1323         * location used in some other context or more tightly than can be
1324         * determined from the proxy context.
1325         * 
1326         * @param proxyClass The Class object for the proxy interface for which this
1327         *            location is to be completed.
1328         * @return An StpLocation suitable for use with a proxy of the given class.
1329         *         The result will be this location if it is already suitable and a
1330         *         new StpLocation if not; will never be <b>null</b>.
1331         * @throws WvcmException if it is not possible to complete the location from
1332         *             available defaults or if the completed location is
1333         *             inappropriate in some other (obvious) way, such as having a
1334         *             domain or namespace inconsistent with the given class.
1335         */
1336        StpLocation forClass(Class<? extends Resource> proxyClass) throws WvcmException;
1337    
1338        /**
1339         * Returns an StpLocation whose segmented name field is one segment shorter
1340         * than the name field of this StpLocation <i>provided</i> the name field
1341         * of the resulting StpLocation would be valid. All other fields of the
1342         * StpLocation are left unchanged.
1343         * <p>
1344         * NOTE: For repository-path scheme locations this method operates on the
1345         * segmented repo field rather than the name field. But in all other
1346         * respects the behavior is the same.
1347         * <p>
1348         * For object-selector scheme locations, an empty name field is valid, but
1349         * for path-scheme locations, the name/repo field is valid only if it
1350         * contains at least one segment of the original path (even if that segment
1351         * is empty). These examples illustrate the edge cases <code><pre>
1352         *      StpLocation        |    Parent        
1353         *      -------------------+---------------
1354         *      /food              | /        
1355         *      vob:/food          | vob:/      
1356         *      http://server/path | http://server 
1357         *      file://author/path | file://author 
1358         *      http://server      | &lt;null&gt; 
1359         *      file://author      | &lt;null&gt; 
1360         *      pname:path         | &lt;null&gt;      
1361         *      file:/             | &lt;null&gt;      
1362         * </pre></code>
1363         * 
1364         * @return A new StpLocation instance; will be <b>null</b> if the name
1365         *         field of this StpLocation has no segments that can be removed.
1366         */
1367        Location parent();
1368    
1369        /**
1370         * Returns an StpLocation whose name field is the name field of this
1371         * StpLocation extended by the given child segment. All other fields are the
1372         * same as the fields of this StpLocation. For repository-path-scheme
1373         * locations, the repo field is extended rather than the name field.
1374         * <p>
1375         * Unlike most of the other methods of this class, the child() method
1376         * encodes the new child segment according to the requirements of the
1377         * scheme. Thus, this method may be used to add only one segment at a time
1378         * to the StpLocation. In any scheme, any embedded segment delimiters in the
1379         * child segment will be encoded to make them part of the segment.
1380         * <p>
1381         * Even if this method successfully returns an StpLocation, there is no
1382         * guarantee that the returned location is a valid resource location. The
1383         * returned location may be invalid even if the original location was valid.
1384         * Some resources simply do not have parents even though their location
1385         * suggests that they do.
1386         * <p>
1387         * For example, <b>field:Defect/Headline@7.0.0.0/SAMPL</b> is the location
1388         * for the description of the <b>Headline</b> field of the <b>Defect</b>
1389         * record type in the sample ClearQuest database. However, its parent
1390         * location, <b>field:Defect@7.0.0.0/SAMPL</b>, is <i>not</i> a valid
1391         * location. While this may seem to address the <b>Defect</b> record type
1392         * resource, it does not. The location for the <b>Defect</b> record type
1393         * resource is, in fact, <b><u>record</u>:Defect@7.0.0.0/SAMPL</b>, which
1394         * is in a different namespace from the parent of the field description
1395         * resource.
1396         * <p>
1397         * In general, clients are discouraged from manipulating locations to
1398         * traverse the object model. They should use the properties defined for
1399         * this purpose instead. If, for example, the client wants to traverse from
1400         * a field description to the record type of that field, then it should use
1401         * the RECORD_TYPE property of the field rather than taking the parent and
1402         * changing the namespace. Note that if the field location is a
1403         * stable-selector scheme location, simply changing the namespace of the
1404         * parent will not work.
1405         * 
1406         * @param child The new segment to be appended to the name field of this
1407         *            StpLocation. To be consistent with the Location.child method,
1408         *            it is assumed that the String is not yet encoded. It will be
1409         *            encoded as a single segment before adding it to the name
1410         *            field.
1411         * 
1412         * @return A new StpLocation with an extended name field.
1413         */
1414        Location child(String child);
1415    
1416        /**
1417         * Returns the last segment of the name field of this StpLocation. (Returns
1418         * the last segment of the repo field for repository-path-scheme locations.)
1419         * Any encoding used within the last segment is removed before returning a
1420         * value. Thus it's the case that
1421         * <b>loc.equals(loc.parent().child(loc.lastSegment()))</b> as long as
1422         * <b>loc.parent()</b> is not null.
1423         * <p>
1424         * At the root of the namespace (parent() returns &lt;null>), returns either
1425         * the name of the root or the empty string if the root is unnamed. These
1426         * examples illustrate the edge cases <code><pre>
1427         *      StpLocation        | lastSegment | parent        
1428         *      -------------------+-------------+------------- 
1429         *      /food              |   food      | /   
1430         *      /                  |  &lt;empty&gt;    | &lt;null&gt;       
1431         *      pname:/food        |   food      | pname:/
1432         *      http://server/path |   path      | http://server
1433         *      file://author/path |   path      | file://author
1434         *      http://server      |  &lt;empty&gt;    | &lt;null&gt;
1435         *      file://author      |  &lt;empty&gt;    | &lt;null&gt;
1436         *      pname:path         |   path      | &lt;null&gt;
1437         *      pname:/            |  &lt;empty&gt;    | &lt;null&gt;
1438         *      pname:\            |  &lt;empty&gt;    | &lt;null&gt;
1439         *      record:food@cq:s/u |   food      | record:@cq:s/u
1440         *      record:@cq:s/u     |  &lt;empty&gt;    | &lt;null&gt;
1441         * </pre></code>
1442         * 
1443         * @return A String containing the last segment of the name field of this
1444         *         StpLocation stripped of all encodings. Will never be null, but
1445         *         may be empty if the last segment is unnamed.
1446         */
1447        String lastSegment();
1448    
1449        /**
1450         * Interprets this StpLocation as a file-path-scheme location and returns
1451         * the <i>canonical</i> pathname for the file. If this StpLocation is not a
1452         * file-path-scheme location, the original location specification used to
1453         * construct this StpLocation is used as the pathname to be canonicalized.
1454         * <p>
1455         * For a location in the FILE namespace, this method constructs a URI from
1456         * the given file-scheme URL and then constructs a java.io.File from that
1457         * URI. Whether or not this succeeds depends on the JVM. (IBM's JVM 1.4.2,
1458         * for example, requires that the authority portion be empty.)
1459         * 
1460         * @see java.io.File#getCanonicalPath()
1461         * 
1462         * @return The canonicalized pathname for this resource. Will never be
1463         *         <b>null</b>.
1464         * 
1465         * @throws StpException if IO errors are encountered while determining the
1466         *             canonical path or converting the file-scheme URL to a File.
1467         */
1468        String getCanonicalPath() throws StpException;
1469    
1470        /**
1471         * Returns a File object that references the path defined by this
1472         * StpLocation. If this StpLocation is not a file-path-scheme location, the
1473         * original location specification used to construct this StpLocation is
1474         * used as the pathname from which the java.io.File object is constructed.
1475         * <p>
1476         * For a location in the FILE namespace, this method constructs a URI from
1477         * the given URL and then constructs a java.io.File from that URI. Whether
1478         * or not this succeeds depends on the JVM. (IBM's JVM 1.4.2, for example,
1479         * requires that the authority portion be undefined.)
1480         * 
1481         * @return A File object for the path defined by this StpLocation; Will
1482         *         never be <b>null</b>.
1483         * 
1484         * @throws MalformedURLException if the selector is a file scheme URL for
1485         *             which a File cannot be constructed.
1486         * @throws StpException
1487         * @throws IllegalStateException If {@link #isFilePathScheme()} is <b> false</b>.
1488         */
1489        File getFile() throws MalformedURLException, StpException;
1490    
1491    }