Pastebin launched a little side project called HostCabi.net, check it out ;-)Pastebin is 300% more awesome when you are logged in. Sign Up, it's FREE!
Guest

CaribeanAlien

By: a guest on Feb 22nd, 2010  |  syntax: Java  |  size: 2.54 KB  |  hits: 127  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public static void main(String arg[])
  2.   {
  3.  
  4.     ResourceSet resourceSet = new ResourceSetImpl();
  5.  
  6.     resourceSet.getPackageRegistry().put(UMLPackage.eNS_URI, UMLPackage.eINSTANCE);
  7.  
  8.     resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
  9.     Map uriMap = resourceSet.getURIConverter().getURIMap();
  10.     URI uri = URI.createURI("jar:file:/C:/org.eclipse.uml2.uml.resources_2.2.0.v200805131030.jar!/");
  11.     uriMap.put(URI.createURI(UMLResource.LIBRARIES_PATHMAP), uri.appendSegment("libraries").appendSegment(""));
  12.     uriMap.put(URI.createURI(UMLResource.METAMODELS_PATHMAP), uri.appendSegment("metamodels").appendSegment(""));
  13.     uriMap.put(URI.createURI(UMLResource.PROFILES_PATHMAP), uri.appendSegment("profiles").appendSegment(""));
  14.  
  15.    
  16.    
  17.  
  18.     System.out.println("[readMM] : try to access to " + UMLResource.UML_METAMODEL_URI);
  19.     Resource res = resourceSet.getResource(URI.createURI(UMLResource.UML_METAMODEL_URI), true);
  20.     EcoreUtil.resolveAll(res);
  21.     System.out.println(">" + res.toString());
  22.     TreeIterator<EObject> it = res.getAllContents();
  23.  
  24.     while (it.hasNext())
  25.       {
  26.         EObject eobj = (EObject)it.next();
  27.  
  28.         System.out.println(">>" + eobj.getClass().getName() + " " + eobj.hashCode());
  29.  
  30.         if (eobj.eIsProxy())
  31.         {
  32.           System.out.println("proxy PROBLEM");
  33.           System.out.println(eobj.eClass().getName());
  34.  
  35.           EObject eobjResolved = EcoreUtil.resolve(eobj, resourceSet);
  36.           if (eobjResolved.equals(eobj))
  37.           {
  38.             System.err.println("Proxy not solved");
  39.           }
  40.           else
  41.           {
  42.             System.out.println("Proxy solved : " + eobjResolved.hashCode());
  43.             eobj = eobjResolved;
  44.           }
  45.         }
  46.  
  47.         EList<EStructuralFeature> listee = eobj.eClass().getEAllStructuralFeatures();
  48.         ListIterator<EStructuralFeature> li = listee.listIterator();
  49.         while (li.hasNext())
  50.         {
  51.           EStructuralFeature esf = li.next();
  52.           try
  53.           {
  54.             System.out.println("\t" + esf.getName() + " : " + eobj.eClass().eGet(esf));
  55.           }
  56.           catch (Exception e)
  57.           {//e.printStackTrace();
  58.  
  59.           }
  60.         }
  61.  
  62.         if (eobj.eClass() instanceof EClass)
  63.         {// if
  64.           if (eobj.eContainer() == null)
  65.           {
  66.             System.out.println("this element has a null container : is it the root element? ");
  67.           }
  68.         }
  69.  
  70.         //it.prune();
  71.      
  72.      
  73.     }
  74.  
  75.   }