Example #1
0
  /** INTERNAL: Get the XMLDescriptor associated with this Type or generate a new one. */
  public void initializeNamespaces(List namespaceResolvers) {
    if (!isDataType()) {
      NamespaceResolver nr = new NamespaceResolver();

      // copy namespaces between resolvers for well known and SDO namespaces
      if (namespaceResolvers != null) {
        for (int i = 0; i < namespaceResolvers.size(); i++) {
          NamespaceResolver nextNR = (NamespaceResolver) namespaceResolvers.get(i);
          if (nextNR != null) {
            for (int j = 0, size = nextNR.getNamespaces().size(); j < size; j++) {
              Namespace nextNamespace = (Namespace) nextNR.getNamespaces().get(j);
              if ((!nextNamespace.getPrefix().equals(XMLConstants.XMLNS))
                  && (!nextNamespace.getNamespaceURI().equals(XMLConstants.SCHEMA_URL))
                  && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOJAVA_URL))
                  && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOXML_URL))
                  && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDO_URL))) {
                String newPrefix =
                    ((SDOTypeHelper) aHelperContext.getTypeHelper())
                        .addNamespace(nextNamespace.getPrefix(), nextNamespace.getNamespaceURI());
                nr.put(newPrefix, nextNamespace.getNamespaceURI());
              }
            }
          }
        }
      }
      xmlDescriptor.setNamespaceResolver(nr);
      if (getURI() != null) {
        String prefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(getURI());
        xmlDescriptor.getNamespaceResolver().put(prefix, getURI());
      }
      xmlDescriptor
          .getNamespaceResolver()
          .put(XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL);
    }
  }
Example #2
0
  public void setupInheritance(SDOType parentType) {
    if (parentType == null) {
      // root of inheritance
      addClassIndicator(getXmlDescriptor(), getImplClass(), true);
    } else {
      if ((parentType.getURI() != null) && (!parentType.getURI().equals(SDOConstants.SDO_URL))) {
        // set parent descriptor indicator if necessary
        if (!parentType.getXmlDescriptor().hasInheritance()) {
          addClassIndicator(parentType.getXmlDescriptor(), parentType.getImplClass(), false);
        }

        XMLDescriptor parentDescriptor =
            (XMLDescriptor)
                parentType.getXmlDescriptor().getInheritancePolicy().getRootParentDescriptor();
        NamespaceResolver parentNR = parentDescriptor.getNonNullNamespaceResolver();
        if (parentNR != null) {
          for (int i = 0; i < parentNR.getNamespaces().size(); i++) {
            Namespace nextNamespace = (Namespace) parentNR.getNamespaces().get(i);
            if ((!nextNamespace.getPrefix().equals(XMLConstants.XMLNS))
                && (!nextNamespace.getNamespaceURI().equals(XMLConstants.SCHEMA_URL))
                && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOJAVA_URL))
                && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOXML_URL))
                && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDO_URL))) {
              getXmlDescriptor()
                  .getNonNullNamespaceResolver()
                  .put(nextNamespace.getPrefix(), nextNamespace.getNamespaceURI());
            }
          }
        }
        if (getInstanceClassName() != null) {
          String indicator = getName();
          String prefix = parentDescriptor.getNamespaceResolver().resolveNamespaceURI(getURI());
          if (prefix == null) {
            prefix = getXmlDescriptor().getNamespaceResolver().resolveNamespaceURI(getURI());
            if (prefix != null) {
              parentDescriptor.getNamespaceResolver().put(prefix, getURI());
            }
          }
          if (prefix != null) {
            indicator = prefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + indicator;
          }
          Class implClass = getImplClass();
          parentDescriptor.getInheritancePolicy().addClassIndicator(implClass, indicator);
          parentDescriptor.getInheritancePolicy().setShouldReadSubclasses(true);
          Class parentClass = parentType.getImplClass();
          getXmlDescriptor().getInheritancePolicy().setParentClass(parentClass);
          getXmlDescriptor()
              .getInheritancePolicy()
              .setParentDescriptor(parentType.getXmlDescriptor());
          parentType
              .getXmlDescriptor()
              .getNamespaceResolver()
              .put(XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL);
          getXmlDescriptor()
              .getNamespaceResolver()
              .put(XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL);
        }
      }
    }
    // now setup inheritance for any subtypes
    if (isBaseType()) {
      for (int i = 0; i < subTypes.size(); i++) {
        SDOType nextSubType = (SDOType) subTypes.get(i);
        if (!nextSubType.isDataType() && nextSubType.isSubType()) {
          nextSubType.setupInheritance(this);
        }
      }
    }
  }