Example usage for javax.xml.datatype DatatypeFactory newInstance

List of usage examples for javax.xml.datatype DatatypeFactory newInstance

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newInstance.

Prototype

public static DatatypeFactory newInstance() throws DatatypeConfigurationException 

Source Link

Document

Obtain a new instance of a DatatypeFactory .

Usage

From source file:org.apache.juddi.webconsole.hub.UddiHub.java

/**
 * Returns bootstrap stylized html representing all changes in the last
 * refresh// ww w .  java  2s .  com
 *
 * @param lastRefresh
 * @return formatted html
 * @throws DatatypeConfigurationException
 */
public String GetNewsFeed(XMLGregorianCalendar lastRefresh) throws DatatypeConfigurationException {
    if (GetToken() == null) {
        return ToErrorAlert(ResourceLoader.GetResource(session, "errors.notsignedin"));
    }
    if (df == null) {
        df = DatatypeFactory.newInstance();
    }
    List<Subscription> subscriptions = new ArrayList<Subscription>();
    try {
        try {
            subscriptions = subscription.getSubscriptions(GetToken());

        } catch (Exception ex) {
            if (isExceptionExpiration(ex)) {
                token = null;

                subscriptions = subscription.getSubscriptions(GetToken());

            } else {
                throw ex;
            }
        }
    } catch (Exception ex) {
        return HandleException(ex);
    }

    GregorianCalendar gcal = new GregorianCalendar();
    gcal.setTimeInMillis(System.currentTimeMillis());

    GetSubscriptionResults r = new GetSubscriptionResults();
    r.setAuthInfo(GetToken());
    r.setCoveragePeriod(new CoveragePeriod());
    r.getCoveragePeriod().setEndPoint(df.newXMLGregorianCalendar(gcal));

    r.getCoveragePeriod().setStartPoint(lastRefresh);
    StringBuilder sb = new StringBuilder();
    if (subscriptions.isEmpty()) {
        return ToErrorAlert(ResourceLoader.GetResource(session, "errors.subscriptionfeed.nosubs"));
    }
    for (int k = 0; k < subscriptions.size(); k++) {

        r.setSubscriptionKey(subscriptions.get(k).getSubscriptionKey());
        SubscriptionResultsList subscriptionResults = null;
        try {
            try {
                subscriptionResults = subscription.getSubscriptionResults(r);

            } catch (Exception ex) {
                if (isExceptionExpiration(ex)) {
                    token = null;
                    r.setAuthInfo(GetToken());
                    subscriptionResults = subscription.getSubscriptionResults(r);

                } else {
                    throw ex;
                }
            }
        } catch (Exception ex) {
            return HandleException(ex);
        }

        if (subscriptionResults != null) {
            //    subscriptionResults.getAssertionStatusReport().
            if (subscriptionResults.getAssertionStatusReport() != null) {
                sb.append(ResourceLoader.GetResource(session, "items.subscriptions.assertion"))
                        .append("<table class=\"table table-hover\">");
                for (int i = 0; i < subscriptionResults.getAssertionStatusReport().getAssertionStatusItem()
                        .size(); i++) {
                    sb.append("<tr><td>");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getAssertionStatusReport()
                            .getAssertionStatusItem().get(i).getFromKey()));
                    sb.append("</td><td>");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getAssertionStatusReport()
                            .getAssertionStatusItem().get(i).getToKey()));
                    sb.append("</td><td>");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getAssertionStatusReport()
                            .getAssertionStatusItem().get(i).getCompletionStatus().toString()));
                    sb.append("</td></tr>");
                }
                sb.append("</table><br>");
            }
            if (subscriptionResults.getBindingDetail() != null) {
                sb.append(ResourceLoader.GetResource(session, "items.subscriptions.bindings"))
                        .append("<table class=\"table table-hover\">");
                for (int i = 0; i < subscriptionResults.getBindingDetail().getBindingTemplate().size(); i++) {
                    sb.append("<tr><td>");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getBindingDetail()
                            .getBindingTemplate().get(i).getServiceKey()));
                    sb.append("</td><td>");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getBindingDetail()
                            .getBindingTemplate().get(i).getBindingKey()));
                    sb.append("</td></tr>");
                }
                sb.append("</table><br>");
            }
            if (subscriptionResults.getBusinessDetail() != null) {
                sb.append(ResourceLoader.GetResource(session, "items.subscriptions.business"))
                        .append("<table class=\"table table-hover\">");
                for (int i = 0; i < subscriptionResults.getBusinessDetail().getBusinessEntity().size(); i++) {
                    sb.append("<tr><td><a href=\"businessEditor2.jsp?id=");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getBusinessDetail()
                            .getBusinessEntity().get(i).getBusinessKey()));
                    sb.append("\">");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getBusinessDetail()
                            .getBusinessEntity().get(i).getBusinessKey()));
                    sb.append("<i class=\"icon-large icon-edit\"></i></a></td></tr>");
                }
                sb.append("</table><br>");
            }
            if (subscriptionResults.getRelatedBusinessesList() != null) {
                sb.append(ResourceLoader.GetResource(session, "items.subscriptions.assertion2"))
                        .append("<table class=\"table table-hover\">");
                // for (int i = 0; i < subscriptionResults.getRelatedBusinessesList().getBusinessKey().size(); i++) {
                sb.append("<tr><td>");
                sb.append(StringEscapeUtils
                        .escapeHtml(subscriptionResults.getRelatedBusinessesList().getBusinessKey()));
                sb.append("</td></tr>");
                //}
                sb.append("</table><br>");
            }
            if (subscriptionResults.getServiceDetail() != null) {
                sb.append(ResourceLoader.GetResource(session, "items.subscriptions.services"))
                        .append("<table class=\"table table-hover\">");
                for (int i = 0; i < subscriptionResults.getServiceDetail().getBusinessService().size(); i++) {
                    sb.append("<tr><td><a href=\"serviceEditor.jsp?id=");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getServiceDetail()
                            .getBusinessService().get(i).getServiceKey()));
                    sb.append("\">");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getServiceDetail()
                            .getBusinessService().get(i).getServiceKey()));
                    sb.append("<i class=\"icon-large icon-edit\"></i></a></td></tr>");
                }
                sb.append("</table><br>");
            }
            if (subscriptionResults.getServiceList() != null) {
                sb.append(ResourceLoader.GetResource(session, "items.subscriptions.servicelist"))
                        .append("<table class=\"table table-hover\">");
                for (int i = 0; i < subscriptionResults.getServiceList().getServiceInfos().getServiceInfo()
                        .size(); i++) {
                    sb.append("<tr><td>");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getServiceList()
                            .getServiceInfos().getServiceInfo().get(i).getServiceKey()));

                    sb.append("</td><td>");
                    sb.append(StringEscapeUtils.escapeHtml(Printers.ListNamesToString(subscriptionResults
                            .getServiceList().getServiceInfos().getServiceInfo().get(i).getName())));
                    sb.append("</td></tr>");
                }
                sb.append("</table><br>");
            }
            if (subscriptionResults.getTModelDetail() != null) {
                sb.append(ResourceLoader.GetResource(session, "items.subscriptions.tmodels"))
                        .append("<br><table class=\"table table-hover\">");
                for (int i = 0; i < subscriptionResults.getTModelDetail().getTModel().size(); i++) {
                    sb.append("<tr><td>");
                    sb.append(StringEscapeUtils.escapeHtml(
                            subscriptionResults.getTModelDetail().getTModel().get(i).getTModelKey()));
                    sb.append("</td><td>");
                    sb.append(StringEscapeUtils.escapeHtml(
                            (subscriptionResults.getTModelDetail().getTModel().get(i).getName().getValue())));
                    sb.append("</td></tr>");
                }
                sb.append("</table><br>");
            }
            if (subscriptionResults.getTModelList() != null) {
                sb.append(ResourceLoader.GetResource(session, "items.subscriptions.tmodels2"))
                        .append("<table class=\"table table-hover\">");
                for (int i = 0; i < subscriptionResults.getTModelList().getTModelInfos().getTModelInfo()
                        .size(); i++) {
                    sb.append("<tr><td><a href=\"serviceEditor.jsp?id=");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getTModelList().getTModelInfos()
                            .getTModelInfo().get(i).getTModelKey()));
                    sb.append("\">");
                    sb.append(StringEscapeUtils.escapeHtml(subscriptionResults.getTModelList().getTModelInfos()
                            .getTModelInfo().get(i).getTModelKey()));
                    sb.append("<i class=\"icon-large icon-edit\"></i></a></td><td>");
                    sb.append(StringEscapeUtils.escapeHtml((subscriptionResults.getTModelList().getTModelInfos()
                            .getTModelInfo().get(i).getName().getValue())));
                    sb.append("</td></tr>");
                }
                sb.append("</table>");
            }

        }
    }
    return sb.toString();
}

From source file:org.apache.lens.cli.TestLensQueryCommands.java

/**
 * Sets up query command instances and adds partitions to a table.
 * @throws Exception//from   w  w w.j  a v a2 s  . c o m
 */
@BeforeClass
public void setup() throws Exception {
    LensClient client = new LensClient();
    LensCubeCommands command = new LensCubeCommands();
    command.setClient(client);

    log.debug("Starting to test cube commands");
    URL cubeSpec = TestLensQueryCommands.class.getClassLoader()
            .getResource("schema/cubes/base/sample-cube.xml");
    command.createCube(new File(cubeSpec.toURI()));
    TestLensDimensionCommands.createDimension();
    TestLensDimensionTableCommands.addDim1Table("dim_table", "schema/dimtables/dim_table.xml", "local");

    // Add partition
    URL dataDir = TestLensQueryCommands.class.getClassLoader().getResource("dim2-part");
    XPartition xp = new XPartition();
    xp.setFactOrDimensionTableName("dim_table");
    xp.setLocation(new Path(dataDir.toURI()).toString());
    xp.setUpdatePeriod(XUpdatePeriod.HOURLY);
    XTimePartSpec timePart = new XTimePartSpec();
    XTimePartSpecElement partElement = new XTimePartSpecElement();
    partElement.setKey("dt");
    partElement.setValue(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
    timePart.getPartSpecElement().add(partElement);
    xp.setTimePartitionSpec(timePart);
    APIResult result = client.addPartitionToDim("dim_table", "local", xp);
    assertEquals(result.getStatus(), APIResult.Status.SUCCEEDED);
}

From source file:org.apache.lens.cube.metadata.JAXBUtils.java

/**
 * Get XMLGregorianCalendar from Date./*from  w ww  .  java 2  s .  c  o m*/
 *
 * Useful for converting from java code to XML spec.
 *
 * @param d Date value
 * @return XML value
 */
public static XMLGregorianCalendar getXMLGregorianCalendar(Date d) {
    if (d == null) {
        return null;
    }

    GregorianCalendar c1 = new GregorianCalendar();
    c1.setTime(d);
    try {
        return DatatypeFactory.newInstance().newXMLGregorianCalendar(c1);
    } catch (DatatypeConfigurationException e) {
        log.warn("Error converting date " + d, e);
        return null;
    }
}

From source file:org.apache.lens.server.metastore.TestMetastoreService.java

private XBaseCube createTestCube(String cubeName) throws Exception {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(new Date());
    final XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    c.add(GregorianCalendar.DAY_OF_MONTH, 7);
    final XMLGregorianCalendar endDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

    XBaseCube cube = cubeObjectFactory.createXBaseCube();
    cube.setName(cubeName);/*from w w w  .j a v a 2  s .  c o  m*/
    cube.setDimAttributes(new XDimAttributes());
    cube.setExpressions(new XExpressions());
    cube.setMeasures(new XMeasures());
    cube.setJoinChains(new XJoinChains());
    cube.setProperties(new XProperties());
    XDimAttribute xd1 = cubeObjectFactory.createXDimAttribute();
    xd1.setName("dim1");
    xd1.setType("STRING");
    xd1.setDescription("first dimension");
    xd1.setDisplayString("Dimension1");
    // Don't set endtime on this dim to validate null handling on server side
    xd1.setStartTime(startDate);
    xd1.setNumDistinctValues(2000L);

    XDimAttribute xd2 = cubeObjectFactory.createXDimAttribute();
    xd2.setName("dim2");
    xd2.setType("INT");
    xd2.setDescription("second dimension");
    xd2.setDisplayString("Dimension2");
    // Don't set start time on this dim to validate null handling on server side
    xd2.setEndTime(endDate);

    XDimAttribute xd3 = cubeObjectFactory.createXDimAttribute();
    xd3.setName("testdim2col2");
    xd3.setType("STRING");
    xd3.setDescription("ref chained dimension");
    xd3.setDisplayString("Chained Dimension");
    XChainColumn xcc = new XChainColumn();
    xcc.setChainName("chain1");
    xcc.setRefCol("col2");
    xd3.getChainRefColumn().add(xcc);
    xd3.setNumDistinctValues(1000L);

    // add attribute with complex type
    XDimAttribute xd4 = cubeObjectFactory.createXDimAttribute();
    xd4.setName("dim4");
    xd4.setType("struct<a:INT,b:array<string>,c:map<int,array<struct<x:int,y:array<int>>>");
    xd4.setDescription("complex attribute");
    xd4.setDisplayString("Complex Attribute");

    cube.getDimAttributes().getDimAttribute().add(xd1);
    cube.getDimAttributes().getDimAttribute().add(xd2);
    cube.getDimAttributes().getDimAttribute().add(xd3);
    cube.getDimAttributes().getDimAttribute().add(xd4);

    XMeasure xm1 = new XMeasure();
    xm1.setName("msr1");
    xm1.setType(XMeasureType.DOUBLE);
    xm1.setDescription("first measure");
    xm1.setDisplayString("Measure1");
    // Don't set start time and end time to validate null handling on server side.
    //xm1.setStarttime(startDate);
    //xm1.setEndtime(endDate);
    xm1.setDefaultAggr("sum");

    XMeasure xm2 = new XMeasure();
    xm2.setName("msr2");
    xm2.setType(XMeasureType.INT);
    xm2.setDescription("second measure");
    xm2.setDisplayString("Measure2");
    xm2.setStartTime(startDate);
    xm2.setEndTime(endDate);
    xm2.setDefaultAggr("max");

    cube.getMeasures().getMeasure().add(xm1);
    cube.getMeasures().getMeasure().add(xm2);

    XJoinChain xj1 = new XJoinChain();
    xj1.setName("chain1");
    xj1.setDescription("first chain");
    xj1.setDisplayString("Chain-1");
    xj1.setPaths(new XJoinPaths());
    XJoinPath path1 = cubeObjectFactory.createXJoinPath();
    path1.setEdges(new XJoinEdges());
    XTableReference link1 = new XTableReference();
    link1.setTable(cubeName);
    link1.setColumn("col1");
    XTableReference link2 = new XTableReference();
    link2.setTable("testdim");
    link2.setColumn("col1");
    link2.setMapsToMany(true);
    XJoinEdge edge1 = cubeObjectFactory.createXJoinEdge();
    edge1.setFrom(link1);
    edge1.setTo(link2);
    path1.getEdges().getEdge().add(edge1);
    xj1.getPaths().getPath().add(path1);
    cube.getJoinChains().getJoinChain().add(xj1);

    XJoinChain xj2 = new XJoinChain();
    xj2.setName("dim2chain");
    xj2.setDescription("testdim2 chain");
    xj2.setDisplayString("Chain-2");
    xj2.setPaths(new XJoinPaths());
    XJoinPath path = cubeObjectFactory.createXJoinPath();
    path.setEdges(new XJoinEdges());
    path.getEdges().getEdge().add(edge1);
    XJoinEdge edge2 = cubeObjectFactory.createXJoinEdge();
    XTableReference link3 = new XTableReference();
    link3.setTable("testdim");
    link3.setColumn("col2");
    XTableReference link4 = new XTableReference();
    link4.setTable("testdim2");
    link4.setColumn("col1");
    edge2.setFrom(link3);
    edge2.setTo(link4);
    path.getEdges().getEdge().add(edge2);
    xj2.getPaths().getPath().add(path);
    cube.getJoinChains().getJoinChain().add(xj2);

    XExprColumn xe1 = new XExprColumn();
    xe1.setName("expr1");
    xe1.setType("DOUBLE");
    xe1.setDescription("first expression");
    xe1.setDisplayString("Expression1");
    XExprSpec es = new XExprSpec();
    es.setExpr("msr1/1000");
    xe1.getExprSpec().add(es);

    XExprColumn xe2 = new XExprColumn();
    xe2.setName("expr2");
    xe2.setType("float");
    xe2.setDescription("multi expression");
    xe2.setDisplayString("Expression2");
    XExprSpec es1 = new XExprSpec();
    es1.setExpr("msr1/1000");
    xe2.getExprSpec().add(es1);
    XExprSpec es2 = new XExprSpec();
    es2.setExpr("(msr1/1000) + 0.01");
    es2.setStartTime(startDate);
    xe2.getExprSpec().add(es2);
    XExprSpec es3 = new XExprSpec();
    es3.setExpr("(msr1/1000) + 0.03");
    es3.setEndTime(endDate);
    xe2.getExprSpec().add(es3);
    XExprSpec es4 = new XExprSpec();
    es4.setExpr("(msr1/1000) - 0.01");
    es4.setStartTime(startDate);
    es4.setEndTime(endDate);
    xe2.getExprSpec().add(es4);

    cube.getExpressions().getExpression().add(xe1);
    cube.getExpressions().getExpression().add(xe2);

    XProperty xp1 = cubeObjectFactory.createXProperty();
    xp1.setName("foo");
    xp1.setValue("bar");
    cube.getProperties().getProperty().add(xp1);
    return cube;
}

From source file:org.apache.lens.server.metastore.TestMetastoreService.java

private XDimension createDimension(String dimName) throws Exception {
    GregorianCalendar c = new GregorianCalendar();
    c.setTime(new Date());
    final XMLGregorianCalendar startDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
    c.add(GregorianCalendar.DAY_OF_MONTH, 7);
    final XMLGregorianCalendar endDate = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);

    XDimension dimension = cubeObjectFactory.createXDimension();
    dimension.setName(dimName);/*from w  ww .  j a  v  a 2s .c  o m*/

    dimension.setAttributes(new XDimAttributes());
    dimension.setExpressions(new XExpressions());
    dimension.setJoinChains(new XJoinChains());
    dimension.setProperties(new XProperties().withProperty(
            new XProperty().withName(MetastoreUtil.getDimTimedDimensionKey(dimName)).withValue("dt")));
    XDimAttribute xd1 = cubeObjectFactory.createXDimAttribute();
    xd1.setName("col1");
    xd1.setType("STRING");
    xd1.setDescription("first column");
    xd1.setDisplayString("Column1");
    // Don't set endtime on this dim to validate null handling on server side
    xd1.setStartTime(startDate);

    XDimAttribute xd2 = cubeObjectFactory.createXDimAttribute();
    xd2.setName("col2");
    xd2.setType("INT");
    xd2.setDescription("second column");
    xd2.setDisplayString("Column2");
    // Don't set start time on this dim to validate null handling on server side
    xd2.setEndTime(endDate);

    dimension.getAttributes().getDimAttribute().add(xd1);
    dimension.getAttributes().getDimAttribute().add(xd2);

    XExprColumn xe1 = new XExprColumn();
    xe1.setName("dimexpr");
    xe1.setType("STRING");
    xe1.setDescription("dimension expression");
    xe1.setDisplayString("Dim Expression");
    XExprSpec es = new XExprSpec();
    es.setExpr("substr(col1, 3)");
    xe1.getExprSpec().add(es);
    dimension.getExpressions().getExpression().add(xe1);

    XProperty xp1 = cubeObjectFactory.createXProperty();
    xp1.setName("dimension.foo");
    xp1.setValue("dim.bar");
    dimension.getProperties().getProperty().add(xp1);
    return dimension;
}

From source file:org.apache.lens.server.scheduler.SchedulerDAOTest.java

private XJob getTestJob() throws DatatypeConfigurationException {
    XJob job = new XJob();
    job.setTrigger(getTestTrigger());/*  w ww  . j a  va  2s.  c o  m*/
    job.setName("Test lens Job");
    GregorianCalendar startTime = new GregorianCalendar();
    startTime.setTimeInMillis(System.currentTimeMillis());
    XMLGregorianCalendar start = DatatypeFactory.newInstance().newXMLGregorianCalendar(startTime);

    GregorianCalendar endTime = new GregorianCalendar();
    endTime.setTimeInMillis(System.currentTimeMillis());
    XMLGregorianCalendar end = DatatypeFactory.newInstance().newXMLGregorianCalendar(endTime);

    job.setStartTime(start);
    job.setEndTime(end);
    job.setExecution(getTestExecution());
    return job;
}

From source file:org.apache.taverna.prov.W3ProvenanceExport.java

public W3ProvenanceExport(ProvenanceAccess provenanceAccess, String workflowRunId, Saver saver) {
    this.saver = saver;
    this.setWorkflowRunId(workflowRunId);
    this.setProvenanceAccess(provenanceAccess);

    try {/*from   www .  j  av a2  s  .  co  m*/
        datatypeFactory = DatatypeFactory.newInstance();
    } catch (DatatypeConfigurationException e) {
        throw new IllegalStateException("Can't find a DatatypeFactory implementation", e);
    }
    prepareScufl2();

}

From source file:org.apromore.canoniser.bpmn.cpf.CpfCanonicalProcessTypeUnitTest.java

/**
 * Test canonization of <a href="{@docRoot}/../../../src/test/resources/BPMN_models/Case 12.bpmn">case #12</a>.
 *
 * <div><img src="{@docRoot}/../../../src/test/resources/BPMN_models/Case 12.svg"/></div>
 *//*from  w w  w.  j av a 2 s  . c om*/
@Test
public void testCanonise12() throws Exception {
    CpfCanonicalProcessType cpf = testCanonise("Case 12.bpmn");

    // Check that the timer has the correct date
    CpfTimerType timer = (CpfTimerType) cpf.getElement("sid-9901B6DB-42A9-48EF-B0D6-8EA51944CA42");
    assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar("2012-11-12T20:44:00"),
            timer.getTimeDate());
    assertNull(timer.getTimeDuration());
    assertNull(timer.getTimeExpression());

    // Check that A and its timer boundary event cancel each other
    CpfTaskType a = (CpfTaskType) cpf.getElement("sid-FA5E54FC-9090-45F4-8649-49052F106ABE");
    assertEquals(Collections.singleton(timer), a.getBoundaryEvents());
    assertEquals(1, a.getCancelNodeId().size());
    assertEquals(timer.getId(), a.getCancelNodeId().get(0).getRefId());
    assertEquals(1, timer.getCancelNodeId().size());
    assertEquals(a.getId(), timer.getCancelNodeId().get(0).getRefId());
}

From source file:org.apromore.canoniser.bpmn.cpf.CpfCanonicalProcessTypeUnitTest.java

/**
 * Test canonization of <a href="{@docRoot}/../../../src/test/resources/BPMN_models/Case 13.bpmn">case #13</a>.
 *
 * This is identical to case #12, except that the boundary timer event is non-interrupting.
 *//*from ww  w . j  a  v a 2 s .co m*/
@Test
public void testCanonise13() throws Exception {
    CpfCanonicalProcessType cpf = testCanonise("Case 13.bpmn");

    // Check that the timer has the correct date
    CpfTimerType timer = (CpfTimerType) cpf.getElement("sid-9901B6DB-42A9-48EF-B0D6-8EA51944CA42");
    assertEquals(DatatypeFactory.newInstance().newXMLGregorianCalendar("2012-11-12T20:44:00"),
            timer.getTimeDate());
    assertNull(timer.getTimeDuration());
    assertNull(timer.getTimeExpression());

    // Check that A cancels its timer boundary event, but that the event doesn't cancel the task
    CpfTaskType a = (CpfTaskType) cpf.getElement("sid-FA5E54FC-9090-45F4-8649-49052F106ABE");
    assertEquals(Collections.singleton(timer), a.getBoundaryEvents());
    assertEquals(1, a.getCancelNodeId().size());
    assertEquals(timer.getId(), a.getCancelNodeId().get(0).getRefId());
    assertEquals(0, timer.getCancelNodeId().size());
}

From source file:org.artificer.integration.artifactbuilder.WsdlDocumentArtifactBuilderTest.java

@Test
public void testDeriverWsdl() throws Exception {
    DatatypeFactory dtFactory = DatatypeFactory.newInstance();

    WsdlDocumentArtifactBuilder builder = new WsdlDocumentArtifactBuilder();
    WsdlDocument testSrcArtifact = new WsdlDocument();
    testSrcArtifact.setArtifactType(BaseArtifactEnum.WSDL_DOCUMENT);
    testSrcArtifact.setUuid(UUID.randomUUID().toString());
    testSrcArtifact.setName("sample.wsdl");
    testSrcArtifact.setVersion("2012/09");
    testSrcArtifact.setContentEncoding("UTF-8");
    testSrcArtifact.setContentType("application/xml");
    testSrcArtifact.setContentSize(92779L);
    testSrcArtifact.setCreatedBy("anonymous");
    XMLGregorianCalendar xmlGC = dtFactory.newXMLGregorianCalendar(new GregorianCalendar());
    testSrcArtifact.setCreatedTimestamp(xmlGC);
    testSrcArtifact.setDescription("Sample WSDL.");
    testSrcArtifact.setLastModifiedBy("anonymous");
    testSrcArtifact.setLastModifiedTimestamp(xmlGC);

    InputStream testSrcContent = null;
    try {//from ww w . j a v a 2 s.com
        testSrcContent = getClass().getResourceAsStream("/sample-files/wsdl/deriver.wsdl");
        Collection<BaseArtifactType> derivedArtifacts = builder
                .buildArtifacts(testSrcArtifact, new ArtifactContent("deriver.wsdl", testSrcContent))
                .getDerivedArtifacts();
        Assert.assertNotNull(derivedArtifacts);
        Assert.assertEquals(35, derivedArtifacts.size());

        // Index the results by artifact type and name
        Map<QName, DerivedArtifactType> index = new HashMap<QName, DerivedArtifactType>();
        for (BaseArtifactType da : derivedArtifacts) {
            DerivedArtifactType artifact = (DerivedArtifactType) da;
            if (artifact instanceof NamedWsdlDerivedArtifactType) {
                NamedWsdlDerivedArtifactType arty = (NamedWsdlDerivedArtifactType) artifact;
                if (arty.getNCName() != null)
                    index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            } else if (artifact instanceof WsdlExtension) {
                WsdlExtension arty = (WsdlExtension) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), arty);
            } else if (artifact instanceof ElementDeclaration) {
                ElementDeclaration arty = (ElementDeclaration) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            } else if (artifact instanceof AttributeDeclaration) {
                AttributeDeclaration arty = (AttributeDeclaration) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            } else if (artifact instanceof SimpleTypeDeclaration) {
                SimpleTypeDeclaration arty = (SimpleTypeDeclaration) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            } else if (artifact instanceof ComplexTypeDeclaration) {
                ComplexTypeDeclaration arty = (ComplexTypeDeclaration) artifact;
                index.put(new QName(arty.getArtifactType().toString(), arty.getNCName()), artifact);
            }
        }

        // Do some specific assertions
        ////////////////////////////////////////////

        // Find the message named 'findRequest'
        DerivedArtifactType artifact = index.get(new QName(BaseArtifactEnum.MESSAGE.toString(), "findRequest"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findRequest", artifact.getName());
        Assert.assertEquals("findRequest", ((Message) artifact).getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl",
                ((Message) artifact).getNamespace());
        Message message = (Message) artifact;
        Assert.assertEquals(1, message.getPart().size());

        // Find the element decl named 'findResponse'
        artifact = index.get(new QName(BaseArtifactEnum.ELEMENT_DECLARATION.toString(), "findResponse"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findResponse", artifact.getName());
        Assert.assertEquals("findResponse", ((ElementDeclaration) artifact).getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl/types",
                ((ElementDeclaration) artifact).getNamespace());

        // Find the simple type named 'keywordType'
        artifact = index.get(new QName(BaseArtifactEnum.SIMPLE_TYPE_DECLARATION.toString(), "keywordType"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("keywordType", artifact.getName());
        Assert.assertEquals("keywordType", ((SimpleTypeDeclaration) artifact).getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl/types",
                ((SimpleTypeDeclaration) artifact).getNamespace());
        String typeUuid = artifact.getUuid();

        // Find the part named 'keyword'
        artifact = index.get(new QName(BaseArtifactEnum.PART.toString(), "keyword"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("keyword", artifact.getName());
        Part part = (Part) artifact;
        Assert.assertEquals("keyword", part.getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl", part.getNamespace());
        Assert.assertNotNull(part.getType());
        Assert.assertEquals(typeUuid, part.getType().getValue());

        // Find the port type named 'SamplePortType'
        artifact = index.get(new QName(BaseArtifactEnum.PORT_TYPE.toString(), "SamplePortType"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("SamplePortType", artifact.getName());
        Assert.assertEquals("SamplePortType", ((PortType) artifact).getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl",
                ((PortType) artifact).getNamespace());
        PortType portType = (PortType) artifact;
        Assert.assertEquals(2, portType.getOperation().size());

        // Find the operation named 'find'
        artifact = index.get(new QName(BaseArtifactEnum.OPERATION.toString(), "find"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("find", artifact.getName());
        Operation operation = (Operation) artifact;
        Assert.assertEquals("find", operation.getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl",
                operation.getNamespace());
        Assert.assertNotNull(operation.getInput());
        Assert.assertNotNull(operation.getOutput());
        Assert.assertNotNull(operation.getFault());
        Assert.assertEquals(2, operation.getFault().size());

        // Find the operation input named 'findRequest'
        artifact = index.get(new QName(BaseArtifactEnum.OPERATION_INPUT.toString(), "findRequest"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findRequest", artifact.getName());
        OperationInput operationInput = (OperationInput) artifact;
        Assert.assertEquals("findRequest", operationInput.getNCName());
        Assert.assertNotNull(operationInput.getMessage());
        Assert.assertNotNull(operationInput.getMessage().getValue());
        Assert.assertEquals(index.get(new QName(BaseArtifactEnum.MESSAGE.toString(), "findRequest")).getUuid(),
                operationInput.getMessage().getValue());

        // Find the operation output named 'findResponse'
        artifact = index.get(new QName(BaseArtifactEnum.OPERATION_OUTPUT.toString(), "findResponse"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findResponse", artifact.getName());
        OperationOutput operationOutput = (OperationOutput) artifact;
        Assert.assertEquals("findResponse", operationOutput.getNCName());
        Assert.assertNotNull(operationOutput.getMessage());
        Assert.assertNotNull(operationOutput.getMessage().getValue());
        Assert.assertEquals(index.get(new QName(BaseArtifactEnum.MESSAGE.toString(), "findResponse")).getUuid(),
                operationOutput.getMessage().getValue());

        // Find the binding named 'SampleBinding'
        artifact = index.get(new QName(BaseArtifactEnum.BINDING.toString(), "SampleBinding"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("SampleBinding", artifact.getName());
        Assert.assertEquals("SampleBinding", ((Binding) artifact).getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl",
                ((Binding) artifact).getNamespace());
        Binding binding = (Binding) artifact;
        Assert.assertEquals(2, binding.getBindingOperation().size());
        Assert.assertEquals(1, binding.getExtension().size());

        // Find the document style soap:binding
        artifact = index.get(new QName(BaseArtifactEnum.SOAP_BINDING.toString(), "binding"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("soap:binding", artifact.getName());
        Assert.assertEquals("binding", ((SoapBinding) artifact).getNCName());
        Assert.assertEquals("http://schemas.xmlsoap.org/wsdl/soap/", ((SoapBinding) artifact).getNamespace());
        SoapBinding soapBinding = (SoapBinding) artifact;
        Assert.assertEquals("document", soapBinding.getStyle());
        Assert.assertEquals("http://schemas.xmlsoap.org/soap/http", soapBinding.getTransport());
        Assert.assertEquals(binding.getExtension().get(0).getValue(), soapBinding.getUuid());

        // Find the binding operation named 'find'
        artifact = index.get(new QName(BaseArtifactEnum.BINDING_OPERATION.toString(), "find"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("find", artifact.getName());
        BindingOperation bindingOperation = (BindingOperation) artifact;
        Assert.assertEquals("find", bindingOperation.getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl",
                bindingOperation.getNamespace());
        Assert.assertNotNull(bindingOperation.getInput());
        Assert.assertNotNull(bindingOperation.getOutput());
        Assert.assertNotNull(bindingOperation.getFault());
        Assert.assertEquals(2, bindingOperation.getFault().size());
        Assert.assertNotNull(bindingOperation.getOperation());
        Assert.assertEquals(operation.getUuid(), bindingOperation.getOperation().getValue());

        // Find the binding operation input named 'findRequest'
        artifact = index.get(new QName(BaseArtifactEnum.BINDING_OPERATION_INPUT.toString(), "findRequest"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findRequest", artifact.getName());
        BindingOperationInput bindingOperationInput = (BindingOperationInput) artifact;
        Assert.assertEquals("findRequest", bindingOperationInput.getNCName());
        Assert.assertEquals(bindingOperation.getInput().getValue(), bindingOperationInput.getUuid());

        // Find the binding operation output named 'findResponse'
        artifact = index.get(new QName(BaseArtifactEnum.BINDING_OPERATION_OUTPUT.toString(), "findResponse"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("findResponse", artifact.getName());
        BindingOperationOutput bindingOperationOutput = (BindingOperationOutput) artifact;
        Assert.assertEquals("findResponse", bindingOperationOutput.getNCName());
        Assert.assertEquals(bindingOperation.getOutput().getValue(), bindingOperationOutput.getUuid());

        // Find the service named 'SampleService'
        artifact = index.get(new QName(BaseArtifactEnum.WSDL_SERVICE.toString(), "SampleService"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("SampleService", artifact.getName());
        Assert.assertEquals("SampleService", ((WsdlService) artifact).getNCName());
        Assert.assertEquals("http://ewittman.redhat.com/sample/2012/09/wsdl/sample.wsdl",
                ((WsdlService) artifact).getNamespace());
        WsdlService service = (WsdlService) artifact;
        Assert.assertEquals(1, service.getPort().size());

        // Find the port named 'SamplePort'
        artifact = index.get(new QName(BaseArtifactEnum.PORT.toString(), "SamplePort"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("SamplePort", artifact.getName());
        Assert.assertEquals("SamplePort", ((Port) artifact).getNCName());
        Port port = (Port) artifact;
        Assert.assertNotNull(port.getBinding());
        Assert.assertEquals(port.getBinding().getValue(), binding.getUuid());
        Assert.assertEquals(1, port.getExtension().size());

        // Find the soap:address
        artifact = index.get(new QName(BaseArtifactEnum.SOAP_ADDRESS.toString(), "address"));
        Assert.assertNotNull(artifact);
        Assert.assertEquals("soap:address", artifact.getName());
        Assert.assertEquals("address", ((SoapAddress) artifact).getNCName());
        Assert.assertEquals("http://schemas.xmlsoap.org/wsdl/soap/", ((SoapAddress) artifact).getNamespace());
        SoapAddress soapAddress = (SoapAddress) artifact;
        Assert.assertEquals("http://localhost:8080/sample/sampleEP", soapAddress.getSoapLocation());
        Assert.assertEquals(port.getExtension().get(0).getValue(), soapAddress.getUuid());

    } finally {
        IOUtils.closeQuietly(testSrcContent);
    }
}