]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.project/src/org/simantics/project/management/OntologySpec.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.project / src / org / simantics / project / management / OntologySpec.java
index 4324fd3ddc9de0b247114d963b7a7424e39816ae..1fd1f070618aea763ac5d3e44dccbed8e7e5f0c1 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.project.management;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Collection;\r
-import java.util.List;\r
-import java.util.TreeMap;\r
-import java.util.regex.Pattern;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.exception.DatabaseException;\r
-import org.simantics.db.request.Read;\r
-import org.simantics.layer0.DatabaseManagementResource;\r
-import org.simantics.layer0.Layer0;\r
-\r
-/**\r
- * A description of an graph bundle\r
- *\r
- * @author Toni Kalajainen <toni.kalajainen@vtt.fi>\r
- */\r
-public class OntologySpec {\r
-\r
-       /** Versioned Id pattern */     \r
-       static String ID_PATTERN_STRING =                "[a-zA-Z_0-9]+(?:\\.[a-zA-Z_0-9]+)*";\r
-       static String VERSION_PATTERN_STRING =           "(\\d+).(\\d+).(\\d+).([a-zA-Z_0-9\\-]+)";\r
-       static Pattern ID_PATTERN = Pattern.compile(ID_PATTERN_STRING);\r
-       static Pattern VERSION_PATTERN = Pattern.compile(VERSION_PATTERN_STRING);\r
-       static Pattern VERSIONED_ID_PATTERN = Pattern.compile("(" + ID_PATTERN_STRING + ")/" + VERSION_PATTERN_STRING + "");\r
-       \r
-       /** Display name */\r
-       String name;    \r
-       /** OSGi versioned ID - id/major.minor.micro(.qualifier) */\r
-       String versionedId;\r
-       \r
-       /**\r
-        * Create new bundle spec \r
-        * \r
-        * @param name optional name\r
-        * @param versionedId\r
-        */\r
-       public OntologySpec(String name, String versionedId) {\r
-               if (!VERSIONED_ID_PATTERN.matcher(versionedId).matches()) \r
-                       throw new IllegalArgumentException("not versioned id");\r
-               this.versionedId = versionedId;\r
-               this.name = name == null ? versionedId : name;\r
-       }\r
-       \r
-       public String getName() {\r
-               return name;\r
-       }\r
-\r
-       public String getVersionedId() {\r
-               return versionedId;\r
-       }\r
-\r
-       @Override\r
-       public int hashCode() {\r
-               return versionedId.hashCode();\r
-       }\r
-       \r
-       @Override\r
-       public boolean equals(Object obj) {\r
-               if (obj == null) return false;\r
-               if (obj instanceof OntologySpec == false) return false;\r
-               OntologySpec other = (OntologySpec) obj;\r
-               return other.versionedId.equals(versionedId);\r
-       }\r
-       \r
-       @Override\r
-       public String toString() {\r
-               return name + "("+versionedId+")";\r
-       }\r
-\r
-       /** A query that reads all bundles from the database, result is ordered by versioned id */\r
-       static Read<List<OntologySpec>> QUERY = new Read<List<OntologySpec>>() {\r
-               @Override\r
-               public List<OntologySpec> perform(ReadGraph g) throws DatabaseException {\r
-                       DatabaseManagementResource DatabaseManagement = DatabaseManagementResource.getInstance(g);\r
-                       Layer0 L0 = Layer0.getInstance(g);\r
-                       Collection<Resource> tgs = g.getObjects(DatabaseManagement.InstalledGraphBundles, L0.ConsistsOf);\r
-                       TreeMap<String, OntologySpec> result = new TreeMap<String, OntologySpec>();                     \r
-                       for (Resource tg : tgs) {\r
-                               if ( !g.isInstanceOf(tg, DatabaseManagement.GraphBundle) ) continue; \r
-                               try {\r
-                                       String name = g.getPossibleRelatedValue(tg, L0.HasName);\r
-                                       String versionedId = g.getPossibleRelatedValue(tg, DatabaseManagement.HasVersionedId);\r
-                                       OntologySpec bs = new OntologySpec(name, versionedId);\r
-                                       result.put( bs.versionedId, bs );\r
-                               } catch (IllegalArgumentException iae) {\r
-                                       continue;\r
-                               }\r
-                       }                                       \r
-                       return new ArrayList<OntologySpec>(result.values());\r
-               }\r
-       };\r
-       \r
-}\r
-\r
+/*******************************************************************************
+ * Copyright (c) 2007 VTT Technical Research Centre of Finland and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.project.management;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.TreeMap;
+import java.util.regex.Pattern;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.request.Read;
+import org.simantics.layer0.DatabaseManagementResource;
+import org.simantics.layer0.Layer0;
+
+/**
+ * A description of an graph bundle
+ *
+ * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
+ */
+public class OntologySpec {
+
+       /** Versioned Id pattern */     
+       static String ID_PATTERN_STRING =                "[a-zA-Z_0-9]+(?:\\.[a-zA-Z_0-9]+)*";
+       static String VERSION_PATTERN_STRING =           "(\\d+).(\\d+).(\\d+).([a-zA-Z_0-9\\-]+)";
+       static Pattern ID_PATTERN = Pattern.compile(ID_PATTERN_STRING);
+       static Pattern VERSION_PATTERN = Pattern.compile(VERSION_PATTERN_STRING);
+       static Pattern VERSIONED_ID_PATTERN = Pattern.compile("(" + ID_PATTERN_STRING + ")/" + VERSION_PATTERN_STRING + "");
+       
+       /** Display name */
+       String name;    
+       /** OSGi versioned ID - id/major.minor.micro(.qualifier) */
+       String versionedId;
+       
+       /**
+        * Create new bundle spec 
+        * 
+        * @param name optional name
+        * @param versionedId
+        */
+       public OntologySpec(String name, String versionedId) {
+               if (!VERSIONED_ID_PATTERN.matcher(versionedId).matches()) 
+                       throw new IllegalArgumentException("not versioned id");
+               this.versionedId = versionedId;
+               this.name = name == null ? versionedId : name;
+       }
+       
+       public String getName() {
+               return name;
+       }
+
+       public String getVersionedId() {
+               return versionedId;
+       }
+
+       @Override
+       public int hashCode() {
+               return versionedId.hashCode();
+       }
+       
+       @Override
+       public boolean equals(Object obj) {
+               if (obj == null) return false;
+               if (obj instanceof OntologySpec == false) return false;
+               OntologySpec other = (OntologySpec) obj;
+               return other.versionedId.equals(versionedId);
+       }
+       
+       @Override
+       public String toString() {
+               return name + "("+versionedId+")";
+       }
+
+       /** A query that reads all bundles from the database, result is ordered by versioned id */
+       static Read<List<OntologySpec>> QUERY = new Read<List<OntologySpec>>() {
+               @Override
+               public List<OntologySpec> perform(ReadGraph g) throws DatabaseException {
+                       DatabaseManagementResource DatabaseManagement = DatabaseManagementResource.getInstance(g);
+                       Layer0 L0 = Layer0.getInstance(g);
+                       Collection<Resource> tgs = g.getObjects(DatabaseManagement.InstalledGraphBundles, L0.ConsistsOf);
+                       TreeMap<String, OntologySpec> result = new TreeMap<String, OntologySpec>();                     
+                       for (Resource tg : tgs) {
+                               if ( !g.isInstanceOf(tg, DatabaseManagement.GraphBundle) ) continue; 
+                               try {
+                                       String name = g.getPossibleRelatedValue(tg, L0.HasName);
+                                       String versionedId = g.getPossibleRelatedValue(tg, DatabaseManagement.HasVersionedId);
+                                       OntologySpec bs = new OntologySpec(name, versionedId);
+                                       result.put( bs.versionedId, bs );
+                               } catch (IllegalArgumentException iae) {
+                                       continue;
+                               }
+                       }                                       
+                       return new ArrayList<OntologySpec>(result.values());
+               }
+       };
+       
+}
+