@@ -3,6 +3,7 @@ package graph
33import graph.plugin.Plugin
44import graph.type.EdgeSpec
55import graph.type.EdgeSpecFactory
6+ import graph.type.Type
67import graph.type.VertexSpec
78import graph.type.VertexSpecFactory
89import graph.type.DefaultVertexFactory
@@ -34,6 +35,7 @@ class Graph {
3435 private Set<? extends Edge > edges = [] as LinkedHashSet<? extends Edge >
3536 private final Set<Class > edgeTraitsSet = [] as LinkedHashSet<Class >
3637 private final Set<? extends Plugin > plugins = [] as LinkedHashSet<? extends Plugin >
38+ private final Set<? extends Type > types = [] as LinkedHashSet<? extends Type >
3739 @PackageScope
3840 EdgeFactory edgeFactory = new UnDirectedEdgeFactory ()
3941 @PackageScope
@@ -170,6 +172,10 @@ class Graph {
170172 Collections . unmodifiableSet(plugins)
171173 }
172174
175+ Set<? extends Type > getTypes () {
176+ Collections . unmodifiableSet(types)
177+ }
178+
173179 /**
174180 * Creates and applies a {@link Plugin} to this graph.
175181 * @param pluginClass - the {@link Plugin} to create and apply to this graph.
@@ -186,6 +192,30 @@ class Graph {
186192 plugin. apply(this )
187193 }
188194
195+ void apply (String pluginName ) {
196+ Properties properties = new Properties ()
197+ properties. load(getClass(). getResourceAsStream(" /META-INF/graph-plugins/${ pluginName} .properties" ))
198+ apply(Class . forName((String ) properties. ' implementation-class' ))
199+ }
200+
201+ void type (Class typeClass ) {
202+ if (types. contains(typeClass)) {
203+ throw new IllegalArgumentException (" $typeClass . name is already applied." )
204+ }
205+ if (! typeClass. interfaces. contains(Type )) {
206+ throw new IllegalArgumentException (" $typeClass . name does not implement Plugin" )
207+ }
208+ types << typeClass
209+ Type type = typeClass. newInstance()
210+ type. apply(this )
211+ }
212+
213+ void type (String typeName ) {
214+ Properties properties = new Properties ()
215+ properties. load(getClass(). getResourceAsStream(" /META-INF/graph-types/${ typeName} .properties" ))
216+ type(Class . forName((String ) properties. ' implementation-class' ))
217+ }
218+
189219 /**
190220 * Applies trait to all vertices and all future vertices.
191221 * @param traits to add to vertices and all future vertices
0 commit comments