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, 2010. 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><domain></i>.][<i><namespace></i>]:] [<i><object-name></i>][@[<i><repository-name></i>]] 062 * <p> 063 * The <i><object-name></i>, and <i><repository-name></i> fields are 064 * segmented names where the segments are separated by '/'s or '\'s. The 065 * permitted <i><namespace></i>s are defined by 066 * {@link StpLocation.Namespace} and the permitted <i><domain></i>s are 067 * defined by {@link StpProvider.Domain}. 068 * <p> 069 * The character '@' 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><domain></i>.][<i><namespace></i>]:] [<i><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 policy */ 319 POLICY("policy" /* NOI18N */), 320 321 /** The user-friendly-selector-scheme Namespace for a pool */ 322 @RpcEnum(id=30, simpleName="pool") 323 POOL("pool" /* NOI18N */), 324 325 /** The user-friendly-selector-scheme Namespace for a project. */ 326 @RpcEnum(id=31, simpleName="project") 327 PROJECT("project" /* NOI18N */), 328 329 /** 330 * The user-friendly-selector-scheme Namespace for a project 331 * configuration 332 */ 333 @RpcEnum(id=32, simpleName="projconfig") 334 PROJECT_CONFIGURATION("projconfig" /* NOI18N */), 335 336 /** 337 * The user-friendly-selector-scheme Namespace for a query, chart, 338 * report, report format, or query folder. 339 */ 340 @RpcEnum(id=33, simpleName="query") 341 QUERY("query" /* NOI18N */), 342 343 /** 344 * The user-friendly-selector-scheme Namespace for a record, record 345 * type, attachment folder, or attachment 346 */ 347 @RpcEnum(id=34, simpleName="record") 348 RECORD("record" /* NOI18N */), 349 350 /** 351 * The user-friendly, efficient, and stable-scheme Namespace for a 352 * ClearCase registry region. 353 */ 354 @RpcEnum(id=35, simpleName="registryregion") 355 REGISTRY_REGION("registryregion" /* NOI18N */), 356 357 /** The user-friendly-selector-scheme Namespace for a replica */ 358 @RpcEnum(id=36, simpleName="replica") 359 REPLICA("replica" /* NOI18N */), 360 361 /** The user-friendly-selector-scheme Namespace for a rolemap */ 362 ROLEMAP("rolemap" /* NOI18N */), 363 364 /** The user-friendly-selector-scheme Namespace for an rptype */ 365 @RpcEnum(id=39, simpleName="rptype") 366 RPTYPE("rptype" /* NOI18N */), 367 368 /** 369 * The user-friendly, efficient, and stable-scheme Namespace for a 370 * ClearCase storage location. 371 */ 372 STORAGE_LOCATION("stgloc" /* NOI18N */), 373 374 /** The user-friendly-selector-scheme Namespace for a stream */ 375 @RpcEnum(id=40, simpleName="stream") 376 STREAM("stream" /* NOI18N */), 377 378 /** The user-friendly-selector-scheme Namespace for a trigger type */ 379 @RpcEnum(id=41, simpleName="trtype") 380 TRTYPE("trtype" /* NOI18N */), 381 382 /** 383 * The URL-path-scheme Namespace denoting a location presented in the 384 * form of an HTTP URI or URL 385 */ 386 @RpcEnum(id=21, simpleName="http") 387 HTTP("http" /* NOI18N */), 388 389 /** 390 * The URL-path-scheme Namespace denoting a location presented in the 391 * form of an HTTPS URI or URL 392 */ 393 @RpcEnum(id=22, simpleName="https") 394 HTTPS("https" /* NOI18N */), 395 396 /** The user-friendly-selector-scheme Namespace for a user */ 397 @RpcEnum(id=42, simpleName="user") 398 USER("user" /* NOI18N */), 399 400 /** 401 * The user-friendly, efficient, and stable-scheme Namespace for a view 402 * tag. 403 */ 404 @RpcEnum(id=44, simpleName="viewtag") 405 VIEWTAG("viewtag" /* NOI18N */), 406 407 /** 408 * The user-friendly, efficient, and stable-scheme Namespace for a VOB 409 * tag. 410 */ 411 @RpcEnum(id=47, simpleName="vobtag") 412 VOBTAG("vobtag" /* NOI18N */), 413 414 /** 415 * The path-scheme Namespace for a ClearCase VOB tag, treated in some 416 * senses as a directory. 417 * 418 * Note: This namespace is an implementation detail of the server, which 419 * unfortunately must be exposed to clients. 420 * 421 * It is not intended that clients should attempt to create resources 422 * within this namespace. Undefined behavior is guaranteed if clients 423 * attempt this. 424 * 425 * It is not expected that the server will return resources within this 426 * namespace. 427 */ 428 @RpcEnum(id=48, simpleName="vobtagasdirectory") 429 VOB_TAG_AS_DIRECTORY("vobtagasdirectory" /* NOI18N */), 430 431 /** The path-scheme Namespace for a workspace */ 432 @RpcEnum(id=49, simpleName="workspace") 433 WORKSPACE("workspace" /* NOI18N */), 434 435 /** 436 * The user-friendly-selector-scheme Namespace for a server; 437 * e.g. ClearCase or ClearQuest 438 */ 439 @RpcEnum(id=9, simpleName="domainserver") 440 DOMAINSERVER("server" /* NOI18N */), 441 442 /** The path-scheme for a CCRC (aka, "legacy") server */ 443 @RpcEnum(id=25, simpleName="legacyserver") 444 LEGACYSERVER("legacyserver" /* NOI18N */); 445 446 /** 447 * Returns the word token for this Namespace in the namespace field of a 448 * location specification. 449 * 450 * @return A String containing the namespace field value that denotes 451 * this Namespace. 452 */ 453 public String toNamespaceField() 454 { 455 return m_namespaceField; 456 } 457 458 /** 459 * Finds the Namespace enumerator from the identifier used in the 460 * namespace field of a location specification. 461 * 462 * @param field The word token as it appears in a location namespace 463 * field. 464 * 465 * @return The Namespace that the namespace field identifier denotes. 466 * Namespace.INVALID is returned if no Namespace enumerator 467 * matches the symbol exactly. 468 */ 469 public static final Namespace fromNamespaceField(String field) 470 { 471 // Force to lower case before consulting symbol map 472 String symbol = field.toLowerCase(); 473 474 Namespace namespace = g_symbolToNamespaceMap.get(symbol); 475 476 return namespace == null? Namespace.INVALID : namespace; 477 } 478 479 /** 480 * EnumSet definitions for the various classifications of Namespaces 481 */ 482 private static EnumSet<Namespace> invalid = EnumSet.of(INVALID, NONE); 483 private static EnumSet<Namespace> valid = EnumSet.complementOf(invalid); 484 private static EnumSet<Namespace> filePathSchemes = 485 EnumSet.of(PNAME, 486 PNAME_IMPLIED, 487 FILE); 488 private static EnumSet<Namespace> repositoryPathSchemes = 489 EnumSet.of(VOB, 490 VIEW_UUID, 491 REPLICA_UUID, 492 USER_DB, 493 DB_SET, 494 LEGACYSERVER); 495 private static EnumSet<Namespace> urlPathSchemes = EnumSet.of(FILE, 496 HTTP, 497 HTTPS); 498 private static EnumSet<Namespace> pathSchemes = 499 union(EnumSet.of(WORKSPACE, NONE, DEFAULT, INVALID), 500 filePathSchemes, 501 urlPathSchemes, 502 repositoryPathSchemes); 503 private static EnumSet<Namespace> escapeEncoded = 504 union(EnumSet.complementOf(union(pathSchemes, invalid)), 505 EnumSet.of(USER_DB, DB_SET)); 506 private static EnumSet<Namespace> extendedNamespaces = 507 EnumSet.of(REPO, FAST); 508 509 /** 510 * Computes the union of a set of EnumSets 511 * 512 * @param set Two or more EnumSet<Namespace> objects to be combined 513 * into one. 514 * @return The logical union of the given EnumSets. 515 */ 516 private static EnumSet<Namespace> union(EnumSet... set) 517 { 518 EnumSet<Namespace> result = EnumSet.noneOf(Namespace.class); 519 520 for (EnumSet s : set) 521 result.addAll(StpException.<EnumSet<Namespace>>unchecked_cast(s)); 522 523 return result; 524 } 525 526 /** 527 * Determines whether this namespace is valid (not NONE or INVALID). 528 * 529 * @return <b>true</b> if this Namespace represents a valid namespace; 530 * <b>false</b> otherwise. 531 */ 532 public boolean isValid() 533 { 534 return valid.contains(this); 535 } 536 537 /** 538 * @return <b>true</b> iff this namespace prefixes a path scheme 539 */ 540 public boolean isPathScheme() 541 { 542 return pathSchemes.contains(this); 543 } 544 545 /** 546 * @return <b>true</b> iff this namespace prefixes a file path scheme. 547 */ 548 public boolean isFilePathScheme() 549 { 550 return filePathSchemes.contains(this); 551 } 552 553 554 /** 555 * @return <b>true</b> iff this namespace prefixes a path scheme 556 * selector for the name of a repository (or repository-like 557 * entity not in a repository). Said path is the value of the 558 * Repo field rather than the Name field of an StpLocation. 559 */ 560 public boolean isRepositoryPathScheme() 561 { 562 return repositoryPathSchemes.contains(this); 563 } 564 565 566 /** 567 * @return <b>true</b> iff this namespace prefixes a path scheme 568 * selector expressed as a URL or URI. The complete URI, 569 * including this prefix is contained wholly within the Name 570 * field of the StpLocation 571 */ 572 public boolean isUrlPathScheme() 573 { 574 return urlPathSchemes.contains(this); 575 } 576 577 /** 578 * @return <b>true</b> iff this namespace requires additional segments 579 * to complete its specification. 580 */ 581 public boolean isExtendedNamespace() 582 { 583 return extendedNamespaces.contains(this); 584 } 585 586 /** 587 * @return Whether or not the name field of a location specification 588 * prefixed by this namespace should be %-escaped encoded. 589 */ 590 public boolean isEscapeEncoded() 591 { 592 return escapeEncoded.contains(this); 593 } 594 595 /** 596 * Creates a new Namespace object given its namespace field image. 597 * 598 * @param symbol The identifier used in the namespace field to denote 599 * this namespace. 600 */ 601 private Namespace(String symbol) 602 { 603 m_namespaceField = symbol; 604 } 605 606 /** A map from namespace Symbol to Namespace */ 607 private static Map<String, Namespace> g_symbolToNamespaceMap = 608 new Hashtable<String, Namespace>(); 609 610 static { 611 for (Namespace n : Namespace.values()) 612 if (null != g_symbolToNamespaceMap.put(n.m_namespaceField, 613 n)) { 614 throw new IllegalArgumentException 615 ("Duplicate Selector.Namespace symbol" /* NOI18N */); 616 } 617 } 618 619 /** The symbol used in a selector to denote this Namespace */ 620 private String m_namespaceField; 621 622 /** Serialization version UID */ 623 private static final long serialVersionUID = -3736971155548723312L; 624 } 625 626 /** 627 * The characters within a location specification that syntactically delimit 628 * the fields of the selector. 629 */ 630 static final String FIELD_DELIMITERS = "@" /* NOI18N */; 631 632 /** 633 * The characters within a selector field that syntactically delimit the 634 * segments of a field. 635 */ 636 static final String SEGMENT_DELIMITERS = "/\\" /* NOI18N */; 637 638 /** 639 * The characters within a selector that syntactically delimit the fields 640 * and segments embedded within the selector. 641 */ 642 static final String DELIMITERS = FIELD_DELIMITERS + SEGMENT_DELIMITERS; 643 644 /** 645 * If one of the characters of DELIMITERS is to be part of a name segment it 646 * must be protected from its syntactic interpretation by preceding it with 647 * this escape character. The escape character must also be escaped if it is 648 * to be part of a name segment. 649 */ 650 static final String ESCAPE_CHAR = "%" /* NOI18N */; 651 652 /** 653 * Overall status of this StpLocation 654 * 655 * @return <b>true</b> if all required fields were found in the given 656 * location specification. 657 */ 658 boolean isOk(); 659 660 /** 661 * Generates an StpException object that reports the state of this 662 * StpLocation. 663 * 664 * @return An StpException whose message reports the state of this 665 * StpLocation. Will be <b>null</b> if this StpLocation is valid. 666 */ 667 StpException status(); 668 669 /** 670 * Throws an INVALID_OBJECT_SELECTOR StpException if this StpLocation does 671 * not reflect a syntactically complete and correct location specification. 672 * 673 * @throws StpException if any required fields are missing from the 674 * StpLocation specification. 675 */ 676 void throwIfNotOk() throws StpException; 677 678 /** 679 * Returns whether or not this location is specified using a pathname 680 * format. Such locations specify a location as a segmented pathname 681 * following an explicit scheme prefix: 682 * <p>[<i>domain</i> .] <i>namespace</i> : <i>segmented-path</i>. 683 * <p> 684 * The segmented-path is the value of either the name field or the repo 685 * field of this StpLocation and the other field is not used and empty. The 686 * segmented path is stored in the name field unless the predicate 687 * {@link #isRepositoryPathScheme} is also <b>true</b>. 688 * <p> 689 * Included in this scheme classification are the location specifications 690 * that are not complete enough to classify more precisely; i.e. it includes 691 * the locations with the following special Namespace values. 692 * <ul> 693 * <li>NONE: The location specification did not include a scheme delimiter 694 * (":") (at least, not before the first occurrence of a character not 695 * allowed in a scheme prefix). The original input is in the name field of 696 * this StpLocation. 697 * <li>INVALID: The location specification began with a syntactically valid 698 * scheme prefix, but the spelling of the namespace subfield did not match 699 * any known namespace. The location was parsed as a path-scheme location 700 * with all text following the first ':' stored in the name field. The 701 * apparently misspelled namespace field is available from the 702 * ExtendedNamespace field of this StpLocation. 703 * <li>DEFAULT: The location specification began with a syntactically valid 704 * scheme prefix, but the namespace field was empty. The location was parsed 705 * as a path-scheme location, with all text following the first ':' stored 706 * in the name field. 707 * </ul> 708 * 709 * @return <b>true</b> if this is a path-scheme location; <b>false</b> otherwise 710 */ 711 boolean isPathScheme(); 712 713 /** 714 * Returns whether or not this location is specified using the URL path- 715 * scheme format. Such locations are formatted as standards-conforming URLs 716 * (URL-encoded). The entire URL, including the scheme-prefix of the URL, 717 * such as "http:" or "file:" is included in the name field of the 718 * StpLocation object. An optional domain field is permitted before the 719 * scheme-prefix, but it is not included in the name field. A URL path 720 * scheme is a specialized form of path scheme. The URL could designate a 721 * server, a repository, or a resource inside or outside of a repository. 722 * The URL is stored in the repo field if {@link #isRepositoryPathScheme} is 723 * <b>true</b>; otherwise it is stored in the name field. 724 * 725 * @return <b>true</b> if this is a URL path-location; <b>false</b> 726 * otherwise 727 */ 728 boolean isUrlPathScheme(); 729 730 /** 731 * Returns whether or not this location specifies a repository using a path- 732 * scheme format. Such locations have a repository field specified as a 733 * segmented pathname (un-encoded). A repository path-scheme is a 734 * specialized form of path-scheme in which the path is found in the repo 735 * field of the StpLocation object. For all other forms of path-location the 736 * path is found in the name field of the StpLocation object. 737 * 738 * @return <b>true</b> if this is a repository path-location; <b>false</b> 739 * otherwise 740 */ 741 boolean isRepositoryPathScheme(); 742 743 /** 744 * Returns whether or not this location is specified using the file path- 745 * scheme format. In this format, the resource location is specified in the 746 * name field of this StpLocation as a segmented pathname (using native file 747 * system encoding conventions) to a file system object, perhaps extended by 748 * a ClearCase history-mode selector. The variant of the file path location 749 * format used in the specification of this StpLocation is indicated by the 750 * value of getNamespace(). 751 * <ul> 752 * <li>FILE: The "file:" URL scheme prefix was used to specify this 753 * StpLocation. Since this is also a URL path-scheme, the file-scheme prefix 754 * is included in the name field of this object. Conversion of this location 755 * to a File via {@link #getFile()} or canonical path via 756 * {@link #getCanonicalPath()} will first use the java.net.URI class to 757 * parse the file URL. 758 * <li>PNAME: This location was specified with an explicit "pname:" prefix. 759 * The "pname:" prefix is <i>not</i> included in the name field of this 760 * object; it contains only the characters following "pname:" 761 * <li>PNAME_IMPLIED: This location was not specified with an explicit 762 * "pname:" prefix but is being treated as if it were a pname. The implied 763 * "pname:" prefix is <i>not</i> included in the name field of this object 764 * nor does it appear in the string image of this StpLocation. 765 * </ul> 766 * <p> 767 * Note that this and the other predicates are purely syntactic. The user 768 * may have intended to name a file, but if it so happens that its name 769 * looks exactly like a valid object selector, it will be parsed and 770 * classified as an object selector. {@link #isObjectSelectorScheme()} will 771 * be <b>true</b> not {@link #isFilePathScheme()}. Clients wishing to 772 * interpret a location as a file path location, may always use the 773 * {@link #getFile()} or {@link #getCanonicalPath()} methods to investigate 774 * that option further. If this StpLocation isn't in the FILE or PNAME 775 * namespace, these methods will use the original input in its entirety as 776 * the intended pathname. 777 * <p> 778 * Similarly, {@link #recomposeWithNamespace(StpLocation.Namespace) 779 * recomposeWithNamespace(Namespace.PNAME)} will "do the right thing" and 780 * force the original input into an explicit file path selector. Note, 781 * however, that in this case, the image of that StpLocation will include 782 * the "pname:" prefix. 783 * 784 * @return <code><b>true</b></code> if this selector is most likely a 785 * pathname to a file system object, <code><b>false</b></code> if 786 * there is a more likely interpretation. 787 */ 788 boolean isFilePathScheme(); 789 790 /** 791 * Returns whether or not this file-path scheme location uses the optional 792 * ClearCase history-mode naming syntax. 793 * 794 * @return <b>true</b> if the name segment of this location contains 795 * history-mode naming syntax. 796 */ 797 boolean isHistoryModeScheme(); 798 799 /** 800 * Returns whether or not this location uses either a stable, fast 801 * (efficient), or user-friendly object selector scheme. Locations using the 802 * object selector format have a pre-defined namespace and separate name and 803 * repository fields. 804 * 805 * @return <b>true</b> if this location uses the object selector format; 806 * <b>false</b> otherwise, in which case it uses either a path 807 * scheme. 808 */ 809 boolean isObjectSelectorScheme(); 810 811 /** 812 * Returns whether or not this location uses an object selector scheme with 813 * user-friendly namespace, name, and repository fields. 814 * 815 * @return <b>true</b> if this is an object name selector; <b>false</b> 816 * otherwise. 817 * 818 */ 819 boolean isUserFriendlySelectorScheme(); 820 821 /** 822 * Returns whether or not this location uses an object selector scheme with 823 * a compound REPO namespace. Its name and repository fields are densely 824 * encoded for greater stability and more efficient retrieval. 825 * 826 * @return <b>true</b> if the location uses the REPO namespace; <b> false</b> 827 * otherwise. 828 */ 829 boolean isRepoSelectorScheme(); 830 831 /** 832 * Returns whether or not this location uses an object selector scheme with 833 * a compound FAST namespace. Its name and repository fields are densely 834 * encoded for greater stability and more efficient retrieval. 835 * 836 * @return <b>true</b> if the location uses the FAST namespace; <b> false</b> 837 * otherwise. 838 */ 839 boolean isFastSelectorScheme(); 840 841 /** 842 * Returns whether or not this location uses an object selector scheme with 843 * a compound OID namespace. Its name and repository fields are densely 844 * encoded for greater stability and more efficient retrieval. 845 * 846 * @return <b>true</b> if the location uses the OID namespace; <b> false</b> 847 * otherwise. 848 */ 849 boolean isOidSelectorScheme(); 850 851 /** 852 * Returns the StpLocation.Namespace of this selector. 853 * <p> 854 * The special Namespace.INVALID indicates that the namespace field was 855 * present but spelled different from any namespace known to the library. 856 * <p> 857 * The special Namespace.DEFAULT indicates that the namespace field was 858 * present but empty, indicating that the default namespace ought to be 859 * used. 860 * <p> 861 * The special Namespace.NONE indicates that the namespace field was not 862 * present (i.e. there was no ':' in the specification before the first 863 * occurrence of a character not allowed in a scheme prefix), making it 864 * quite likely that this is a file selector. 865 * <p> 866 * Namespace.HTTP, Namespace.HTTPS, and Namespace.FILE indicate that the 867 * selector used the URI/URL syntax, the entirety of which is present in the 868 * name property. 869 * <p> 870 * Namespace.PNAME indicates that the selector used the PNAME namespace 871 * prefix. The file pathname following the PNAME prefix is the value of the 872 * name field. 873 * <p> 874 * See the complete list of possible namespaces in the Namespace enum 875 * specification. 876 * 877 * @return The namespace used in this location specification as a Namespace 878 * object. This will never be <b>null</b>. 879 */ 880 Namespace getNamespace(); 881 882 /** 883 * Returns the resource type field of a location specification if it used a 884 * compound namespace. 885 * 886 * @return The resource type segment of this StpLocation. This field is 887 * defined only for compound namespace locations (i.e. those that 888 * use Namespace.REPO, Namespace.FAST, or Namespace.OID). It will be 889 * an empty string otherwise. 890 */ 891 String getResourceType(); 892 893 /** 894 * An object containing additional information associated with certain 895 * Namespace enumerators. 896 */ 897 interface ExtendedNamespace 898 { 899 900 /** 901 * @return Returns the namespace. 902 */ 903 Namespace getNamespace(); 904 905 /** 906 * @return Returns the resource type portion of the compound REPO 907 * namespace field. Returns the empty string if the namespace is 908 * not REPO, FAST, or OID. 909 */ 910 String getResourceType(); 911 912 /** 913 * The image of the extended namespace field. For Namespace.REPO, FAST, 914 * or OID, this includes the resource type subfield; for 915 * Namespace.INVALID, this is the (misspelled) namespace field as 916 * entered. 917 * 918 * @return A String containing the image of the namespace field for this 919 * extended namespace (without the delimiting ':'). Will be 920 * empty if the namespace is DEFAULT and <b>null</b> if the 921 * location specification has no namespace field separate from 922 * the name field, i.e. if the namespace is NONE, PNAME_IMPLIED, 923 * HTTP, HTTPS, or FILE. 924 */ 925 String toNamespaceField(); 926 927 /** 928 * Generates a debug image for this ExtendedNamespace object 929 * 930 * @return Returns the value of {@link #toNamespaceField()}, 931 * substituting "<null>" for <b>null</b>. 932 */ 933 public String toString(); 934 } 935 936 /** 937 * Returns an ExtendedNamespace object that, for some namespaces, contains 938 * additional information about the namespace field beyond its Namespace 939 * value. 940 * 941 * @return For a REPO, FAST, or OID namespace, the ExtendedNamespace 942 * specifies the resource type segment that is associated with it; 943 * for an INVALID namespace, the ExtendedNamespace object specifies 944 * the misspelled namespace field; for other namespaces, no 945 * additional information is available. Will not be <b>null</b>. 946 */ 947 ExtendedNamespace getExtendedNamespace(); 948 949 /** 950 * Returns the object name field specified for this location. This field is 951 * relevant and meaningful in all schemes <i>except</i> the repository-path 952 * scheme. In a repository-path scheme, it will be an empty Sting. The 953 * encoding of the returned String is unchanged from the original input. 954 * 955 * @return An empty string for a repository-path-scheme location; otherwise 956 * the object name field of an object selector or the pathname of a 957 * path-scheme location. Will be never be <b> null</b>, but may be 958 * empty. 959 */ 960 String getName(); 961 962 /** 963 * The number of segments in the object name. 964 * 965 * @return The length of the Sting array returned by 966 * {@link #getNameSegments(int) getNameSegments(Integer.MAX_VALUE)}. 967 */ 968 int getNameSegmentCount(); 969 970 /** 971 * Returns the first N segments of the name field of this location 972 * specification. If the requested number of segments is greater than the 973 * number in the name field, the entire name is returned; if zero or less, 974 * an empty array is returned. 975 * <p> 976 * Constructs a String array containing the segments of the given field. The 977 * elements of the array are the character sequences that preceded each 978 * segment delimiter plus the character sequence at the end of the field not 979 * followed by a delimiter as long as it is not empty. Thus, the array is 980 * empty if the field is empty; otherwise, the array has N+1 segments, where 981 * N is the number of segment delimiters in the field not counting the last 982 * delimiter if it appears at the end of the field. 983 * <p> 984 * The following examples illustrate the way a field is segmented. 985 * 986 * <pre> 987 * "" ==> {} 988 * "fob/bar" ==> {"fob", "bar"} 989 * "fob/" ==> {"fob"} 990 * "fob" ==> {"fob"} 991 * "/fob" ==> {"", "fob"} 992 * "/" ==> {""} 993 * "//" ==> {"", ""} 994 * "fob//bar" ==> {"fob", "", "bar"} 995 * "http://server" ==> {"http:", "", "server"} 996 * "http://" ==> {"http:", ""} 997 * "file:///" ==> {"file", "", ""} 998 * </pre> 999 * 1000 * Note that a trailing segment delimiter is "lost" only if it follows a 1001 * non-empty segment. Consequently, when reconstructing the field from the 1002 * array, segment delimiters should be inserted between each array element 1003 * and a trailing delimiter should be added only if the last segment is 1004 * empty. 1005 * 1006 * <p> 1007 * Note: The returned segments are encoded just as they were on input to the 1008 * constructor. Any escape characters present in the field on input remain 1009 * in each returned segment. Only the unescaped segment delimiters have been 1010 * removed from the input field. 1011 * 1012 * @param nSegs the number of segments to return 1013 * 1014 * @return a String array containing the first nSegs segments of the name 1015 * field of this StpLocation. 1016 */ 1017 String[] getNameSegments(int nSegs); 1018 1019 /** 1020 * Returns contiguous segments of the name field of this selector. Segments 1021 * returned are in the intersection of the specified range and the actual 1022 * range of name segments. The first segment is at index zero. 1023 * 1024 * <p> 1025 * Note: The returned segments are encoded just as they were on input to the 1026 * constructor. Any escape characters present in the field on input remain 1027 * in each returned segment. Only the unescaped segment delimiters have been 1028 * removed from the input field. 1029 * 1030 * @param firstSeg the first segment to include 1031 * @param lastSeg the last segment to include 1032 * 1033 * @return the requested segments of the object name. Will never be null, 1034 * but may be empty if the specified range includes none of the 1035 * segments of the name field. 1036 */ 1037 String[] getNameSegments(int firstSeg, 1038 int lastSeg); 1039 1040 /** 1041 * Returns the repository field of this location specification. This field 1042 * is irrelevant and empty in any path scheme location that does not have a 1043 * repository field. Conversely, if this location specification specified a 1044 * repository, it will be in this field. 1045 * 1046 * @return An empty string if there was no repository field found in the 1047 * location specification; otherwise the image of the repository 1048 * field (without a repository field delimiter). 1049 */ 1050 String getRepo(); 1051 1052 /** 1053 * The number of segments in the repository name. 1054 * 1055 * @return The length of the String array returned by 1056 * {@link #getRepoSegments(int) getRepoSegments(Integer.MAX_VALUE)}. 1057 */ 1058 int getRepoSegmentCount(); 1059 1060 /** 1061 * Returns the first N segments of the repository field of this location. If 1062 * the requested number of segments is greater than the number in the 1063 * repository name, the entire repository name is returned; if zero or less, 1064 * an empty array is returned. 1065 * 1066 * <p> 1067 * Note: The returned segments are encoded just as they were on input to the 1068 * constructor. Any escape characters present in the field on input remain 1069 * in each returned segment. Only the unescaped segment delimiters have been 1070 * removed from the input field. 1071 * 1072 * @param nSegs the number of segments to return 1073 * 1074 * @return a String containing the first nSegs segments of the repository 1075 * name. 1076 * 1077 * @see #getNameSegments(int) for a description of how segments are parsed 1078 * and counted. 1079 */ 1080 String[] getRepoSegments(int nSegs); 1081 1082 /** 1083 * Returns contiguous segments of the repository name of this location. 1084 * Segments returned are in the intersection of the specified range and the 1085 * actual range of name segments. The first segment is at index zero. 1086 * 1087 * <p> 1088 * Note: The returned segments are encoded just as they were on input to the 1089 * constructor. Any escape characters present in the field on input remain 1090 * in each returned segment. Only the unescaped segment delimiters have been 1091 * removed from the input field. 1092 * 1093 * @param firstSeg the first segment to include 1094 * @param lastSeg the last segment to include 1095 * 1096 * @return the requested segments of the repository name. Will never be 1097 * null, but may be empty if the specified range includes none of 1098 * the segments of the name. 1099 */ 1100 String[] getRepoSegments(int firstSeg, 1101 int lastSeg); 1102 1103 /** 1104 * Returns the domain specified or implied by the selector. In 1105 * URL-path-scheme locations this field is optional and will be NONE if no 1106 * domain information is available. In the other formats, the value NONE 1107 * denotes the default domain. 1108 * 1109 * @return Returns the StpProvider.Domain. Will never be <b>null</b>, but 1110 * may be {@link StpProvider.Domain#NONE NONE} or {@link 1111 * StpProvider.Domain#INVALID INVALID}. 1112 */ 1113 StpProvider.Domain getDomain(); 1114 1115 /** 1116 * Reconstitutes the location specification from its component fields. 1117 * 1118 * @return For a valid StpLocation, a syntactically correct location 1119 * specification string composed from the current values for the 1120 * namespace, name, domain, and repo fields; otherwise the location 1121 * specification as passed to the constructor. 1122 * 1123 * @see java.lang.Object#toString() 1124 */ 1125 String toString(); 1126 1127 /** 1128 * As above, but returns a location string <i>without</i> the domain 1129 * prefix. 1130 */ 1131 String toStringWithoutDomain(); 1132 1133 /** 1134 * @see java.lang.Object#equals(java.lang.Object) 1135 */ 1136 boolean equals(Object arg0); 1137 1138 /** 1139 * Uses the hash code of the composed String image 1140 * 1141 * @see java.lang.Object#hashCode() 1142 */ 1143 int hashCode(); 1144 1145 /** 1146 * Constructs an StpLocation object based on the fields of this StpLocation 1147 * with optional replacements for some of the fields. A <b>null</b> 1148 * argument generally means to use the corresponding field of this 1149 * StpLocation in the new StpLocation. 1150 * <p> 1151 * NOTE: This method does not change the host StpLocation object. But 1152 * constructs and returns a new instance of StpLocation. 1153 * 1154 * @param namespace The namespace for the new location expressed either as 1155 * an ExtendedNamespace object, a Namespace enumeration or as a 1156 * String containing the resource type of a REPO namespace. If 1157 * namespace is Namespace.NONE no namespace prefix is generated 1158 * for the selector. If namespace is <b>null</b>, the current 1159 * value of getExtendedNamespace() is used. 1160 * @param name The name field of the new selector. If <b>null</b>, the 1161 * current value of getName() is used. 1162 * @param domain The StpProvider.Domain for the new selector. If null, the 1163 * current value of getDomain() is used. 1164 * @param repo The repository field for the new selector. If <b>null</b>, 1165 * the current value of getRepo() is used. Must be <b>null</b> 1166 * for path-path scheme locations that are not 1167 * repository-path-schemes. If empty, no repository field will be 1168 * generated for the selector. 1169 * 1170 * @return A new StpLocation composed from the current namespace, name, type 1171 * and repo fields, optionally overwritten by the given arguments. 1172 * 1173 * @throws StpException Thrown if the given selector String is not in the 1174 * correct form. StpReasonCode=INVALID_OBJECT_SELECTOR 1175 */ 1176 StpLocation recomposeWithMods(Object namespace, 1177 String name, 1178 StpProvider.Domain domain, 1179 String repo) throws StpException; 1180 1181 /** 1182 * Constructs new location based on this location but with a replacement for 1183 * its namespace field. 1184 * 1185 * @param namespace The namespace for the new StpLocation. If namespace is 1186 * Namespace.NONE, no namespace prefix is generated for the 1187 * selector. If namespace is <b>null</b>, the current value of 1188 * Namespace is used, effectively cloning this StpLocation 1189 * object. 1190 * 1191 * @return An StpLocation composed from the current name, domain and repo 1192 * fields and the specified namespace argument. 1193 * 1194 * @throws StpException if the given selector String is not in the 1195 * correct form. StpReasonCode=INVALID_OBJECT_SELECTOR 1196 */ 1197 StpLocation recomposeWithNamespace(StpLocation.Namespace namespace) 1198 throws StpException; 1199 1200 /** 1201 * Constructs a new location based on this location with a replacement for 1202 * its name field. 1203 * 1204 * @param name The new selector name field. If null, the current value of 1205 * name() is used. 1206 * 1207 * @return The selector composed from the current namespace, domain and repo 1208 * fields and the specified name argument. 1209 * 1210 * @throws StpException Thrown if the given selector String is not in the 1211 * correct form. StpReasonCode=INVALID_OBJECT_SELECTOR 1212 */ 1213 StpLocation recomposeWithName(String name) throws StpException; 1214 1215 /** 1216 * Constructs a new location based on this location with a replacement for 1217 * its repository field. 1218 * 1219 * @param repo The new repository field for the location. If <b>null</b>, 1220 * the current value of getRepo() is used. If empty, no 1221 * repository field will be generated for the location. 1222 * 1223 * @return An StpLocation composed from the current namespace, name, and 1224 * domain fields and the specified repo argument. 1225 * 1226 * @throws StpException Thrown if the given selector String is not in the 1227 * correct form. StpReasonCode=INVALID_OBJECT_SELECTOR 1228 */ 1229 StpLocation recomposeWithRepo(String repo) throws StpException; 1230 1231 /** 1232 * Constructs a new location based on this location with a replacement for 1233 * its domain field. 1234 * 1235 * @param domain The new domain for the selector. If <b>null</b>, the 1236 * current value of getDomain() is used. 1237 * 1238 * @return An StpLocation composed from the current namespace, name, and 1239 * repo fields and the specified domain argument. 1240 * 1241 * @throws StpException Thrown if the given selector String is not in the 1242 * correct form. StpReasonCode=INVALID_OBJECT_SELECTOR 1243 */ 1244 StpLocation recomposeWithDomain(StpProvider.Domain domain) 1245 throws StpException; 1246 1247 /** 1248 * Constructs an object selector with a replacement for its resource type 1249 * field, forcing the namespace to REPO. 1250 * 1251 * @param rType The resource type for the new location. If <b>null</b>, the 1252 * current value of getResourceType() is used. 1253 * 1254 * @return A stable-selector scheme StpLocation composed from the current 1255 * name, repo and domain fields and the specified resource type. 1256 * 1257 * @throws StpException Thrown if the given selector String is not in the 1258 * correct form. StpReasonCode=INVALID_OBJECT_SELECTOR 1259 */ 1260 StpLocation recomposeWithResourceType(String rType) throws StpException; 1261 1262 /** 1263 * Constructs an StpLocation for a pname based on the image of this 1264 * StpLocation. The StpLocation can be constructed with or without a pname 1265 * prefix and can be assigned a StpProvider.Domain. 1266 * <p> 1267 * In most cases, the entire image of this StpLocation (as returned by 1268 * toString()) becomes the value of the name field of the returned 1269 * StpLocation even if that image includes a namespace and/or a domain 1270 * prefix. The domain prefix can be elided from the name field of the new 1271 * location by using <b>null</b> for the domain argument to this method. 1272 * <p> 1273 * To convert any ill-formed selector to an implied pname, the following 1274 * logic might be used <code><pre> 1275 * if (!myLoc.isOk()) { 1276 * // Convert to an implied pname so that it prints as it was 1277 * // entered, but is treated internally as an OK file path selector 1278 * myLoc = myLoc.recomposeAsPname(false, MY_DOMAIN); 1279 * } 1280 * </pre></code> 1281 * <p> 1282 * To convert any input not already formatted as a file-path-scheme location 1283 * to an explicit pname, the following logic might be used <code><pre> 1284 * if (!(myLoc.isFilePathScheme() && myLoc.isOk())) { 1285 * myLoc = myLoc.recomposeAsPname(true, MY_DOMAIN); 1286 * } 1287 * </pre></code> 1288 * <p> 1289 * To convert all input to an implied pname, the following logic might be 1290 * used <code><pre> 1291 * if (myLoc.getNamespace() == Namespace.PNAME) { 1292 * // Keep the original "pname:" prefix out of the implied pname 1293 * // Preserve any domain data from the input. 1294 * myLoc = myLoc.recomposeWithNamespace(Namespace.PNAME_IMPLIED); 1295 * } else if (myLoc.getNamespace() == Namespace.FILE) { 1296 * // Remove any domain info from the "file:" prefix, but push the 1297 * // rest of the "file:" prefix into the pname. 1298 * myLoc = myLoc.recomposeAsPname(false, null); 1299 * } else { 1300 * // All other input not using an explicit pname: or file: prefix is 1301 * // treated as a raw pname. 1302 * myLoc = myLoc.recomposeAsPname(false, MY_DOMAIN); 1303 * } 1304 * 1305 * // Set the domain type if not already specified. 1306 * if (myLoc.getDomain() == Domain.NONE) 1307 * myLoc = recomposeWithType(MY_DOMAIN); 1308 * </pre></code> 1309 * 1310 * @param withPrefix if <b>true</b>, the namespace of the returned 1311 * StpLocation will be Namespace.PNAME; if <b>false</b>, the 1312 * namespace will be Namespace.PNAME_IMPLIED. 1313 * @param domain The StpProvider.Domain of the returned StpLocation. If 1314 * <b>null</b> the StpProvider.Domain of the current StpLocation 1315 * will be used <i>and the image of that domain will be elided 1316 * from the pname.</i> 1317 * @return An StpLocation reconfigured as a Pname instance, explicit or 1318 * implied as requested 1319 */ 1320 StpLocation recomposeAsPname(boolean withPrefix, 1321 StpProvider.Domain domain) throws StpException; 1322 1323 /** 1324 * Constructs a location suitable for addressing resources of the type 1325 * indicated by the supplied proxy class by filling in unspecified fields of 1326 * this location using provider-defined or resource-type-dependent defaults. 1327 * <p> 1328 * Note, when an StpLocation object is passed to a Provider proxy factory 1329 * method this forClass is implicitly invoked using the Class of the proxy 1330 * returned by the proxy factory method. Similarly, when an StpLocation is 1331 * passed to a method of a proxy, that method implicitly invokes forClass 1332 * using a proxy class deduced from the host proxy and the operation. 1333 * <p> 1334 * Clients need to use this method only if they want to complete/verify a 1335 * location used in some other context or more tightly than can be 1336 * determined from the proxy context. 1337 * 1338 * @param proxyClass The Class object for the proxy interface for which this 1339 * location is to be completed. 1340 * @return An StpLocation suitable for use with a proxy of the given class. 1341 * The result will be this location if it is already suitable and a 1342 * new StpLocation if not; will never be <b>null</b>. 1343 * @throws WvcmException if it is not possible to complete the location from 1344 * available defaults or if the completed location is 1345 * inappropriate in some other (obvious) way, such as having a 1346 * domain or namespace inconsistent with the given class. 1347 */ 1348 StpLocation forClass(Class<? extends Resource> proxyClass) throws WvcmException; 1349 1350 /** 1351 * Returns an StpLocation whose segmented name field is one segment shorter 1352 * than the name field of this StpLocation <i>provided</i> the name field 1353 * of the resulting StpLocation would be valid. All other fields of the 1354 * StpLocation are left unchanged. 1355 * <p> 1356 * NOTE: For repository-path scheme locations this method operates on the 1357 * segmented repo field rather than the name field. But in all other 1358 * respects the behavior is the same. 1359 * <p> 1360 * For object-selector scheme locations, an empty name field is valid, but 1361 * for path-scheme locations, the name/repo field is valid only if it 1362 * contains at least one segment of the original path (even if that segment 1363 * is empty). These examples illustrate the edge cases <code><pre> 1364 * StpLocation | Parent 1365 * -------------------+--------------- 1366 * /food | / 1367 * vob:/food | vob:/ 1368 * http://server/path | http://server 1369 * file://author/path | file://author 1370 * http://server | <null> 1371 * file://author | <null> 1372 * pname:path | <null> 1373 * file:/ | <null> 1374 * </pre></code> 1375 * 1376 * @return A new StpLocation instance; will be <b>null</b> if the name 1377 * field of this StpLocation has no segments that can be removed. 1378 */ 1379 Location parent(); 1380 1381 /** 1382 * Returns an StpLocation whose name field is the name field of this 1383 * StpLocation extended by the given child segment. All other fields are the 1384 * same as the fields of this StpLocation. For repository-path-scheme 1385 * locations, the repo field is extended rather than the name field. 1386 * <p> 1387 * Unlike most of the other methods of this class, the child() method 1388 * encodes the new child segment according to the requirements of the 1389 * scheme. Thus, this method may be used to add only one segment at a time 1390 * to the StpLocation. In any scheme, any embedded segment delimiters in the 1391 * child segment will be encoded to make them part of the segment. 1392 * <p> 1393 * Even if this method successfully returns an StpLocation, there is no 1394 * guarantee that the returned location is a valid resource location. The 1395 * returned location may be invalid even if the original location was valid. 1396 * Some resources simply do not have parents even though their location 1397 * suggests that they do. 1398 * <p> 1399 * For example, <b>field:Defect/Headline@7.0.0.0/SAMPL</b> is the location 1400 * for the description of the <b>Headline</b> field of the <b>Defect</b> 1401 * record type in the sample ClearQuest database. However, its parent 1402 * location, <b>field:Defect@7.0.0.0/SAMPL</b>, is <i>not</i> a valid 1403 * location. While this may seem to address the <b>Defect</b> record type 1404 * resource, it does not. The location for the <b>Defect</b> record type 1405 * resource is, in fact, <b><u>record</u>:Defect@7.0.0.0/SAMPL</b>, which 1406 * is in a different namespace from the parent of the field description 1407 * resource. 1408 * <p> 1409 * In general, clients are discouraged from manipulating locations to 1410 * traverse the object model. They should use the properties defined for 1411 * this purpose instead. If, for example, the client wants to traverse from 1412 * a field description to the record type of that field, then it should use 1413 * the RECORD_TYPE property of the field rather than taking the parent and 1414 * changing the namespace. Note that if the field location is a 1415 * stable-selector scheme location, simply changing the namespace of the 1416 * parent will not work. 1417 * 1418 * @param child The new segment to be appended to the name field of this 1419 * StpLocation. To be consistent with the Location.child method, 1420 * it is assumed that the String is not yet encoded. It will be 1421 * encoded as a single segment before adding it to the name 1422 * field. 1423 * 1424 * @return A new StpLocation with an extended name field. 1425 */ 1426 Location child(String child); 1427 1428 /** 1429 * Returns the last segment of the name field of this StpLocation. (Returns 1430 * the last segment of the repo field for repository-path-scheme locations.) 1431 * Any encoding used within the last segment is removed before returning a 1432 * value. Thus it's the case that 1433 * <b>loc.equals(loc.parent().child(loc.lastSegment()))</b> as long as 1434 * <b>loc.parent()</b> is not null. 1435 * <p> 1436 * At the root of the namespace (parent() returns <null>), returns either 1437 * the name of the root or the empty string if the root is unnamed. These 1438 * examples illustrate the edge cases <code><pre> 1439 * StpLocation | lastSegment | parent 1440 * -------------------+-------------+------------- 1441 * /food | food | / 1442 * / | <empty> | <null> 1443 * pname:/food | food | pname:/ 1444 * http://server/path | path | http://server 1445 * file://author/path | path | file://author 1446 * http://server | <empty> | <null> 1447 * file://author | <empty> | <null> 1448 * pname:path | path | <null> 1449 * pname:/ | <empty> | <null> 1450 * pname:\ | <empty> | <null> 1451 * record:food@cq:s/u | food | record:@cq:s/u 1452 * record:@cq:s/u | <empty> | <null> 1453 * </pre></code> 1454 * 1455 * @return A String containing the last segment of the name field of this 1456 * StpLocation stripped of all encodings. Will never be null, but 1457 * may be empty if the last segment is unnamed. 1458 */ 1459 String lastSegment(); 1460 1461 /** 1462 * Interprets this StpLocation as a file-path-scheme location and returns 1463 * the <i>canonical</i> pathname for the file. If this StpLocation is not a 1464 * file-path-scheme location, the original location specification used to 1465 * construct this StpLocation is used as the pathname to be canonicalized. 1466 * <p> 1467 * For a location in the FILE namespace, this method constructs a URI from 1468 * the given file-scheme URL and then constructs a java.io.File from that 1469 * URI. Whether or not this succeeds depends on the JVM. (IBM's JVM 1.4.2, 1470 * for example, requires that the authority portion be empty.) 1471 * 1472 * @see java.io.File#getCanonicalPath() 1473 * 1474 * @return The canonicalized pathname for this resource. Will never be 1475 * <b>null</b>. 1476 * 1477 * @throws StpException if IO errors are encountered while determining the 1478 * canonical path or converting the file-scheme URL to a File. 1479 */ 1480 String getCanonicalPath() throws StpException; 1481 1482 /** 1483 * Returns a File object that references the path defined by this 1484 * StpLocation. If this StpLocation is not a file-path-scheme location, the 1485 * original location specification used to construct this StpLocation is 1486 * used as the pathname from which the java.io.File object is constructed. 1487 * <p> 1488 * For a location in the FILE namespace, this method constructs a URI from 1489 * the given URL and then constructs a java.io.File from that URI. Whether 1490 * or not this succeeds depends on the JVM. (IBM's JVM 1.4.2, for example, 1491 * requires that the authority portion be undefined.) 1492 * 1493 * @return A File object for the path defined by this StpLocation; Will 1494 * never be <b>null</b>. 1495 * 1496 * @throws MalformedURLException if the selector is a file scheme URL for 1497 * which a File cannot be constructed. 1498 * @throws StpException 1499 * @throws IllegalStateException If {@link #isFilePathScheme()} is <b> false</b>. 1500 */ 1501 File getFile() throws MalformedURLException, StpException; 1502 1503 }