Example usage for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED

List of usage examples for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED.

Prototype

int FIELD_UNDEFINED

To view the source code for javax.xml.datatype DatatypeConstants FIELD_UNDEFINED.

Click Source Link

Document

Designation that an "int" field is not set.

Usage

From source file:org.betaconceptframework.astroboa.engine.jcr.io.Serializer.java

private String convertCalendarToXMLFormat(Calendar calendar, boolean dateTimePattern) {
    if (dateTimePattern) {
        GregorianCalendar gregCalendar = new GregorianCalendar(calendar.getTimeZone());
        gregCalendar.setTimeInMillis(calendar.getTimeInMillis());

        return df.newXMLGregorianCalendar(gregCalendar).toXMLFormat();
    } else {//from   w  w w  . j  a va 2s . c o m
        return df.newXMLGregorianCalendarDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, // Calendar.MONTH is zero based, XSD Date datatype's month field starts
                //   with JANUARY as 1.
                calendar.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED).toXMLFormat();
    }
}

From source file:org.betaconceptframework.astroboa.model.jaxb.visitor.ContentObjectMarshalVisitor.java

protected <T> void marshallValueForSimpleProperty(SimpleCmsPropertyDefinition<T> simplePropertyDefinition,
        CmsPropertyInfo simpleCmsProperty, Object value) {

    if (value != null) {

        switch (simplePropertyDefinition.getValueType()) {
        case String:
        case Boolean:
        case Double:
        case Long:
        case Date:

            final SimpleCmsPropertyType simpleCmsPropertyType = new SimpleCmsPropertyType();

            simpleCmsPropertyType.setExportAsAnAttribute(
                    ((SimpleCmsPropertyDefinitionImpl) simplePropertyDefinition).isRepresentsAnXmlAttribute());

            if (marshalOutputTypeIsJSON() && simplePropertyDefinition.isMultiple()) {
                simpleCmsPropertyType.setExportAsAnArray(true);
            }//from   w ww.  j  a va  2 s.co  m

            CmsPropertyTypeJAXBElement<SimpleCmsPropertyType> simpleCmsPropertyTypeJaxbElement = new CmsPropertyTypeJAXBElement(
                    new QName(simplePropertyDefinition.getQualifiedName().getLocalPart()),
                    SimpleCmsPropertyType.class, null, simpleCmsPropertyType);

            if (value instanceof String) {
                simpleCmsPropertyTypeJaxbElement.getValue().setContent((String) value);
            } else if (value instanceof Boolean) {
                simpleCmsPropertyTypeJaxbElement.getValue().setContent(((Boolean) value).toString());
            } else if (value instanceof Double) {
                simpleCmsPropertyTypeJaxbElement.getValue().setContent(((Double) value).toString());
            } else if (value instanceof Long) {
                simpleCmsPropertyTypeJaxbElement.getValue().setContent(((Long) value).toString());
            } else if (value instanceof Calendar) {
                Calendar calendar = (Calendar) value;

                try {
                    if (((CalendarPropertyDefinition) simplePropertyDefinition).isDateTime()) {
                        GregorianCalendar gregCalendar = new GregorianCalendar(calendar.getTimeZone());
                        gregCalendar.setTimeInMillis(calendar.getTimeInMillis());

                        simpleCmsPropertyTypeJaxbElement.getValue()
                                .setContent(df.newXMLGregorianCalendar(gregCalendar).toXMLFormat());
                    } else {
                        simpleCmsPropertyTypeJaxbElement.getValue()
                                .setContent(df.newXMLGregorianCalendarDate(calendar.get(Calendar.YEAR),
                                        calendar.get(Calendar.MONTH) + 1, // Calendar.MONTH is zero based, XSD Date datatype's month field starts
                                        //   with JANUARY as 1.
                                        calendar.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED)
                                        .toXMLFormat());
                    }
                } catch (Exception e) {
                    throw new CmsException("Property " + simpleCmsProperty.getFullPath() + " Calendar value "
                            + DateUtils.format(calendar), e);
                }
            } else {
                throw new CmsException("Property " + simpleCmsProperty.getFullPath() + " has value type "
                        + simplePropertyDefinition.getValueType() + " but contains value of type "
                        + value.getClass().getName());
            }

            addJaxbElementToCurrentParentComplexCmsPropertyType(simpleCmsPropertyTypeJaxbElement);

            break;
        case TopicReference:

            try {
                TopicType topicType = marshalTopicReference(value);

                if (marshalOutputTypeIsJSON() && simplePropertyDefinition.isMultiple()) {
                    topicType.setExportAsAnArray(true);
                }

                CmsPropertyTypeJAXBElement<TopicType> topicTypeJaxbElement = new CmsPropertyTypeJAXBElement(
                        new QName(simplePropertyDefinition.getQualifiedName().getLocalPart()), TopicType.class,
                        null, topicType);

                addJaxbElementToCurrentParentComplexCmsPropertyType(topicTypeJaxbElement);

            } catch (Exception e) {
                throw new CmsException("Unable to marshal topic " + ((Topic) value).getName(), e);
            }

            break;
        case Binary:
            try {
                BinaryChannelType binaryChannelType = getBinaryChannelAdapter().marshal((BinaryChannel) value);

                if (marshalOutputTypeIsJSON() && simplePropertyDefinition.isMultiple()) {
                    binaryChannelType.setExportAsAnArray(true);
                }

                CmsPropertyTypeJAXBElement<BinaryChannelType> binaryChannelTypeJaxbElement = new CmsPropertyTypeJAXBElement(
                        new QName(simplePropertyDefinition.getQualifiedName().getLocalPart()),
                        BinaryChannelType.class, null, binaryChannelType);

                addJaxbElementToCurrentParentComplexCmsPropertyType(binaryChannelTypeJaxbElement);

            } catch (Exception e) {
                throw new CmsException("Unable to marshal binary channel " + ((BinaryChannel) value).getName(),
                        e);
            }

            break;
        case ObjectReference:
            try {

                logger.debug("\t Property is a reference to another object");

                Marshaller objectReferenceMarshaller = CmsEntitySerialization.Context
                        .createMarshaller(marshalOutputTypeIsJSON() ? ResourceRepresentationType.JSON
                                : ResourceRepresentationType.XML, prettyPrintIsEnabled());

                //For now only porifle.title is provided. 
                objectReferenceMarshaller.setProperty(AstroboaMarshaller.CMS_PROPERTIES_TO_BE_MARSHALLED,
                        Arrays.asList("profile.title"));

                ContentObjectAdapter adapter = new ContentObjectAdapter();
                adapter.setMarshaller(objectReferenceMarshaller, marshallBinaryContent, false);
                objectReferenceMarshaller.setAdapter(adapter);

                ContentObjectType contentObjectType = objectReferenceMarshaller
                        .getAdapter(ContentObjectAdapter.class).marshal((ContentObject) value);

                if (marshalOutputTypeIsJSON() && simplePropertyDefinition.isMultiple()) {
                    contentObjectType.setExportAsAnArray(true);
                }

                CmsPropertyTypeJAXBElement<ContentObjectType> contentObjectReferenceTypeJaxbElement = new CmsPropertyTypeJAXBElement(
                        new QName(simplePropertyDefinition.getQualifiedName().getLocalPart()),
                        ContentObjectType.class, null, contentObjectType);

                addJaxbElementToCurrentParentComplexCmsPropertyType(contentObjectReferenceTypeJaxbElement);

            } catch (Exception e) {
                throw new CmsException("Unable to marshal contentObject " + ((ContentObject) value).getId(), e);
            }

            break;
        default:
            break;
        }

    }
}

From source file:org.betaconceptframework.astroboa.test.engine.AbstractRepositoryTest.java

protected String convertCalendarToXMLFormat(Calendar calendar, boolean dateTimePattern) {
     if (dateTimePattern) {
         GregorianCalendar gregCalendar = new GregorianCalendar(calendar.getTimeZone());
         gregCalendar.setTimeInMillis(calendar.getTimeInMillis());

         return df.newXMLGregorianCalendar(gregCalendar).toXMLFormat();
     } else {//from  w w  w.jav  a 2  s  .c om
         return df.newXMLGregorianCalendarDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH) + 1, // Calendar.MONTH is zero based, XSD Date datatype's month field starts
                 //   with JANUARY as 1.
                 calendar.get(Calendar.DAY_OF_MONTH), DatatypeConstants.FIELD_UNDEFINED).toXMLFormat();
     }
 }

From source file:org.eclipse.smila.ontology.records.SesameRecordReader.java

/**
 * get only the date (year, month, day) part of the calendar literal, don't calculate with timezones.
 * /*  ww w.jav a  2s. c  om*/
 * @param ontoCal
 *          a ontology calendar literal value.
 * @return a Calendar with only the date part.
 */
private Calendar getDateOnly(final XMLGregorianCalendar ontoCal) {
    final Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(0);
    if (ontoCal.getYear() != DatatypeConstants.FIELD_UNDEFINED) {
        cal.set(Calendar.YEAR, ontoCal.getYear());
    }
    if (ontoCal.getMonth() != DatatypeConstants.FIELD_UNDEFINED) {
        cal.set(Calendar.MONTH, ontoCal.getMonth() - 1);
    }
    if (ontoCal.getDay() != DatatypeConstants.FIELD_UNDEFINED) {
        cal.set(Calendar.DAY_OF_MONTH, ontoCal.getDay());
    }
    return cal;
}

From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java

private XMLGregorianCalendar convertToXMLDateTime(DatatypeFactory dataTypeFactory, DateTime documentDate) {
    return dataTypeFactory.newXMLGregorianCalendar(documentDate.getYear(), documentDate.getMonthOfYear(),
            documentDate.getDayOfMonth(), documentDate.getHourOfDay(), documentDate.getMinuteOfHour(),
            documentDate.getSecondOfMinute(), 0, DatatypeConstants.FIELD_UNDEFINED);
}

From source file:org.fenixedu.treasury.services.integration.erp.ERPExporter.java

private Header createSAFTHeader(DateTime startDate, DateTime endDate, FinantialInstitution finantialInstitution,
        String auditVersion) {// w w w  .ja  v a  2s.  c  o  m

    Header header = new Header();
    DatatypeFactory dataTypeFactory;
    try {

        dataTypeFactory = DatatypeFactory.newInstance();

        // AuditFileVersion
        header.setAuditFileVersion(auditVersion);

        // BusinessName - Nome da Empresa
        header.setBusinessName(finantialInstitution.getCompanyName());
        header.setCompanyName(finantialInstitution.getName());

        // CompanyAddress
        AddressStructurePT companyAddress = null;
        //TODOJN Locale por resolver
        companyAddress = convertAddressToAddressPT(finantialInstitution.getAddress(),
                finantialInstitution.getZipCode(),
                finantialInstitution.getMunicipality() != null
                        ? finantialInstitution.getMunicipality().getLocalizedName(new Locale("pt"))
                        : "---",
                finantialInstitution.getAddress());
        header.setCompanyAddress(companyAddress);

        // CompanyID
        /*
         * Obtem -se pela concatena??o da conservat?ria do registo comercial
         * com o n?mero do registo comercial, separados pelo car?cter
         * espa?o. Nos casos em que n?o existe o registo comercial, deve ser
         * indicado o NIF.
         */
        header.setCompanyID(finantialInstitution.getComercialRegistrationCode());

        // CurrencyCode
        /*
         * 1.11 * C?digo de moeda (CurrencyCode) . . . . . . . Preencher com
         * ?EUR?
         */
        header.setCurrencyCode(finantialInstitution.getCurrency().getCode());

        // DateCreated
        DateTime now = new DateTime();
        header.setDateCreated(convertToXMLDateTime(dataTypeFactory, now));

        // Email
        // header.setEmail(StringUtils.EMPTY);

        // EndDate
        header.setEndDate(convertToXMLDateTime(dataTypeFactory, endDate));

        // Fax
        // header.setFax(StringUtils.EMPTY);

        // FiscalYear
        /*
         * Utilizar as regras do c?digo do IRC, no caso de per?odos
         * contabil?sticos n?o coincidentes com o ano civil. (Ex: per?odo de
         * tributa??o de 01 -10 -2008 a 30 -09 -2009 corresponde FiscalYear
         * 2008). Inteiro 4
         */
        header.setFiscalYear(endDate.getYear());

        // Ir obter a data do ?ltimo
        // documento(por causa de submeter em janeiro, documentos de
        // dezembro)

        // HeaderComment
        // header.setHeaderComment(org.apache.commons.lang.StringUtils.EMPTY);

        // ProductCompanyTaxID
        // Preencher com o NIF da entidade produtora do software
        header.setProductCompanyTaxID(SaftConfig.PRODUCT_COMPANY_TAX_ID());

        // ProductID
        /*
         * 1.16 * Nome do produto (ProductID). . . . . . . . . . . Nome do
         * produto que gera o SAF -T (PT) . . . . . . . . . . . Deve ser
         * indicado o nome comercial do software e o da empresa produtora no
         * formato ?Nome produto/nome empresa?.
         */
        header.setProductID(SaftConfig.PRODUCT_ID());

        // Product Version
        header.setProductVersion(SaftConfig.PRODUCT_VERSION());

        // SoftwareCertificateNumber
        header.setSoftwareCertificateNumber(BigInteger.valueOf(SaftConfig.SOFTWARE_CERTIFICATE_NUMBER()));

        // StartDate
        header.setStartDate(dataTypeFactory.newXMLGregorianCalendarDate(startDate.getYear(),
                startDate.getMonthOfYear(), startDate.getDayOfMonth(), DatatypeConstants.FIELD_UNDEFINED));

        // TaxAccountingBasis
        /*
         * Deve ser preenchido com: contabilidade; facturao; ?I? ? dados
         * integrados de factura??o e contabilidade; ?S? ? autofactura??o;
         * ?P? ? dados parciais de factura??o
         */
        header.setTaxAccountingBasis("P");

        // TaxEntity
        /*
         * Identifica??o do estabelecimento (TaxEntity) No caso do ficheiro
         * de factura??o dever? ser especificado a que estabelecimento diz
         * respeito o ficheiro produzido, se aplic?vel, caso contr?rio,
         * dever? ser preenchido com a especifica??o ?Global?. No caso do
         * ficheiro de contabilidade ou integrado, este campo dever? ser
         * preenchido com a especifica??o ?Sede?. Texto 20
         */
        header.setTaxEntity("Global");

        // TaxRegistrationNumber
        /*
         * N?mero de identifica??o fiscal da empresa
         * (TaxRegistrationNumber). Preencher com o NIF portugu?s sem
         * espa?os e sem qualquer prefixo do pa?s. Inteiro 9
         */
        try {
            header.setTaxRegistrationNumber(Integer.parseInt(finantialInstitution.getFiscalNumber()));
        } catch (Exception ex) {
            throw new RuntimeException("Invalid Fiscal Number.");
        }

        // header.setTelephone(finantialInstitution.get);

        // header.setWebsite(finantialInstitution.getEmailContact());

        return header;
    } catch (DatatypeConfigurationException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.openanzo.rdf.utils.StatementUtils.java

/**
 * Convert an xsd:dateTime Literal to its long representation. Note that xsd:dateTime allows the time zone to be omitted. However, to convert a literal to a
 * millisecond value, requires a time zone. That's because the millisecond long value is supposed to represent an absolute time. that is, milliseconds since
 * January 1, 1970, 00:00:00 GMT. Without a time zone in the xsd:dateTime literal, that number cannot be derived.
 * //from ww w .  java2  s  . c om
 * Note that this may cause information loss. xsd:dateTime support arbitrary precision fractional seconds. This method reduces the precision to
 * milliseconds.
 * 
 * @param dateTime
 *            xsd:dateTime Literal to convert
 * @return long representation of literal. null if the literal couldn't be parsed into a long such as for lack of a time zone being specified in the
 *         literal.
 */
protected static Long convertToMilliseconds(TypedLiteral dateTime) {
    Long ret = null;
    Object nativeValue = dateTime.getNativeValue();
    if (nativeValue instanceof XMLGregorianCalendar) {
        XMLGregorianCalendar xmlCal = (XMLGregorianCalendar) nativeValue;
        try {
            if (xmlCal.getXMLSchemaType().equals(DatatypeConstants.DATETIME)
                    && xmlCal.getTimezone() != DatatypeConstants.FIELD_UNDEFINED) {
                ret = xmlCal.toGregorianCalendar().getTimeInMillis();
            }
        } catch (IllegalStateException e) {
            // XMLGregorianCalendar#getXMLSchemaType() will throw an IllegalStateException if the XMLGregorianCalendar is invalid.
            log.debug(LogUtils.GLITTER_MARKER,
                    "Error parsing dateTime literal into millisecond representation: {}", dateTime.toString());
        }
    }
    return ret;
}

From source file:org.openanzo.test.client.TestDateTime.java

/**
 * Test that XMLGregorianCalendar objects of various flavors are converted into the appropriate lexical representation with the appropriate datatype.
 * //  w w w . java2  s  .  c o  m
 * @throws Exception
 */
public void testXsdTimeRelatedTypeLiteralsBecomeXMLGregorianCalendar() throws Exception {

    AnzoClient client = null;
    try {
        client = new AnzoClient(getDefaultClientConfiguration());
        client.connect();
        client.reset(loadStatements("initialize.trig"), null);
        ClientGraph graph = client.getReplicaGraph(GRAPH_URI);

        DatatypeFactory df = DatatypeFactory.newInstance();

        // xsd:dateTime
        // Without time zone
        XMLGregorianCalendar cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357,
                DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11T16:48:32.357", XMLSchema.DATETIME, cal);
        // Without time zone without fractional seconds
        cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 12, 16, 48, 32,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-12T16:48:32", XMLSchema.DATETIME, cal);
        // With time zone
        cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357, 7 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11T16:48:32.357+07:00", XMLSchema.DATETIME,
                cal);
        // With time zone and nanosecond precision 
        cal = df.newXMLGregorianCalendar(BigInteger.valueOf(2008), DatatypeConstants.JULY, 11, 16, 48, 32,
                BigDecimal.valueOf(123665845, 9), -8 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11T16:48:32.123665845-08:00",
                XMLSchema.DATETIME, cal);
        // UTC
        cal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357, 0);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11T16:48:32.357Z", XMLSchema.DATETIME, cal);

        // xsd:date
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, 12,
                DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-12", XMLSchema.DATE, cal);
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, 11, -8 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-11-08:00", XMLSchema.DATE, cal);

        // xsd:time
        // Without time zone
        cal = df.newXMLGregorianCalendarTime(16, 48, 32, 357, DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "16:48:32.357", XMLSchema.TIME, cal);
        // With time zone
        cal = df.newXMLGregorianCalendarTime(16, 48, 32, 357, 4 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "16:48:32.357+04:00", XMLSchema.TIME, cal);

        // xsd:gYearMonth
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.JULY, DatatypeConstants.FIELD_UNDEFINED,
                -4 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-07-04:00", XMLSchema.GYEARMONTH, cal);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2008, DatatypeConstants.AUGUST, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "2008-08", XMLSchema.GYEARMONTH, cal);

        // xsd:gYear
        // With time zone
        cal = df.newXMLGregorianCalendarDate(2009, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, -6 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "2009-06:00", XMLSchema.GYEAR, cal);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(2010, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "2010", XMLSchema.GYEAR, cal);

        // xsd:gMonthDay
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.JULY, 15,
                -6 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "--07-15-06:00", XMLSchema.GMONTHDAY, cal);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.JULY, 16,
                DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "--07-16", XMLSchema.GMONTHDAY, cal);

        // xsd:gMonth
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.AUGUST,
                DatatypeConstants.FIELD_UNDEFINED, -6 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "--08-06:00", XMLSchema.GMONTH, cal);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.SEPTEMBER,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "--09", XMLSchema.GMONTH, cal);

        // xsd:gDay
        // With time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, 15, -6 * 60);
        retrieveLexicalLiteralAsNativeType(client, graph, "---15-06:00", XMLSchema.GDAY, cal);
        // Without time zone
        cal = df.newXMLGregorianCalendarDate(DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, 16, DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "---16", XMLSchema.GDAY, cal);

    } finally {
        if (client != null) {
            client.close();
        }
    }
}

From source file:org.openanzo.test.client.TestDateTime.java

/**
 * Test that Duration objects of various flavors are converted into the appropriate lexical representation with the appropriate datatype.
 * /*w w  w. j  ava 2  s  .c o m*/
 * @throws Exception
 */
public void testXsdDurationRelatedTypeLiteralsBecomeDuration() throws Exception {

    AnzoClient client = null;
    try {
        client = new AnzoClient(getDefaultClientConfiguration());
        client.connect();
        client.reset(loadStatements("initialize.trig"), null);
        ClientGraph graph = client.getReplicaGraph(GRAPH_URI);

        DatatypeFactory df = DatatypeFactory.newInstance();

        // xsd:duration
        Duration duration = df.newDuration(true, 28, 5, 16, 1, 15, 37);
        retrieveLexicalLiteralAsNativeType(client, graph, "P28Y5M16DT1H15M37S", XMLSchema.DURATION, duration);

        // xsd:yearMonthDuration
        duration = df.newDuration(true, 28, 5, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED,
                DatatypeConstants.FIELD_UNDEFINED);
        retrieveLexicalLiteralAsNativeType(client, graph, "P28Y5M", XMLSchema.DURATION_YEARMONTH, duration);

        // xsd:dayTimeDuration
        duration = df.newDuration(true, DatatypeConstants.FIELD_UNDEFINED, DatatypeConstants.FIELD_UNDEFINED,
                16, 1, 15, 37);
        retrieveLexicalLiteralAsNativeType(client, graph, "P16DT1H15M37S", XMLSchema.DURATION_DAYTIME,
                duration);

    } finally {
        if (client != null) {
            client.close();
        }
    }
}

From source file:org.openanzo.test.client.TestDateTime.java

/**
 * Test the conversion of java.util.Calendar objects in the Anzo.java API into xsd:dateTime RDF literals with time zones. The test will add statements using
 * java.util.Calendar objects and verify that when those statements are retrieved, the expected lexical value, datatype, etc. are correct.
 * /* ww  w  .j  ava  2 s .  c om*/
 * @throws Exception
 */
public void testCalendarBecomesXsdDateTime() throws Exception {

    AnzoClient client = null;
    try {
        client = new AnzoClient(getDefaultClientConfiguration());
        client.connect();
        client.reset(loadStatements("initialize.trig"), null);
        ClientGraph graph = client.getReplicaGraph(GRAPH_URI);

        DatatypeFactory df = DatatypeFactory.newInstance();

        // UTC
        Calendar cal = getCleanCalendar();
        cal.set(2008, Calendar.JULY, 11, 16, 48, 32);
        XMLGregorianCalendar xmlcal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32,
                DatatypeConstants.FIELD_UNDEFINED, 0);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2008-07-11T16:48:32Z", XMLSchema.DATETIME);

        // Time zone offset
        cal = getCleanCalendar();
        cal.set(2008, Calendar.JULY, 11, 16, 48, 32);
        cal.setTimeZone(TimeZone.getTimeZone("GMT-09:00"));
        xmlcal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32,
                DatatypeConstants.FIELD_UNDEFINED, -9 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2008-07-11T16:48:32-09:00",
                XMLSchema.DATETIME);

        // Fractional seconds
        cal = getCleanCalendar();
        cal.set(2008, Calendar.JULY, 11, 16, 48, 32);
        cal.set(Calendar.MILLISECOND, 357);
        cal.setTimeZone(TimeZone.getTimeZone("GMT-03:00"));
        xmlcal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 16, 48, 32, 357, -3 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2008-07-11T16:48:32.357-03:00",
                XMLSchema.DATETIME);

        // A partially filled Calendar still ends up as a fully specified xsd:dateTime with the default values
        // used for unspecified fields (i.e. 0 for time fields, January for month, 1 for day of month, etc.) 
        cal = getCleanCalendar();
        cal.set(2008, Calendar.JULY, 11);
        cal.setTimeZone(TimeZone.getTimeZone("GMT-03:00"));
        xmlcal = df.newXMLGregorianCalendar(2008, DatatypeConstants.JULY, 11, 0, 0, 0,
                DatatypeConstants.FIELD_UNDEFINED, -3 * 60);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2008-07-11T00:00:00-03:00",
                XMLSchema.DATETIME);

        // Another partially filled Calendar. 
        cal = getCleanCalendar();
        cal.set(Calendar.YEAR, 2012);
        xmlcal = df.newXMLGregorianCalendar(2012, DatatypeConstants.JANUARY, 1, 0, 0, 0,
                DatatypeConstants.FIELD_UNDEFINED, 0);
        addAndRetrieveNativeLiteral(client, graph, cal, xmlcal, "2012-01-01T00:00:00Z", XMLSchema.DATETIME);

    } finally {
        if (client != null) {
            client.close();
        }
    }
}