Esempio n. 1
0
  private SingletonMap moveNsDeclaration(BpelEntity entity, Attr attr)
      throws InvalidNamespaceException {
    String namespaceURI = attr.getValue();
    ExNamespaceContext context = entity.getNamespaceContext();
    /*
     * Fantom addition of namespace. This call will not do anything,
     * it just check correcttness of namespaceURI. If it bad then
     * InvalidNamespaceException will appear and we go to catch.
     */
    context.addNamespace(namespaceURI);

    // here we remove namespace declararation
    ((BpelEntityImpl) entity)
        .setAttribute(attr.getName(), new PrefixAttribute(attr.getName()), null);

    String localName = attr.getLocalName();
    Iterator<String> iterator = context.getPrefixes();
    boolean usePrefix = true;
    while (iterator.hasNext() && localName != null) {
      String prefix = iterator.next();
      if (localName.equals(prefix)) {
        usePrefix = false;
      }
    }
    String prefix = null;
    if (XMLNS.equals(attr.getName()) || localName == null || !usePrefix) {
      prefix = context.addNamespace(attr.getValue());
    } else {
      prefix = localName;
      context.addNamespace(localName, attr.getValue());
    }
    return new SingletonMap(localName, prefix);
  }
Esempio n. 2
0
 private void updateListAttribute(
     BpelEntity entity, String oldPrefix, String newPrefix, Attribute attribute) {
   StringTokenizer tokenizer = new StringTokenizer(entity.getAttribute(attribute), " ");
   StringBuilder builder = new StringBuilder();
   boolean change = false;
   while (tokenizer.hasMoreTokens()) {
     String next = tokenizer.nextToken();
     String newValue = getUpdatedReferenceAttribute(entity, next, oldPrefix, newPrefix);
     if (newValue == null) {
       builder.append(next);
       builder.append(" ");
     } else {
       change = true;
       builder.append(newValue);
       builder.append(" ");
     }
   }
   if (!change) {
     return;
   }
   String resultValue = null;
   if (builder.length() > 0) {
     resultValue = builder.substring(0, builder.length() - 1);
   }
   if (resultValue != null) {
     ((BpelEntityImpl) entity).setAttribute(attribute.getName(), attribute, resultValue);
   }
 }
Esempio n. 3
0
 private void handleNsAttribute(
     BpelEntity entity, BpelEntity parent, Map<String, String> prefixMap, Attr attr) {
   String namespaceURI = attr.getValue();
   if (XMLNS.equals(attr.getName()) || (XMLNS.equals(attr.getPrefix()))) {
     if (namespaceURI.equals(entity.getPeer().getNamespaceURI())) {
       // do not touch namespace that correspond namespace of current element
       return;
     }
     ExNamespaceContext context = parent.getNamespaceContext();
     Iterator<String> iterator = context.getPrefixes();
     while (iterator.hasNext()) {
       String next = iterator.next();
       String namespace = context.getNamespaceURI(next);
       if (namespaceURI.equals(namespace)) {
         String prefixName = attr.getLocalName();
         // put prefix corresponding found namespace into map for changing it further
         if (!prefixName.equals(next)) {
           prefixMap.put(prefixName, next);
         }
         // remove namespace delcaration.
         ((BpelEntityImpl) entity)
             .setAttribute(attr.getName(), new PrefixAttribute(attr.getName()), null);
       }
     }
   }
 }
Esempio n. 4
0
  private void updatePrefixInAttribute(
      BpelEntity entity, String key, String value, Attribute attribute) {
    if (entity.getAttribute(attribute) == null) {
      return;
    }
    if (!Utils.canUpdatePrefix(attribute)) {
      return;
    }

    Class clazz = attribute.getType();
    if (QName.class.isAssignableFrom(clazz) || Referenceable.class.isAssignableFrom(clazz)) {
      String newValue =
          getUpdatedReferenceAttribute(entity, entity.getAttribute(attribute), key, value);
      if (newValue == null) {
        return;
      }
      ((BpelEntityImpl) entity).setAttribute(attribute.getName(), attribute, newValue);
    } else if (List.class.isAssignableFrom(clazz)
        && Referenceable.class.isAssignableFrom(attribute.getMemberType())) {
      updateListAttribute(entity, key, value, attribute);
    }
  }