001package org.hl7.fhir.r4.model; 002 003import java.io.IOException; 004import java.io.Serializable; 005import java.util.ArrayList; 006import java.util.HashMap; 007import java.util.List; 008import java.util.Map; 009 010import org.hl7.fhir.r4.elementmodel.Element; 011import org.hl7.fhir.r4.elementmodel.ObjectConverter; 012import org.hl7.fhir.exceptions.FHIRException; 013import org.hl7.fhir.instance.model.api.IBase; 014import org.hl7.fhir.utilities.Utilities; 015import org.hl7.fhir.utilities.xhtml.XhtmlNode; 016import org.hl7.fhir.utilities.xhtml.XhtmlParser; 017 018import ca.uhn.fhir.model.api.IElement; 019//Add comment to test SVN 020public abstract class Base implements Serializable, IBase, IElement { 021 022 /** 023 * User appended data items - allow users to add extra information to the class 024 */ 025private Map<String, Object> userData; 026 027 /** 028 * Round tracking xml comments for testing convenience 029 */ 030 private List<String> formatCommentsPre; 031 032 /** 033 * Round tracking xml comments for testing convenience 034 */ 035 private List<String> formatCommentsPost; 036 037 038 public Object getUserData(String name) { 039 if (userData == null) 040 return null; 041 return userData.get(name); 042 } 043 044 public void setUserData(String name, Object value) { 045 if (userData == null) 046 userData = new HashMap<String, Object>(); 047 userData.put(name, value); 048 } 049 050 public void clearUserData(String name) { 051 if (userData != null) 052 userData.remove(name); 053 } 054 055 public void setUserDataINN(String name, Object value) { 056 if (value == null) 057 return; 058 059 if (userData == null) 060 userData = new HashMap<String, Object>(); 061 userData.put(name, value); 062 } 063 064 public boolean hasUserData(String name) { 065 if (userData == null) 066 return false; 067 else 068 return userData.containsKey(name); 069 } 070 071 public String getUserString(String name) { 072 Object ud = getUserData(name); 073 if (ud == null) 074 return null; 075 if (ud instanceof String) 076 return (String) ud; 077 return ud.toString(); 078 } 079 080 public int getUserInt(String name) { 081 if (!hasUserData(name)) 082 return 0; 083 return (Integer) getUserData(name); 084 } 085 086 public boolean hasFormatComment() { 087 return (formatCommentsPre != null && !formatCommentsPre.isEmpty()) || (formatCommentsPost != null && !formatCommentsPost.isEmpty()); 088 } 089 090 public List<String> getFormatCommentsPre() { 091 if (formatCommentsPre == null) 092 formatCommentsPre = new ArrayList<String>(); 093 return formatCommentsPre; 094 } 095 096 public List<String> getFormatCommentsPost() { 097 if (formatCommentsPost == null) 098 formatCommentsPost = new ArrayList<String>(); 099 return formatCommentsPost; 100 } 101 102 // these 3 allow evaluation engines to get access to primitive values 103 public boolean isPrimitive() { 104 return false; 105 } 106 107 public boolean isBooleanPrimitive() { 108 return false; 109 } 110 111 public boolean hasPrimitiveValue() { 112 return isPrimitive(); 113 } 114 115 public String primitiveValue() { 116 return null; 117 } 118 119 public abstract String fhirType() ; 120 121 public boolean hasType(String... name) { 122 String t = fhirType(); 123 for (String n : name) 124 if (n.equalsIgnoreCase(t)) 125 return true; 126 return false; 127 } 128 129 protected abstract void listChildren(List<Property> result) ; 130 131 public Base setProperty(String name, Base value) throws FHIRException { 132 throw new FHIRException("Attempt to set unknown property "+name); 133 } 134 135 public Base addChild(String name) throws FHIRException { 136 throw new FHIRException("Attempt to add child with unknown name "+name); 137 } 138 139 /** 140 * Supports iterating the children elements in some generic processor or browser 141 * All defined children will be listed, even if they have no value on this instance 142 * 143 * Note that the actual content of primitive or xhtml elements is not iterated explicitly. 144 * To find these, the processing code must recognise the element as a primitive, typecast 145 * the value to a {@link Type}, and examine the value 146 * 147 * @return a list of all the children defined for this element 148 */ 149 public List<Property> children() { 150 List<Property> result = new ArrayList<Property>(); 151 listChildren(result); 152 return result; 153 } 154 155 public Property getChildByName(String name) { 156 List<Property> children = new ArrayList<Property>(); 157 listChildren(children); 158 for (Property c : children) 159 if (c.getName().equals(name)) 160 return c; 161 return null; 162 } 163 164 public List<Base> listChildrenByName(String name) throws FHIRException { 165 List<Base> result = new ArrayList<Base>(); 166 for (Base b : listChildrenByName(name, true)) 167 if (b != null) 168 result.add(b); 169 return result; 170 } 171 172 public Base[] listChildrenByName(String name, boolean checkValid) throws FHIRException { 173 if (name.equals("*")) { 174 List<Property> children = new ArrayList<Property>(); 175 listChildren(children); 176 List<Base> result = new ArrayList<Base>(); 177 for (Property c : children) 178 result.addAll(c.getValues()); 179 return result.toArray(new Base[result.size()]); 180 } 181 else 182 return getProperty(name.hashCode(), name, checkValid); 183 } 184 185 public boolean isEmpty() { 186 return true; // userData does not count 187 } 188 189 public boolean equalsDeep(Base other) { 190 return other != null; 191 } 192 193 public boolean equalsShallow(Base other) { 194 return other != null; 195 } 196 197 public static boolean compareDeep(List<? extends Base> e1, List<? extends Base> e2, boolean allowNull) { 198 if (noList(e1) && noList(e2) && allowNull) 199 return true; 200 if (noList(e1) || noList(e2)) 201 return false; 202 if (e1.size() != e2.size()) 203 return false; 204 for (int i = 0; i < e1.size(); i++) { 205 if (!compareDeep(e1.get(i), e2.get(i), allowNull)) 206 return false; 207 } 208 return true; 209 } 210 211 private static boolean noList(List<? extends Base> list) { 212 return list == null || list.isEmpty(); 213 } 214 215 public static boolean compareDeep(Base e1, Base e2, boolean allowNull) { 216 if (allowNull) { 217 boolean noLeft = e1 == null || e1.isEmpty(); 218 boolean noRight = e2 == null || e2.isEmpty(); 219 if (noLeft && noRight) { 220 return true; 221 } 222 } 223 if (e1 == null || e2 == null) 224 return false; 225 if (e2.isMetadataBased() && !e1.isMetadataBased()) // respect existing order for debugging consistency; outcome must be the same either way 226 return e2.equalsDeep(e1); 227 else 228 return e1.equalsDeep(e2); 229 } 230 231 public static boolean compareDeep(XhtmlNode div1, XhtmlNode div2, boolean allowNull) { 232 if (div1 == null && div2 == null && allowNull) 233 return true; 234 if (div1 == null || div2 == null) 235 return false; 236 return div1.equalsDeep(div2); 237 } 238 239 240 public static boolean compareValues(List<? extends PrimitiveType> e1, List<? extends PrimitiveType> e2, boolean allowNull) { 241 if (e1 == null && e2 == null && allowNull) 242 return true; 243 if (e1 == null || e2 == null) 244 return false; 245 if (e1.size() != e2.size()) 246 return false; 247 for (int i = 0; i < e1.size(); i++) { 248 if (!compareValues(e1.get(i), e2.get(i), allowNull)) 249 return false; 250 } 251 return true; 252 } 253 254 public static boolean compareValues(PrimitiveType e1, PrimitiveType e2, boolean allowNull) { 255 boolean noLeft = e1 == null || e1.isEmpty(); 256 boolean noRight = e2 == null || e2.isEmpty(); 257 if (noLeft && noRight && allowNull) { 258 return true; 259 } 260 if (noLeft != noRight) 261 return false; 262 return e1.equalsShallow(e2); 263 } 264 265 // -- converters for property setters 266 267 public Type castToType(Base b) throws FHIRException { 268 if (b instanceof Type) 269 return (Type) b; 270 else if (b.isMetadataBased()) 271 return ((org.hl7.fhir.r4.elementmodel.Element) b).asType(); 272 else 273 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Reference"); 274 } 275 276 277 public BooleanType castToBoolean(Base b) throws FHIRException { 278 if (b instanceof BooleanType) 279 return (BooleanType) b; 280 else 281 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Boolean"); 282 } 283 284 public IntegerType castToInteger(Base b) throws FHIRException { 285 if (b instanceof IntegerType) 286 return (IntegerType) b; 287 else 288 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Integer"); 289 } 290 291 public DecimalType castToDecimal(Base b) throws FHIRException { 292 if (b instanceof DecimalType) 293 return (DecimalType) b; 294 else 295 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Decimal"); 296 } 297 298 public Base64BinaryType castToBase64Binary(Base b) throws FHIRException { 299 if (b instanceof Base64BinaryType) 300 return (Base64BinaryType) b; 301 else 302 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Base64Binary"); 303 } 304 305 public InstantType castToInstant(Base b) throws FHIRException { 306 if (b instanceof InstantType) 307 return (InstantType) b; 308 else 309 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Instant"); 310 } 311 312 public StringType castToString(Base b) throws FHIRException { 313 if (b instanceof StringType) 314 return (StringType) b; 315 else if (b.hasPrimitiveValue()) 316 return new StringType(b.primitiveValue()); 317 else 318 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a String"); 319 } 320 321 public UriType castToUri(Base b) throws FHIRException { 322 if (b instanceof UriType) 323 return (UriType) b; 324 else if (b.hasPrimitiveValue()) 325 return new UriType(b.primitiveValue()); 326 else 327 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Uri"); 328 } 329 330 public UrlType castToUrl(Base b) throws FHIRException { 331 if (b instanceof UrlType) 332 return (UrlType) b; 333 else if (b.hasPrimitiveValue()) 334 return new UrlType(b.primitiveValue()); 335 else 336 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Uri"); 337 } 338 339 public CanonicalType castToCanonical(Base b) throws FHIRException { 340 if (b instanceof CanonicalType) 341 return (CanonicalType) b; 342 else if (b.hasPrimitiveValue()) 343 return new CanonicalType(b.primitiveValue()); 344 else 345 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Uri"); 346 } 347 348 public DateType castToDate(Base b) throws FHIRException { 349 if (b instanceof DateType) 350 return (DateType) b; 351 else if (b.hasPrimitiveValue()) 352 return new DateType(b.primitiveValue()); 353 else 354 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Date"); 355 } 356 357 public DateTimeType castToDateTime(Base b) throws FHIRException { 358 if (b instanceof DateTimeType) 359 return (DateTimeType) b; 360 else if (b.fhirType().equals("dateTime")) 361 return new DateTimeType(b.primitiveValue()); 362 else 363 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a DateTime"); 364 } 365 366 public TimeType castToTime(Base b) throws FHIRException { 367 if (b instanceof TimeType) 368 return (TimeType) b; 369 else 370 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Time"); 371 } 372 373 public CodeType castToCode(Base b) throws FHIRException { 374 if (b instanceof CodeType) 375 return (CodeType) b; 376 else if (b.isPrimitive()) 377 return new CodeType(b.primitiveValue()); 378 else 379 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Code"); 380 } 381 382 public OidType castToOid(Base b) throws FHIRException { 383 if (b instanceof OidType) 384 return (OidType) b; 385 else 386 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Oid"); 387 } 388 389 public IdType castToId(Base b) throws FHIRException { 390 if (b instanceof IdType) 391 return (IdType) b; 392 else 393 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Id"); 394 } 395 396 public UnsignedIntType castToUnsignedInt(Base b) throws FHIRException { 397 if (b instanceof UnsignedIntType) 398 return (UnsignedIntType) b; 399 else 400 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a UnsignedInt"); 401 } 402 403 public PositiveIntType castToPositiveInt(Base b) throws FHIRException { 404 if (b instanceof PositiveIntType) 405 return (PositiveIntType) b; 406 else 407 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a PositiveInt"); 408 } 409 410 public MarkdownType castToMarkdown(Base b) throws FHIRException { 411 if (b instanceof MarkdownType) 412 return (MarkdownType) b; 413 else 414 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Markdown"); 415 } 416 417 public Annotation castToAnnotation(Base b) throws FHIRException { 418 if (b instanceof Annotation) 419 return (Annotation) b; 420 else 421 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Annotation"); 422 } 423 424 public Dosage castToDosage(Base b) throws FHIRException { 425 if (b instanceof Dosage) 426 return (Dosage) b; 427 else throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an DosageInstruction"); 428 } 429 430 431 public Attachment castToAttachment(Base b) throws FHIRException { 432 if (b instanceof Attachment) 433 return (Attachment) b; 434 else 435 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Attachment"); 436 } 437 438 public Identifier castToIdentifier(Base b) throws FHIRException { 439 if (b instanceof Identifier) 440 return (Identifier) b; 441 else 442 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Identifier"); 443 } 444 445 public CodeableConcept castToCodeableConcept(Base b) throws FHIRException { 446 if (b instanceof CodeableConcept) 447 return (CodeableConcept) b; 448 else if (b instanceof Element) { 449 return ObjectConverter.readAsCodeableConcept((Element) b); 450 } else if (b instanceof CodeType) { 451 CodeableConcept cc = new CodeableConcept(); 452 cc.addCoding().setCode(((CodeType) b).asStringValue()); 453 return cc; 454 } else 455 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a CodeableConcept"); 456 } 457 458 public Coding castToCoding(Base b) throws FHIRException { 459 if (b instanceof Coding) 460 return (Coding) b; 461 else if (b instanceof Element) { 462 ICoding c = ((Element) b).getAsICoding(); 463 if (c == null) 464 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Coding"); 465 return new Coding().setCode(c.getCode()).setSystem(c.getSystem()).setVersion(c.getVersion()).setDisplay(c.getDisplay()); 466 } else if (b instanceof ICoding) { 467 ICoding c = (ICoding) b; 468 return new Coding().setCode(c.getCode()).setSystem(c.getSystem()).setVersion(c.getVersion()).setDisplay(c.getDisplay()); 469 } else 470 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Coding"); 471 } 472 473 public Quantity castToQuantity(Base b) throws FHIRException { 474 if (b instanceof Quantity) 475 return (Quantity) b; 476 else 477 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Quantity"); 478 } 479 480 public Money castToMoney(Base b) throws FHIRException { 481 if (b instanceof Money) 482 return (Money) b; 483 else 484 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Money"); 485 } 486 487 public Duration castToDuration(Base b) throws FHIRException { 488 if (b instanceof Duration) 489 return (Duration) b; 490 else 491 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an Duration"); 492 } 493 494 public SimpleQuantity castToSimpleQuantity(Base b) throws FHIRException { 495 if (b instanceof SimpleQuantity) 496 return (SimpleQuantity) b; 497 else if (b instanceof Quantity) { 498 Quantity q = (Quantity) b; 499 SimpleQuantity sq = new SimpleQuantity(); 500 sq.setValueElement(q.getValueElement()); 501 sq.setComparatorElement(q.getComparatorElement()); 502 sq.setUnitElement(q.getUnitElement()); 503 sq.setSystemElement(q.getSystemElement()); 504 sq.setCodeElement(q.getCodeElement()); 505 return sq; 506 } else 507 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to an SimpleQuantity"); 508 } 509 510 public Range castToRange(Base b) throws FHIRException { 511 if (b instanceof Range) 512 return (Range) b; 513 else 514 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Range"); 515 } 516 517 public Period castToPeriod(Base b) throws FHIRException { 518 if (b instanceof Period) 519 return (Period) b; 520 else 521 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Period"); 522 } 523 524 public Ratio castToRatio(Base b) throws FHIRException { 525 if (b instanceof Ratio) 526 return (Ratio) b; 527 else 528 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Ratio"); 529 } 530 531 public SampledData castToSampledData(Base b) throws FHIRException { 532 if (b instanceof SampledData) 533 return (SampledData) b; 534 else 535 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a SampledData"); 536 } 537 538 public Signature castToSignature(Base b) throws FHIRException { 539 if (b instanceof Signature) 540 return (Signature) b; 541 else 542 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Signature"); 543 } 544 545 public HumanName castToHumanName(Base b) throws FHIRException { 546 if (b instanceof HumanName) 547 return (HumanName) b; 548 else 549 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a HumanName"); 550 } 551 552 public Address castToAddress(Base b) throws FHIRException { 553 if (b instanceof Address) 554 return (Address) b; 555 else 556 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Address"); 557 } 558 559 public ContactDetail castToContactDetail(Base b) throws FHIRException { 560 if (b instanceof ContactDetail) 561 return (ContactDetail) b; 562 else 563 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ContactDetail"); 564 } 565 566 public Contributor castToContributor(Base b) throws FHIRException { 567 if (b instanceof Contributor) 568 return (Contributor) b; 569 else 570 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Contributor"); 571 } 572 573 public UsageContext castToUsageContext(Base b) throws FHIRException { 574 if (b instanceof UsageContext) 575 return (UsageContext) b; 576 else 577 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a UsageContext"); 578 } 579 580 public RelatedArtifact castToRelatedArtifact(Base b) throws FHIRException { 581 if (b instanceof RelatedArtifact) 582 return (RelatedArtifact) b; 583 else 584 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a RelatedArtifact"); 585 } 586 587 public ContactPoint castToContactPoint(Base b) throws FHIRException { 588 if (b instanceof ContactPoint) 589 return (ContactPoint) b; 590 else 591 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ContactPoint"); 592 } 593 594 public Timing castToTiming(Base b) throws FHIRException { 595 if (b instanceof Timing) 596 return (Timing) b; 597 else 598 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Timing"); 599 } 600 601 public Reference castToReference(Base b) throws FHIRException { 602 if (b instanceof Reference) 603 return (Reference) b; 604 else if (b.isPrimitive() && Utilities.isURL(b.primitiveValue())) 605 return new Reference().setReference(b.primitiveValue()); 606 else if (b instanceof org.hl7.fhir.r4.elementmodel.Element && b.fhirType().equals("Reference")) { 607 org.hl7.fhir.r4.elementmodel.Element e = (org.hl7.fhir.r4.elementmodel.Element) b; 608 return new Reference().setReference(e.getChildValue("reference")).setDisplay(e.getChildValue("display")); 609 } else 610 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Reference"); 611 } 612 613 public Meta castToMeta(Base b) throws FHIRException { 614 if (b instanceof Meta) 615 return (Meta) b; 616 else 617 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Meta"); 618 } 619 620 621 public MarketingStatus castToMarketingStatus(Base b) throws FHIRException { 622 if (b instanceof MarketingStatus) 623 return (MarketingStatus) b; 624 else 625 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a MarketingStatus"); 626 } 627 628 public ProductShelfLife castToProductShelfLife(Base b) throws FHIRException { 629 if (b instanceof ProductShelfLife) 630 return (ProductShelfLife) b; 631 else 632 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ProductShelfLife"); 633 } 634 635 public ProdCharacteristic castToProdCharacteristic(Base b) throws FHIRException { 636 if (b instanceof ProdCharacteristic) 637 return (ProdCharacteristic) b; 638 else 639 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ProdCharacteristic"); 640 } 641 642 643 public SubstanceAmount castToSubstanceAmount(Base b) throws FHIRException { 644 if (b instanceof SubstanceAmount) 645 return (SubstanceAmount) b; 646 else 647 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a SubstanceAmount"); 648 } 649 650 public Extension castToExtension(Base b) throws FHIRException { 651 if (b instanceof Extension) 652 return (Extension) b; 653 else 654 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Extension"); 655 } 656 657 public Resource castToResource(Base b) throws FHIRException { 658 if (b instanceof Resource) 659 return (Resource) b; 660 else 661 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Resource"); 662 } 663 664 public Narrative castToNarrative(Base b) throws FHIRException { 665 if (b instanceof Narrative) 666 return (Narrative) b; 667 else 668 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a Narrative"); 669 } 670 671 672 public ElementDefinition castToElementDefinition(Base b) throws FHIRException { 673 if (b instanceof ElementDefinition) 674 return (ElementDefinition) b; 675 else 676 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ElementDefinition"); 677 } 678 679 public DataRequirement castToDataRequirement(Base b) throws FHIRException { 680 if (b instanceof DataRequirement) 681 return (DataRequirement) b; 682 else 683 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a DataRequirement"); 684 } 685 686 public ParameterDefinition castToParameterDefinition(Base b) throws FHIRException { 687 if (b instanceof ParameterDefinition) 688 return (ParameterDefinition) b; 689 else 690 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a ParameterDefinition"); 691 } 692 693 public TriggerDefinition castToTriggerDefinition(Base b) throws FHIRException { 694 if (b instanceof TriggerDefinition) 695 return (TriggerDefinition) b; 696 else 697 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to a TriggerDefinition"); 698 } 699 700 public XhtmlNode castToXhtml(Base b) throws FHIRException { 701 if (b instanceof Element) { 702 return ((Element) b).getXhtml(); 703 } else if (b instanceof StringType) { 704 try { 705 return new XhtmlParser().parseFragment(((StringType) b).asStringValue()); 706 } catch (IOException e) { 707 throw new FHIRException(e); 708 } 709 } else 710 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to XHtml"); 711 } 712 713 public String castToXhtmlString(Base b) throws FHIRException { 714 if (b instanceof Element) { 715 return ((Element) b).getValue(); 716 } else if (b instanceof StringType) { 717 return ((StringType) b).asStringValue(); 718 } else 719 throw new FHIRException("Unable to convert a "+b.getClass().getName()+" to XHtml string"); 720 } 721 722 protected boolean isMetadataBased() { 723 return false; 724 } 725 726 public Base[] getProperty(int hash, String name, boolean checkValid) throws FHIRException { 727 if (checkValid) 728 throw new FHIRException("Attempt to read invalid property '"+name+"' on type "+fhirType()); 729 return null; 730 } 731 732 public Base setProperty(int hash, String name, Base value) throws FHIRException { 733 throw new FHIRException("Attempt to write to invalid property '"+name+"' on type "+fhirType()); 734 } 735 736 public Base makeProperty(int hash, String name) throws FHIRException { 737 throw new FHIRException("Attempt to make an invalid property '"+name+"' on type "+fhirType()); 738 } 739 740 public String[] getTypesForProperty(int hash, String name) throws FHIRException { 741 throw new FHIRException("Attempt to get types for an invalid property '"+name+"' on type "+fhirType()); 742 } 743 744 public static boolean equals(String v1, String v2) { 745 if (v1 == null && v2 == null) 746 return true; 747 else if (v1 == null || v2 == null) 748 return false; 749 else 750 return v1.equals(v2); 751 } 752 753 public boolean isResource() { 754 return false; 755 } 756 757 758 public abstract String getIdBase(); 759 public abstract void setIdBase(String value); 760 761 public Property getNamedProperty(String _name) throws FHIRException { 762 return getNamedProperty(_name.hashCode(), _name, false); 763 } 764 public Property getNamedProperty(int _hash, String _name, boolean _checkValid) throws FHIRException { 765 if (_checkValid) 766 throw new FHIRException("Attempt to read invalid property '"+_name+"' on type "+fhirType()); 767 return null; 768 } 769 770}