/** For internal use only. */
 private static Object makeDerivedWrapper(Element elt, String baseTypeName) {
   synchronized (DOMUtils.getDOMLock(elt)) {
     QName typeName = XArchUtils.getXSIType(elt);
     if (typeName == null) {
       return null;
     } else {
       if (!DOMUtils.hasXSIType(
           elt, "http://www.ics.uci.edu/pub/arch/xArch/changesets.xsd", baseTypeName)) {
         try {
           String packageTitle = XArchUtils.getPackageTitle(typeName.getNamespaceURI());
           String packageName = XArchUtils.getPackageName(packageTitle);
           String implName = XArchUtils.getImplName(packageName, typeName.getName());
           Class c = Class.forName(implName);
           java.lang.reflect.Constructor con = c.getConstructor(new Class[] {Element.class});
           Object o = con.newInstance(new Object[] {elt});
           return o;
         } catch (Exception e) {
           // Lots of bad things could happen, but this
           // is OK, because this is best-effort anyway.
         }
       }
       return null;
     }
   }
 }
Exemplo n.º 2
0
 /** GetBindingFromInterfaceName Method. */
 public TBinding getBindingFromInterfaceName(TDefinitions descriptionType, String interfaceName) {
   for (TDocumented nextElement : descriptionType.getAnyTopLevelOptionalElement()) {
     // Create the service type
     if (nextElement instanceof TBinding) {
       QName qname = ((TBinding) nextElement).getType();
       if (interfaceName.equalsIgnoreCase(qname.getLocalPart())) return (TBinding) nextElement;
     }
   }
   return null;
 }
Exemplo n.º 3
0
 static QName create(Namespace namespace, String localName) {
   //    A null namespace indicates a wild-card match for any namespace
   //    A null localName indicates "*" from the point of view of ECMA357
   if (localName != null && localName.equals("*"))
     throw new RuntimeException("* is not valid localName");
   QName rv = new QName();
   rv.namespace = namespace;
   rv.localName = localName;
   return rv;
 }
Exemplo n.º 4
0
 void invalidateNamespacePrefix() {
   if (!(dom instanceof Element)) throw new IllegalStateException();
   String prefix = this.dom.getPrefix();
   QName after = QName.create(this.dom.getNamespaceURI(), this.dom.getLocalName(), null);
   renameNode(after);
   NamedNodeMap attrs = this.dom.getAttributes();
   for (int i = 0; i < attrs.getLength(); i++) {
     if (attrs.item(i).getPrefix().equals(prefix)) {
       createImpl(attrs.item(i))
           .renameNode(
               QName.create(attrs.item(i).getNamespaceURI(), attrs.item(i).getLocalName(), null));
     }
   }
 }
Exemplo n.º 5
0
 /** Search through the messages for this one and return the element name. */
 public String getElementNameFromMessageName(TDefinitions descriptionType, TParam message) {
   QName qName = message.getMessage();
   String name = qName.getLocalPart();
   for (TDocumented nextElement : descriptionType.getAnyTopLevelOptionalElement()) {
     // Create the service type
     if (nextElement instanceof TMessage) {
       String msgName = ((TMessage) nextElement).getName();
       for (TPart part : ((TMessage) nextElement).getPart()) {
         if (name.equals(part.getName())) {
           return part.getElement().getLocalPart();
         }
       }
     }
   }
   return null;
 }
Exemplo n.º 6
0
 final void setLocalName(String localName) {
   if (dom instanceof ProcessingInstruction) {
     setProcessingInstructionName(localName);
   } else {
     String prefix = dom.getPrefix();
     if (prefix == null) prefix = "";
     this.dom =
         dom.getOwnerDocument()
             .renameNode(dom, dom.getNamespaceURI(), QName.qualify(prefix, localName));
   }
 }
  /**
   * Find a type object in the context of the class.
   *
   * @param name The name to search for.
   */
  public Named find(Matcher<Named> matcher, Context context) throws SemanticException {
    Name name = matcher.name();

    if (Report.should_report(TOPICS, 2)) Report.report(2, "Looking for " + name + " in " + this);

    if (!(type instanceof ClassType)) {
      throw new NoClassException(name.toString(), type);
    }

    ClassType type = (ClassType) this.type;

    Named m = null;

    QName fullName = null;
    QName rawName = null;

    if (type.isGloballyAccessible()) {
      fullName = QName.make(type.fullName(), name);
      QName q = ts.getTransformedClassName(type.def());
      rawName = QName.make(q.qualifier(), Name.make(q.name() + "$" + name));
    }

    if (fullName != null) {
      // First check the system resolver.
      m = ts.systemResolver().check(fullName);

      // Try the raw class file name.
      if (m == null) {
        m = ts.systemResolver().check(rawName);
      }

      if (m == null) {
        // Go to disk, but only if there is no job for the type.
        // If there is a job, all members should be in the resolver
        // already.
        boolean useLoadedResolver = true;

        if (type instanceof ParsedTypeObject) {
          ParsedTypeObject pto = (ParsedTypeObject) type;
          if (pto.job() != null) {
            useLoadedResolver = false;
          }
        }

        if (useLoadedResolver) {
          try {
            m = ts.systemResolver().find(rawName);
          } catch (SemanticException e) {
            // Not found; will fall through to error handling code
          }
        }
      }

      // If we found something, verify that it matches.
      if (m != null) {
        try {
          m = matcher.instantiate(m);
        } catch (SemanticException e) {
          // Doesn't match; try again.
          m = null;
        }
      }
    }

    // Check if the member was explicitly declared.
    if (m == null) {
      m = type.memberTypeMatching(matcher);
    }

    // If we found something, make sure it's accessible.
    if (m instanceof ClassType) {
      ClassType mt = (ClassType) m;

      if (!mt.isMember()) {
        throw new SemanticException(
            "Class " + mt + " is not a member class, " + " but was found in " + type + ".");
      }

      if (!mt.outer().equals((Object) type)) {
        throw new SemanticException(
            "Class " + mt + " is not a member class " + " of " + type + ".");
      }

      return mt;
    }

    if (m instanceof MemberInstance) {
      MemberInstance<?> mi = (MemberInstance<?>) m;

      if (!mi.container().equals((Object) type)) {
        throw new SemanticException("Type " + mi + " is not a member " + " of " + type + ".");
      }
    }

    if (m != null) {
      if (!canAccess(m, context.currentClassDef(), context)) {
        throw new SemanticException("Cannot access member type \"" + m + "\".");
      }
      return m;
    }

    // If we struck out, try the super types.

    // Collect all members of the super types.
    // Use a Set to eliminate duplicates.
    Set<Named> acceptable = new HashSet<Named>();

    if (type.superClass() != null) {
      Type sup = type.superClass();
      if (sup instanceof ClassType) {
        Resolver r = ts.classContextResolver((ClassType) sup, context);
        try {
          Named n = r.find(matcher);
          acceptable.add(n);
        } catch (SemanticException e) {
        }
      }
    }

    for (Iterator<Type> i = type.interfaces().iterator(); i.hasNext(); ) {
      Type sup = (Type) i.next();
      if (sup instanceof ClassType) {
        Resolver r = ts.classContextResolver((ClassType) sup, context);
        try {
          Named n = r.find(matcher);
          acceptable.add(n);
        } catch (SemanticException e) {
        }
      }
    }

    if (acceptable.size() == 0) {
      throw new NoClassException(name.toString(), type);
    } else if (acceptable.size() > 1) {
      Set<Type> containers = new HashSet<Type>(acceptable.size());
      for (Named n : acceptable) {
        if (n instanceof MemberInstance) {
          MemberInstance<?> mi = (MemberInstance<?>) n;
          containers.add(mi.container());
        }
      }

      if (containers.size() == 2) {
        Iterator<Type> i = containers.iterator();
        Type t1 = (Type) i.next();
        Type t2 = (Type) i.next();
        throw new SemanticException(
            "Member \""
                + name
                + "\" of "
                + type
                + " is ambiguous; it is defined in both "
                + t1
                + " and "
                + t2
                + ".");
      } else if (containers.size() == 0) {
        throw new SemanticException("Member \"" + name + "\" of " + type + " is ambiguous.");
      } else {
        throw new SemanticException(
            "Member \""
                + name
                + "\" of "
                + type
                + " is ambiguous; it is defined in "
                + CollectionUtil.listToString(new ArrayList<Type>(containers))
                + ".");
      }
    }

    assert acceptable.size() == 1;

    Named t = acceptable.iterator().next();

    if (Report.should_report(TOPICS, 2)) Report.report(2, "Found member type " + t);

    return t;
  }
Exemplo n.º 8
0
 void setAttribute(QName name, String value) {
   if (!(dom instanceof Element))
     throw new IllegalStateException("Can only set attribute on elements.");
   name.setAttribute((Element) dom, value);
 }
Exemplo n.º 9
0
 final QName getQname() {
   String uri = (dom.getNamespaceURI()) == null ? "" : dom.getNamespaceURI();
   String prefix = (dom.getPrefix() == null) ? "" : dom.getPrefix();
   return QName.create(uri, dom.getLocalName(), prefix);
 }
Exemplo n.º 10
0
 final void renameNode(QName qname) {
   this.dom = dom.getOwnerDocument().renameNode(dom, qname.getUri(), qname.qualify(dom));
 }
Exemplo n.º 11
0
 /**
  * Bind a variable to the given value within all query expression evaluated subsequently.
  *
  * @param variableName the qualified name of the variable to bind; prefixes are taken from the
  *     namespace mappings of the folder that provided this service; if the name starts with a
  *     <code>$</code>, it will be stripped automatically
  * @param value the value the variable should take
  * @return this service, to chain calls
  */
 public QueryService let(String variableName, Object value) {
   if (variableName == null) throw new NullPointerException("null variable name");
   if (variableName.startsWith("$")) variableName = variableName.substring(1);
   if (variableName.length() == 0) throw new IllegalArgumentException("empty variable name");
   return let(QName.parse(variableName, namespaceBindings, ""), value);
 }