Package ca.uhn.fhir.context

Examples of ca.uhn.fhir.context.RuntimeResourceDefinition


  public void encodeResourceToWriter(IResource theResource, Writer theWriter) throws IOException {
    Validate.notNull(theResource, "Resource can not be null");

    JsonGenerator eventWriter = createJsonGenerator(theWriter);

    RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);
    encodeResourceToJsonStreamWriter(resDef, theResource, eventWriter, null);
    eventWriter.flush();
  }
View Full Code Here


    JsonValue resourceTypeObj = object.get("resourceType");
    assertObjectOfType(resourceTypeObj, JsonValue.ValueType.STRING, "resourceType");
    String resourceType = ((JsonString) resourceTypeObj).getString();

    RuntimeResourceDefinition def;
    if (theResourceType != null) {
      def = myContext.getResourceDefinition(theResourceType);
    } else {
      def = myContext.getResourceDefinition(resourceType);
    }

    ParserState<? extends IResource> state = ParserState.getPreResourceInstance(def.getImplementingClass(), myContext, true);
    state.enteringNewElement(null, def.getName());

    parseChildren(object, state);

    state.endingElement();
View Full Code Here

  }

  private void encodeResourceToJsonStreamWriter(RuntimeResourceDefinition theResDef, IResource theResource, JsonGenerator theEventWriter, String theObjectNameOrNull) throws IOException {
    super.containResourcesForEncoding(theResource);

    RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);

    if (theObjectNameOrNull == null) {
      theEventWriter.writeStartObject();
    } else {
      theEventWriter.writeStartObject(theObjectNameOrNull);
    }

    theEventWriter.write("resourceType", resDef.getName());
    if (theResource.getId() != null && isNotBlank(theResource.getId().getValue())) {
      theEventWriter.write("id", theResource.getId().getValue());
    }

    extractAndWriteExtensionsAsDirectChild(theResource, theEventWriter, resDef, theResDef, theResource);
View Full Code Here

    super(theMethod, theContext, Delete.class);

    Delete deleteAnnotation = theMethod.getAnnotation(Delete.class);
    Class<? extends IResource> resourceType = deleteAnnotation.resourceType();
    if (resourceType != Delete.NotSpecified.class) {
      RuntimeResourceDefinition def = theContext.getResourceDefinition(resourceType);
      myResourceName = def.getName();
    } else {
      if (theProvider != null) {
        RuntimeResourceDefinition def = theContext.getResourceDefinition(theProvider.getResourceType());
        myResourceName = def.getName();
      } else {
        throw new ConfigurationException("Can not determine resource type for method '" + theMethod.getName() + "' on type " + theMethod.getDeclaringClass().getCanonicalName() + " - Did you forget to include the resourceType() value on the @"
            + Delete.class.getSimpleName() + " method annotation?");
      }
    }
View Full Code Here

        if (!StringUtils.equals(theLocalPart, definition.getName())) {
          throw new DataFormatException("Incorrect resource root element '" + theLocalPart + "', expected: '" + definition.getName() + "'");
        }
      }

      RuntimeResourceDefinition def = (RuntimeResourceDefinition) definition;
      myInstance = def.newInstance();
      if (myEntry != null) {
        myEntry.setResource(myInstance);
      }

      push(new ElementCompositeState(this, def, myInstance));
View Full Code Here

   *
   */
  private void encodeResourceToXmlStreamWriter(IResource theResource, XMLStreamWriter theEventWriter, boolean theIncludedResource) throws XMLStreamException, DataFormatException {
    super.containResourcesForEncoding(theResource);

    RuntimeResourceDefinition resDef = myContext.getResourceDefinition(theResource);
    if (resDef == null) {
      throw new ConfigurationException("Unknown resource type: " + theResource.getClass());
    }

    theEventWriter.writeStartElement(resDef.getName());
    theEventWriter.writeDefaultNamespace(FHIR_NS);

    if (theIncludedResource && StringUtils.isNotBlank(theResource.getId().getValue())) {
      theEventWriter.writeAttribute("id", theResource.getId().getValue());
    }
View Full Code Here

            throw new DataFormatException("Element '" + theLocalPart + "' is not a resource, expected a resource at this position");
          }
        }
      }

      RuntimeResourceDefinition def = (RuntimeResourceDefinition) definition;
      myInstance = def.newInstance();
      if (myEntry != null) {
        myEntry.setResource(myInstance);
      }

      if ("Binary".equals(def.getName())) {
        push(new BinaryResourceState(getRootPreResourceState(), (Binary) myInstance));
      } else {
        push(new ElementCompositeState(getRootPreResourceState(), def, myInstance));
      }
    }
View Full Code Here

        theProvider);

    Delete deleteAnnotation = theMethod.getAnnotation(Delete.class);
    Class<? extends IResource> resourceType = deleteAnnotation.type();
    if (resourceType != IResource.class) {
      RuntimeResourceDefinition def = theContext.getResourceDefinition(resourceType);
      myResourceName = def.getName();
    } else {
      if (theProvider != null && theProvider instanceof IResourceProvider) {
        RuntimeResourceDefinition def = theContext.getResourceDefinition(((IResourceProvider) theProvider).getResourceType());
        myResourceName = def.getName();
      } else {
        throw new ConfigurationException("Can not determine resource type for method '" + theMethod.getName() + "' on type " + theMethod.getDeclaringClass().getCanonicalName() + " - Did you forget to include the resourceType() value on the @"
            + Delete.class.getSimpleName() + " method annotation?");
      }
    }
View Full Code Here

    }

    IResource resource = entry.getResource();
    if (resource == null && id != null && isNotBlank(id.getResourceType())) {
      String resourceType = id.getResourceType();
      RuntimeResourceDefinition def = myContext.getResourceDefinition(resourceType);
      if (def == null) {
        throw new DataFormatException("Entry references unknown resource type: " + resourceType);
      }
      resource = def.newInstance();
      resource.setId(id);
      entry.setResource(resource);
    }

    if (resource != null) {
View Full Code Here

          String resourceName = foundMethodBinding.getResourceName();
          ResourceBinding resourceBinding;
          if (resourceName == null) {
            resourceBinding = myNullResourceBinding;
          } else {
            RuntimeResourceDefinition definition = myFhirContext.getResourceDefinition(resourceName);
            if (myResourceNameToProvider.containsKey(definition.getName())) {
              resourceBinding = myResourceNameToProvider.get(definition.getName());
            } else {
              resourceBinding = new ResourceBinding();
              resourceBinding.setResourceName(resourceName);
              myResourceNameToProvider.put(resourceName, resourceBinding);
            }
View Full Code Here

TOP

Related Classes of ca.uhn.fhir.context.RuntimeResourceDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.