Examples of HelperContext


Examples of commonj.sdo.helper.HelperContext

        commentary(COMMENTARY_FOR_INTERMEDIATE,
            "As we are dealing with a DataGraph,  the SDO API has some gray areas at the moment\n"+
            "in that the DataGraph API hasn't yet been developed to deal with scopes\n"+
            "other than the default scope. So here is an occasion where we must use"+
            "the default singleton scope");
        HelperContext scope = useDefaultScopeForTypes();
        loadTypesFromXMLSchemaFile(scope, SampleInfrastructure.COMPANY_XSD);
      
        commentary (COMMENTARY_FOR_INTERMEDIATE,
            "Here is the use of the Tuscany API for creating a DataGraph instance\n\n"+
            "DataGraph dataGraph = SDOUtil.createDataGraph();");
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

        + "and printing the values of its Properties.  As the sample traverses a couple of\n"
        + "graphs it provides commentary about what it has found and what actions it\n"
        + "is taking, whilst building up a text representation of the graph. It then\n"
        + "shows you the results of its labours.");

    HelperContext scope = createScopeForTypes();

    commentary(
        COMMENTARY_ALWAYS,
        "First we look at a data graph of a Purchase Order which has a fairly simple XML schema\n"
            + "and the graph's containment hierarchy has a couple of levels of depth");
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

        "HelperContext scope = SDOUtil.createHelperContext();",
       
        "Creating a new HelperContext scope for types for the next sample run as we did in previous samples"
    );
       
    HelperContext scope = SDOUtil.createHelperContext();
    return scope;
  }
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

        "which don't all support the type scoping extensions which were introduced in the SDO 2.1 specification",
       
        "Retrieving the default HelperContext scope for types for the next sample run as we saw in a previous sample"
    );
       
    HelperContext scope = HelperProvider.getDefaultContext();
    return scope;
  }
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

    SDOFacets.SAVING_DATA_TO_XML
  };

  public void runSample() throws Exception {

    HelperContext scope = SDOUtil.createHelperContext();

    if (typesViaAPI) {

      commentary("In this execution of the sample we use Types created\n"
          + "using the SDO API");

      createTypesViaAPI(scope);

    } else {

      commentary("In this execution of the sample we use Types created\n"
          + "by loading a variant of the XMLSchema that includes a change summary Property");

      loadTypesFromXMLSchemaFile(scope, "MedicalTest_CS.xsd");

    }

    commentary(
        COMMENTARY_FOR_NOVICE,
        "The DataFactory associated with the scope that the types were created within\n"
            + "can be used to create an instance of the Person Type\n\n"
            + "DataFactory dataFactory = scope.getDataFactory();\n"
            + "DataObject person1 = dataFactory.create(\"www.example.org/people\", \"Person\");");

    DataFactory dataFactory = scope.getDataFactory();
    DataObject person1 = dataFactory.create("www.example.org/people", "Person");

    commentary("The setString() of dataObject method is used to set the properties of the\n"
        + "new Person DataObject, including a unique identifier reference value\n"
        + "for the Person instance.\n\n"
        + "person1.setString(\"id\", \"1\");\n"
        + "person1.setString(\"name\", \"Joe Johnson Snr.\");\n"
        + "person1.setString(\"gender\", \"male\"););");

    person1.setString("id", "1");
    person1.setString("name", "Joe Johnson Snr.");
    person1.setString("gender", "male");

    commentary("An alternative approach to using the DataFactory directly to create\n"
        + "all DataObjects is to use a top-down approach,  where we create the\n"
        + "root object for a data graph,  and then use the createDataObject(String propertyName)\n"
        + "method to create the contained DataObjects.  Here we create the overall\n"
        + "medical test DataObject,  and then create the contained \"referrals\" DataObject\n\n"
        + "DataObject test = dataFactory.create(\"www.example.org/MedicalTest\", \"Test\");\n"
        + "DataObject referrals = test.createDataObject(\"referrals\");");

    DataObject test = dataFactory.create("www.example.org/MedicalTest", "Test");

    DataObject referrals = test.createDataObject("referrals");

    commentary("The default state for monitoring changes for da DataObject when created in this\n" +
        "way is thay monitoring is switched off, so we switch it on. (Note that if you\n" +
        "get your data graphs from a data Access Service then this service may turn on\n" +
        "change monitoring be default\n\n" +
        "test.getChangeSummary().beginLogging();");
    test.getChangeSummary().beginLogging();
   
    commentary("We'll repeat the whole of the MedicalScenario sample,  but then at the \n" +
        "last minute we'll decide it was all wrong and roll back the changes......");
   
    commentary("Now we can add the person we created earlier into the set of people who have\n"
        + "been referred for this medical test.\n\n"
        + "test.set(\"referrals\", referrals);\n"
        + "referrals.getList(\"person\").add(person1);");

    test.set("referrals", referrals);
    referrals.getList("person").add(person1);

    commentary("Let's take a look at how the current state of the data"
        + "graph is rendered in XML ...");

    System.out.println(scope.getXMLHelper().save(test,
        "www.example.org/MedicalTest", "test"));

    commentary("The scenario unfolds and the Joe Johnson Snr. becomes a patient\n\n"
        + "DataObject patients = test.createDataObject(\"patients\");\n"
        + "patients.getList(\"person\").add(person1);");

    DataObject patients = test.createDataObject("patients");

    patients.getList("person").add(person1);

    commentary("Having added Joe Johnson Snr. to the set of patients we can see\n"
        + "the way that SDO preserves a single containment hierarchy within a\n"
        + "datagraph.  If we look at the XML rendering of the graph again, we will\n"
        + "see that by adding him to the set of patients he has been removed from the\n"
        + "containment property associated with the referrals set ...");

    System.out.println(scope.getXMLHelper().save(test,
        "www.example.org/MedicalTest", "test"));

    commentary("The 'Person' Type we are making use of here has been designed to be\n"
        + "multi-purpose,  in that the type has been declared to be 'Open'.\n"
        + "That means that we can make use of 'Open Content' Properties\n"
        + "(If the type system has been defined using an XML schema\n"
        + "then these properties will derive from global elements)\n"
        + "We can look up open content Properties using the TypeHelper\n\n"
        + "Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(\n"
        + "    \"www.example.org/MedicalTest\", \"condition\");");

    Property conditionProperty = scope.getTypeHelper().getOpenContentProperty(
        "www.example.org/MedicalTest", "condition");

    commentary("We can create a value of the appropriate Type for this open\n"
        + "content Property\n\n"
        + "DataObject condition = dataFactory.create(conditionProperty.getType());\n"
        + "condition.setString(\"name\", \"Panar Syndrome\");");

    DataObject condition = dataFactory.create(conditionProperty.getType());
    condition.setString("name", "Panar Syndrome");

    commentary("If you ask a DataObject that has an 'Open' Type for its list of\n"
        + "values associated with an open content Property, and the DataObject\n"
        + "doesn't currently have any values for the Property,  it will return\n"
        + "an empty list. We can use the list to add values for the Property\n\n"
        + "List conditions = person1.getList(conditionProperty);\n"
        + "conditions.add(condition);");

    List conditions = person1.getList(conditionProperty);
    conditions.add(condition);

    commentary("A further look at the data graph in XML form shows\n"
        + "the presence of the new condition Property's value ...");

    System.out.println(scope.getXMLHelper().save(test,
        "www.example.org/MedicalTest", "test"));

    commentary("Having looked at the way SDO handles Open content\n"
        + "We now turn our attention to 'non-containment' relationships.\n"
        + "To do this we first create the set of people in the test that\n"
        + "constitute the blood relatives of patients -- 'relatives'\n"
        + "and define a new person to be Joe Johnson Snr's child.\n\n"
        + "DataObject relatives = test.createDataObject(\"relatives\");\n"
        + "DataObject person2 = relatives.createDataObject(\"person\");\n"
        + "person2.setString(\"id\", \"2\");\n"
        + "person2.setString(\"name\", \"Joe Johnson Jnr.\");\n"
        + "person2.setString(\"gender\", \"male\");");

    DataObject relatives = test.createDataObject("relatives");
    DataObject person2 = relatives.createDataObject("person");

    person2.setString("id", "2");
    person2.setString("name", "Joe Johnson Jnr.");
    person2.setString("gender", "male");

    commentary("Another quick look at the XML rendering of the graph confirms that\n"
        + "the set of relatives now includes Joe Johnson Jnr, but we haven't yet\n"
        + "defined who he is related to, or how.");

    System.out.println(scope.getXMLHelper().save(test,
        "www.example.org/MedicalTest", "test"));

    commentary("The Person type has a Property 'relative'\n"
        + "so we create a relative for Joe Johnson Snr.\n\n"
        + "DataObject relation = person1.createDataObject(\"relative\");\n"
        + "relation.set(\"target\", person2);\n"
        + "relation.set(\"relationship\", \"child\");");

    DataObject relation = person1.createDataObject("relative");
    relation.set("target", person2);
    relation.set("relationship", "child");

    commentary("Now when we look at the XML rendering of the data graph\n"
        + "we can see that the action of setting the 'target' of the\n"
        + "relationship to Joe Johnson Jnr didn't displace him from the\n"
        + "set of 'relatives',  because the 'target' Property is a\n"
        + "non-containment Property.  This non-containment relationship\n"
        + "is reflected in the XML by a reference to the Person DataObject\n"
        + "describing Joe Johnson Jnr, \"2\" ...\n"
        + "If the Type system has been created from an XML schema then the\n"
        + "unique ID of the target can be used in the serialization.\n"
        + "If however the type system was defined dynamically,  then the reference\n"
        + "will be represented as an XPath from the root of the data graph.");

    System.out.println(scope.getXMLHelper().save(test,
        "www.example.org/MedicalTest", "test"));
   
    commentary("Now that the graph is complete we can use the PrintDataGraph sample utility\n" +
        "to reveal the full SDO nature of the final data graph\n\n" +
        "");
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

     * throw a null pointer exception if the key is null.  
     */
    public static HelperContext getHelperContext() {
        ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
        // check the map for contextClassLoader and return it if it exists
        HelperContext hCtx = getHelperContext(contextClassLoader);
        if (hCtx != null) {
            return hCtx;
        }
        Object key = getDelegateMapKey(contextClassLoader);
        hCtx = helperContexts.get(key);
        if (hCtx == null) {
            hCtx = new SDOHelperContext();
            HelperContext existingCtx = helperContexts.putIfAbsent(key, hCtx);
            if (existingCtx != null) {
                hCtx = existingCtx;
            }
            if (key.getClass() == ClassConstants.STRING) {
                helperContexts.put(contextClassLoader, hCtx);
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

     * ADVANCED:
     * Remove the HelperContext for the application associated with a
     * given key, if it exists in the map.
     */
    private static void resetHelperContext(Object key) {
        HelperContext hCtx = helperContexts.get(key);
        if (hCtx != null) {
            helperContexts.remove(key);       
        }
    }
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

            } else if (XMLConstants.SCHEMA_INSTANCE_URL.equals(uri) && XMLConstants.SCHEMA_TYPE_ATTRIBUTE.equals(attrName)) {
                //do nothing
            } else if (SDOConstants.CHANGESUMMARY_REF.equals(attrName) && SDOConstants.SDO_URL.equals(uri)) {
                ((SDODataObject)dataObject)._setSdoRef(stringValue);
            } else {
                HelperContext aHelperContext = ((SDOType)dataObject.getType()).getHelperContext();
                Property prop = aHelperContext.getXSDHelper().getGlobalProperty(uri, attrName, false);
                if (prop != null) {
                    Object convertedValue = ((SDODataHelper)aHelperContext.getDataHelper()).convertFromStringValue(stringValue, prop.getType());
                    dataObject.set(prop, convertedValue);
                } else {
                    Object convertedValue = ((SDODataHelper)aHelperContext.getDataHelper()).convertFromStringValue(stringValue, SDOConstants.SDO_STRING);

                    //can't use create on demand property via a set by string name operation because that would create an element
                    prop = defineNewSDOProperty(uri, attrName, false, SDOConstants.SDO_STRING);
                    dataObject.set(prop, convertedValue);
                }
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

                    currentDataObject = null;
                } else {
                    currentDataObject = (DataObject)currentDataObjects.peek();
                }
            }
            HelperContext aHelperContext = ((SDOType)currentDataObject.getType()).getHelperContext();
            if (currentSchemaType != null) {
                Type sdoType = ((SDOTypeHelper)aHelperContext.getTypeHelper()).getSDOTypeFromXSDType(currentSchemaType);

                if (sdoType != null) {
                    ((SDOProperty)currentProperty).setType(sdoType);
                }

                if ((currentProperty.getType() != null) && simple) {
                    value = ((SDODataHelper)aHelperContext.getDataHelper()).convertFromStringValue((String)value, currentProperty.getType(), currentSchemaType);
                }
                currentSchemaType = null;
            } else if ((currentProperty.getType() != null) && currentProperty.getType().isDataType()) {
                value = ((SDODataHelper)aHelperContext.getDataHelper()).convertFromStringValue((String)value, currentProperty.getType());
            }

            if (currentDataObject != null) {
                if (!simple) {
                    parentRecord.getUnmarshaller().getUnmarshalListener().afterUnmarshal(value, currentDataObject);
View Full Code Here

Examples of commonj.sdo.helper.HelperContext

      Type type = DataObjectUtil.getType(dataObject, namespaceURI, typeName);
      return createDataObject(dataObject, property, type);
    }
    else {
      if (dataObject.getType().isOpen()) {
        HelperContext ctx = HelperProvider.getDefaultContext();
        Type propertyType = ctx.getTypeHelper().getType( namespaceURI, typeName );
        if (propertyType == null) {
          throw new IllegalStateException( "type does not exist: uri=" + namespaceURI + ", name=" + typeName );
        }
        DataObject value = ctx.getDataFactory().create( propertyType );
        List list = new ArrayList(1);
        list.add(value);
        dataObject.setList( propertyName, list );
        return value;
      }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.