- public static <C> String print(RosettaEnv env, String nameOrContentType, boolean optional) throws APIException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
- // Discover ClassName
- String className = null;
- String version = null;
- TYPE type = TYPE.JSON; // default
- if(nameOrContentType.startsWith("application/")) {
- for(String ct : nameOrContentType.split("\\s*,\\s*")) {
- for(String elem : ct.split("\\s*;\\s*")) {
- if(elem.endsWith("+json")) {
- type = TYPE.JSON;
- className = elem.substring(elem.indexOf('/')+1, elem.length()-5);
- } else if(elem.endsWith("+xml")) {
- type = TYPE.XML;
- className = elem.substring(elem.indexOf('/')+1, elem.length()-4);
- } else if(elem.startsWith("version=")) {
- version = elem.substring(8);
- }
- }
- if(className!=null && version!=null)break;
- }
- if(className==null) {
- throw new APIException(nameOrContentType + " does not contain Class Information");
- }
- } else {
- className = nameOrContentType;
- }
-
- // No Void.class in aaf.v2_0 package causing errors when trying to use a newVoidv2_0
- // method similar to others in this class. This makes it work, but is it right?
- if ("Void".equals(className)) return "";
-
- if("1.1".equals(version)) {
- version = "v1_0";
- } else if(version!=null) {
- version = "v" + version.replace('.', '_');
- } else {
- version = "v2_0";
- }
-
- Class<?> cls;
- try {
- cls = Examples.class.getClassLoader().loadClass("aaf."+version+'.'+className);
- } catch (ClassNotFoundException e) {
- throw new APIException(e);
- }
-
- Method meth;
- try {
- meth = Examples.class.getDeclaredMethod("new"+cls.getSimpleName()+version,boolean.class);
- } catch (Exception e) {
- throw new APIException("ERROR: " + cls.getName() + " does not have an Example in Code. Request from AAF Developers");
- }
-
- RosettaDF<C> df = env.newDataFactory(cls);
- df.option(Data.PRETTY);
-
- Object data = meth.invoke(null,optional);
-
- @SuppressWarnings("unchecked")
- String rv = df.newData().load((C)data).out(type).asString();
-// Object obj = df.newData().in(type).load(rv).asObject();
- return rv;
- }
-
- /*
- * Set Base Class Request (easier than coding over and over)
- */
- private static void setOptional(Request req) {
- GregorianCalendar gc = new GregorianCalendar();
- req.setStart(Chrono.timeStamp(gc));
- gc.add(GregorianCalendar.MONTH, 6);
- req.setEnd(Chrono.timeStamp(gc));
-// req.setForce("false");
-
- }
-
- @SuppressWarnings("unused")
- private static Request newRequestv2_0(boolean optional) {
- Request r = new Request();
- setOptional(r);
- return r;
- }
- @SuppressWarnings("unused")
- private static RolePermRequest newRolePermRequestv2_0(boolean optional) {
- RolePermRequest rpr = new RolePermRequest();
- Pkey pkey = new Pkey();
- pkey.setType("org.osaaf.myns.mytype");
- pkey.setInstance("myInstance");
- pkey.setAction("myAction");
- rpr.setPerm(pkey);
- rpr.setRole("org.osaaf.myns.myrole");
- if(optional)setOptional(rpr);
- return rpr;
- }
-
- @SuppressWarnings("unused")
- private static Roles newRolesv2_0(boolean optional) {
- Role r;
- Pkey p;
- Roles rs = new Roles();
- rs.getRole().add(r = new Role());
- r.setName("org.osaaf.myns.myRole");
- r.getPerms().add(p = new Pkey());
- p.setType("org.osaaf.myns.myType");
- p.setInstance("myInstance");
- p.setAction("myAction");
-
- r.getPerms().add(p = new Pkey());
- p.setType("org.osaaf.myns.myType");
- p.setInstance("myInstance");
- p.setAction("myOtherAction");
-
- rs.getRole().add(r = new Role());
- r.setName("org.osaaf.myns.myOtherRole");
- r.getPerms().add(p = new Pkey());
- p.setType("org.osaaf.myns.myOtherType");
- p.setInstance("myInstance");
- p.setAction("myAction");
-
- r.getPerms().add(p = new Pkey());
- p.setType("org.osaaf.myns.myOthertype");
- p.setInstance("myInstance");
- p.setAction("myOtherAction");
+ public static <C> String print(RosettaEnv env, String nameOrContentType, boolean optional) throws APIException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
+ // Discover ClassName
+ String className = null;
+ String version = null;
+ TYPE type = TYPE.JSON; // default
+ if (nameOrContentType.startsWith("application/")) {
+ for (String ct : nameOrContentType.split("\\s*,\\s*")) {
+ for (String elem : ct.split("\\s*;\\s*")) {
+ if (elem.endsWith("+json")) {
+ type = TYPE.JSON;
+ className = elem.substring(elem.indexOf('/')+1, elem.length()-5);
+ } else if (elem.endsWith("+xml")) {
+ type = TYPE.XML;
+ className = elem.substring(elem.indexOf('/')+1, elem.length()-4);
+ } else if (elem.startsWith("version=")) {
+ version = elem.substring(8);
+ }
+ }
+ if (className!=null && version!=null)
+ break;
+ }
+ if (className==null) {
+ throw new APIException(nameOrContentType + " does not contain Class Information");
+ }
+ } else {
+ className = nameOrContentType;
+ }
+
+ // No Void.class in aaf.v2_0 package causing errors when trying to use a newVoidv2_0
+ // method similar to others in this class. This makes it work, but is it right?
+ if ("Void".equals(className))
+ return "";
+
+ if ("1.1".equals(version)) {
+ version = "v1_0";
+ } else if (version!=null) {
+ version = "v" + version.replace('.', '_');
+ } else {
+ version = "v2_0";
+ }
+
+ Class<?> cls=null;
+ int minorIdx = version.indexOf('_');
+ if(minorIdx<0) {
+ throw new APIException("Invalid Interface Version " + version);
+ }
+ int minor = Integer.parseInt(version.substring(minorIdx+1));
+ String vprefix=version.substring(0, minorIdx+1);
+ while(cls==null && minor>=0) {
+ try {
+ cls = Examples.class.getClassLoader().loadClass("aaf."+vprefix+minor+'.'+className);
+ } catch (ClassNotFoundException e) {
+ if(--minor<0) {
+ throw new APIException("No Example for Version " + version + " found.");
+ }
+ }
+ }
+
+ if(cls==null) {
+ throw new APIException("ERROR: " + "aaf."+vprefix+"X not found.");
+ }
+
+ Method meth;
+ try {
+ meth = Examples.class.getDeclaredMethod("new"+cls.getSimpleName()+vprefix+minor,boolean.class);
+ } catch (Exception e) {
+ throw new APIException("ERROR: " + cls.getName() + " does not have an Example in Code. Request from AAF Developers");
+ }
+
+ RosettaDF<C> df = env.newDataFactory(cls);
+ df.option(Data.PRETTY);
+
+ Object data = meth.invoke(null,optional);
+
+ @SuppressWarnings("unchecked")
+ String rv = df.newData().load((C)data).out(type).asString();
+// Object obj = df.newData().in(type).load(rv).asObject();
+ return rv;
+ }
+
+ /*
+ * Set Base Class Request (easier than coding over and over)
+ */
+ private static void setOptional(Request req) {
+ GregorianCalendar gc = new GregorianCalendar();
+ req.setStart(Chrono.timeStamp(gc));
+ gc.add(GregorianCalendar.MONTH, 6);
+ req.setEnd(Chrono.timeStamp(gc));
+// req.setForce("false");
+
+ }
+
+ @SuppressWarnings("unused")
+ private static Request newRequestv2_0(boolean optional) {
+ Request r = new Request();
+ setOptional(r);
+ return r;
+ }
+ @SuppressWarnings("unused")
+ private static RolePermRequest newRolePermRequestv2_0(boolean optional) {
+ RolePermRequest rpr = new RolePermRequest();
+ Pkey pkey = new Pkey();
+ pkey.setType("org.osaaf.myns.mytype");
+ pkey.setInstance("myInstance");
+ pkey.setAction("myAction");
+ rpr.setPerm(pkey);
+ rpr.setRole("org.osaaf.myns.myrole");
+ if (optional)setOptional(rpr);
+ return rpr;
+ }
+
+ @SuppressWarnings("unused")
+ private static Roles newRolesv2_0(boolean optional) {
+ Role r;
+ Pkey p;
+ Roles rs = new Roles();
+ r = new Role();
+ rs.getRole().add(r);
+ r.setName("org.osaaf.myns.myRole");
+ p = new Pkey();
+ r.getPerms().add(p);
+ p.setType("org.osaaf.myns.myType");
+ p.setInstance("myInstance");
+ p.setAction("myAction");
+
+ p = new Pkey();
+ r.getPerms().add(p);
+ p.setType("org.osaaf.myns.myType");
+ p.setInstance("myInstance");
+ p.setAction("myOtherAction");
+
+ r = new Role();
+ rs.getRole().add(r);
+ r.setName("org.osaaf.myns.myOtherRole");
+ p = new Pkey();
+ r.getPerms().add(p);
+ p.setType("org.osaaf.myns.myOtherType");
+ p.setInstance("myInstance");
+ p.setAction("myAction");
+
+ p = new Pkey();
+ r.getPerms().add(p);
+ p.setType("org.osaaf.myns.myOthertype");
+ p.setInstance("myInstance");
+ p.setAction("myOtherAction");
+
+ return rs;
+ }
+
+
+ @SuppressWarnings("unused")
+ private static PermRequest newPermRequestv2_0(boolean optional) {
+ PermRequest pr = new PermRequest();
+ pr.setType("org.osaaf.myns.myType");
+ pr.setInstance("myInstance");
+ pr.setAction("myAction");
+ if (optional) {
+ pr.setDescription("Short and meaningful verbiage about the Permission");
+
+ setOptional(pr);
+ }
+ return pr;
+ }
+
+ @SuppressWarnings("unused")
+ private static Perm newPermv2_0(boolean optional) {
+ Perm pr = new Perm();
+ pr.setType("org.osaaf.myns.myType");
+ pr.setInstance("myInstance");
+ pr.setAction("myAction");
+ pr.getRoles().add("org.osaaf.aaf.myRole");
+ pr.getRoles().add("org.osaaf.aaf.myRole2");
+ pr.setDescription("This is my description, and I'm sticking with it");
+ if (optional) {
+ pr.setDescription("Short and meaningful verbiage about the Permission");
+ }
+ return pr;
+ }