private void emitReferencedValue(AttributeList attrs) throws SAXException {
    if (expectingTarget) {
      String previousElement = "";
      if (!elementStack.empty()) {
        previousElement = (String) elementStack.peek();
      }

      int prevSrxId = XmiMapping.getSrxId(previousElement);
      // enabledOutput = toProcess(prevSrxId);
      if (!enabledOutput) {
        return;
      }

      if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
          String attr = attrs.getName(i);
          if (attr.equals(kTarget)) {
            String key = attrs.getValue(i);
            String name = (String) idTable.get(key);
            if (name != null) {
              emit(name + eol);
            }
            expectingTarget = false;
          }
        } // end for
      } // end if
    } // end if
  } // end emitReferencedValue()
Esempio n. 2
0
    public void startElement(String name, AttributeList atts) 
        throws org.xml.sax.SAXException
    {
        
        //-- strip namespace prefix
        int idx = name.indexOf(':');
        if (idx >= 0) {
            name = name.substring(idx+1);
        }

        StateInfo sInfo = null;
        
        boolean topLevel = false;
        //-- if we are currently in another element 
        //-- definition...flag as complex content
        if (!_siStack.isEmpty()) {
            sInfo = (StateInfo)_siStack.peek();
            sInfo.complex = true;
        }
        else {
            topLevel = true;
        }
        
        //-- create current holder for stateInformation
        sInfo = new StateInfo();
        sInfo.topLevel = topLevel;
        _siStack.push(sInfo);
        
        //-- create element definition
        sInfo.element = new ElementDecl(_schema, name);
        
        //-- create attributes
        for (int i = 0; i < atts.getLength(); i++) {
            
            String attName = atts.getName(i);
            
            //-- skip namespace declarations
            if (attName.equals(XMLNS)) continue;
            String prefix = "";
            idx = attName.indexOf(':');
            if (idx >= 0) {
                prefix = attName.substring(0, idx);
                attName = attName.substring(idx+1);
            }
            if (prefix.equals(XMLNS)) continue;
            
            AttributeDecl attr = new AttributeDecl(_schema, attName);
            
            //-- guess simple type
            String typeName = _nsPrefix + ':' + 
                DatatypeHandler.guessType(atts.getValue(i));
                
            attr.setSimpleTypeReference(typeName);
            
            sInfo.attributes.addElement(attr);
        }
        
    } //-- startElement
  private void emitNewOccurrence(int srxId, AttributeList attrs) throws SAXException {

    enabledOutput = toProcess(srxId);
    if (!enabledOutput) {
      return;
    }

    currentSrxId = srxId;
    String mappedName = XmiMapping.getMappingName(srxId);
    emit(eol + kOccurrenceType + " " + mappedName + eol);

    // if it's a component, write its composite
    String composite = XmiMapping.getComposite(srxId);
    if (composite != null) {
      if (!occurrenceNameStack.empty()) {
        String compositeName = (String) occurrenceNameStack.peek();
        if (compositeName != null) {
          emit(composite + " " + compositeName + eol);
        }
      } // end if
    } // end if

    // Keep its XMI.id
    if (attrs != null) {
      for (int i = 0; i < attrs.getLength(); i++) {
        String attr = attrs.getName(i);
        if (attr.equals(kXmiId)) {
          currentXmiId = attrs.getValue(i);
        } // end if
      } // end for
    } // end if

    // Keep its current XMI name & SRX name
    currentXmiName = XmiMapping.getXmiName(srxId);
    currentSrxName = XmiMapping.getSrxName(srxId);
  }