Package ca.uhn.fhir.context

Examples of ca.uhn.fhir.context.ConfigurationException


          outerCollectionType = innerCollectionType;
          innerCollectionType = (Class<? extends java.util.Collection<?>>) parameterType;
          parameterType = ReflectionUtil.getGenericCollectionTypeOfMethodParameter(theMethod, paramIndex);
        }
        if (Collection.class.isAssignableFrom(parameterType)) {
          throw new ConfigurationException("Argument #" + paramIndex + " of Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is of an invalid generic type (can not be a collection of a collection of a collection)");
        }
      }
      if (parameterType.equals(HttpServletRequest.class) || parameterType.equals(ServletRequest.class)) {
        param = new ServletRequestParameter();
      } else if (parameterType.equals(HttpServletResponse.class) || parameterType.equals(ServletResponse.class)) {
        param = new ServletResponseParameter();
      } else {
        for (int i = 0; i < annotations.length && param == null; i++) {
          Annotation nextAnnotation = annotations[i];

          if (nextAnnotation instanceof RequiredParam) {
            SearchParameter parameter = new SearchParameter();
            parameter.setName(((RequiredParam) nextAnnotation).name());
            parameter.setRequired(true);
            parameter.setType(parameterType, innerCollectionType, outerCollectionType);
            extractDescription(parameter, annotations);
            param = parameter;
          } else if (nextAnnotation instanceof OptionalParam) {
            SearchParameter parameter = new SearchParameter();
            parameter.setName(((OptionalParam) nextAnnotation).name());
            parameter.setRequired(false);
            parameter.setType(parameterType, innerCollectionType, outerCollectionType);
            extractDescription(parameter, annotations);
            param = parameter;
          } else if (nextAnnotation instanceof IncludeParam) {
            Class<? extends Collection<Include>> instantiableCollectionType;
            Class<?> specType;

            if (parameterType == String.class) {
              instantiableCollectionType = null;
              specType = String.class;
            } else if ((parameterType != Include.class && parameterType != PathSpecification.class) || innerCollectionType == null || outerCollectionType != null) {
              throw new ConfigurationException("Method '" + theMethod.getName() + "' is annotated with @" + IncludeParam.class.getSimpleName() + " but has a type other than Collection<" + Include.class.getSimpleName() + ">");
            } else {
              instantiableCollectionType = (Class<? extends Collection<Include>>) CollectionBinder.getInstantiableCollectionType(innerCollectionType, "Method '" + theMethod.getName() + "'");
              specType = parameterType;
            }

            param = new IncludeParameter((IncludeParam) nextAnnotation, instantiableCollectionType, specType);
          } else if (nextAnnotation instanceof ResourceParam) {
            if (!IResource.class.isAssignableFrom(parameterType)) {
              throw new ConfigurationException("Method '" + theMethod.getName() + "' is annotated with @" + ResourceParam.class.getSimpleName() + " but has a type that is not an implemtation of " + IResource.class.getCanonicalName());
            }
            param = new ResourceParameter((Class<? extends IResource>) parameterType);
          } else if (nextAnnotation instanceof IdParam || nextAnnotation instanceof VersionIdParam) {
            param = new NullParameter();
          } else if (nextAnnotation instanceof ServerBase) {
            param = new ServerBaseParameter();
          } else if (nextAnnotation instanceof Since) {
            param = new SinceParameter();
          } else if (nextAnnotation instanceof Count) {
            param = new CountParameter();
          } else if (nextAnnotation instanceof Sort) {
            param = new SortParameter();
          } else if (nextAnnotation instanceof TransactionParam) {
            param = new TransactionParameter();
          } else {
            continue;
          }

        }

      }

      if (param == null) {
        throw new ConfigurationException("Parameter #" + ((paramIndex+1))+"/" + (parameterTypes.length) + " of method '" + theMethod.getName() + "' on type '" + theMethod.getDeclaringClass().getCanonicalName()
            + "' has no recognized FHIR interface parameter annotations. Don't know how to handle this parameter");
      }

      param.initializeTypes(theMethod, outerCollectionType, innerCollectionType, parameterType);
      parameters.add(param);
View Full Code Here


      }
      index++;
    }

    if (myTransactionParamIndex==-1) {
      throw new ConfigurationException("Method '" + theMethod.getName() + "' in type " + theMethod.getDeclaringClass().getCanonicalName() + " does not have a parameter annotated with the @" + TransactionParam.class + " annotation");
    }
  }
View Full Code Here

    } else if (IQueryParameterAnd.class.isAssignableFrom(type)) {
      myParamBinder = new QueryParameterAndBinder((Class<? extends IQueryParameterAnd>) type);
    } else if (String.class.equals(type)) {
      myParamBinder = new StringBinder();
    } else {
      throw new ConfigurationException("Unsupported data type for parameter: " + type.getCanonicalName());
    }

    if (String.class.equals(type)) {
      myParamType = SearchParamTypeEnum.STRING;
    } else if (StringDt.class.isAssignableFrom(type)) {
      myParamType = SearchParamTypeEnum.STRING;
    } else if (QualifiedDateParam.class.isAssignableFrom(type)) {
      myParamType = SearchParamTypeEnum.DATE;
    } else if (DateRangeParam.class.isAssignableFrom(type)) {
      myParamType = SearchParamTypeEnum.DATE;
    } else if (CodingListParam.class.isAssignableFrom(type)) {
      myParamType = SearchParamTypeEnum.TOKEN;
    } else if (IdentifierDt.class.isAssignableFrom(type)) {
      myParamType = SearchParamTypeEnum.TOKEN;
    } else if (QuantityDt.class.isAssignableFrom(type)) {
      myParamType = SearchParamTypeEnum.QUANTITY;
    } else if (ReferenceParam.class.isAssignableFrom(type)) {
      myParamType = SearchParamTypeEnum.REFERENCE;
    } else if (IdentifierListParam.class.isAssignableFrom(type)) {
      myParamType = SearchParamTypeEnum.TOKEN;
    } else {
      throw new ConfigurationException("Unknown search parameter type: " + type);
    }

    // NB: Once this is enabled, we should return true from handlesMissing if
    // it's a collection type
    // if (theInnerCollectionType != null) {
View Full Code Here

      }
      index++;
    }

    if (resourceParameter == null) {
      throw new ConfigurationException("Method " + theMethod.getName() + " in type " + theMethod.getDeclaringClass().getCanonicalName() + " does not have a parameter annotated with @" + ResourceParam.class.getSimpleName());
    }

  }
View Full Code Here

    Class<? extends IResource> returnTypeFromRp = null;
    if (theProvider instanceof IResourceProvider) {
      returnTypeFromRp = ((IResourceProvider) theProvider).getResourceType();
      if (!verifyIsValidResourceReturnType(returnTypeFromRp)) {
        throw new ConfigurationException("getResourceType() from " + IResourceProvider.class.getSimpleName() + " type " + theMethod.getDeclaringClass().getCanonicalName() + " returned "
            + toLogString(returnTypeFromRp) + " - Must return a resource type");
      }
    }

    Class<?> returnTypeFromMethod = theMethod.getReturnType();
    if (getTags != null) {
      if (!TagList.class.equals(returnTypeFromMethod)) {
        throw new ConfigurationException("Method '" + theMethod.getName() + "' from type " + theMethod.getDeclaringClass().getCanonicalName() + " is annotated with @"
            + GetTags.class.getSimpleName() + " but does not return type " + TagList.class.getName());
      }
    } else if (MethodOutcome.class.equals(returnTypeFromMethod)) {
      // returns a method outcome
    } else if (IBundleProvider.class.equals(returnTypeFromMethod)) {
      // returns a bundle provider
    } else if (Bundle.class.equals(returnTypeFromMethod)) {
      // returns a bundle
    } else if (void.class.equals(returnTypeFromMethod)) {
      // returns a bundle
    } else if (Collection.class.isAssignableFrom(returnTypeFromMethod)) {
      returnTypeFromMethod = ReflectionUtil.getGenericCollectionTypeOfMethodReturnType(theMethod);
      if (!verifyIsValidResourceReturnType(returnTypeFromMethod) && !IResource.class.equals(returnTypeFromMethod)) {
        throw new ConfigurationException("Method '" + theMethod.getName() + "' from " + IResourceProvider.class.getSimpleName() + " type " + theMethod.getDeclaringClass().getCanonicalName()
            + " returns a collection with generic type " + toLogString(returnTypeFromMethod)
            + " - Must return a resource type or a collection (List, Set) with a resource type parameter (e.g. List<Patient> )");
      }
    } else {
      if (!IResource.class.equals(returnTypeFromMethod) && !verifyIsValidResourceReturnType(returnTypeFromMethod)) {
        throw new ConfigurationException("Method '" + theMethod.getName() + "' from " + IResourceProvider.class.getSimpleName() + " type " + theMethod.getDeclaringClass().getCanonicalName()
            + " returns " + toLogString(returnTypeFromMethod) + " - Must return a resource type (eg Patient, " + Bundle.class.getSimpleName() + ", "
            + IBundleProvider.class.getSimpleName() + ", etc., see the documentation for more details)");
      }
    }

    Class<? extends IResource> returnTypeFromAnnotation = IResource.class;
    if (read != null) {
      returnTypeFromAnnotation = read.type();
    } else if (search != null) {
      returnTypeFromAnnotation = search.type();
    } else if (history != null) {
      returnTypeFromAnnotation = history.type();
    } else if (delete != null) {
      returnTypeFromAnnotation = delete.type();
    } else if (create != null) {
      returnTypeFromAnnotation = create.type();
    } else if (update != null) {
      returnTypeFromAnnotation = update.type();
    } else if (validate != null) {
      returnTypeFromAnnotation = validate.type();
    } else if (getTags != null) {
      returnTypeFromAnnotation = getTags.type();
    } else if (addTags != null) {
      returnTypeFromAnnotation = addTags.type();
    } else if (deleteTags != null) {
      returnTypeFromAnnotation = deleteTags.type();
    }

    if (returnTypeFromRp != null) {
      if (returnTypeFromAnnotation != null && returnTypeFromAnnotation != IResource.class) {
        if (!returnTypeFromRp.isAssignableFrom(returnTypeFromAnnotation)) {
          throw new ConfigurationException("Method '" + theMethod.getName() + "' in type " + theMethod.getDeclaringClass().getCanonicalName() + " returns type "
              + returnTypeFromMethod.getCanonicalName() + " - Must return " + returnTypeFromRp.getCanonicalName() + " (or a subclass of it) per IResourceProvider contract");
        }
        if (!returnTypeFromRp.isAssignableFrom(returnTypeFromAnnotation)) {
          throw new ConfigurationException("Method '" + theMethod.getName() + "' in type " + theMethod.getDeclaringClass().getCanonicalName() + " claims to return type "
              + returnTypeFromAnnotation.getCanonicalName() + " per method annotation - Must return " + returnTypeFromRp.getCanonicalName()
              + " (or a subclass of it) per IResourceProvider contract");
        }
        returnType = returnTypeFromAnnotation;
      } else {
        returnType = returnTypeFromRp;
      }
    } else {
      if (returnTypeFromAnnotation != IResource.class) {
        if (!verifyIsValidResourceReturnType(returnTypeFromAnnotation)) {
          throw new ConfigurationException("Method '" + theMethod.getName() + "' from " + IResourceProvider.class.getSimpleName() + " type "
              + theMethod.getDeclaringClass().getCanonicalName() + " returns " + toLogString(returnTypeFromAnnotation) + " according to annotation - Must return a resource type");
        }
        returnType = returnTypeFromAnnotation;
      } else {
        returnType = (Class<? extends IResource>) returnTypeFromMethod;
      }
    }

    if (read != null) {
      return new ReadMethodBinding(returnType, theMethod, theContext, theProvider);
    } else if (search != null) {
      String queryName = search.queryName();
      return new SearchMethodBinding(returnType, theMethod, queryName, theContext, theProvider);
    } else if (conformance != null) {
      return new ConformanceMethodBinding(theMethod, theContext, theProvider);
    } else if (create != null) {
      return new CreateMethodBinding(theMethod, theContext, theProvider);
    } else if (update != null) {
      return new UpdateMethodBinding(theMethod, theContext, theProvider);
    } else if (delete != null) {
      return new DeleteMethodBinding(theMethod, theContext, theProvider);
    } else if (history != null) {
      return new HistoryMethodBinding(theMethod, theContext, theProvider);
    } else if (validate != null) {
      return new ValidateMethodBinding(theMethod, theContext, theProvider);
    } else if (getTags != null) {
      return new GetTagsMethodBinding(theMethod, theContext, theProvider, getTags);
    } else if (addTags != null) {
      return new AddTagsMethodBinding(theMethod, theContext, theProvider, addTags);
    } else if (deleteTags != null) {
      return new DeleteTagsMethodBinding(theMethod, theContext, theProvider, deleteTags);
    } else if (transaction != null) {
      return new TransactionMethodBinding(theMethod, theContext, theProvider);
    } else {
      throw new ConfigurationException("Did not detect any FHIR annotations on method '" + theMethod.getName() + "' on type: " + theMethod.getDeclaringClass().getCanonicalName());
    }

    // // each operation name must have a request type annotation and be
    // unique
    // if (null != read) {
View Full Code Here

    for (Object object : theAnnotations) {
      if (object != null) {
        if (obj1 == null) {
          obj1 = object;
        } else {
          throw new ConfigurationException("Method " + theNextMethod.getName() + " on type '" + theNextMethod.getDeclaringClass().getSimpleName() + " has annotations @"
              + obj1.getClass().getSimpleName() + " and @" + object.getClass().getSimpleName() + ". Can not have both.");
        }

      }
    }
View Full Code Here

    } else if (Bundle.class.isAssignableFrom(methodReturnType)) {
      myMethodReturnType = MethodReturnTypeEnum.BUNDLE;
    } else if (IBundleProvider.class.isAssignableFrom(methodReturnType)) {
      myMethodReturnType = MethodReturnTypeEnum.BUNDLE_PROVIDER;
    } else {
      throw new ConfigurationException("Invalid return type '" + methodReturnType.getCanonicalName() + "' on method '" + theMethod.getName() + "' on type: " + theMethod.getDeclaringClass().getCanonicalName());
    }

    myResourceType = theReturnResourceType;
    if (theReturnResourceType != null) {
      ResourceDef resourceDefAnnotation = theReturnResourceType.getAnnotation(ResourceDef.class);
      if (resourceDefAnnotation == null) {
        throw new ConfigurationException(theReturnResourceType.getCanonicalName() + " has no @" + ResourceDef.class.getSimpleName() + " annotation");
      }
      myResourceName = resourceDefAnnotation.name();
    }
  }
View Full Code Here

      myAllow = Collections.emptySet();
    }

    mySpecType = theSpecType;
    if (mySpecType != Include.class && mySpecType != PathSpecification.class && mySpecType != String.class) {
      throw new ConfigurationException("Invalid @" + IncludeParam.class.getSimpleName() + " parameter type: " + mySpecType);
    }

  }
View Full Code Here

      }

      eventWriter.writeEndElement();
      eventWriter.close();
    } catch (XMLStreamException e) {
      throw new ConfigurationException("Failed to initialize STaX event factory", e);
    }
  }
View Full Code Here

      eventWriter = createXmlWriter(theWriter);

      encodeResourceToXmlStreamWriter(theResource, eventWriter, false);
      eventWriter.flush();
    } catch (XMLStreamException e) {
      throw new ConfigurationException("Failed to initialize STaX event factory", e);
    }
  }
View Full Code Here

TOP

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

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.