From 195774c489a1a671aca514b0afa88332bf9c6ee3 Mon Sep 17 00:00:00 2001 From: lresende Date: Tue, 10 Nov 2009 19:20:12 +0000 Subject: Moving SDO tags git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@834617 13f79535-47bb-0310-9956-ffa450edef68 --- .../sdo/basic/AccessingTheContentsOfASequence.java | 115 +++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 sdo-java/tags/1.1/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessingTheContentsOfASequence.java (limited to 'sdo-java/tags/1.1/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessingTheContentsOfASequence.java') diff --git a/sdo-java/tags/1.1/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessingTheContentsOfASequence.java b/sdo-java/tags/1.1/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessingTheContentsOfASequence.java new file mode 100644 index 0000000000..e24a837ccc --- /dev/null +++ b/sdo-java/tags/1.1/sample/src/main/java/org/apache/tuscany/samples/sdo/basic/AccessingTheContentsOfASequence.java @@ -0,0 +1,115 @@ +/** + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.samples.sdo.basic; + + +import org.apache.tuscany.samples.sdo.SampleBase; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.helper.HelperContext; + +/** + * Demonstrates accessing the sequence from a DataObject containing mixed content. + *

+ *

Running this Sample

See the main overview for instructions on how to run this + * sample. + */ + +public class AccessingTheContentsOfASequence extends SampleBase { + + HelperContext scope; + + public AccessingTheContentsOfASequence(Integer userLevel) { + super(userLevel, SAMPLE_LEVEL_BASIC); + } + + + /** + * previously created XSD file used + */ + public static final String LETTER_XSD = "letter.xsd"; + + /** + * previously created XML file used + */ + public static final String LETTER_XML = "letter.xml"; + + /** + * Execute this method in order to run the sample. + * + * @param args + */ + public static void main(String[] args) { + + AccessingTheContentsOfASequence sample = + new AccessingTheContentsOfASequence(COMMENTARY_FOR_NOVICE); + + sample.run(); + + } + + /* + * metadata for the sample documenting the areas of SDO that are explored + */ + public static int [] CORE_FUNCTION = { + SDOFacets.ACCESSING_VALUES_IN_A_SEQUENCE + }; + + public void runSample () throws Exception { + + commentary("Demonstrates accessing the sequence from a DataObject containing mixed content."); + + scope = createScopeForTypes(); + loadTypesFromXMLSchemaFile(scope, LETTER_XSD); + DataObject letter = getDataObjectFromFile(scope, LETTER_XML); + + // print letter sequence + commentary("We've loaded a document from an XML file that contains mixed content.\n" + + "Here's how the XML looks ...\n"); + System.out.println(scope.getXMLHelper().save(letter, "letter.xsd", "letter")); + + commentary("We can iterate over the sequence, getting the Property / Value pairs\n" + + "using the Sequence.getProperty(int) and Sequence.getValue(int) methods.\n" + + "The model for this document is \"mixed\", i.e.\n" + + "letter.getType().isMixed() returns \"true\".\n" + + "Let's take a look at the Properties in this sequence."); + + Sequence letterSequence = letter.getSequence(); + + for (int i = 0; i < letterSequence.size(); i++) { + Property prop = letterSequence.getProperty(i); + if (prop == null) { + String text = (String) letterSequence.getValue(i); + System.out.println("Unstructured text (" + text + ")"); + } else { + System.out.println("Property: " + prop.getName() + " Value : " + letterSequence.getValue(i)); + } + } + + commentary("The values of the modeled Properties are still accessible through the DataObject\n" + + "getter and setter methods, but only through the Sequence API can we get to the unstructured\n" + + "text and see the ordering of the instance document"); + + } +} -- cgit v1.2.3