Package org.jpox

Examples of org.jpox.ClassLoaderResolver


            // Null value so nothing to do
            return;
        }

        // Check if the field has a FK defined
        ClassLoaderResolver clr = sm.getObjectManager().getClassLoaderResolver();
        MappedStoreManager storeMgr = (MappedStoreManager)sm.getObjectManager().getStoreManager();
        AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
        // TODO Cater for more than 1 related field
        boolean dependent = fmd.isDependent();
        boolean hasFK = false;
View Full Code Here


     * @param ownerSM the owner StateManager
     * @param ownerFieldNumber the owner absolute field number
     */   
    public void setObject(ObjectManager om, Object ps, int[] pos, Object value, StateManager ownerSM, int ownerFieldNumber)
    {
        ClassLoaderResolver clr = om.getClassLoaderResolver();
        ApiAdapter api = om.getApiAdapter();

        int n = 0;
        boolean foundClassAssignableFromValue = false;
        NotYetFlushedException notYetFlushed = null;

        if (value != null)
        {
          if (!om.isInserting(value))
          {
              // Object either already exists, or is not yet being inserted.
              Object id = api.getIdForObject(value);

              // Check if the PersistenceCapable exists in this datastore
              boolean requiresPersisting = false;
              if (om.getApiAdapter().isDetached(value) && ownerSM != null)
              {
                  // Detached object that needs attaching (or persisting if detached from a different datastore)
                  requiresPersisting = true;
              }
              else if (id == null)
              {
                  // Transient object, so we need to persist it
                  requiresPersisting = true;
              }
              else
              {
                    ObjectManager valueOM = ObjectManagerHelper.getObjectManager(value);
                  if (valueOM != null && om != valueOM)
                  {
                      throw new JPOXUserException(LOCALISER.msg("041015"), id);
                  }
              }
             
              if (requiresPersisting)
              {
                  // The object is either not yet persistent or is detached and so needs attaching
                  Object pcNew = om.persistObjectInternal(value, null, null, -1, StateManager.PC);
                  om.flushInternal(false);
                  id = api.getIdForObject(pcNew);
                  if (om.getApiAdapter().isDetached(value) && ownerSM != null)
                  {
                      // Update any detached reference to refer to the attached variant
                      ownerSM.replaceField(ownerFieldNumber, pcNew, true);
                        int relationType = fmd.getRelationType(clr);
                        if (relationType == Relation.ONE_TO_ONE_BI)
                        {
                            StateManager relatedSM = om.findStateManager(pcNew);
                            AbstractMemberMetaData[] relatedMmds = fmd.getRelatedMemberMetaData(clr);
                            // TODO Allow for multiple related fields
                            relatedSM.replaceField(relatedMmds[0].getAbsoluteFieldNumber(), ownerSM.getObject(), true);
                        }
                        else if (relationType == Relation.MANY_TO_ONE_BI)
                        {
                            // TODO Update the container element with the attached variant
                            if (JPOXLogger.PERSISTENCE.isInfoEnabled())
                            {
                                JPOXLogger.PERSISTENCE.info("PCMapping.setObject : object " + ownerSM.getInternalObjectId() +
                                    " has field " + ownerFieldNumber +
                                    " that is 1-N bidirectional - should really update the reference in the relation. Not yet supported");
                            }
                        }
                  }
              }       
            if (getNumberOfDatastoreFields() <= 0)
            {
                // If the field doesnt map to any datastore fields, omit the set process
              return;
            }         
          }
        }

        Class type = null;
        StateManager sm = null;
        if (value != null)
        {
            sm = om.findStateManager(value);
        }
        try
        {
          if (pos == null)
          {
            return;
          }
          if (sm != null)
          {
              sm.setStoringPC();
          }

            MetaDataManager mmgr = om.getStoreManager().getOMFContext().getMetaDataManager();
          boolean isPersistentInterface = mmgr.getMetaDataForInterface(clr.classForName(getType()), clr) != null;
          if (isPersistentInterface)
          {
              // Field is declared as a "persistent-interface" type so all impls of that type should match
              type = clr.classForName(getType());
          }
          else if (fmd != null && fmd.getFieldTypes() != null && fmd.getFieldTypes().length == 1)
          {
              isPersistentInterface = mmgr.getMetaDataForInterface(clr.classForName(fmd.getFieldTypes()[0]), clr) != null;
              if (isPersistentInterface)
              {
                  // Field is declared as interface and accepts "persistent-interface" value, so all impls should match
                  type = clr.classForName(fmd.getFieldTypes()[0]);
              }
          }

          for (int i=0; i<javaTypeMappings.length; i++)
          {
              if (n >=pos.length)
              {
                //this means we store all implementations to the same columns, so we reset the index
                n = 0;
                }
              int[] posMapping;
              if (javaTypeMappings[i].getReferenceMapping() != null)
              {          
                  posMapping = new int[javaTypeMappings[i].getReferenceMapping().getNumberOfDatastoreFields()];             
              }
              else
              {
                posMapping = new int[javaTypeMappings[i].getNumberOfDatastoreFields()];
              }
              for (int j=0; j<posMapping.length; j++)
              {
                  posMapping[j] = pos[n++];
              }
              try
              {
                    if (!isPersistentInterface)
                    {
                        // Normal interface
                        type = clr.classForName(javaTypeMappings[i].getType());
                    }
                    if (value != null && type.isAssignableFrom(value.getClass()))
                    {
                        foundClassAssignableFromValue = true;
                        javaTypeMappings[i].setObject(om, ps, posMapping, value);
View Full Code Here

    /**
     * Test for whether classes are descendents of each other.
     */
    public void testClassesAreDescendents()
    {
        ClassLoaderResolver clr = new JDOClassLoaderResolver(null);
       
        assertTrue("java.util.Collection and java.util.ArrayList should have been direct descendents but weren't",
            ClassUtils.classesAreDescendents(clr, "java.util.Collection", "java.util.ArrayList"));
        assertTrue("java.util.ArrayList and java.util.Collection should have been direct descendents but weren't",
            ClassUtils.classesAreDescendents(clr, "java.util.ArrayList", "java.util.Collection"));
View Full Code Here

public class PluginParserTest extends TestCase
{
    public void testParseExtensionPoint()
    {
        ClassLoaderResolver clr = new JDOClassLoaderResolver();
        NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION");
        assertEquals(0,mgr.getExtensionPoints().length);
        Bundle bundle0 = mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST0.MF",null));
        mgr.registerPluginExtensions(clr.getResource("/org/jpox/samples/plugin/plugin1expoint.xml",null),bundle0);
        assertEquals(2,mgr.getExtensionPoints().length);
        assertNull(mgr.getExtensionPoint("testID"));
        assertNull(mgr.getExtensionPoint("testID2"));
        assertNotNull(mgr.getExtensionPoint("org.jpox.testID"));
        assertNotNull(mgr.getExtensionPoint("org.jpox.testID2"));
        ExtensionPoint point = mgr.getExtensionPoint("org.jpox.testID");
        assertEquals("testID", point.getId());
        assertEquals("org.jpox.testID", point.getUniqueId());
        assertEquals("testName", point.getName());
        assertNotNull(clr.getResource("/org/jpox/samples/plugin/plugin1.xsd",null));
        assertEquals(clr.getResource("/org/jpox/samples/plugin/plugin1.xsd",null), point.getSchema());
        assertEquals(0,point.getExtensions().length);
        mgr.registerPluginExtensions(clr.getResource("/org/jpox/samples/plugin/plugin1.xml",null),bundle0);
        assertEquals(2,point.getExtensions().length);       
        Extension[] exts = point.getExtensions();
        assertEquals(exts[0].getPlugin(),exts[1].getPlugin());
        assertEquals(2,exts[0].getConfigurationElements().length);
       
View Full Code Here

        assertEquals(0,level1[0].getChildren().length);
    }
   
    public void testParseSymbolicName()
    {
        ClassLoaderResolver clr = new JDOClassLoaderResolver();
        NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION");
        Bundle bundle1 = mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST1.MF",null));
        mgr.registerPluginExtensions(clr.getResource("/org/jpox/samples/plugin/plugin1expoint.xml",null),bundle1);
        assertEquals(2,mgr.getExtensionPoints().length);
        assertNull(mgr.getExtensionPoint("testID"));
        assertNull(mgr.getExtensionPoint("testID2"));
        assertNotNull(mgr.getExtensionPoint("org.jpox.plugin.test1.testID"));
        assertNotNull(mgr.getExtensionPoint("org.jpox.plugin.test1.testID2"));

        Bundle bundle2 = mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST2.MF",null));
        mgr.registerPluginExtensions(clr.getResource("/org/jpox/samples/plugin/plugin1expoint.xml",null),bundle2);
        assertEquals(4,mgr.getExtensionPoints().length);
        assertNotNull(mgr.getExtensionPoint("org.jpox.plugin.test2.testID"));
        assertNotNull(mgr.getExtensionPoint("org.jpox.plugin.test2.testID2"));

        Extension[] ex = mgr.getExtensionPoint("org.jpox.plugin.test2.testID").getExtensions();
View Full Code Here

     * NonManagedPluginRegistry cannot handle multiple versions
     * of the same plugin, so it must raise an exception
     */
    public void testDuplicatedBundleSymbolicNameSameOrDifferentVersion()
    {
        ClassLoaderResolver clr = new JDOClassLoaderResolver();
        NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION");
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST1.MF",null));
        try
        {
            mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST1-1.MF",null));
          fail("Expected JPOXException");
        }
        catch(JPOXException ex)
        {
          //expected
View Full Code Here

        catch(JPOXUserException e){}
    }

    public void testRequireBundle()
    {
        ClassLoaderResolver clr = new JDOClassLoaderResolver();
        NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION");
        assertEquals(0,mgr.getExtensionPoints().length);
        Bundle bundle3 = mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST3.MF",null));
        Bundle bundle4 = mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST4.MF",null));
        Bundle bundle5 = mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST5.MF",null));
        assertEquals(1,bundle3.getRequireBundle().size());
        assertEquals("org.jpox.plugin.test4",((Bundle.BundleDescription)bundle3.getRequireBundle().iterator().next()).getBundleSymbolicName());
        assertEquals(0,bundle4.getRequireBundle().size());
        assertEquals(2,bundle5.getRequireBundle().size());
        assertEquals("org.jpox.plugin.test6",((Bundle.BundleDescription)bundle5.getRequireBundle().get(0)).getBundleSymbolicName());
View Full Code Here

            public void close(){}
            public void clearFilters(){}
            public void addFilter(Filter arg0){}
       
        });
        ClassLoaderResolver clr = new JDOClassLoaderResolver();
        NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION");
        assertEquals(0,mgr.getExtensionPoints().length);
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST3.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST4.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST5.MF",null));
        mgr.resolveConstraints();
        try
        {
            assertEquals(2,messages.size());
            assertTrue(messages.contains("Bundle \"org.jpox.plugin.test5\" requires \"org.jpox.plugin.test6\" but it cannot be resolved."));
View Full Code Here

            public void close(){}
            public void clearFilters(){}
            public void addFilter(Filter arg0){}
       
        });
        ClassLoaderResolver clr = new JDOClassLoaderResolver();
        NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION");
        assertEquals(0,mgr.getExtensionPoints().length);
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST10.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST11.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST12.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST13.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST14.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST15.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST16.MF",null));
        mgr.registerBundle(clr.getResource("/org/jpox/samples/plugin/MANIFEST17.MF",null));
        mgr.resolveConstraints();
        try
        {
            assertEquals(3,messages.size());
            assertTrue(messages.contains("Bundle \"org.jpox.plugin.test12\" requires \"org.jpox.plugin.test11\" version \"(1.2.0.b2\" but the resolved bundle has version \"1.2.0.b2\" which is outside the expected range."));
View Full Code Here

        getCallbackHandler().postCreate(myPC);

        if (myOM.getOMFContext().getPersistenceConfiguration().getBooleanProperty("org.jpox.manageRelationships"))
        {
            // Managed Relations : register non-null bidir fields for later processing
            ClassLoaderResolver clr = myOM.getClassLoaderResolver();
            int[] relationPositions = cmd.getRelationMemberPositions(myOM.getClassLoaderResolver());
            if (relationPositions != null)
            {
                for (int i=0;i<relationPositions.length;i++)
                {
View Full Code Here

TOP

Related Classes of org.jpox.ClassLoaderResolver

Copyright © 2018 www.massapicom. 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.