public void testVersionIncrease() { Item item = (Item) retrieveOnlyInstance(Item.class); ObjectInfo objectInfo = db().getObjectInfo(item); long version1 = objectInfo.getCommitTimestamp(); item._name = "modified"; db().store(item); db().commit(); long version2 = objectInfo.getCommitTimestamp(); Assert.isGreater(version1, version2); db().store(item); db().commit(); objectInfo = db().getObjectInfo(item); long version3 = objectInfo.getCommitTimestamp(); Assert.isGreater(version2, version3); }
/** * Remove all objects in the database. Read the SQL file and check all CREATE TABLE statements to * collect the list of table to remove. * * @param dbms * @throws FileNotFoundException * @throws IOException */ public void removeObjects( ServletContext servletContext, Dbms dbms, String appPath, String filePath, String filePrefix) throws FileNotFoundException, IOException { if (Log.isDebugEnabled(Geonet.DB)) Log.debug(Geonet.DB, "Removing database objects"); List<String> schema = loadSchemaFile(servletContext, dbms, appPath, filePath, filePrefix); // --- step 1 : collect objects to remove ArrayList<ObjectInfo> objects = new ArrayList<ObjectInfo>(); for (String row : schema) if (row.toUpperCase().startsWith("CREATE ")) { ObjectInfo oi = new ObjectInfo(); oi.name = getObjectName(row); oi.type = getObjectType(row); if (!oi.type.toLowerCase().equals("index")) objects.add(oi); } // --- step 2 : remove objects while (true) { boolean removed = false; for (Iterator<ObjectInfo> i = objects.iterator(); i.hasNext(); ) { ObjectInfo oi = i.next(); if (Log.isDebugEnabled(Geonet.DB)) Log.debug(Geonet.DB, " * Dropping " + oi.name); String query = "DROP " + oi.type + " " + oi.name; if (safeExecute(dbms, query)) { removed = true; i.remove(); } } if (objects.size() == 0) return; // --- if no object was removed then we have a cyclic loop if (!removed) { ArrayList<String> al = new ArrayList<String>(); for (ObjectInfo oi : objects) al.add(oi.name); return; } } }
/** * Adds an object to the inspector. * * @param o the object that is to be added * @param objID the ID of the object (only used when loading from file or if replacing instance, * because then we need to restore the ID) if <code>null</code> the id will be generated * (usual case) * @return <code>true</code>, if successfully added, i.e. is not already atached to the inspector; * <code>false</code> otherwise */ public boolean addObject(Object o, Integer objID) { System.out.println(">> Add Object: " + o); boolean alreadyAdded = false; // search for an already existing reference to object o for (ObjectEntry oE : objects) { if (oE.getObject() == o) { System.out.println(" --> Object already added!"); alreadyAdded = true; break; } } // Object annotations ObjectInfo objectInfo = null; Annotation[] objectAnnotations = o.getClass().getAnnotations(); for (Annotation a : objectAnnotations) { if (a.annotationType().equals(ObjectInfo.class)) { objectInfo = (ObjectInfo) a; break; } } if (objectInfo != null && objectInfo.instances() <= numberOfInstances(o.getClass().getName())) { System.err.println( ">> Cannot add Object: only " + objectInfo.instances() + " instances allowed!"); return false; } if (!alreadyAdded) { ObjectDescription oDesc = generateObjectDescription(o, objID, true); if (oDesc == null) { return false; } getObjectDescriptions().add(oDesc); } // end if(!alredyAdded) return !alreadyAdded; }
/** * Update local information from the scene. It's important that this method is synchronized * because we get ConcurrentModificationException's during rendering otherwise. * * <p>This method is called from sceneChanged(). */ protected synchronized void updateCharges(Scene theScene) { // Clear cached infos. cachedBounds = null; cachedWire = null; charges.clear(); setPositive = null; setNegative = null; // Get all selection sets. Object layersObj = theScene.getMetadata("selectionsPlugin.selectionSets"); if (layersObj == null) return; if (!(layersObj instanceof ArrayList)) return; ArrayList<ObjectSet> layers = (ArrayList<ObjectSet>) layersObj; // Try to find those which are of interest for us. for (ObjectSet set : layers) { if (set.getName().equals(setNamePositive)) { setPositive = set; } else if (set.getName().equals(setNameNegative)) { setNegative = set; } } // Create charges. if (setPositive != null) { for (ObjectInfo oi : setPositive.getObjects(theScene)) { if (oi.getObject() instanceof Sphere) { Sphere s = (Sphere) oi.getObject(); double q = s.getRadii().x; Vec3 pos = oi.getCoords().getOrigin(); charges.add(new SphereCharge(pos, q)); } } } if (setNegative != null) { for (ObjectInfo oi : setNegative.getObjects(theScene)) { if (oi.getObject() instanceof Sphere) { Sphere s = (Sphere) oi.getObject(); double q = -s.getRadii().x; Vec3 pos = oi.getCoords().getOrigin(); charges.add(new SphereCharge(pos, q)); } } } }
public static void writeScene( Scene theScene, m2 out, boolean wholeScene, double tol, boolean smooth, boolean inject) { // Write the objects in the scene. int numVert = 0, numNorm = 0, numTexVert = 0; Hashtable<String, String> groupNames = new Hashtable<String, String>(); NumberFormat nf = NumberFormat.getNumberInstance(Locale.US); nf.setMaximumFractionDigits(5); nf.setGroupingUsed(false); for (int i = 0; i < theScene.getNumObjects(); i++) { // Get a rendering mesh for the object. ObjectInfo info = theScene.getObject(i); if (!wholeScene && !info.selected) continue; if (info.getObject().getTexture() == null) continue; FacetedMesh mesh; if (!smooth && info.getObject() instanceof FacetedMesh) mesh = (FacetedMesh) info.getObject(); else mesh = info.getObject().convertToTriangleMesh(tol); if (mesh == null) continue; // Find the normals. Vec3 norm[]; int normIndex[][] = new int[mesh.getFaceCount()][]; if (mesh instanceof TriangleMesh) { RenderingMesh rm = ((TriangleMesh) mesh).getRenderingMesh(Double.MAX_VALUE, false, info); norm = rm.norm; for (int j = 0; j < normIndex.length; j++) normIndex[j] = new int[] {rm.triangle[j].n1, rm.triangle[j].n2, rm.triangle[j].n3}; } else { norm = mesh.getNormals(); for (int j = 0; j < normIndex.length; j++) { normIndex[j] = new int[mesh.getFaceVertexCount(j)]; for (int k = 0; k < normIndex[j].length; k++) normIndex[j][k] = mesh.getFaceVertexIndex(j, k); } } // Write out the object. Mat4 trans = info.getCoords().fromLocal(); MeshVertex vert[] = mesh.getVertices(); System.out.println("nVertixes:\t" + out.vertex.length); for (int j = 0; j < vert.length; j++) { Vec3 v = trans.times(vert[j].r); float[] tf = new float[3]; tf[0] = (float) v.x; tf[1] = (float) v.y; tf[2] = (float) v.z; out.vertex[j].setVertexPos(tf); } /*short faceCount[][]=new short[mesh.getFaceCount()][3]; for(int f=0;f<mesh.getFaceCount();f++){ faceCount[f][0]=(short) mesh.getFaceVertexIndex(f, 0); faceCount[f][1]=(short) mesh.getFaceVertexIndex(f, 1); faceCount[f][2]=(short) mesh.getFaceVertexIndex(f, 2); } System.out.println("Old nTriangles:\t"+out.movi.nTriangles); out.movi.setnewSize(faceCount.length, inject); out.movi.render(); System.out.println("New nTriangles:\t"+out.movi.nTriangles); for (int j = 0; j < faceCount.length; j++) { out.movi.setnewIndex(j, faceCount[j]); } if(useuv==true){ UVMapping uvmap=(UVMapping) info.getObject().getTextureMapping(); Vec2 uv[]=uvmap.findTextureCoordinates(mesh); out.motv.setnewSize(out.movt.nVertices, inject); for(int n=0;n<out.movt.nVertices;n++){ if(n<=uv.length){ float[] txcoord={(float) uv[n].x,(float) uv[n].y}; out.motv.setnewTexVertex(n, txcoord);} else{ float[] txcoord={0.0f,0.0f}; out.motv.setnewTexVertex(n, txcoord); } }} if(inject==false){ out.moba.setnewSize(1, false); out.movt.render(); out.movi.render(); out.moba.entrys[0]=new MOBA_Entry((short)0,(short)out.movt.nVertices,0,out.movi.nTriangles); out.mobn.setnewSize(1, false); out.mobn.entrys[0]=new MOBN_Entry(out.movi.nTriangles, 1); }*/ /* out.monr.setnewSize(norm.length); out.monr.render(); for (int j = 0; j < norm.length; j++) { float[] tf = new float[3]; if (norm[j] == null){ tf[0]=1f;tf[1]=0f;tf[2]=0f; out.monr.setNormalPos(j, tf);} else { Vec3 v = trans.timesDirection(norm[j]); tf[0]=(float) v.x;tf[1]=(float) v.y;tf[2]=(float)v.z; out.monr.setnewNormalPos(j, tf); } }*/ numVert += vert.length; numNorm += norm.length; } save(out); }
public ObjectDescription generateObjectDescription(Object o, Integer objID, boolean addObject) { ObjectDescription result = null; // Object annotations ObjectInfo objectInfo = null; Annotation[] objectAnnotations = o.getClass().getAnnotations(); for (Annotation a : objectAnnotations) { if (a.annotationType().equals(ObjectInfo.class)) { objectInfo = (ObjectInfo) a; break; } } if (addObject) { ObjectEntry oEntry = new ObjectEntry(o); if (objID != null) { objects.addWithID(oEntry, objID); } else { objects.add(oEntry); objID = oEntry.getID(); } } boolean hasCustomReferenceMethod = false; // we need special treatment for proxy objects if (o instanceof ProxyObject) { ProxyObject proxy = (ProxyObject) o; result = proxy.getObjectDescription(); result.setName(o.getClass().getName()); result.setID(objID); // update objID of methods for (MethodDescription mDesc : result.getMethods()) { mDesc.setObjectID(objID); } } else { result = new ObjectDescription(); result.setInfo(objectInfo); result.setName(o.getClass().getName()); result.setID(objID); Class<?> c = o.getClass(); Method[] theMethods = null; if (objectInfo != null && objectInfo.showInheritedMethods()) { theMethods = c.getMethods(); } else { ArrayList<Method> methods = new ArrayList<Method>(); // methods declared by class c for (Method m : c.getDeclaredMethods()) { methods.add(m); } // methods declared in superclasses of c for (Method m : c.getMethods()) { MethodInfo info = m.getAnnotation(MethodInfo.class); // if m is marked as inheritGUI this method will // be visualized even if it is a method declared // in a superclass of c if (info != null && info.inheritGUI()) { if (!methods.contains(m)) { methods.add(m); } } } Method[] tmpArray = new Method[methods.size()]; theMethods = methods.toArray(tmpArray); } for (int i = 0; i < theMethods.length; i++) { // filter groovy object specific methods String method = theMethods[i].getName(); boolean isGroovyObject = o instanceof GroovyObject; boolean isGroovyMethod = method.equals("setProperty") || method.equals("getProperty") || method.equals("invokeMethod") || method.equals("getMetaClass") || method.equals("setMetaClass"); // || // // the following methods are only present // // for Groovy >= 1.6 // method.equals("super$1$wait") || // method.equals("super$1$toString") || // method.equals("super$1$notify") || // method.equals("super$1$notifyAll") || // method.equals("super$1$getClass") || // method.equals("super$1$equals") || // method.equals("super$1$clone") || // method.equals("super$1$hashCode") || // method.equals("super$1$finalize"); // For Groovy >= 1.6 private methods have $ sign in their // name, e.g., // private doSomething() // will be changed to // this$2$doSomething() // which is unfortunately accessible and thus will be // visualized by vrl. // To prevent groovys strange behavior // methods with $ sign are ignored and treated as private. boolean isPrivateGroovyMethod = method.contains("$"); // TODO improve that code! if ((isGroovyObject && isGroovyMethod) || isPrivateGroovyMethod) { continue; } Class[] parameterTypes = theMethods[i].getParameterTypes(); Annotation[][] allParameterAnnotations = theMethods[i].getParameterAnnotations(); ArrayList<String> paramNames = new ArrayList<String>(); ArrayList<ParamInfo> paramAnnotations = new ArrayList<ParamInfo>(); ArrayList<ParamGroupInfo> paramGroupAnnotations = new ArrayList<ParamGroupInfo>(); // retrieving annotation information for each parameter for (int j = 0; j < allParameterAnnotations.length; j++) { Annotation[] annotations = allParameterAnnotations[j]; // add name element and set it to null // because we don't know if parameter j is annotated paramNames.add(null); paramAnnotations.add(null); paramGroupAnnotations.add(null); // check all annotations of parameter j // if we have a ParamInfo annotation retrieve data // and store it as element of paramName for (Annotation a : annotations) { if (a.annotationType().equals(ParamInfo.class)) { ParamInfo n = (ParamInfo) a; if (!n.name().equals("")) { paramNames.set(j, n.name()); } paramAnnotations.set(j, n); } else { if (a.annotationType().equals(ParamGroupInfo.class)) { ParamGroupInfo n = (ParamGroupInfo) a; paramGroupAnnotations.set(j, n); } } } // end for a } // end for j // convert list to array String[] parameterNames = paramNames.toArray(new String[paramNames.size()]); ParamInfo[] parameterAnnotations = paramAnnotations.toArray(new ParamInfo[paramAnnotations.size()]); ParamGroupInfo[] parameterGroupAnnotations = paramGroupAnnotations.toArray(new ParamGroupInfo[paramGroupAnnotations.size()]); Class returnType = theMethods[i].getReturnType(); String methodString = theMethods[i].getName(); String methodTitle = ""; String returnValueName = null; int modifiers = theMethods[i].getModifiers(); String modifierString = Modifier.toString(modifiers); // Method Annotations Annotation[] annotations = theMethods[i].getAnnotations(); MethodInfo methodInfo = null; OutputInfo outputInfo = null; boolean interactive = true; boolean hide = false; for (Annotation a : annotations) { if (a.annotationType().equals(MethodInfo.class)) { MethodInfo n = (MethodInfo) a; methodTitle = n.name(); interactive = n.interactive(); hide = n.hide(); returnValueName = n.valueName(); methodInfo = n; } if (a.annotationType().equals(OutputInfo.class)) { outputInfo = (OutputInfo) a; } } if (theMethods[i].getAnnotation(ReferenceMethodInfo.class) != null) { hasCustomReferenceMethod = true; MethodDescription customReferenceMethod = new MethodDescription( objID, 0, methodString, methodTitle, null, parameterTypes, parameterNames, parameterAnnotations, parameterGroupAnnotations, returnType, returnValueName, interactive, methodInfo, outputInfo); if (customReferenceMethod.getParameterTypes() == null || customReferenceMethod.getParameterTypes().length != 1) { throw new IllegalArgumentException( " Cannot to use " + "\"" + methodString + "\" as reference method" + " because the number of parameters does not" + " match. Exactly one parameter must be" + " provided."); } if (customReferenceMethod.getReturnType() == void.class || customReferenceMethod.getReturnType().isPrimitive()) { throw new IllegalArgumentException( " Cannot to use " + "\"" + methodString + "\" as reference method" + " because it does not return an object." + " Returning primitives or void is not" + " allowed."); } customReferenceMethod.setMethodType(MethodType.CUSTOM_REFERENCE); result.addMethod(customReferenceMethod); } // // TODO: at the moment method id is always 0 and will only be // set from corresponding method representations // // is it necessary to change that? else if (modifierString.contains("public") && (methodInfo == null || !methodInfo.ignore())) { result.addMethod( new MethodDescription( objID, 0, methodString, methodTitle, null, parameterTypes, parameterNames, parameterAnnotations, parameterGroupAnnotations, returnType, returnValueName, interactive, methodInfo, outputInfo)); } } // end for i // Object name if (objectInfo != null && !objectInfo.name().equals("")) { result.setName(objectInfo.name()); } } // end else if (o instanceof ProxyObject) if (!hasCustomReferenceMethod) { result.addMethod(MethodDescription.createReferenceMethod(objID, o.getClass())); } return result; }
public String getPid() { return baseObject.getPid(); }
private void setPanel(List<ObjectInfo> tar) { this.targetObject = tar; columnWidth = new HashMap<Integer, Integer>(); rowLength = new HashMap<Integer, Integer>(); cellpanel.clear(); for (int i = 0; i < tar.size(); i++) { ObjectInfo oin = tar.get(i); if ((oin.isLinked() == true || oin.hasLink() == true) && oin.set == true) { if (!mode) { cellpanel.put(oin, new CellPanel(oin)); } else { } Integer length = rowLength.get(oin.getPy()); Integer width = columnWidth.get(oin.getPx()); if (length == null || cellpanel.get(oin).getPreferredSize().height > length) { rowLength.put( new Integer(oin.getPy()), new Integer(cellpanel.get(oin).getPreferredSize().height)); } if (width == null || cellpanel.get(oin).getPreferredSize().width > width) { columnWidth.put( new Integer(oin.getPx()), new Integer(cellpanel.get(oin).getPreferredSize().width)); } } } for (Iterator<Entry<ObjectInfo, CellPanel>> it = cellpanel.entrySet().iterator(); it.hasNext(); ) { Entry<ObjectInfo, CellPanel> entry = it.next(); ObjectInfo object = entry.getKey(); CellPanel panel = entry.getValue(); try { if (panel != null) { /*int px = 0; int py = 0; for(int i = 0; i < object.getPx(); i++){ px += rowLength.get(i); } for(int i = 0; i < object.getPy(); i++){ py += columnWidth.get(i); } if(panel.getCellLength() > cellLength /2){ panel.setBounds(object.getPx() * (columnWidth.get(object.getPx())+ 40) + 25 , object.getPy() * (rowLength.get(object.getPy())+ 40) + 20, panel.getMaximumSize().width,panel.getMaximumSize().height ); }else{ panel.setBounds(object.getPx() * (columnWidth.get(object.getPx())+ 40) + 25 , object.getPy() * (rowLength.get(object.getPy())+ 40) +(rowLength.get(object.getPy()) /2) - panel.getCellLength()/2, panel.getMaximumSize().width,panel.getMaximumSize().height ); } add(panel, JLayeredPane.DEFAULT_LAYER);*/ if (panel != null) { int px = 0; int py = 0; for (int i = 0; i < object.getPy(); i++) { if (rowLength.get(i) != null) { py += rowLength.get(i); } py += 60; } for (int i = 0; i < object.getPx(); i++) { if (columnWidth.get(i) != null) { px += columnWidth.get(i); } px += 60; } panel.setBounds( px + 25, py + 40, panel.getMaximumSize().width, panel.getMaximumSize().height); add(panel, JLayeredPane.DEFAULT_LAYER); } } } catch (Exception e) { e.printStackTrace(); } } }