Package ca.uhn.fhir.context

Examples of ca.uhn.fhir.context.ConfigurationException


      Validator validator = schema.newValidator();
      MyErrorHandler handler = new MyErrorHandler(theContext);
      validator.setErrorHandler(handler);
      validator.validate(new StreamSource(new StringReader(theContext.getXmlEncodedResource())));
    } catch (SAXException e) {
      throw new ConfigurationException("Could not apply schema file", e);
    } catch (IOException e) {
      // This shouldn't happen since we're using a string source
      throw new ConfigurationException("Could not load/parse schema file", e);
    }
  }
View Full Code Here


      schemaFactory.setResourceResolver(new MyResourceResolver("dstu"));

      try {
        schema = schemaFactory.newSchema(new Source[] { baseSource });
      } catch (SAXException e) {
        throw new ConfigurationException("Could not load/parse schema file", e);
      }
      myKeyToSchema.put(key, schema);
      return schema;
    }
  }
View Full Code Here

        return input;

      }

      throw new ConfigurationException("Unknown schema: " + theBaseURI);
    }
View Full Code Here

          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.setDeclaredTypes(((RequiredParam) nextAnnotation).targetTypes());
            parameter.setCompositeTypes(((RequiredParam) nextAnnotation).compositeTypes());
            parameter.setChainlists(((RequiredParam) nextAnnotation).chainWhitelist(), ((RequiredParam) nextAnnotation).chainBlacklist());
            parameter.setType(parameterType, innerCollectionType, outerCollectionType);
            MethodUtil.extractDescription(parameter, annotations);
            param = parameter;
          } else if (nextAnnotation instanceof OptionalParam) {
            SearchParameter parameter = new SearchParameter();
            parameter.setName(((OptionalParam) nextAnnotation).name());
            parameter.setRequired(false);
            parameter.setDeclaredTypes(((OptionalParam) nextAnnotation).targetTypes());
            parameter.setCompositeTypes(((OptionalParam) nextAnnotation).compositeTypes());
            parameter.setChainlists(((OptionalParam) nextAnnotation).chainWhitelist(), ((OptionalParam) nextAnnotation).chainBlacklist());
            parameter.setType(parameterType, innerCollectionType, outerCollectionType);
            MethodUtil.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 ServerBaseParamBinder();
          } 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 TransactionParamBinder();
          } 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

    T retVal;
    try {
      retVal = theTargetType.newInstance();
    } catch (InstantiationException e) {
      throw new ConfigurationException("Failed to instantiate " + theTargetType, e);
    } catch (IllegalAccessException e) {
      throw new ConfigurationException("Failed to instantiate " + theTargetType, e);
    }

    copyChildren(sourceDef, (BaseElement) theResource, targetDef, (BaseElement) retVal);

    return retVal;
View Full Code Here

  public BaseOutcomeReturningMethodBinding(Method theMethod, FhirContext theContext, Class<?> theMethodAnnotation, Object theProvider) {
    super(theMethod, theContext, theProvider);

    if (!theMethod.getReturnType().equals(MethodOutcome.class)) {
      if (!allowVoidReturnType()) {
        throw new ConfigurationException("Method " + theMethod.getName() + " in type " + theMethod.getDeclaringClass().getCanonicalName() + " is a @" + theMethodAnnotation.getSimpleName()
            + " method but it does not return " + MethodOutcome.class);
      } else if (theMethod.getReturnType() == void.class) {
        myReturnVoid = true;
      }
    }
View Full Code Here

    myType = theType;
    myCompositeTypes = theCompositeTypes;
   
    if (myType.equals(CompositeParam.class)) {
      if (myCompositeTypes.size() != 2) {
        throw new ConfigurationException("Search parameter of type " + myType.getName() + " must have 2 composite types declared in parameter annotation, found " + theCompositeTypes.size());
      }
    }
   
    try {
      Class<?>[] types = new Class<?>[myCompositeTypes.size()];
      for (int i = 0; i < myCompositeTypes.size(); i++) {
        types[i] = myCompositeTypes.get(i).getClass();
      }
      myConstructor = myType.getConstructor(types);
    } catch (NoSuchMethodException e) {
      throw new ConfigurationException("Query parameter type " + theType.getName() + " has no constructor with types " + theCompositeTypes);
    }
  }
View Full Code Here

  }

  @Override
  public void initializeTypes(Method theMethod, Class<? extends Collection<?>> theOuterCollectionType, Class<? extends Collection<?>> theInnerCollectionType, Class<?> theParameterType) {
    if (theOuterCollectionType != null || theInnerCollectionType != null) {
      throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + " but can not be of collection type");
    }
    if (!theParameterType.equals(SortSpec.class)) {
      throw new ConfigurationException("Method '" + theMethod.getName() + "' in type '" + theMethod.getDeclaringClass().getCanonicalName() + "' is annotated with @" + Sort.class.getName() + " but is an invalid type, must be: " + SortSpec.class.getCanonicalName());
    }

  }
View Full Code Here

      }
      for (String next : propFileName) {
        loadProperties(next);
      }
    } catch (IOException e) {
      throw new ConfigurationException("Can not load property file " + propFileName, e);
    }

    {
      myProfileTemplateEngine = new TemplateEngine();
      TemplateResolver resolver = new TemplateResolver();
View Full Code Here

        String narrativePropName = name + ".narrative";
        String narrativeName = file.getProperty(narrativePropName);
        String titlePropName = name + ".title";
        String titleName = file.getProperty(titlePropName);
        if (isBlank(narrativeName) && isBlank(titleName)) {
          throw new ConfigurationException("Found property '" + nextKey + "' but no corresponding property '" + narrativePropName + "' or '" + titlePropName + "' in file " + propFileName);
        }

        myProfileToName.put(file.getProperty(nextKey), name);

        if (StringUtils.isNotBlank(narrativeName)) {
          String narrative = IOUtils.toString(loadResource(narrativeName));
          myNameToNarrativeTemplate.put(name, narrative);
        }
        if (StringUtils.isNotBlank(titleName)) {
          String title = IOUtils.toString(loadResource(titleName));
          myNameToTitleTemplate.put(name, title);
        }

      } else if (nextKey.endsWith(".class")) {

        String name = nextKey.substring(0, nextKey.indexOf(".class"));
        if (isBlank(name)) {
          continue;
        }

        String className = file.getProperty(nextKey);

        Class<?> clazz;
        try {
          clazz = Class.forName(className);
        } catch (ClassNotFoundException e) {
          ourLog.warn("Unknown datatype class '{}' identified in narrative file {}", name, propFileName);
          continue;
        }

        String narrativePropName = name + ".narrative";
        String narrativeName = file.getProperty(narrativePropName);
        String titlePropName = name + ".title";
        String titleName = file.getProperty(titlePropName);
        if (isBlank(narrativeName) && isBlank(titleName)) {
          throw new ConfigurationException("Found property '" + nextKey + "' but no corresponding property '" + narrativePropName + "' or '" + titlePropName + "' in file " + propFileName);
        }

        myClassToName.put(clazz, name);

        if (StringUtils.isNotBlank(narrativeName)) {
          String narrative = IOUtils.toString(loadResource(narrativeName));
          myNameToNarrativeTemplate.put(name, narrative);
        }
        if (StringUtils.isNotBlank(titleName)) {
          String title = IOUtils.toString(loadResource(titleName));
          myNameToTitleTemplate.put(name, title);
        }

      } else if (nextKey.endsWith(".narrative")) {
        continue;
      } else if (nextKey.endsWith(".title")) {
        continue;
      } else {
        throw new ConfigurationException("Invalid property name: " + nextKey);
      }

    }
  }
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.