Пример #1
0
  @Override
  public void startElement(String uri, String localName, String qName, Attributes attributes)
      throws SAXException {
    ModelReader6Handler.ElementHandler current =
        (myHandlersStack.empty()
            ? (ModelReader6Handler.ElementHandler) null
            : myHandlersStack.peek());
    if (current == null) {
      // root
      current = modelhandler;
    } else {
      current = current.createChild(qName);
    }

    // check required
    for (String attr : current.requiredAttributes()) {
      if (attributes.getValue(attr) == null) {
        throw new SAXParseException("attribute " + attr + " is absent", null);
      }
    }

    Object result = current.createObject(attributes);
    if (myHandlersStack.empty()) {
      myResult = (ModelLoadResult) result;
    }

    // handle attributes
    for (int i = 0; i < attributes.getLength(); i++) {
      String name = attributes.getQName(i);
      String value = attributes.getValue(i);
      current.handleAttribute(result, name, value);
    }
    myHandlersStack.push(current);
    myValues.push(result);
  }
Пример #2
0
 @Override
 public void characters(char[] array, int start, int len) throws SAXException {
   ModelReader6Handler.ElementHandler current =
       (myHandlersStack.empty()
           ? (ModelReader6Handler.ElementHandler) null
           : myHandlersStack.peek());
   if (current != null) {
     current.handleText(myValues.peek(), new String(array, start, len));
   }
 }
Пример #3
0
 @Override
 public void endElement(String uri, String localName, String qName) throws SAXException {
   ModelReader6Handler.ElementHandler current = myHandlersStack.pop();
   Object childValue = myValues.pop();
   if (current != null) {
     current.validate(childValue);
     if (myHandlersStack.empty()) {
       myResult = (ModelLoadResult) childValue;
     } else {
       myHandlersStack.peek().handleChild(myValues.peek(), qName, childValue);
     }
   }
 }
Пример #4
0
 @Override
 protected void handleChild(Object resultObject, String tagName, Object value)
     throws SAXException {
   SNode result = (SNode) resultObject;
   if ("property".equals(tagName)) {
     String[] child = (String[]) value;
     if (child[1] != null) {
       SNodeAccessUtil.setProperty(result, fieldhelper.readName(child[0]), child[1]);
     }
     return;
   }
   if ("link".equals(tagName)) {
     String[] child = (String[]) value;
     if (child[2] == null) {
       LOG.error("couldn't create reference '" + child[0] + "' : traget node id is null");
       return;
     }
     SReference ref = fieldhelper.readLink(result, child[0], child[2], child[1]);
     if (ref != null) {
       result.setReference(ref.getRole(), ref);
     }
     return;
   }
   if ("node".equals(tagName)) {
     SNode child = (SNode) value;
     result.addChild(((String) child.getUserObject("role")), child);
     child.putUserObject("role", null);
     return;
   }
   super.handleChild(resultObject, tagName, value);
 }
Пример #5
0
 @Override
 protected void handleAttribute(Object resultObject, String name, String value)
     throws SAXException {
   String result = (String) resultObject;
   if ("namespace".equals(name)) {
     return;
   }
   super.handleAttribute(resultObject, name, value);
 }
Пример #6
0
 @Override
 protected void handleAttribute(Object resultObject, String name, String value)
     throws SAXException {
   Integer result = (Integer) resultObject;
   if ("version".equals(name)) {
     return;
   }
   super.handleAttribute(resultObject, name, value);
 }
Пример #7
0
 @Override
 protected void handleAttribute(Object resultObject, String name, String value)
     throws SAXException {
   ModelLoadResult result = (ModelLoadResult) resultObject;
   if ("modelUID".equals(name)) {
     return;
   }
   super.handleAttribute(resultObject, name, value);
 }
Пример #8
0
 @Override
 protected void handleChild(Object resultObject, String tagName, Object value)
     throws SAXException {
   Object result = (Object) resultObject;
   if ("node".equals(tagName)) {
     SNode child = (SNode) value;
     if (fieldtoState == ModelLoadingState.ROOTS_LOADED && child != null) {
       fieldmodel.addRoot(child);
     }
     return;
   }
   super.handleChild(resultObject, tagName, value);
 }
Пример #9
0
 @Override
 protected void handleChild(Object resultObject, String tagName, Object value)
     throws SAXException {
   ModelLoadResult result = (ModelLoadResult) resultObject;
   if ("persistence".equals(tagName)) {
     return;
   }
   if ("language".equals(tagName)) {
     String child = (String) value;
     fieldmodel.addLanguage(ModuleReference.fromString(child));
     return;
   }
   if ("language-engaged-on-generation".equals(tagName)) {
     String child = (String) value;
     fieldmodel.addEngagedOnGenerationLanguage(ModuleReference.fromString(child));
     return;
   }
   if ("devkit".equals(tagName)) {
     String child = (String) value;
     fieldmodel.addDevKit(ModuleReference.fromString(child));
     return;
   }
   if ("import".equals(tagName)) {
     String[] child = (String[]) value;
     fieldhelper.addImport(
         fieldmodel, child[0], child[1], Integer.parseInt(child[2]), child[3] != null);
     return;
   }
   if ("node".equals(tagName)) {
     SNode child = (SNode) value;
     if (child != null) {
       fieldmodel.addRoot(child);
     }
     return;
   }
   if ("root_stubs".equals(tagName)) {
     Object child = (Object) value;
     if (fieldtoState == ModelLoadingState.ROOTS_LOADED) {
       result.setState(ModelLoadingState.ROOTS_LOADED);
       throw new BreakParseSAXException();
     }
     return;
   }
   super.handleChild(resultObject, tagName, value);
 }
Пример #10
0
 @Override
 protected void handleAttribute(Object resultObject, String name, String value)
     throws SAXException {
   String[] result = (String[]) resultObject;
   if ("role".equals(name)) {
     result[0] = value;
     return;
   }
   if ("resolveInfo".equals(name)) {
     result[1] = value;
     return;
   }
   if ("targetNodeId".equals(name)) {
     result[2] = value;
     return;
   }
   super.handleAttribute(resultObject, name, value);
 }
Пример #11
0
 @Override
 protected void handleAttribute(Object resultObject, String name, String value)
     throws SAXException {
   String[] result = (String[]) resultObject;
   if ("index".equals(name)) {
     return;
   }
   if ("version".equals(name)) {
     return;
   }
   if ("modelUID".equals(name)) {
     return;
   }
   if ("implicit".equals(name)) {
     result[3] = value;
     return;
   }
   super.handleAttribute(resultObject, name, value);
 }
Пример #12
0
 @Override
 protected void handleAttribute(Object resultObject, String name, String value)
     throws SAXException {
   SNode result = (SNode) resultObject;
   if ("type".equals(name)) {
     return;
   }
   if ("role".equals(name)) {
     result.putUserObject("role", fieldhelper.readRole(value));
     return;
   }
   if ("id".equals(name)) {
     SNodeId id = jetbrains.mps.smodel.SNodeId.fromString(value);
     if (id == null) {
       throw new SAXParseException("bad node ID", null);
     }
     ((jetbrains.mps.smodel.SNode) result).setId(id);
     return;
   }
   super.handleAttribute(resultObject, name, value);
 }