Package org.apache.ws.jaxme.xs

Examples of org.apache.ws.jaxme.xs.XSSimpleType


  private SimpleTypeSGChain newAtomicTypeRestriction(TypeSG pController,
                                                     SGFactory pFactory,
                                                     SchemaSG pSchema,
                                                     XSType pType)
      throws SAXException {
    XSSimpleType simpleType = pType.getSimpleType();
    SimpleTypeSGChain result = newSimpleTypeSG(pController, pFactory, pSchema, simpleType.getRestrictedType());
    result = new SimpleTypeRestrictionSG(result, pType, simpleType);
   
    if (simpleType.getEnumerations().length > 0) {
        boolean generateTypesafeEnumClass = false;
        String className = null;
       
        if (simpleType instanceof JAXBSimpleType) {
            JAXBSimpleType jaxbSimpleType = (JAXBSimpleType) simpleType;
            JAXBTypesafeEnumClass jaxbTypesafeEnumClass = jaxbSimpleType.getJAXBTypesafeEnumClass();
            if (jaxbTypesafeEnumClass != null) {
                generateTypesafeEnumClass = true;
                className = jaxbTypesafeEnumClass.getName();
            }
        }
       
        if (!generateTypesafeEnumClass) {
            XSEnumeration[] enumerations = simpleType.getEnumerations();
            for (int i = 0;  i < enumerations.length;  i++) {
                XSEnumeration enumeration = enumerations[i];
                if (enumeration instanceof JAXBEnumeration) {
                    JAXBEnumeration jaxbEnumeration = (JAXBEnumeration) enumeration;
                    if (jaxbEnumeration.getJAXBTypesafeEnumMember() != null) {
View Full Code Here


        for (int i = 0;  i < globalJavaTypes.length;  i++) {
            if (globalJavaTypes[i].getXmlType().equals(currentType.getName())) {
            return globalJavaTypes[i];
            }
        }
        XSSimpleType simpleType = currentType.getSimpleType();
        if (simpleType.isRestriction()) {
          currentType = simpleType.getRestrictedType();
        } else {
          currentType = null;
        }
    }
    return null;
View Full Code Here

    }

    JAXBJavaType javaType = findJavaType(pSchema, pType);
    SimpleTypeSGChain result;
    if (javaType == null  ||  javaType.getName() == null) {
        XSSimpleType simpleType = pType.getSimpleType();
        JavaQName runtimeType;
        if (simpleType.isAtomic()) {
          result = newGlobalAtomicTypeSG(pFactory, pSchema, pType);
            if (result == null) {
                if (!simpleType.isRestriction()) {
                    throw new SAXParseException("Atomic type must be either a builtin or a restriction of another atomic type",
                                                pType.getLocator());
                }
                TypeSG type = pSchema.getType(simpleType.getRestrictedType().getName());
                runtimeType = type.getSimpleTypeSG().getRuntimeType();
                result = newAtomicTypeRestriction(pController, pFactory, pSchema, pType);
            } else {
                SimpleTypeSG simpleTypeSG = new SimpleTypeSGImpl(result);
                simpleTypeSG.init();
              runtimeType = simpleTypeSG.getRuntimeType();
            }
            if (javaType == null) {
                JAXBJavaType[] globalJavaTypes = pSchema.getJAXBJavaTypes();
                for (int i = 0;  i < globalJavaTypes.length;  i++) {
                  if (runtimeType.equals(globalJavaTypes[i].getName())) {
                        javaType = globalJavaTypes[i];
                        break;
                    }
                }
            }
        } else if (simpleType.isList()) {
          result = new ListTypeSGImpl(pFactory, pSchema, pType, classContext, pController.getName());
        } else if (simpleType.isUnion()) {
            result = new UnionTypeSGImpl(pFactory, pSchema, pType, classContext, pController.getName());
        } else {
            throw new IllegalStateException("Simple type " + pType + " is neither of atomic, list, or union");
        }
    } else {
View Full Code Here

    }
    XSObjectFactory factory = pParent.getXSSchema().getXSObjectFactory();
    if (myComplexType.isExtension()) {
      XSType extendedType = myComplexType.getSimpleContent().getType();
      extendedType.validate();
      XSSimpleType extendedSimpleType = extendedType.getSimpleType();
 
      XSSimpleType mySimpleType;
      if (extendedSimpleType.isAtomic()) {
        mySimpleType = factory.newXSAtomicType(this, extendedType, pRestriction);
      } else if (extendedSimpleType.isList()) {
        mySimpleType = factory.newXSListType(this, extendedType, pRestriction);
      } else if (extendedSimpleType.isUnion()) {
        mySimpleType = factory.newXSUnionType(this, extendedType, pRestriction);
      } else {
        throw new LocSAXException("Unknown restriction type: " + extendedType,
                              pRestriction.getLocator());
      }

      simpleType = mySimpleType;
      //was: setSimpleType( extendedType.getSimpleType() );
    } else {
      XsTLocalSimpleType localSimpleType = pRestriction.getSimpleType();
      XSType restrictedType;
      if (localSimpleType != null) {
        restrictedType = factory.newXSType(this, localSimpleType);
      } else {
        restrictedType = myComplexType.getSimpleContent().getType();
      }
      restrictedType.validate();
      XSSimpleType restrictedSimpleType = restrictedType.getSimpleType();
      if (restrictedSimpleType.isAtomic()) {
        simpleType = factory.newXSAtomicType(this, restrictedType, pRestriction);
      } else if (restrictedSimpleType.isList()) {
        simpleType = factory.newXSListType(this, restrictedType, pRestriction);
      } else if (restrictedSimpleType.isUnion()) {
        simpleType = factory.newXSUnionType(this, restrictedType, pRestriction);
      }
    }
    this.name = null;
    isSimple = true;
View Full Code Here

      result.validate();
      annotations = new XSAnnotation[]{result};
    }

    if (isSimple()) {
      XSSimpleType mySimpleType;
      Object baseObject = getXsObject();
      if (baseObject instanceof XsTSimpleType) {
        XsTSimpleType myXsTSimpleType = (XsTSimpleType) baseObject;
        XsEList list = myXsTSimpleType.getList();
        if (list == null) {
          XsEUnion union = myXsTSimpleType.getUnion();
          if (union == null) {
            XsERestriction restriction = myXsTSimpleType.getRestriction();
            if (restriction == null) {
              throw new LocSAXException("Either of the 'list', 'union', or 'restriction' child elements must be set.",
                  myXsTSimpleType.getLocator());
            }
            XsQName myName = restriction.getBase();
            XSType restrictedType;         
            if (myName == null) {
              XsTLocalSimpleType baseType = restriction.getSimpleType();
              if (baseType == null) {
                throw new LocSAXException("Neither the 'base' attribute nor an inner 'simpleType' element are present",
                    restriction.getLocator());
              } else {
                restrictedType = getXSSchema().getXSObjectFactory().newXSType(this, baseType);
              }
            } else {
              restrictedType = getXSSchema().getType(myName);
              if (restrictedType == null) {
                throw new LocSAXException("Unknown base type: " + myName,
                    restriction.getLocator());
              }
            }
            restrictedType.validate();
            if (!restrictedType.isSimple()) {
              throw new LocSAXException("The restricted type " + myName + " is complex.",
                  restriction.getLocator());
            }
            XSSimpleType baseType = restrictedType.getSimpleType();
            if (baseType.isAtomic()) {
              mySimpleType = getXSSchema().getXSObjectFactory().newXSAtomicType(this, restrictedType, restriction);
            } else if (baseType.isList()) {
              mySimpleType = getXSSchema().getXSObjectFactory().newXSListType(this, restrictedType, restriction);
            } else if (baseType.isUnion()) {
              mySimpleType = getXSSchema().getXSObjectFactory().newXSUnionType(this, restrictedType, restriction);
            } else {
              throw new LocSAXException("Unknown restriction type: " + baseType, restriction.getLocator());
            }
          } else {
View Full Code Here

    }
  }

  public XSSimpleType getSimpleType() throws SAXException {
    validate();
    XSSimpleType result = simpleType;
    if (result == null) {
      throw new IllegalStateException("This is a complex type.");
    }
    return result;
  }
View Full Code Here

  private SimpleTypeSGChain newSimpleTypeSG(TypeSG pController, SGFactory pFactory,
                                             SchemaSG pSchema, XSType pType) throws SAXException {
    if (!pType.isSimple()) {
      throw new IllegalStateException("Expected a simple type");
    }
    XSSimpleType simpleType = pType.getSimpleType();
    if (simpleType.isAtomic()) {
      if (pType.isGlobal()) {
        XsQName myName = pType.getName();
        if (myName.equals(XSEntity.getInstance().getName())      ||
            myName.equals(XSNotation.getInstance().getName())    ||
            myName.equals(XSGYearMonth.getInstance().getName())  ||
            myName.equals(XSGYear.getInstance().getName())       ||
            myName.equals(XSGMonthDay.getInstance().getName())   ||
            myName.equals(XSGMonth.getInstance().getName())      ||
            myName.equals(XSGDay.getInstance().getName())) {
          throw new SAXException("The type " + myName + " is not supported.");
        } else if (myName.equals(XSIDREF.getInstance().getName())) {
          return new IDREFSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSID.getInstance().getName())) {
          return new IDSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSByte.getInstance().getName())) {
          return new ByteSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSShort.getInstance().getName())) {
          return new ShortSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSInt.getInstance().getName())) {
          return new IntSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSLong.getInstance().getName())) {
          return new LongSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSUnsignedByte.getInstance().getName())  ||
                    myName.equals(XSUnsignedShort.getInstance().getName())) {
          return new UnsignedShortSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSUnsignedInt.getInstance().getName())) {
          return new UnsignedIntSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSInteger.getInstance().getName())             ||
                    myName.equals(XSNonPositiveInteger.getInstance().getName())  ||
                    myName.equals(XSNegativeInteger.getInstance().getName())     ||
                    myName.equals(XSUnsignedLong.getInstance().getName())        ||
                    myName.equals(XSPositiveInteger.getInstance().getName())     ||
                    myName.equals(XSNonNegativeInteger.getInstance().getName())) {
          return new IntegerSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSDecimal.getInstance().getName())) {
          return new DecimalSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSQName.getInstance().getName())) {
          return new QNameSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSDouble.getInstance().getName())) {
          return new DoubleSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSFloat.getInstance().getName())) {
          return new FloatSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSHexBinary.getInstance().getName())) {
          return new HexBinarySG(pFactory, pSchema, pType);
        } else if (myName.equals(XSBase64Binary.getInstance().getName())) {
          return new Base64BinarySG(pFactory, pSchema, pType);
        } else if (myName.equals(XSBoolean.getInstance().getName())) {
          return new BooleanSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSDate.getInstance().getName())) {
          return new DateSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSDateTime.getInstance().getName())) {
          return new DateTimeSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSTime.getInstance().getName())) {
          return new TimeSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSDuration.getInstance().getName())) {
          return new DurationSG(pFactory, pSchema, pType);
        } else if (myName.equals(XSAnySimpleType.getInstance().getName())     ||
                    myName.equals(XSString.getInstance().getName())            ||
                    myName.equals(XSAnyURI.getInstance().getName())            ||
                    myName.equals(XSNormalizedString.getInstance().getName())  ||
                    myName.equals(XSToken.getInstance().getName())             ||
                    myName.equals(XSLanguage.getInstance().getName())          ||
                    myName.equals(XSName.getInstance().getName())              ||
                    myName.equals(XSNMToken.getInstance().getName())           ||
                    myName.equals(XSNCName.getInstance().getName())) {
          return new StringSG(pFactory, pSchema, pType);
        }
      }

      SimpleTypeSGChain result = newSimpleTypeSG(pController, pFactory, pSchema, simpleType.getRestrictedType());

      result = new SimpleTypeRestrictionSG(result, pType, simpleType);

      if (simpleType.getEnumerations().length > 0) {
        boolean generateTypesafeEnumClass = false;
        String className = null;
        String packageName = null;

        if (simpleType instanceof JAXBSimpleType) {
          JAXBSimpleType jaxbSimpleType = (JAXBSimpleType) simpleType;
          JAXBTypesafeEnumClass jaxbTypesafeEnumClass = jaxbSimpleType.getJAXBTypesafeEnumClass();
          if (jaxbTypesafeEnumClass != null) {
            generateTypesafeEnumClass = true;
            className = jaxbTypesafeEnumClass.getName();
          }
        }

        if (!generateTypesafeEnumClass) {
          XSEnumeration[] enumerations = simpleType.getEnumerations();
          for (int i = 0;  i < enumerations.length;  i++) {
            XSEnumeration enumeration = enumerations[i];
            if (enumeration instanceof JAXBEnumeration) {
              JAXBEnumeration jaxbEnumeration = (JAXBEnumeration) enumeration;
              if (jaxbEnumeration.getJAXBTypesafeEnumMember() != null) {
                generateTypesafeEnumClass = true;
                break;
              }
            }
          }
        }

        if (!generateTypesafeEnumClass  &&  pType.isGlobal()) {
          XsQName[] qNames = new XsQName[]{XSNMToken.getInstance().getName()};
          XSSchema xsSchema = xsType.getXSSchema();
          if (xsSchema instanceof JAXBSchema) {
            JAXBSchema jaxbSchema = (JAXBSchema) xsSchema;
            JAXBGlobalBindings globalBindings = jaxbSchema.getJAXBGlobalBindings();
            if (globalBindings != null) {
              qNames = globalBindings.getTypesafeEnumBase();
            }
          }

          for (XSType restrType = xsType;  !generateTypesafeEnumClass;  ) {
            restrType = restrType.getSimpleType().getRestrictedType();
            if (restrType.isGlobal()) {
              for (int i = 0;  i < qNames.length;  i++) {
                if (qNames[i].equals(restrType.getName())) {
                  generateTypesafeEnumClass = true;
                  break;
                }
              }
              if (XSAnySimpleType.getInstance().getName().equals(restrType.getName())) {
                break;
              }
            }
          }
        }

        if (xsType instanceof JAXBType) {
          JAXBSchemaBindings jaxbSchemaBindings = ((JAXBType) xsType).getJAXBSchemaBindings();
          if (jaxbSchemaBindings != null) {
            JAXBSchemaBindings.Package jaxbPackage = jaxbSchemaBindings.getPackage();
            if (jaxbPackage != null) {
              packageName = jaxbPackage.getName();
            }
          }
        }
        if (packageName == null) {
          XsQName qName = pController.getName();
          packageName = AbstractContext.getPackageNameFromURI(pController.getLocator(), qName.getNamespaceURI());
        }

        if (generateTypesafeEnumClass) {
          if (className == null) {
            XsQName qName = pType.isGlobal() ? pType.getName() : pController.getName();
            className = AbstractContext.getClassNameFromLocalName(pController.getLocator(),
                                                                  qName.getLocalName(),
                                                                  pSchema) + "Class";
          }
          result = new EnumerationSG(result, JavaQNameImpl.getInstance(packageName, className), pType);
        }
      }

      return result;
    } else if (simpleType.isList()) {
      return new ListTypeSGImpl(pFactory, pSchema, pType, classContext, pController.getName());
    } else if (simpleType.isUnion()) {
      return new UnionTypeSGImpl(pFactory, pSchema, pType, classContext, pController.getName());
    } else {
      throw new IllegalStateException("Simple type " + pType + " is neither of atomic, list, or union");
    }
  }
View Full Code Here

    return result;
  }

  protected XSSimpleType assertSimpleType(XSType pType) throws SAXException {
    assertTrue(pType.isSimple());
    XSSimpleType result = pType.getSimpleType();
    assertNotNull(result);
    boolean haveException = false;
    try {
      pType.getComplexType();
    } catch (IllegalStateException e) {
View Full Code Here

   */
  protected EnumerationSG(SimpleTypeSGChain o, JavaQName pName, XSType pType) throws SAXException {
    super(o);
    qName = pName;

    XSSimpleType simpleType = pType.getSimpleType();
    XSEnumeration[] enumerations = simpleType.getEnumerations();
    List enums = new ArrayList();
    for (int i = 0;  i < enumerations.length;  i++) {
      XSEnumeration en = enumerations[i];
      String name = null;
      String value = en.getValue();
View Full Code Here

    XSType[] types = schema.getTypes();
    assertEquals(3, types.length);

    XSType t1 = types[0];
    assertEquals(new XsQName((String) null, "a"), t1.getName());
    XSSimpleType st1 = assertSimpleType(t1);
    assertAtomicType(st1);
    XSType t1_1 = assertRestriction(st1);
    assertEquals(XSString.getInstance(), t1_1);

    XSType t2 = types[1];
    assertEquals(new XsQName((String) null, "b"), t2.getName());
    XSSimpleType st2 = assertSimpleType(t2);
    XSListType lt = assertListType(st2);
    XSType it = lt.getItemType();
    assertNotNull(it);
    assertEquals(XSInt.getInstance(), it);
    XSSimpleType it2 = assertSimpleType(it);
    assertAtomicType(it2);

    XSType t3 = types[2];
    assertEquals(new XsQName((String) null, "c"), t3.getName());
    XSSimpleType st3 = assertSimpleType(t3);
    XSUnionType ut3 = assertUnionType(st3);
    XSType[] memberTypes = ut3.getMemberTypes();
    assertEquals(2, memberTypes.length);
    XSType mt3_1 = memberTypes[0];
    assertEquals(mt3_1, t1);
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.xs.XSSimpleType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.