// !! !! // required conditions: 1) DataObject is open // purpose: when property is undefined, set still does 'set', get still 'get', instance property // list is still ok. // test undefined is not in instance property list // tset after set, it is in the list, and value is what we want public void testSetGetWithUnDefinedProperty_openDataObject() { try { dataObject.set(UNDEFINED_PROPERTY_INDEX, CONTROL_STRING_1); // set undefined Property value } catch (SDOException e) { assertEquals(SDOException.PROPERTY_NOT_FOUND_AT_INDEX, e.getErrorCode()); return; } fail("an SDOException should have occurred."); }
// required conditions: 1) DataObject is not open // purpose: IllegalArgumentException can be thrown for undefined Property when get. public void testGetInvalidPropertyIndex_WithDataObject_Not_Open() { try { dataObject_Not_Open.get(UNDEFINED_PROPERTY_INDEX); // get undefined Property value } catch (SDOException e) { assertEquals(SDOException.PROPERTY_NOT_FOUND_AT_INDEX, e.getErrorCode()); return; } fail("an SDOException should have occurred."); }
// required condition: none // purpose: test get with index -1 public void testGetWith_MINUS_ONE() { try { dataObject_Not_Open.get(MINUS_ONE); // get undefined Property value fail("An IllegalArgumentException should have been thrown."); } catch (SDOException e) { assertEquals(SDOException.PROPERTY_NOT_FOUND_AT_INDEX, e.getErrorCode()); return; } fail("an SDOException should have occurred."); }
// required conditions: 1) DataObject is not open // purpose: IllegalArgumentException can be thrown for valid Property index when set. public void testSetValidPropertyINdex_WithDataObject_Not_Open() { try { dataObject_Not_Open.set( DEFINED_PROPERTY_INDEX, CONTROL_STRING_1); // set defined Property value } catch (SDOException e) { assertEquals(SDOException.PROPERTY_NOT_FOUND_AT_INDEX, e.getErrorCode()); return; } fail("an SDOException should have occurred."); }
// required condition: none // purpose: test set with -1 public void testSetWith_MINUS_ONE() { try { SDOProperty NUll = null; dataObject_Not_Open.set(MINUS_ONE, CONTROL_STRING_1); // set undefined Property value } catch (SDOException e) { assertEquals(SDOException.PROPERTY_NOT_FOUND_AT_INDEX, e.getErrorCode()); return; } fail("an SDOException should have occurred."); }
/** INTERNAL: */ public Class getImplClass() { if ((javaImplClass == null) && (getImplClassName() != null)) { try { SDOClassLoader loader = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getLoader(); javaImplClass = loader.loadClass(getImplClassName(), this); xmlDescriptor.setJavaClass(javaImplClass); } catch (ClassNotFoundException e) { throw SDOException.classNotFound(e, getURI(), getName()); } catch (SecurityException e) { throw SDOException.classNotFound(e, getURI(), getName()); } } return javaImplClass; }
public void testDefine() { DefaultSchemaResolver schemaResolver = new DefaultSchemaResolver(); schemaResolver.setBaseSchemaLocation(getSchemaLocation()); try { ((SDOXSDHelper) xsdHelper).define(new StreamSource(getSchemaToDefine()), schemaResolver); } catch (SDOException e) { assertEquals(SDOException.REFERENCED_PROPERTY_NOT_FOUND, e.getErrorCode()); return; } fail("An exception should have occurred but didn't"); }
/** * INTERNAL: Make this Type an opened Type to allow open content by assigning true value or a Type * not to accept any additional properties by assigning false value, {@link isOpen()}. * * @param bOpen boolean value implying if this Type is open */ public void setOpen(boolean bOpen) { if (isDataType() && bOpen) { throw SDOException.typeCannotBeOpenAndDataType(getURI(), getName()); } if (open != bOpen) { open = bOpen; if (open) { if (isSubType()) { Type baseType = (Type) getBaseTypes().get(0); if (!baseType.isOpen()) { addOpenMappings(); } } else { addOpenMappings(); } if (isBaseType()) { for (int i = 0; i < getSubTypes().size(); i++) { SDOType nextSubType = (SDOType) getSubTypes().get(i); nextSubType.setOpen(bOpen); } } } } }
private void save(XMLDocument xmlDocument, Writer outputWriter, XMLMarshaller anXMLMarshaller) throws IOException { if (xmlDocument == null) { throw new IllegalArgumentException( SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument")); } // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration()); anXMLMarshaller.setEncoding(xmlDocument.getEncoding()); anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation()); anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation()); WriterRecord writerRecord; if (anXMLMarshaller.isFormattedOutput()) { writerRecord = new FormattedWriterRecord(); } else { writerRecord = new WriterRecord(); } writerRecord.setWriter(outputWriter); writerRecord.setMarshaller(anXMLMarshaller); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setMarshalledObject(xmlDocument.getRootObject()); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setMarshalledObjectRootQName( new QName(xmlDocument.getRootElementURI(), xmlDocument.getRootElementName())); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setRootMarshalRecord(writerRecord); anXMLMarshaller.marshal(xmlDocument, writerRecord); outputWriter.flush(); }
public DataObject create(String uri, String typeName) { Type sdoType = getHelperContext().getTypeHelper().getType(uri, typeName); if (sdoType != null) { return create(sdoType); } throw new IllegalArgumentException(SDOException.typeNotFound(uri, typeName)); }
public DataObject create(Type type) { if (type == null) { throw new IllegalArgumentException( SDOException.cannotPerformOperationWithNullInputParameter("create", "type")); } SDOType sdoType = (SDOType) type; if (sdoType.isAbstract()) { // throw illegal arg exception // spec page 40 throw new IllegalArgumentException( SDOException.errorCreatingDataObjectForType(sdoType.getURI(), sdoType.getName())); } if (sdoType.isDataType()) { SDOTypeHelper sth = (SDOTypeHelper) getHelperContext().getTypeHelper(); sdoType = (SDOType) sth.getWrappersHashMap().get(sdoType.getQName()); } Class implClass; try { implClass = sdoType.getImplClass(); if (implClass != null) { // initialization of the properties Map Implementation will be done in the default // constructor call below // testcase is in org.apache.tuscany.sdo.test SDODataObject theDataObject = (SDODataObject) implClass.newInstance(); theDataObject._setType(sdoType); theDataObject._setHelperContext(getHelperContext()); return theDataObject; } } catch (InstantiationException e) { throw new IllegalArgumentException( SDOException.errorCreatingDataObjectForClass( e, (sdoType).getInstanceClassName(), sdoType.getURI(), sdoType.getName())); } catch (IllegalAccessException e) { throw new IllegalArgumentException( SDOException.errorCreatingDataObjectForClass( e, (sdoType).getInstanceClassName(), sdoType.getURI(), sdoType.getName())); } SDODataObject dataObject = new SDODataObject(); dataObject._setType(sdoType); dataObject._setHelperContext(getHelperContext()); return dataObject; }
/** * Return the content of the appinfo declared for this Property and source. If the property is * defined by ref= the appinfo of the referenced element or attribute is included. The appinfo * start and end tags and content are returned. The xml namespace context is preserved in the * appinfo element. If more than one appinfo with the same source is declared on the same Type * their contents are concatenated. * * @param property the Property with the appinfo declaration * @param source the source of the appinfo declaration. * @return the appinfo declared for this Property and source. */ public String getAppinfo(Property property, String source) { if (property == null) { throw SDOException.noAppInfoForNull(); } if (source == null) { source = ""; } return (String) ((SDOProperty) property).getAppInfoMap().get(source); }
/** * Returns the DataObject saved as an XML document with the specified root element. Same as * StringWriter stringWriter = new StringWriter(); save(createDocument(dataObject, rootElementURI, * rootElementName), stringWriter, null); stringWriter.toString(); * * @param dataObject specifies DataObject to be saved * @param rootElementURI the Target Namespace URI of the root XML element * @param rootElementName the Name of the root XML element * @return the saved XML document as a string * @throws IllegalArgumentException if the dataObject tree is not closed or has no container. */ public String save(DataObject dataObject, String rootElementURI, String rootElementName) { try { StringWriter writer = new StringWriter(); save(dataObject, rootElementURI, rootElementName, writer, getXmlMarshaller(null)); return writer.toString(); } catch (XMLMarshalException e) { throw SDOException.xmlMarshalExceptionOccurred(e, rootElementURI, rootElementName); } }
/** * Return the appinfo declared for this Type and source. The appinfo start and end tags and * content are returned. The xml namespace context is preserved in the appinfo element. If more * than one appinfo with the same source is declared on the same Type their contents are * concatenated. * * @param type the type with the appinfo declaration * @param source the source of the appinfo declaration. * @return the appinfo declared for this Type and source. */ public String getAppinfo(Type type, String source) { if (type == null) { throw SDOException.noAppInfoForNull(); } if (source == null) { source = ""; } return (String) ((SDOType) type).getAppInfoMap().get(source); }
/** * INTERNAL: Set this Type to a simple Type by passing in boolean value true. Otherwise, If * boolean value is passed in, instances of this type implement DataObject. * * @param datatype boolean value implying if it is a simple Type */ public void setDataType(boolean datatype) { if (datatype && isOpen()) { throw SDOException.typeCannotBeOpenAndDataType(getURI(), getName()); } isDataType = datatype; if (datatype) { setFinalized(true); } }
private void handleXMLMarshalException(XMLMarshalException xmlException) throws IOException { if (xmlException.getErrorCode() == XMLMarshalException.NO_DESCRIPTOR_WITH_MATCHING_ROOT_ELEMENT || xmlException.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT) { throw SDOException.globalPropertyNotFound(); } else if (xmlException.getCause() instanceof IOException) { throw (IOException) xmlException.getCause(); } else { throw xmlException; } }
private void save(XMLDocument xmlDocument, Writer outputWriter, XMLMarshaller anXMLMarshaller) throws IOException { if (xmlDocument == null) { throw new IllegalArgumentException( SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument")); } // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration()); anXMLMarshaller.setEncoding(xmlDocument.getEncoding()); anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation()); anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation()); WriterRecord writerRecord; if (anXMLMarshaller.isFormattedOutput()) { writerRecord = new FormattedWriterRecord(); } else { writerRecord = new WriterRecord(); } writerRecord.setWriter(outputWriter); writerRecord.setMarshaller(anXMLMarshaller); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setMarshalledObject(xmlDocument.getRootObject()); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setMarshalledObjectRootQName( new QName(xmlDocument.getRootElementURI(), xmlDocument.getRootElementName())); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setRootMarshalRecord(writerRecord); try { anXMLMarshaller.marshal(xmlDocument, writerRecord); } catch (XMLMarshalException xme) { if (xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT) { if (aHelperContext != ((SDOType) xmlDocument.getRootObject().getType()).getHelperContext()) { throw SDOException.dataObjectNotFromHelperContext(); } } } outputWriter.flush(); }
public void save(XMLDocument xmlDocument, Result result, Object options) throws IOException { if (xmlDocument == null) { throw new IllegalArgumentException( SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument")); } if (result instanceof StreamResult) { StreamResult streamResult = (StreamResult) result; Writer writer = streamResult.getWriter(); if (null == writer) { save(xmlDocument, streamResult.getOutputStream(), options); } else { save(xmlDocument, writer, options); } } else { // get XMLMarshaller once - as we may create a new instance if this helper isDirty=true XMLMarshaller anXMLMarshaller = getXmlMarshaller(options); // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration()); anXMLMarshaller.setEncoding(xmlDocument.getEncoding()); anXMLMarshaller.setSchemaLocation(xmlDocument.getSchemaLocation()); anXMLMarshaller.setNoNamespaceSchemaLocation(xmlDocument.getNoNamespaceSchemaLocation()); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setMarshalledObject(xmlDocument.getRootObject()); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setMarshalledObjectRootQName( new QName(xmlDocument.getRootElementURI(), xmlDocument.getRootElementName())); if (result instanceof SAXResult) { ContentHandlerRecord marshalRecord = new ContentHandlerRecord(); marshalRecord.setContentHandler(((SAXResult) result).getHandler()); marshalRecord.setMarshaller(anXMLMarshaller); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setRootMarshalRecord(marshalRecord); anXMLMarshaller.marshal(xmlDocument, marshalRecord); } else if (result instanceof DOMResult) { NodeRecord marshalRecord = new NodeRecord(); marshalRecord.setDOM(((DOMResult) result).getNode()); marshalRecord.setMarshaller(anXMLMarshaller); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setRootMarshalRecord(marshalRecord); anXMLMarshaller.marshal(xmlDocument, marshalRecord); } else { StringWriter writer = new StringWriter(); this.save(xmlDocument, writer, options); String xml = writer.toString(); StreamSource source = new StreamSource(new java.io.StringReader(xml)); anXMLMarshaller.getTransformer().transform(source, result); } } }
/** * Return the JAXB mapping for the SDO property. They are matched on their XML schema * representation. */ Mapping getJAXBMappingForProperty(SDOProperty sdoProperty) { DatabaseMapping sdoMapping = sdoProperty.getXmlMapping(); XMLField field; if (sdoMapping instanceof XMLObjectReferenceMapping) { XMLObjectReferenceMapping referenceMapping = (XMLObjectReferenceMapping) sdoMapping; field = (XMLField) referenceMapping.getFields().get(0); } else { field = (XMLField) sdoMapping.getField(); } TreeObjectBuilder treeObjectBuilder = (TreeObjectBuilder) descriptor.getObjectBuilder(); XPathNode xPathNode = treeObjectBuilder.getRootXPathNode(); XPathFragment xPathFragment = field.getXPathFragment(); while (xPathNode != null && xPathFragment != null) { if (xPathFragment.isAttribute()) { if (sdoProperty.isMany() && !sdoProperty.isContainment() && !sdoProperty.getType().isDataType()) { xPathFragment = null; break; } Map attributeChildrenMap = xPathNode.getAttributeChildrenMap(); if (null == attributeChildrenMap) { xPathNode = null; } else { xPathNode = (XPathNode) attributeChildrenMap.get(xPathFragment); } } else if (xPathFragment.nameIsText()) { xPathNode = xPathNode.getTextNode(); } else { Map nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap(); if (null == nonAttributeChildrenMap) { xPathNode = null; } else { xPathNode = (XPathNode) nonAttributeChildrenMap.get(xPathFragment); } } xPathFragment = xPathFragment.getNextFragment(); if (xPathFragment != null && xPathFragment.nameIsText()) { if (sdoProperty.isMany() && !sdoProperty.isContainment()) { xPathFragment = null; break; } } } if (null == xPathFragment && xPathNode != null) { if (xPathNode.getNodeValue().isMappingNodeValue()) { MappingNodeValue mappingNodeValue = (MappingNodeValue) xPathNode.getNodeValue(); return mappingNodeValue.getMapping(); } } throw SDOException.sdoJaxbNoMappingForProperty(sdoProperty.getName(), field.getXPath()); }
/** * Serializes an XMLDocument as an XML document into the outputStream. If the DataObject's Type * was defined by an XSD, the serialization will follow the XSD. Otherwise the serialization will * follow the format as if an XSD were generated as defined by the SDO specification. The * OutputStream will be flushed after writing. Does not perform validation to ensure compliance * with an XSD. * * @param xmlDocument specifies XMLDocument to be saved * @param outputStream specifies the OutputStream to write to. * @param options implementation-specific options. * @throws IOException for stream exceptions. * @throws IllegalArgumentException if the dataObject tree is not closed or has no container. */ public void save(XMLDocument xmlDocument, OutputStream outputStream, Object options) throws IOException { if (xmlDocument == null) { throw new IllegalArgumentException( SDOException.cannotPerformOperationWithNullInputParameter("save", "xmlDocument")); } XMLMarshaller xmlMarshaller = getXmlMarshaller(options); String encoding = xmlMarshaller.getEncoding(); if (xmlDocument.getEncoding() != null) { encoding = xmlDocument.getEncoding(); } OutputStreamWriter writer = new OutputStreamWriter(outputStream, encoding); save(xmlDocument, writer, xmlMarshaller); }
/** * Lazy load the WebLogic MBeanServer instance. * * @return */ private static MBeanServer getWLSMBeanServer() { if (wlsMBeanServer == null) { Context weblogicContext = null; try { weblogicContext = new InitialContext(); try { // The lookup string used depends on the context from which this class is being // accessed, i.e. servlet, EJB, etc. Try java:comp/env lookup wlsMBeanServer = (MBeanServer) weblogicContext.lookup(WLS_ENV_CONTEXT_LOOKUP); } catch (NamingException e) { // Lookup failed - try java:comp try { wlsMBeanServer = (MBeanServer) weblogicContext.lookup(WLS_CONTEXT_LOOKUP); } catch (NamingException ne) { throw SDOException.errorPerformingWLSLookup(WLS_MBEAN_SERVER, ne); } } } catch (NamingException nex) { throw SDOException.errorCreatingWLSInitialContext(nex); } } return wlsMBeanServer; }
/** * INTERNAL: This convenience method will look up a WebLogic execute thread from the runtime MBean * tree. The execute thread contains application information. This code will use the name of the * current thread to lookup the corresponding ExecuteThread. The ExecuteThread will allow us to * obtain the application name (and version, etc). * * @return application name or null if the name cannot be obtained */ private static Object getExecuteThread() { if (getWLSMBeanServer() != null) { // Lazy load the ThreadPoolRuntime instance if (wlsThreadPoolRuntime == null) { ObjectName service = null; ObjectName serverRuntime = null; try { service = new ObjectName(WLS_SERVICE_KEY); } catch (Exception x) { throw SDOException.errorGettingWLSObjectName( WLS_RUNTIME_SERVICE + " [" + WLS_SERVICE_KEY + "]", x); } try { serverRuntime = (ObjectName) wlsMBeanServer.getAttribute(service, WLS_SERVER_RUNTIME); } catch (Exception x) { throw SDOException.errorGettingWLSObjectName(WLS_SERVER_RUNTIME, x); } try { wlsThreadPoolRuntime = (ObjectName) wlsMBeanServer.getAttribute(serverRuntime, WLS_THREADPOOL_RUNTIME); } catch (Exception x) { throw SDOException.errorGettingWLSObjectName(WLS_THREADPOOL_RUNTIME, x); } } try { return wlsMBeanServer.invoke( wlsThreadPoolRuntime, WLS_EXECUTE_THREAD_GET_METHOD_NAME, new Object[] {Thread.currentThread().getName()}, new String[] {String.class.getName()}); } catch (Exception x) { throw SDOException.errorInvokingWLSMethodReflectively( WLS_EXECUTE_THREAD_GET_METHOD_NAME, WLS_THREADPOOL_RUNTIME, x); } } return null; }
public DataObject create(Class interfaceClass) { if (interfaceClass == null) { throw new IllegalArgumentException( SDOException.cannotPerformOperationWithNullInputParameter("create", "interfaceClass")); } Type type = getHelperContext().getTypeHelper().getType(interfaceClass); if (type != null) { return create(type); } // at this point the type may not have been defined or there could be a classloader issue SDOXMLHelper xmlHelper = (SDOXMLHelper) getHelperContext().getXMLHelper(); ClassLoader contextLoader = xmlHelper.getLoader(); ClassLoader interfaceLoader = interfaceClass.getClassLoader(); boolean loadersAreRelated = false; // check the hierarchy to see if the interface loader is a parent of the context loader List<ClassLoader> visitedLoaders = new ArrayList<ClassLoader>(); while (contextLoader != null && !loadersAreRelated) { if (visitedLoaders.contains(contextLoader)) { // if we encounter a loader we've already checked, break out break; } visitedLoaders.add(contextLoader); if (contextLoader == interfaceLoader) { loadersAreRelated = true; } ClassLoader parentLoader = contextLoader.getParent(); if (contextLoader == parentLoader) { break; } contextLoader = parentLoader; } throw new IllegalArgumentException( SDOException.typeNotFoundForInterface(interfaceClass.getName(), loadersAreRelated)); }
private XMLUnmarshaller getXmlUnmarshaller(Object options) { XMLUnmarshaller xmlUnmarshaller = getXmlUnmarshaller().clone(); if (null == options) { return xmlUnmarshaller; } try { DataObject optionsDO = (DataObject) options; if (optionsDO.isSet(SDOConstants.ATTACHMENT_UNMARSHALLER_OPTION)) { xmlUnmarshaller.setAttachmentUnmarshaller( (XMLAttachmentUnmarshaller) optionsDO.get(SDOConstants.ATTACHMENT_UNMARSHALLER_OPTION)); } return xmlUnmarshaller; } catch (ClassCastException ccException) { throw SDOException.optionsMustBeADataObject( ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS); } }
private XMLMarshaller getXmlMarshaller(Object options) { XMLMarshaller xmlMarshaller = getXmlMarshaller().clone(); if (null == options) { return xmlMarshaller; } try { DataObject optionsDO = (DataObject) options; if (optionsDO.isSet(SDOConstants.ATTACHMENT_MARSHALLER_OPTION)) { xmlMarshaller.setAttachmentMarshaller( (XMLAttachmentMarshaller) optionsDO.get(SDOConstants.ATTACHMENT_MARSHALLER_OPTION)); } xmlMarshaller.setMarshalListener( new SDOMarshalListener(xmlMarshaller, (SDOTypeHelper) aHelperContext.getTypeHelper())); return xmlMarshaller; } catch (ClassCastException ccException) { throw SDOException.optionsMustBeADataObject( ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS); } }
/** * INTERNAL: Saves the DataObject as an XML document with the specified root element. Same as * save(createDocument(dataObject, rootElementURI, rootElementName), writer, null); * * @param dataObject specifies DataObject to be saved * @param rootElementURI the Target Namespace URI of the root XML element * @param rootElementName the Name of the root XML element * @param writer specifies the Writer to write to. * @throws IOException for stream exceptions. * @throws IllegalArgumentException if the dataObject tree is not closed or has no container. */ private void save( DataObject rootObject, String rootElementURI, String rootElementName, Writer writer, XMLMarshaller anXMLMarshaller) throws XMLMarshalException { SDOXMLDocument xmlDocument = (SDOXMLDocument) createDocument(rootObject, rootElementURI, rootElementName); // Ask the SDOXMLDocument if we should include the XML declaration in the resulting XML anXMLMarshaller.setFragment(!xmlDocument.isXMLDeclaration()); WriterRecord writerRecord; if (anXMLMarshaller.isFormattedOutput()) { writerRecord = new FormattedWriterRecord(); } else { writerRecord = new WriterRecord(); } writerRecord.setWriter(writer); writerRecord.setMarshaller(anXMLMarshaller); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setMarshalledObject(rootObject); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()) .setMarshalledObjectRootQName(new QName(rootElementURI, rootElementName)); ((SDOMarshalListener) anXMLMarshaller.getMarshalListener()).setRootMarshalRecord(writerRecord); try { anXMLMarshaller.marshal(xmlDocument, writerRecord); } catch (XMLMarshalException xme) { if (xme.getErrorCode() == XMLMarshalException.DESCRIPTOR_NOT_FOUND_IN_PROJECT) { if (aHelperContext != ((SDOType) rootObject.getType()).getHelperContext()) { throw SDOException.dataObjectNotFromHelperContext(); } } } try { writer.flush(); } catch (IOException ex) { throw XMLMarshalException.marshalException(ex); } }
public Class getInstanceClass() { if ((javaClass == null) && (javaClassName != null)) { try { SDOClassLoader loader = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getLoader(); Class clazz = loader.getParent().loadClass(javaClassName); if (isValidInstanceClass(clazz)) { javaClass = clazz; } else { javaClass = getClass(); } } catch (ClassNotFoundException e) { javaClass = getClass(); } catch (SecurityException e) { throw SDOException.classNotFound(e, getURI(), getName()); } } if (javaClass == getClass()) { return null; } return javaClass; }
/** * INTERNAL: This method will return the key to be used to store/retrieve the delegates for a * given application. * * <p>OC4J classLoader levels: 0 - APP.web (servlet/jsp) or APP.wrapper (ejb) 1 - APP.root (parent * for helperContext) 2 - default.root 3 - system.root 4 - oc4j.10.1.3 (remote EJB) or * org.eclipse.persistence:11.1.1.0.0 5 - api:1.4.0 6 - jre.extension:0.0.0 7 - * jre.bootstrap:1.5.0_07 (with various J2SE versions) * * @return Application classloader for OC4J, application name for WebLogic, otherwise * Thread.currentThread().getContextClassLoader() */ private static Object getDelegateMapKey(ClassLoader classLoader) { String classLoaderName = classLoader.getClass().getName(); // Default to Thread.currentThread().getContextClassLoader() Object delegateKey = classLoader; // Delegates in OC4J server will be keyed on classloader if (classLoaderName.startsWith(OC4J_CLASSLOADER_NAME)) { // Check to see if we are running in a Servlet container or a local EJB container if ((classLoader.getParent() != null) // && ((classLoader.toString().indexOf(SDOConstants.CLASSLOADER_WEB_FRAGMENT) != -1) // || (classLoader.toString().indexOf(SDOConstants.CLASSLOADER_EJB_FRAGMENT) != -1))) { classLoader = classLoader.getParent(); } delegateKey = classLoader; // Delegates in WebLogic server will be keyed on application name } else if (classLoaderName.contains(WLS_CLASSLOADER_NAME)) { Object executeThread = getExecuteThread(); if (executeThread != null) { try { Method getMethod = PrivilegedAccessHelper.getPublicMethod( executeThread.getClass(), WLS_APPLICATION_NAME_GET_METHOD_NAME, PARAMETER_TYPES, false); delegateKey = PrivilegedAccessHelper.invokeMethod(getMethod, executeThread); // ExecuteThread returns null if (delegateKey == null) { delegateKey = classLoader; } } catch (Exception e) { throw SDOException.errorInvokingWLSMethodReflectively( WLS_APPLICATION_NAME_GET_METHOD_NAME, WLS_EXECUTE_THREAD, e); } } } return delegateKey; }
/** * According to the requirement, correspondingly perform isset, unset or set function. * * @param frag one string fragment in the path * @param path the String representation of path based access * @param caller the DataObject that pass path information in * @param value the value to be set as the target property's value * @param lastSlashIndex the last index of '/' in the path string * @param convertValue boolean used for set if we should convert the value * @param _case an int value indicating what kind of operation to use: set, isset or unset. * @return true if operation is isset and property's value is set, otherwise false. */ private boolean setIsSetUnSet( String frag, String path, DataObject caller, Object value, int lastSlashIndex, boolean convertValue, int _case) { int indexOfDot = frag.lastIndexOf('.'); int indexOfOpenBracket = frag.lastIndexOf('['); int indexOfCloseBracket = frag.lastIndexOf(']'); int numInLastProperty = getNumberInFrag(frag, indexOfDot, indexOfOpenBracket, indexOfCloseBracket); String lastPropertyName = getPropertyNameInFrag( frag, numInLastProperty, indexOfDot, indexOfOpenBracket); // get last property name on path for case 1 DataObject lastDataObject; if (-1 < lastSlashIndex) { Object lastObject = get(path.substring(0, lastSlashIndex), caller); // get last dataobject on path // If trying to access a list element from a null list, this object will be // an instance of ListWrapper, not DataObject, but the error message is the same // as if it was a null DataObject if (lastObject == null || lastObject instanceof ListWrapper) { throw SDOException.cannotPerformOperationOnProperty(lastPropertyName, path); } lastDataObject = (SDODataObject) lastObject; } else { lastDataObject = caller; } Property lastProperty = lastDataObject.getInstanceProperty(lastPropertyName); // get property of this dataobject switch (_case) { case SET: if (lastProperty == null) { lastProperty = ((SDODataObject) lastDataObject).defineOpenContentProperty(lastPropertyName, value); } if (lastProperty != null) { set(lastProperty, lastDataObject, numInLastProperty, value, convertValue); } return false; case ISSET: if (lastProperty == null) { return false; } return isSet(lastProperty, lastDataObject); case UNSET: if (lastProperty == null) { return false; } unSet(lastProperty, lastDataObject, numInLastProperty); return false; default: return false; } }
/** * INTERNAL: Make a copy of all settings on the original sequence onto the copy sequence while * using a cross-reference doMap that relates the original DataObject key to the copy DataObject * key. This function is used during deep copy and changeSummary copy. * * @param origSequence * @param copySequence * @param doMap */ private void replicateAndRereferenceSequenceCopyPrivate( SDOSequence origSequence, SDOSequence copySequence, DataObject dataObject, DataObject copy, Map doMap, SDOChangeSummary cs) { if (cs != null && cs.isDeleted(dataObject)) { origSequence = cs.getOldSequence(dataObject); } SDOProperty seqProperty = null; try { List settings = origSequence.getSettings(); for (int index = 0, size = origSequence.size(); index < size; index++) { Setting nextSetting = (Setting) settings.get(index); seqProperty = origSequence.getProperty(nextSetting); if ((null == seqProperty) || seqProperty.getType().isDataType()) { Setting copySetting = nextSetting.copy(copy); copySequence.getSettings().add(copySetting); copySequence.addValueToSettings(copySetting); } else { Object copySeqValue = null; Object origSeqValue = origSequence.getValue(index); if (cs != null) { Object orig = cs.getReverseDeletedMap().get(origSeqValue); if (orig != null) { origSeqValue = orig; } } if (origSeqValue instanceof XMLRoot) { origSeqValue = ((XMLRoot) origSeqValue).getObject(); } // lookup copy if not null, if null then the copySeqValue will be null in the reduced // scope assignment above if (null != origSeqValue) { copySeqValue = doMap.get(origSeqValue); } else { // as a secondary verification to the assignment above - make sure the copy is null as // well copySeqValue = null; // this assignment is however redundant in our reduced scope assignment above } // now we have the new value Setting copySetting = nextSetting.copy(copy, copySeqValue); copySequence.getSettings().add(copySetting); copySequence.addValueToSettings(copySetting); } /** * Move assignment inside the loop to minimize scope and to initialize the variable to null * to handle the case where the original is null and no lookup is performed. Do not move the * scope of this variable outside the for loop or we will end up with the previous * iterations' value set for a complex object that is unset(null). see #6026714 */ } } catch (ClassCastException cce) { // catch any failure of a DataObject cast above throw SDOException.foundSimpleValueForNonDataTypeProperty(seqProperty.getName()); } }