Esempio n. 1
0
  /**
   * Loads nested schema type definitions from wsdl.
   *
   * @throws IOException
   * @throws WSDLException
   * @throws TransformerFactoryConfigurationError
   * @throws TransformerException
   * @throws TransformerConfigurationException
   */
  private void loadSchemas()
      throws WSDLException, IOException, TransformerConfigurationException, TransformerException,
          TransformerFactoryConfigurationError {
    Definition definition =
        WSDLFactory.newInstance().newWSDLReader().readWSDL(wsdl.getFile().getAbsolutePath());

    Types types = definition.getTypes();
    List<?> schemaTypes = types.getExtensibilityElements();

    for (Object schemaObject : schemaTypes) {
      if (schemaObject instanceof SchemaImpl) {
        SchemaImpl schema = (SchemaImpl) schemaObject;

        inheritNamespaces(schema, definition);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        Source source = new DOMSource(schema.getElement());
        Result result = new StreamResult(bos);

        TransformerFactory.newInstance().newTransformer().transform(source, result);
        Resource schemaResource = new ByteArrayResource(bos.toByteArray());

        schemas.add(schemaResource);

        if (definition
            .getTargetNamespace()
            .equals(schema.getElement().getAttribute("targetNamespace"))) {
          setXsd(schemaResource);
        }
      } else {
        log.warn("Found unsupported schema type implementation " + schemaObject.getClass());
      }
    }
  }
Esempio n. 2
0
  public static Definition setConfiguration(
      Definition node, org.kframework.kil.loader.Context context, final Configuration conf) {
    try {
      return (Definition)
          node.accept(
              new CopyOnWriteTransformer("Configuration setter", context) {
                @Override
                public ASTNode transform(Configuration node) {
                  return conf;
                }

                @Override
                public ASTNode transform(org.kframework.kil.Context node) {
                  return node;
                }

                @Override
                public ASTNode transform(Rule node) {
                  return node;
                }

                @Override
                public ASTNode transform(Syntax node) {
                  return node;
                }
              });
    } catch (TransformerException e) {
      e.printStackTrace();
    }
    return node;
  }
  /**
   * Generate the display of the results of the Define command
   *
   * @param data the result of the Define command
   * @param word the queried word
   * @return the formatted result
   */
  private String retrieveDefine(List<Definition> data, String word) {
    StringBuffer res = new StringBuffer();
    Definition def;

    for (int i = 0; i < data.size(); i++) {
      def = data.get(i);

      if (i != 0 && data.size() > 0) {
        res.append("<hr>");
      }
      res.append(def.getDefinition().replaceAll("\n", "<br>"))
          .append("<div align=\"right\"><font size=\"-2\">-- From ")
          .append(def.getDictionary())
          .append("</font></div>");
    }

    String result = res.toString();
    result = formatResult(result, "\\\\", "<em>", "</em>");
    result = formatResult(result, "[\\[\\]]", "<cite>", "</cite>");
    result = formatResult(result, "[\\{\\}]", "<strong>", "</strong>");
    result = formatWordDefined(result, word);

    return result;
  }
Esempio n. 4
0
  public static Configuration getConfiguration(
      Definition node, org.kframework.kil.loader.Context context) {
    final List<Configuration> result = new LinkedList<Configuration>();
    node.accept(
        new BasicVisitor(context) {
          @Override
          public void visit(Configuration node) {
            result.add(node);
          }

          @Override
          public void visit(org.kframework.kil.Context node) {
            return;
          }

          @Override
          public void visit(Rule node) {
            return;
          }

          @Override
          public void visit(Syntax node) {
            return;
          }
        });
    if (result.size() == 0) {
      GlobalSettings.kem.register(
          new KException(
              ExceptionType.ERROR,
              KExceptionGroup.INTERNAL,
              "Internal compiler error --- Cannot find configuration.",
              node.getFilename(),
              node.getLocation()));
    }
    return result.get(0);
  }
Esempio n. 5
0
  /**
   * Adds WSDL level namespaces to schema definition if necessary.
   *
   * @param schema
   * @param wsdl
   */
  @SuppressWarnings("unchecked")
  private void inheritNamespaces(SchemaImpl schema, Definition wsdl) {
    Map<String, String> wsdlNamespaces = wsdl.getNamespaces();

    for (Entry<String, String> nsEntry : wsdlNamespaces.entrySet()) {
      if (StringUtils.hasText(nsEntry.getKey())) {
        if (!schema.getElement().hasAttributeNS(WWW_W3_ORG_2000_XMLNS, nsEntry.getKey())) {
          schema
              .getElement()
              .setAttributeNS(
                  WWW_W3_ORG_2000_XMLNS, "xmlns:" + nsEntry.getKey(), nsEntry.getValue());
        }
      } else { // handle default namespace
        if (!schema.getElement().hasAttribute("xmlns")) {
          schema
              .getElement()
              .setAttributeNS(
                  WWW_W3_ORG_2000_XMLNS, "xmlns" + nsEntry.getKey(), nsEntry.getValue());
        }
      }
    }
  }
Esempio n. 6
0
 /** @see jaskell.compiler.JaskellVisitor#visit(Definition) */
 public Object visit(Definition a) {
   return a.getType();
 }